/*
  ==============================================================================

    ModulationSection.h
    Created: 24 Jul 2026
    Author:  Armin

  ==============================================================================
*/

#pragma once
#include <JuceHeader.h>

#include "../PluginProcessor.h"
#include "../PluginParameters.h"
#include "../Utilities/ComponentUtils.h"
#include "../Components/Buttons.h"

/** The modulation section: filter, LFO, phaser, and ring mod controls. */
class ModulationSection final : public CustomComponent
{
public:
    explicit ModulationSection(JustaSampleAudioProcessor& processor);

private:
    void paint(juce::Graphics& g) override;
    void resized() override;
    void lookAndFeelChanged() override;

    void enablementChanged() override;

    void mouseDown(const juce::MouseEvent& event) override;
    void mouseUp(const juce::MouseEvent& event) override;
    void mouseDrag(const juce::MouseEvent& event) override;

    float scale(float value) const { return std::roundf(value * float(getWidth()) / float(Layout::figmaWidth)); }
    float scalef(float value) const { return value * float(getWidth()) / float(Layout::figmaWidth); }

    //==============================================================================
    APVTS& apvts;

    // Section labels
    juce::Label filterLabel, lfoLabel, phaserLabel, ringModLabel;

    // Filter controls
    juce::ComboBox filterTypeBox;
    APVTS::ComboBoxAttachment filterTypeAttachment;
    CustomRotary filterCutoff, filterResonance;
    CustomRotaryAttachment filterCutoffAttachment, filterResonanceAttachment;

    // LFO controls
    juce::ComboBox lfoWaveformBox;
    APVTS::ComboBoxAttachment lfoWaveformAttachment;
    CustomRotary lfoRate;
    CustomRotaryAttachment lfoRateAttachment;
    CustomToggleableButton lfoSyncButton;
    APVTS::ButtonAttachment lfoSyncAttachment;
    juce::ComboBox lfoSyncDivBox;
    APVTS::ComboBoxAttachment lfoSyncDivAttachment;
    CustomRotary lfoFilterDepth, lfoSpeedDepth;
    CustomRotaryAttachment lfoFilterDepthAttachment, lfoSpeedDepthAttachment;

    // Phaser controls
    juce::ToggleButton phaserEnabled;
    APVTS::ButtonAttachment phaserEnabledAttachment;
    CustomRotary phaserDepth, phaserFeedback, phaserStages;
    CustomRotaryAttachment phaserDepthAttachment, phaserFeedbackAttachment;
    CustomRotaryAttachment phaserStagesAttachment;

    // Ring mod controls
    juce::ToggleButton ringModEnabled;
    APVTS::ButtonAttachment ringModEnabledAttachment;
    CustomRotary ringModMix;
    CustomRotaryAttachment ringModMixAttachment;

    // Track all rotaries for mouse forwarding
    juce::Array<CustomRotary*> rotaries;

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ModulationSection)
};
