// 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 "left_control_panel.hpp"
#include "right_control_panel.hpp"
#include "match_control_panel.hpp"
#include "side_loudness_display_panel.hpp"

namespace zlpanel {
    class ControlPanel final : public juce::Component,
                               private juce::ValueTree::Listener {
    public:
        explicit ControlPanel(PluginProcessor& p, zlgui::UIBase& base,
                              MatchFFTPanel& match_fft_panel,
                              const multilingual::TooltipHelper& tooltip_helper);

        ~ControlPanel() override;

        int getIdealWidth() const;

        int getIdealHeight() const;

        void resized() override;

        void repaintCallBack();

        void repaintCallBackSlow();

        void updateBand();

        void updateSampleRate(double sample_rate);

    private:
        PluginProcessor& p_ref_;
        zlgui::UIBase& base_;

        juce::Component mouse_event_eater_;
        LeftControlPanel left_control_panel_;
        RightControlPanel right_control_panel_;
        SideLoudnessDisplayPanel side_loudness_display_panel_;
        MatchControlPanel match_control_panel_;

        std::atomic<float>* dynamic_on_ptr_{nullptr};
        bool c_dynamic_on_{false};

        juce::Rectangle<int> mouse_center_bound_{};
        juce::Rectangle<int> mouse_full_bound_{};
        juce::Rectangle<int> left_bound_{};
        juce::Rectangle<int> center_bound_{};

        void changeLeftRightBound(bool dynamic_on);

        void valueTreePropertyChanged(juce::ValueTree&, const juce::Identifier& property) override;
    };
}
