// TextComponent.h
#pragma once

#include "Component.h"
#include <string>
#include <yaml-cpp/yaml.h>
#include "../core/types/all.h"
#include "../core/utils/AssetManager.h"

class TextComponent : public Component
{
public:
    enum class HorizontalAlign
    {
        Left,
        Center,
        Right
    };
    enum class VerticalAlign
    {
        Top,
        Middle,
        Bottom
    };

    TextComponent(Object *owner);
    virtual ~TextComponent() = default;

    std::string GetName() const override { return "TextComponent"; }

    // --- content ---
    void SetText(const std::string &text);
    const std::string &GetText() const;

    // --- font by UAID only ---
    void SetFontUAID(uint64_t fontUAID);
    uint64_t GetFontUAID() const;
    const FontAssetInfo *GetFontAsset() const;

    // --- styling ---
    void SetFontSize(float size);
    float GetFontSize() const;

    void SetColor(const core::types::Color &color);
    const core::types::Color &GetColor() const;

    void SetWrapWidth(float width);
    float GetWrapWidth() const;

    void SetAlignment(HorizontalAlign h, VerticalAlign v);
    void GetAlignment(HorizontalAlign &h, VerticalAlign &v) const;

    void EnableShadow(const core::types::Vec2 &offset, const core::types::Color &color);
    void DisableShadow();

    void EnableOutline(float thickness, const core::types::Color &color);
    void DisableOutline();

    // --- shadow getters ---
    bool IsShadowEnabled() const { return m_shadowEnabled; }
    const core::types::Vec2 &GetShadowOffset() const { return m_shadowOffset; }
    const core::types::Color &GetShadowColor() const { return m_shadowColor; }

    // --- outline getters ---
    bool IsOutlineEnabled() const { return m_outlineEnabled; }
    float GetOutlineThickness() const { return m_outlineThickness; }
    const core::types::Color &GetOutlineColor() const { return m_outlineColor; }

    // --- serialization ---
    virtual void Save(YAML::Emitter &out) const override;
    virtual void Load(const YAML::Node &node) override;

private:
    std::string m_text;

    uint64_t m_fontUAID = 0;
    float m_fontSize = 16.f;
    core::types::Color m_color = core::types::Color::White();

    float m_wrapWidth = 0.f;
    HorizontalAlign m_hAlign = HorizontalAlign::Left;
    VerticalAlign m_vAlign = VerticalAlign::Top;

    bool m_shadowEnabled = false;
    core::types::Vec2 m_shadowOffset = {2.f, -2.f};
    core::types::Color m_shadowColor = core::types::Color::Black(0.5f);

    bool m_outlineEnabled = false;
    float m_outlineThickness = 1.f;
    core::types::Color m_outlineColor = core::types::Color::Black();
};
