// PRE-GENERATED (design session). Effects window — edits shared EffectsConfig, re-applies live.
using System;
using System.Windows;
using System.Windows.Controls;
using DansoriEQ.Core.Eq;

namespace DansoriEQ.App;

public partial class EffectsWindow : Wpf.Ui.Controls.FluentWindow
{
    private readonly EffectsConfig _fx;
    private readonly Action _onChanged;
    private bool _loading;

    public EffectsWindow(EffectsConfig fx, Action onChanged)
    {
        InitializeComponent();
        _fx = fx;
        _onChanged = onChanged;

        _loading = true;
        SldCrossfeed.Value = fx.CrossfeedLevel;
        SldBass.Value = fx.BassBoostDb;
        SldLeft.Value = fx.PreampLeftDb;
        SldRight.Value = fx.PreampRightDb;
        _loading = false;
        UpdateLabels();
    }

    private void Slider_Changed(object sender, RoutedPropertyChangedEventArgs<double> e)
    {
        if (_loading) return;
        _fx.CrossfeedLevel = SldCrossfeed.Value;
        _fx.BassBoostDb = SldBass.Value;
        _fx.PreampLeftDb = SldLeft.Value;
        _fx.PreampRightDb = SldRight.Value;
        UpdateLabels();
        _onChanged();
    }

    private void UpdateLabels()
    {
        TxtCross.Text = $"{SldCrossfeed.Value:0} %";
        TxtBass.Text = $"{SldBass.Value:0.0} dB";
        TxtLeft.Text = $"{SldLeft.Value:0.0} dB";
        TxtRight.Text = $"{SldRight.Value:0.0} dB";
    }

    private void Close_Click(object sender, RoutedEventArgs e) => Close();
}
