<Window x:Class="ServerManagerTool.Plugin.Discord.Windows.ConfigProfileWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:pc="clr-namespace:ServerManagerTool.Plugin.Common;assembly=ServerManager.Plugin.Common"
        Name="ConfigProfileUI" Title="{DynamicResource ConfigProfileWindow_Title}"
        Icon="/ServerManager.Plugin.Discord;component/Art/favicon.ico"
        Width="640" Height="520" MinWidth="640" MinHeight="480" ResizeMode="CanResizeWithGrip" WindowStyle="ToolWindow" WindowStartupLocation="CenterOwner" ShowInTaskbar="False" 
        Closing="ConfigProfileWindow_Closing">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/ServerManager.Plugin.Discord;component/Globalization/en-US/en-US.xaml"/>
            </ResourceDictionary.MergedDictionaries>

            <SolidColorBrush x:Key="BeigeBorder" Color="#FFD8CCBC"/>
            <LinearGradientBrush x:Key="BeigeGradient" EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FFECE1D4" Offset="1"/>
                <GradientStop Color="#FFEAE8E6"/>
            </LinearGradientBrush>

            <Style x:Key="GroupBoxStyle" TargetType="GroupBox" BasedOn="{StaticResource {x:Type GroupBox}}">
                <Setter Property="BorderBrush" Value="{StaticResource BeigeBorder}"/>
                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                <Setter Property="Background" Value="Transparent"/>
            </Style>
        </ResourceDictionary>
    </Window.Resources>
    
    <Grid Background="{StaticResource BeigeGradient}">
        <Grid.RowDefinitions>
            <RowDefinition/>
        </Grid.RowDefinitions>

        <DockPanel Margin="5" ScrollViewer.VerticalScrollBarVisibility="Auto">
            <Grid DockPanel.Dock="Top">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" MinWidth="100"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>

                <Label    Grid.Row="0" Grid.Column="0" Content="{DynamicResource ConfigProfileWindow_NameLabel}" ToolTip="{DynamicResource ConfigProfileWindow_NameTooltip}"/>
                <TextBox  Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" Margin="1" Text="{Binding Profile.Name}" ToolTip="{DynamicResource ConfigProfileWindow_NameTooltip}" VerticalContentAlignment="Center" />
                <CheckBox Grid.Row="0" Grid.Column="3" Margin="5,2,5,2" Content="{DynamicResource ConfigProfileWindow_IsEnabledLabel}" IsChecked="{Binding Profile.IsEnabled}" ToolTip="{DynamicResource ConfigProfileWindow_IsEnabledTooltip}" VerticalAlignment="Center" HorizontalAlignment="Left"/>

                <Label    Grid.Row="1" Grid.Column="0" Content="{DynamicResource ConfigProfileWindow_WebhookLabel}" ToolTip="{DynamicResource ConfigProfileWindow_WebhookTooltip}"/>
                <TextBox  Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="1" Text="{Binding Profile.DiscordWebhookUrl}" ToolTip="{DynamicResource ConfigProfileWindow_WebhookTooltip}" VerticalContentAlignment="Center" />

                <Label    Grid.Row="2" Grid.Column="0" Content="{DynamicResource ConfigProfileWindow_BotNameLabel}" ToolTip="{DynamicResource ConfigProfileWindow_BotNameTooltip}"/>
                <TextBox  Grid.Row="2" Grid.Column="1" Margin="1" Text="{Binding Profile.DiscordBotName}" ToolTip="{DynamicResource ConfigProfileWindow_BotNameTooltip}" VerticalContentAlignment="Center" />
            </Grid>

            <GroupBox DockPanel.Dock="Top" HorizontalAlignment="Stretch" Style="{StaticResource GroupBoxStyle}">
                <GroupBox.Header>
                    <StackPanel Orientation="Horizontal">
                        <Label Content="{DynamicResource ConfigProfileWindow_MessageOptionsLabel}"/>
                    </StackPanel>
                </GroupBox.Header>

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>

                    <CheckBox Grid.Row="0" Grid.Column="0" Margin="0,2,20,2" Content="{DynamicResource ConfigProfileWindow_PrefixMessageWithProfileNameLabel}" IsChecked="{Binding Profile.PrefixMessageWithProfileName}" ToolTip="{DynamicResource ConfigProfileWindow_PrefixMessageWithProfileNameTooltip}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
                    <CheckBox Grid.Row="0" Grid.Column="1" Margin="10,2,20,2" Content="{DynamicResource ConfigProfileWindow_UseTTSLabel}" IsChecked="{Binding Profile.DiscordUseTTS}" ToolTip="{DynamicResource ConfigProfileWindow_UseTTSTooltip}" VerticalAlignment="Center" HorizontalAlignment="Left"/>

                    <CheckBox Grid.Row="1" Grid.Column="0" Margin="0,2,20,2" Content="{DynamicResource ConfigProfileWindow_MessageOptionsBoldLabel}" IsChecked="{Binding Profile.MessageBold}" ToolTip="{DynamicResource ConfigProfileWindow_MessageOptionsBoldTooltip}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
                    <CheckBox Grid.Row="1" Grid.Column="1" Margin="10,2,20,2" Content="{DynamicResource ConfigProfileWindow_MessageOptionsUnderlineLabel}" IsChecked="{Binding Profile.MessageUnderlined}" ToolTip="{DynamicResource ConfigProfileWindow_MessageOptionsUnderlineTooltip}" VerticalAlignment="Center" HorizontalAlignment="Left"/>

                    <CheckBox Grid.Row="2" Grid.Column="0" Margin="0,2,20,2" Content="{DynamicResource ConfigProfileWindow_MessageOptionsItalicLabel}" IsChecked="{Binding Profile.MessageItalic}" ToolTip="{DynamicResource ConfigProfileWindow_MessageOptionsItalicTooltip}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
                    <CheckBox Grid.Row="2" Grid.Column="1" Margin="10,2,20,2" Content="{DynamicResource ConfigProfileWindow_MessageOptionsCodeBlockLabel}" IsChecked="{Binding Profile.MessageCodeBlock}" ToolTip="{DynamicResource ConfigProfileWindow_MessageOptionsCodeBlockTooltip}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
                </Grid>
            </GroupBox>

            <Grid DockPanel.Dock="Bottom" Margin="0,0,10,0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                
                <Button Grid.Column="0" Content="{DynamicResource ConfigProfileWindow_TestButtonLabel}" Margin="5" MinWidth="75" Click="Test_Click"/>
                <Button Grid.Column="2" Content="{DynamicResource Global_OkButtonLabel}" Margin="5" MinWidth="75" HorizontalAlignment="Right" Click="Ok_Click"/>
                <Button Grid.Column="3" Content="{DynamicResource Global_CancelButtonLabel}" Margin="5" MinWidth="75" HorizontalAlignment="Left" IsCancel="True"/>
            </Grid>

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition Width="10"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>

                <GroupBox Grid.Row="1" Grid.Column="0" HorizontalAlignment="Stretch" Style="{StaticResource GroupBoxStyle}">
                    <GroupBox.Header>
                        <StackPanel Orientation="Horizontal">
                            <Label Content="{DynamicResource ConfigProfileWindow_ProfileNamesLabel}"/>
                            <Button Width="22" Height="22" Click="AddProfileName_Click" Margin="20,0,0,0" ToolTip="{DynamicResource ConfigProfileWindow_AddProfileNameTooltip}">
                                <Image Source="{pc:Icon Path=/ServerManager.Plugin.Discord;component/Art/Add.ico,Size=32}" />
                            </Button>
                            <Button Width="22" Height="22" Click="ClearProfileNames_Click" Margin="10,0,0,0" ToolTip="{DynamicResource ConfigProfileWindow_ClearProfileNamesTooltip}">
                                <Image Source="{pc:Icon Path=/ServerManager.Plugin.Discord;component/Art/Delete.ico,Size=32}" />
                            </Button>
                        </StackPanel>
                    </GroupBox.Header>

                    <DataGrid ItemsSource="{Binding Profile.ProfileNames}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserSortColumns="False" SelectionMode="Single" CanUserResizeColumns="False" CanUserResizeRows="False" RowHeaderWidth="25">
                        <DataGrid.Resources>
                            <Style TargetType="{x:Type DataGridRow}">
                                <Style.Resources>
                                    <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{x:Static SystemColors.HighlightColor}"/>
                                    <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="{x:Static SystemColors.HighlightTextColor}"/>
                                </Style.Resources>
                            </Style>
                        </DataGrid.Resources>

                        <DataGrid.HorizontalGridLinesBrush>
                            <SolidColorBrush Color="#FFB4B4B4"/>
                        </DataGrid.HorizontalGridLinesBrush>
                        <DataGrid.VerticalGridLinesBrush>
                            <SolidColorBrush Color="#FFB4B4B4"/>
                        </DataGrid.VerticalGridLinesBrush>

                        <DataGrid.Columns>
                            <DataGridTemplateColumn Width="*">
                                <DataGridTemplateColumn.Header>
                                    <TextBlock Text="{DynamicResource ConfigProfileWindow_ProfileNameColumnLabel}" />
                                </DataGridTemplateColumn.Header>
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <ComboBox IsEditable="True" ItemsSource="{Binding ProfileList, ElementName=ConfigProfileUI}" SelectedValue="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=Explicit}" SelectedValuePath="ValueMember" DisplayMemberPath="DisplayMember" GotFocus="ComboBox_GotFocus" LostFocus="ComboBox_LostFocus" PreviewMouseWheel="ComboBox_PreviewMouseWheel"/>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                            
                            <DataGridTemplateColumn Width="30" IsReadOnly="True">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Button Width="22" Height="22" Margin="0" IsTabStop="False" HorizontalAlignment="Center" VerticalAlignment="Center" Click="DeleteProfileName_Click" ToolTip="{DynamicResource ConfigProfileWindow_DeleteProfileNameTooltip}">
                                            <Image Source="{pc:Icon Path=/ServerManager.Plugin.Discord;component/Art/Delete.ico,Size=32}" />
                                        </Button>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                        </DataGrid.Columns>
                    </DataGrid>
                </GroupBox>
                
                <GroupBox Grid.Row="1" Grid.Column="2" HorizontalAlignment="Stretch" Style="{StaticResource GroupBoxStyle}">
                    <GroupBox.Header>
                        <StackPanel Orientation="Horizontal">
                            <Label Content="{DynamicResource ConfigProfileWindow_AlertTypesLabel}"/>
                            <Button Width="22" Height="22" Click="AddAlertType_Click" Margin="20,0,0,0" ToolTip="{DynamicResource ConfigProfileWindow_AddAlertTypeTooltip}">
                                <Image Source="{pc:Icon Path=/ServerManager.Plugin.Discord;component/Art/Add.ico,Size=32}" />
                            </Button>
                            <Button Width="22" Height="22" Click="ClearAlertTypes_Click" Margin="10,0,0,0" ToolTip="{DynamicResource ConfigProfileWindow_ClearAlertTypesTooltip}">
                                <Image Source="{pc:Icon Path=/ServerManager.Plugin.Discord;component/Art/Delete.ico,Size=32}" />
                            </Button>
                        </StackPanel>

                    </GroupBox.Header>

                    <DataGrid ItemsSource="{Binding Profile.AlertTypes}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserSortColumns="False" SelectionMode="Single" CanUserResizeColumns="False" CanUserResizeRows="False" RowHeaderWidth="25">
                        <DataGrid.Resources>
                            <Style TargetType="{x:Type DataGridRow}">
                                <Style.Resources>
                                    <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{x:Static SystemColors.HighlightColor}"/>
                                    <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="{x:Static SystemColors.HighlightTextColor}"/>
                                </Style.Resources>
                            </Style>
                        </DataGrid.Resources>

                        <DataGrid.HorizontalGridLinesBrush>
                            <SolidColorBrush Color="#FFB4B4B4"/>
                        </DataGrid.HorizontalGridLinesBrush>
                        <DataGrid.VerticalGridLinesBrush>
                            <SolidColorBrush Color="#FFB4B4B4"/>
                        </DataGrid.VerticalGridLinesBrush>

                        <DataGrid.Columns>
                            <DataGridTemplateColumn Width="*">
                                <DataGridTemplateColumn.Header>
                                    <TextBlock Text="{DynamicResource ConfigProfileWindow_AlertTypeColumnLabel}"/>
                                </DataGridTemplateColumn.Header>
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <ComboBox IsEditable="False" ItemsSource="{Binding AlertTypeList, ElementName=ConfigProfileUI}" SelectedValue="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" SelectedValuePath="ValueMember" DisplayMemberPath="DisplayMember" PreviewMouseWheel="ComboBox_PreviewMouseWheel"/>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                            
                            <DataGridTemplateColumn Width="30" IsReadOnly="True">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Button Width="22" Height="22" Margin="0" IsTabStop="False" HorizontalAlignment="Center" VerticalAlignment="Center" Click="DeleteAlertType_Click" ToolTip="{DynamicResource ConfigProfileWindow_DeleteAlertTypeTooltip}">
                                            <Image Source="{pc:Icon Path=/ServerManager.Plugin.Discord;component/Art/Delete.ico,Size=32}" />
                                        </Button>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                        </DataGrid.Columns>
                    </DataGrid>
                </GroupBox>
            </Grid>
        </DockPanel>
    </Grid>
</Window>
