using Voicemeeter;

namespace HidSliders.Gui;

public class ChannelControlCollection
{
    public NumericUpDown ChannelSelector { get; }
    public TrackBar TrackBar { get; }
    public CheckBox BusA1Checkbox { get; }
    public CheckBox BusA2Checkbox { get; }
    public CheckBox BusA3Checkbox { get; }
    public CheckBox BusA4Checkbox { get; }
    public CheckBox BusA5Checkbox { get; }
    public CheckBox BusB1Checkbox { get; }
    public CheckBox BusB2Checkbox { get; }
    public CheckBox BusB3Checkbox { get; }
    public CheckBox SoloCheckBox { get; }
    public CheckBox MuteCheckBox { get; }
    public Label IndicatorLabel { get; }
    public int CurrentStrip => (int)ChannelSelector.Value;

    public ChannelControlCollection(NumericUpDown channelSelector, TrackBar trackBar, CheckBox busA1Checkbox, CheckBox busA2Checkbox, CheckBox busA3Checkbox, CheckBox busA4Checkbox, CheckBox busA5Checkbox, CheckBox busB1Checkbox, CheckBox busB2Checkbox, CheckBox busB3Checkbox, CheckBox soloCheckBox, CheckBox muteCheckBox, Label indicatorLabel)
    {
        ChannelSelector = channelSelector;
        TrackBar = trackBar;
        BusA1Checkbox = busA1Checkbox;
        BusA1Checkbox.Tag = VMBus.A1;
        BusA2Checkbox = busA2Checkbox;
        BusA2Checkbox.Tag = VMBus.A2;
        BusA3Checkbox = busA3Checkbox;
        BusA3Checkbox.Tag = VMBus.A3;
        BusA4Checkbox = busA4Checkbox;
        BusA4Checkbox.Tag = VMBus.A4;
        BusA5Checkbox = busA5Checkbox;
        BusA5Checkbox.Tag = VMBus.A5;
        BusB1Checkbox = busB1Checkbox;
        BusB1Checkbox.Tag = VMBus.B1;
        BusB2Checkbox = busB2Checkbox;
        BusB2Checkbox.Tag = VMBus.B2;
        BusB3Checkbox = busB3Checkbox;
        BusB3Checkbox.Tag = VMBus.B3;
        SoloCheckBox = soloCheckBox;
        MuteCheckBox = muteCheckBox;
        IndicatorLabel = indicatorLabel;
    }

    public void EnableBusses(RunVoicemeeterParam version)
    {
        BusA1Checkbox.Enabled = true;
        BusB1Checkbox.Enabled = true;

        if (version > RunVoicemeeterParam.Voicemeeter)
        {
            BusA2Checkbox.Enabled = true;
            BusA3Checkbox.Enabled = true;
            BusB2Checkbox.Enabled = true;
        }

        if (version > RunVoicemeeterParam.VoicemeeterBanana)
        {
            BusA4Checkbox.Enabled = true;
            BusA5Checkbox.Enabled = true;
            BusB3Checkbox.Enabled = true;
        }
    }

    public bool OwnsControl(Control control)
    {
        return control == ChannelSelector ||
               control == TrackBar ||
               control == BusA1Checkbox ||
               control == BusA2Checkbox ||
               control == BusA3Checkbox ||
               control == BusA4Checkbox ||
               control == BusA5Checkbox ||
               control == BusB1Checkbox ||
               control == BusB2Checkbox ||
               control == BusB3Checkbox ||
               control == SoloCheckBox ||
               control == MuteCheckBox;
    }
}