<Window x:Class="WPFBeginner.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        Title="{DynamicResource Main_Title}"
        Height="600" Width="900"
        MinWidth="700" MinHeight="400"
        WindowStartupLocation="CenterScreen"
        Background="{DynamicResource WindowBackgroundBrush}">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Top Bar -->
        <Border Grid.Row="0" Background="{DynamicResource SecondaryBrush}" Padding="15,10">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>

                <!-- Search Area -->
                <StackPanel Grid.Column="0" Orientation="Horizontal">
                    <TextBox Text="{Binding SearchKeyword, UpdateSourceTrigger=PropertyChanged}"
                             Style="{DynamicResource DefaultTextBoxStyle}"
                             Width="250"
                             VerticalAlignment="Center"
                             KeyDown="SearchTextBox_KeyDown"/>
                    <Button Content="{DynamicResource Main_Search}"
                            Style="{DynamicResource PrimaryButtonStyle}"
                            Command="{Binding SearchCommand}"
                            Margin="10,0,0,0"
                            Padding="20,8"/>
                </StackPanel>

                <!-- Action Buttons -->
                <StackPanel Grid.Column="1" Orientation="Horizontal">
                    <Button Content="{DynamicResource Main_Add}"
                            Style="{DynamicResource PrimaryButtonStyle}"
                            Command="{Binding AddMemberCommand}"
                            Margin="0,0,10,0"/>
                    <Button Content="{DynamicResource Main_Delete}"
                            Style="{DynamicResource SecondaryButtonStyle}"
                            Command="{Binding DeleteMemberCommand}"
                            Margin="0,0,10,0"/>
                    <Button Content="{DynamicResource Main_Reset}"
                            Style="{DynamicResource SecondaryButtonStyle}"
                            Command="{Binding ResetCommand}"
                            Margin="0,0,10,0"/>
                    <Button x:Name="SettingsButton"
                            Content="{DynamicResource Main_Settings}"
                            Style="{DynamicResource SecondaryButtonStyle}"
                            Click="SettingsButton_Click"/>
                </StackPanel>
            </Grid>
        </Border>

        <!-- Main Content -->
        <Grid Grid.Row="1">
            <!-- DataGrid -->
            <DataGrid ItemsSource="{Binding FilteredMembers}"
                      SelectedItem="{Binding SelectedMember}"
                      Style="{DynamicResource DefaultDataGridStyle}"
                      AutoGenerateColumns="False"
                      IsReadOnly="True"
                      SelectionMode="Single"
                      Margin="15">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="{DynamicResource Main_Column_Name}"
                                        Binding="{Binding Name}"
                                        Width="*"/>
                    <DataGridTextColumn Header="{DynamicResource Main_Column_Call}"
                                        Binding="{Binding Call}"
                                        Width="*"/>
                    <DataGridTextColumn Header="{DynamicResource Main_Column_Email}"
                                        Binding="{Binding EMail}"
                                        Width="2*"/>
                    <DataGridTextColumn Header="{DynamicResource Main_Column_No}"
                                        Binding="{Binding No}"
                                        Width="*"/>
                </DataGrid.Columns>
            </DataGrid>

            <!-- Settings Panel (Popup) -->
            <Popup x:Name="SettingsPopup"
                   Placement="Bottom"
                   PlacementTarget="{Binding ElementName=SettingsButton}"
                   StaysOpen="False"
                   AllowsTransparency="True">
                <Border Background="{DynamicResource SecondaryBrush}"
                        BorderBrush="{DynamicResource BorderBrush}"
                        BorderThickness="1"
                        CornerRadius="4"
                        Padding="15"
                        Margin="5">
                    <Border.Effect>
                        <DropShadowEffect BlurRadius="10" Opacity="0.3"/>
                    </Border.Effect>
                    <StackPanel Width="200">
                        <!-- Language Settings -->
                        <TextBlock Text="{DynamicResource Settings_Language}"
                                   Foreground="{DynamicResource TextBrush}"
                                   FontWeight="SemiBold"
                                   Margin="0,0,0,10"/>
                        <RadioButton Content="{DynamicResource Settings_Korean}"
                                     IsChecked="{Binding IsKorean}"
                                     Style="{DynamicResource DefaultRadioButtonStyle}"
                                     GroupName="Language"
                                     Command="{Binding SetKoreanCommand}"/>
                        <RadioButton Content="{DynamicResource Settings_English}"
                                     IsChecked="{Binding IsEnglish}"
                                     Style="{DynamicResource DefaultRadioButtonStyle}"
                                     GroupName="Language"
                                     Command="{Binding SetEnglishCommand}"/>

                        <Separator Margin="0,15" Background="{DynamicResource BorderBrush}"/>

                        <!-- Theme Settings -->
                        <TextBlock Text="{DynamicResource Settings_Theme}"
                                   Foreground="{DynamicResource TextBrush}"
                                   FontWeight="SemiBold"
                                   Margin="0,0,0,10"/>
                        <RadioButton Content="{DynamicResource Settings_DefaultTheme}"
                                     IsChecked="{Binding IsDefaultTheme}"
                                     Style="{DynamicResource DefaultRadioButtonStyle}"
                                     GroupName="Theme"
                                     Command="{Binding SetDefaultThemeCommand}"/>
                        <RadioButton Content="{DynamicResource Settings_LightTheme}"
                                     IsChecked="{Binding IsLightTheme}"
                                     Style="{DynamicResource DefaultRadioButtonStyle}"
                                     GroupName="Theme"
                                     Command="{Binding SetLightThemeCommand}"/>
                    </StackPanel>
                </Border>
            </Popup>
        </Grid>
    </Grid>
</Window>
