// Copyright (C) 2026 - zsliu98
// This file is part of ZLEqualizer
//
// ZLEqualizer is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License Version 3 as published by the Free Software Foundation.
//
// ZLEqualizer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License along with ZLEqualizer. If not, see <https://www.gnu.org/licenses/>.

#pragma once

#include <juce_gui_basics/juce_gui_basics.h>

#include "../interface_definitions.hpp"

namespace zlgui::label {
    class NameLookAndFeel final : public juce::LookAndFeel_V4 {
    public:
        explicit NameLookAndFeel(UIBase& base) :
            base_(base) {
        }

        void drawLabel(juce::Graphics& g, juce::Label& label) override {
            if (label.isBeingEdited()) {
                return;
            }
            g.setColour(base_.getTextColour());
            g.setFont(base_.getFontSize() * font_scale_);
            g.drawText(label.getText(), label.getLocalBounds().toFloat(), label.getJustificationType());
        }

        void drawTextEditorOutline(juce::Graphics& g, const int width, const int height,
                                   juce::TextEditor& textEditor) override {
            if (textEditor.isEnabled()) {
                const auto outline_thickness = juce::roundToInt(base_.getFontSize() * .2f);
                if (textEditor.hasKeyboardFocus(true) && !textEditor.isReadOnly()) {
                    g.setColour(textEditor.findColour(juce::TextEditor::focusedOutlineColourId));
                    g.drawRect(0, 0, width, height, outline_thickness);
                } else {
                    g.setColour(textEditor.findColour(juce::TextEditor::outlineColourId));
                    g.drawRect(0, 0, width, height, outline_thickness);
                }
            }
        }

        inline void setFontScale(const float x) { font_scale_ = x; }

    private:
        UIBase& base_;

        float font_scale_{kFontNormal};
    };
}
