#pragma once

#include "MaterialNode.h"

#include "FontItem.h"
#include "TextData.h"
#include "Bounds.h"
#include "SceneText.h"

#include <memory>
#include <string>

class FontsManager;
class SceneModel;

class TextNode : public MaterialNode
{
public:
    TextNode(const std::string& content, const Transform& transform);

    ~TextNode();

    static std::unique_ptr<TextNode> Create(const std::string& content, const Transform& transform);

    std::string getContent() const;
    std::string getFontLabel() const;

    SceneItem* getSceneItem(std::size_t idx) const override;
    std::size_t getNumSceneItems() const override;

    double getWidth() const;
    double getHeight() const;

    double getContentWidth(SceneInfo* sceneInfo);
    double getContentHeight(SceneInfo* sceneInfo);

    void setWidth(double width);
    void setHeight(double height);

    void setContent(const std::string& content);
    void setFont(const FontItem& font);

    void setRenderNodeBounds(bool render);
    void setRenderTextBounds(bool render);

    void update(SceneInfo* sceneInfo) override;
private:

    void updateLines(FontsManager* fontsManager);

    TextData mTextData;
    bool mContentIsDirty{true};
    bool mLinesAreDirty{true};

    double mWidth{1};
    double mHeight{1};

    double mContentWidth{ 1 };
    double mContentHeight{ 1 };

    std::unique_ptr<SceneText> mTextItem;

    bool mRenderNodeBounds{ false };
    bool mRenderTextBounds{ false };
    std::unique_ptr<SceneModel> mNodeBounds;
    std::unique_ptr<SceneModel> mTextBounds;
};

using TextNodetr = std::unique_ptr<TextNode>;
