// SPDX-FileCopyrightText: 2026 0064ff
// SPDX-License-Identifier: MIT-0

#pragma once
#include <JuceHeader.h>
#include "PluginProcessor.h"
#include "MyLookAndFeel.h"

//==============================================================================

class ChannelAudioProcessorEditor : public juce::AudioProcessorEditor,
                                    public juce::AudioProcessorValueTreeState::Listener,
                                    private juce::AsyncUpdater
{
public:
    //==============================================================================
    ChannelAudioProcessorEditor(ChannelAudioProcessor&);
    ~ChannelAudioProcessorEditor() override;

    //==============================================================================

    enum SliderType
    {
        None,
        Small,
        Medium,
        Large
    };

    //==============================================================================

    void paint(juce::Graphics&) override;
    void paintOverChildren(juce::Graphics&) override;
    //void resized() override;

    //==============================================================================

private:
    // reference for the editor to access the processor object that created it
    ChannelAudioProcessor& ap;

    //==============================================================================

    MyLookAndFeel lookAndFeel;

    //==============================================================================

    struct SliderStruct
    {
        std::unique_ptr<juce::Slider> strip;
        std::unique_ptr<juce::Label> label;
        std::unique_ptr<juce::Label> label2;
        juce::String labelText;
        juce::String parameterID;
        std::unique_ptr<juce::AudioProcessorValueTreeState::SliderAttachment> attachment;
    };

    SliderStruct fxLoopMix;
    SliderStruct fxLoopSendDB;
    SliderStruct fxLoopReturnDB;
    SliderStruct fxLoopPosition;

    SliderStruct width;
    SliderStruct pan;
    SliderStruct stereoOrder;

    SliderStruct hpFreq;
    SliderStruct hpQ;
    SliderStruct lpFreq;
    SliderStruct lpQ;

    SliderStruct eqFreq;
    SliderStruct eqQ;
    SliderStruct eqPeakDB;
    SliderStruct eqTiltDB;
    SliderStruct eqPosition;

    SliderStruct dynBandLink;
    SliderStruct dynStereoLink;
    SliderStruct dynDriveDB;
    SliderStruct dynThreshold;
    SliderStruct dynThreshold2;
    SliderStruct dynLowerThreshold;
    SliderStruct dynTransientTime;
    SliderStruct dynAttackTime;
    SliderStruct dynReleaseTime;
    SliderStruct dynSlew;
    SliderStruct dynCompensation;
    SliderStruct dynAdaptability;
    SliderStruct dynCrossover1;
    SliderStruct dynCrossover2;
    SliderStruct dynLowCompPower;
    SliderStruct dynHighCompPower;
    SliderStruct dynLowCompOffset;
    SliderStruct dynHighCompOffset;
    SliderStruct dynResponsePower;
    SliderStruct dynNegMix;
    SliderStruct dynRatio;
    SliderStruct dynVariMuMult;
    SliderStruct dynKneeDB;
    SliderStruct dynSmoothTime;
    SliderStruct dynSagTime;
    SliderStruct dynMakeupDB;
    SliderStruct dynMix;

//    SliderStruct dynTestValue1;
//    SliderStruct dynTestValue2;
//    SliderStruct dynTestValue3;

    SliderStruct filterAndDynByp;
    SliderStruct volumeLinear;
    SliderStruct outputDB;
    SliderStruct polarity;

    SliderStruct liveMode;

    //==============================================================================

    void buildLayout();

    void createSlider(SliderType sliderType, SliderStruct& slider,
                      juce::String parameterID, bool isBipolar=false,
                      bool newSection=false, bool newSubSection=false);

    void parameterChanged(juce::String const& parameterID, float newValue) override;
    void handleAsyncUpdate() override;

    void updateBuiltSliderLabels();
    void setSliderLabelText(SliderStruct* slider, juce::String labelText);
    void setColorPalette();

    //==============================================================================

    std::vector<SliderStruct*> builtSliders;
    std::atomic<bool> rebuildPending = false;

    int xpos=0, ypos=0, backgroundWidth=0;
    SliderType lastSliderType = SliderType::None;

    juce::Colour bgColor, textColor, textColorHighlighted, highlightColor;
    juce::Image noiseImage;

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChannelAudioProcessorEditor)
};
