<ui:FluentWindow x:Class="DansoriEQ.App.FilterEditWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
        xmlns:ctrl="clr-namespace:DansoriEQ.App.Controls"
        Title="EQ 밴드 편집" Height="620" Width="640"
        WindowStartupLocation="CenterOwner" ResizeMode="NoResize"
        ExtendsContentIntoTitleBar="True" WindowBackdropType="Mica"
        Background="#141418" Foreground="#F2F3F5"
        FontFamily="Segoe UI Variable, Segoe UI">

    <Window.Resources>
        <SolidColorBrush x:Key="Card"      Color="#1E1E24"/>
        <SolidColorBrush x:Key="CardLo"    Color="#26262E"/>
        <SolidColorBrush x:Key="Stroke"    Color="#3A3A46"/>
        <SolidColorBrush x:Key="TextDim"   Color="#A8ABB4"/>
        <SolidColorBrush x:Key="TextFg"    Color="#F2F3F5"/>
        <SolidColorBrush x:Key="Accent"    Color="#4CC2FF"/>
        <SolidColorBrush x:Key="AccentDk"  Color="#04222F"/>

        <!-- Editable value box (exact numeric entry, Peace-style) -->
        <Style x:Key="ValueBox" TargetType="TextBox">
            <Setter Property="Background" Value="#15151A"/>
            <Setter Property="Foreground" Value="{StaticResource Accent}"/>
            <Setter Property="BorderBrush" Value="{StaticResource Stroke}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Height" Value="30"/>
            <Setter Property="Width" Value="92"/>
            <Setter Property="Padding" Value="8,0"/>
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="FontWeight" Value="SemiBold"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="HorizontalContentAlignment" Value="Right"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="TextBox">
                        <Border Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="6">
                            <ScrollViewer x:Name="PART_ContentHost" Margin="{TemplateBinding Padding}"
                                          VerticalAlignment="Center"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!-- Pill RadioButton style for type selector -->
        <Style x:Key="PillRadio" TargetType="RadioButton">
            <Setter Property="Background" Value="#2A2A32"/>
            <Setter Property="Foreground" Value="{StaticResource TextDim}"/>
            <Setter Property="BorderBrush" Value="{StaticResource Stroke}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="FontSize" Value="12"/>
            <Setter Property="FontWeight" Value="SemiBold"/>
            <Setter Property="Margin" Value="0,0,6,0"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="RadioButton">
                        <Border x:Name="Bd"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="20" Padding="16,7">
                            <ContentPresenter HorizontalAlignment="Center"
                                              VerticalAlignment="Center"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter TargetName="Bd" Property="Background" Value="{StaticResource Accent}"/>
                                <Setter TargetName="Bd" Property="BorderBrush" Value="{StaticResource Accent}"/>
                                <Setter Property="Foreground" Value="{StaticResource AccentDk}"/>
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsMouseOver" Value="True"/>
                                    <Condition Property="IsChecked" Value="False"/>
                                </MultiTrigger.Conditions>
                                <Setter TargetName="Bd" Property="BorderBrush" Value="{StaticResource Accent}"/>
                                <Setter Property="Foreground" Value="{StaticResource TextFg}"/>
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!-- Action button base style -->
        <Style x:Key="ActionBtn" TargetType="Button">
            <Setter Property="Height" Value="38"/>
            <Setter Property="Width" Value="90"/>
            <Setter Property="FontSize" Value="13"/>
            <Setter Property="FontWeight" Value="SemiBold"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border x:Name="Bd"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="8">
                            <ContentPresenter HorizontalAlignment="Center"
                                              VerticalAlignment="Center"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="Bd" Property="Opacity" Value="0.85"/>
                            </Trigger>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter TargetName="Bd" Property="Opacity" Value="0.7"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <ui:TitleBar Grid.Row="0" Title="EQ 밴드 편집" Foreground="#F2F3F5" Padding="14,6"/>
        <Border Grid.Row="1" Style="{StaticResource NeonPopup}">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="44"/>     <!-- Title bar -->
            <RowDefinition Height="240"/>    <!-- EQ Graph (draws its own Hz/dB labels) -->
            <RowDefinition Height="0"/>      <!-- (reserved) -->
            <RowDefinition Height="*"/>      <!-- Controls -->
            <RowDefinition Height="58"/>     <!-- Buttons -->
        </Grid.RowDefinitions>

        <!-- ── Title bar ── -->
        <Border Grid.Row="0" Background="#141418"
                BorderBrush="{StaticResource Stroke}" BorderThickness="0,0,0,1">
            <Grid Margin="20,0">
                <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                    <TextBlock x:Name="BandLabel" Text="" FontSize="13" FontWeight="SemiBold"
                               Foreground="{StaticResource Accent}"
                               VerticalAlignment="Center"/>
                </StackPanel>
                <TextBlock Text="드래그로 이동  ·  휠로 Q 조절  ·  더블클릭으로 추가"
                           HorizontalAlignment="Right" VerticalAlignment="Center"
                           FontSize="10" Foreground="#5A5F6B"/>
            </Grid>
        </Border>

        <!-- ── EQ Graph ── -->
        <ctrl:EqGraphControl x:Name="Graph" Grid.Row="1"
                             Background="#0E0E12"/>

        <!-- ── Parameter controls ── -->
        <Border Grid.Row="3" Background="{StaticResource Card}"
                Margin="0" Padding="24,16,24,12">
            <StackPanel>

                <!-- Type + Enabled row -->
                <Grid Margin="0,0,0,14">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="40"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="타입" Grid.Column="0" FontSize="11"
                               Foreground="{StaticResource TextDim}" VerticalAlignment="Center"/>
                    <ComboBox x:Name="CmbType" Grid.Column="1" Height="34"
                              Background="#2D2D33" Foreground="#F2F3F5"
                              VerticalContentAlignment="Center"
                              SelectionChanged="CmbType_Changed"/>
                    <CheckBox x:Name="ChkEnabled" Grid.Column="2" Content="활성"
                              VerticalAlignment="Center" IsChecked="True" Margin="14,0,0,0"
                              Foreground="{StaticResource TextDim}" FontSize="12"
                              Click="ChkEnabled_Click"/>
                </Grid>

                <!-- Fc row -->
                <Grid Margin="0,0,0,12">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="56"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="주파수" Grid.Column="0" FontSize="11"
                               Foreground="{StaticResource TextDim}" VerticalAlignment="Center"/>
                    <Slider x:Name="SldFc" Grid.Column="1" Minimum="0" Maximum="1000"
                            Margin="4,0,10,0" VerticalAlignment="Center"
                            Foreground="{StaticResource Accent}" ValueChanged="SldFc_Changed"/>
                    <TextBox x:Name="TxtFc" Grid.Column="2" Style="{StaticResource ValueBox}"
                             LostFocus="TxtFc_Commit" KeyDown="Txt_KeyDown"/>
                </Grid>

                <!-- Gain row (hidden for types without gain) -->
                <Grid x:Name="GainRow" Margin="0,0,0,12">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="56"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="게인" Grid.Column="0" FontSize="11"
                               Foreground="{StaticResource TextDim}" VerticalAlignment="Center"/>
                    <Slider x:Name="SldGain" Grid.Column="1" Minimum="-12" Maximum="12"
                            Margin="4,0,10,0" VerticalAlignment="Center"
                            TickFrequency="0.1" Foreground="{StaticResource Accent}"
                            ValueChanged="SldGain_Changed"/>
                    <TextBox x:Name="TxtGain" Grid.Column="2" Style="{StaticResource ValueBox}"
                             LostFocus="TxtGain_Commit" KeyDown="Txt_KeyDown"/>
                </Grid>

                <!-- Third param row (Q / Slope / Order — label & range set in code) -->
                <Grid x:Name="ThirdRow" Margin="0,0,0,2">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="56"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock x:Name="ThirdName" Text="Q" Grid.Column="0" FontSize="11"
                               Foreground="{StaticResource TextDim}" VerticalAlignment="Center"/>
                    <Slider x:Name="SldThird" Grid.Column="1" Minimum="0" Maximum="1000"
                            Margin="4,0,10,0" VerticalAlignment="Center"
                            Foreground="{StaticResource Accent}" ValueChanged="SldThird_Changed"/>
                    <TextBox x:Name="TxtThird" Grid.Column="2" Style="{StaticResource ValueBox}"
                             LostFocus="TxtThird_Commit" KeyDown="Txt_KeyDown"/>
                </Grid>

            </StackPanel>
        </Border>

        <!-- ── Buttons ── -->
        <Border Grid.Row="4" Background="#141418"
                BorderBrush="{StaticResource Stroke}" BorderThickness="0,1,0,0">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"
                        VerticalAlignment="Center" Margin="0,0,20,0">
                <Button Content="취소" Style="{StaticResource ActionBtn}"
                        Background="{StaticResource CardLo}"
                        BorderBrush="{StaticResource Stroke}"
                        Foreground="{StaticResource TextDim}"
                        Margin="0,0,10,0" Click="BtnCancel_Click"/>
                <Button Content="적용" Style="{StaticResource ActionBtn}"
                        Background="{StaticResource Accent}"
                        BorderBrush="Transparent"
                        Foreground="{StaticResource AccentDk}"
                        Click="BtnApply_Click"/>
            </StackPanel>
        </Border>

    </Grid>
        </Border>
    </Grid>
</ui:FluentWindow>
