<Page x:Class="OpenGptChat.Views.Pages.ConfigPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:OpenGptChat.Views.Pages"
      xmlns:utils="clr-namespace:OpenGptChat.Utilities"
      mc:Ignorable="d" 
      d:DesignHeight="1000" d:DesignWidth="880" 
      d:Background="White" d:DataContext="{d:DesignInstance Type=local:ConfigPage}"
      Title="ConfigPage" Style="{DynamicResource AnimatedPageStyle}"
      FocusVisualStyle="{x:Null}">

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

        <Grid>
            <Border Padding="5" BorderThickness="0 0 0 1" BorderBrush="Gray">
                <Grid>
                    <TextBlock Text="{DynamicResource StrConfiguration}"  FontSize="{DynamicResource ExtremLargeFontSize}"/>
                    <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                        <StackPanel.Resources>
                            <Style TargetType="Border">
                                <Setter Property="CornerRadius" Value="3"/>
                            </Style>
                        </StackPanel.Resources>
                        <ToggleButton Content="📍" BorderThickness="0" Padding="3" Margin="0 0 3 0" ToolTip="{DynamicResource StrWindowAlwaysOnTop}"
                                      IsChecked="{Binding ConfigurationService.Configuration.WindowAlwaysOnTop}"/>
                        <Button Content="📄" BorderThickness="0" Padding="3" Margin="0 0 3 0" ToolTip="{DynamicResource StrAboutOpenGptChat}"
                                Command="{Binding AboutOpenChatCommand}"/>
                        <Button Content="🏠︎" BorderThickness="0" Padding="3" ToolTip="{DynamicResource StrGoBackToMainPage}"
                                Command="{Binding GoToMainPageCommand}"/>
                    </StackPanel>
                </Grid>
            </Border>
        </Grid>

        <ScrollViewer Grid.Row="1" Name="configurationScrollViewer">
            <StackPanel Margin="10" MaxWidth="600">
                <StackPanel Margin="0 5">
                    <TextBlock Margin="0 0 0 5">
                        <Run Text="{DynamicResource StrAPIKey}"/>
                        <Run Text=":"/>
                    </TextBlock>
                    <TextBox Padding="5 3" Text="{Binding ConfigurationService.Configuration.ApiKey}"/>
                </StackPanel>
                <StackPanel Margin="0 5">
                    <TextBlock Margin="0 0 0 5">
                        <Run Text="{DynamicResource StrAPIHost}"/>
                        <Run Text=":"/>
                    </TextBlock>
                    <TextBox Padding="5 3" Text="{Binding ConfigurationService.Configuration.ApiHost}"/>
                </StackPanel>
                <StackPanel Margin="0 5">
                    <TextBlock Margin="0 0 0 5">
                        <Run Text="{DynamicResource StrOrganization}"/>
                        <Run Text=":"/>
                    </TextBlock>
                    <TextBox Padding="5 3" Text="{Binding ConfigurationService.Configuration.Organization}"/>
                </StackPanel>
                <StackPanel Margin="0 5">
                    <TextBlock Margin="0 0 0 5">
                        <Run Text="{DynamicResource StrModel}"/>
                        <Run Text=":"/>
                    </TextBlock>
                    <TextBox Padding="5 3" Text="{Binding ConfigurationService.Configuration.Model}"/>
                </StackPanel>
                <StackPanel Margin="0 5">
                    <TextBlock Margin="0 0 0 5">
                        <Run Text="{DynamicResource StrAPITimeout}"/>
                        <Run Text=":"/>
                    </TextBlock>
                    <TextBox Padding="5 3" Text="{Binding ConfigurationService.Configuration.ApiTimeout}"/>
                </StackPanel>
                <StackPanel Margin="0 5">
                    <TextBlock Margin="0 0 0 5">
                        <Run Text="{DynamicResource StrTemperature}"/>
                        <Run Text=":"/>
                    </TextBlock>
                    <TextBox Padding="5 3" Text="{Binding ConfigurationService.Configuration.Temerature}"/>
                </StackPanel>

                <StackPanel Margin="0 5">
                    <Grid>
                        <TextBlock Margin="0 0 0 5">
                            <Run Text="{DynamicResource StrSystemMessages}"/>
                            <Run Text=":"/>
                        </TextBlock>

                        <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                            <Button Content=" - " BorderThickness="0" Padding="3 0"
                                    Command="{Binding RemoveSystemMessageCommand}" ToolTip="Remove a system message"/>
                            <Button Content=" + " BorderThickness="0" Margin="5 0 0 0" Padding="3 0"
                                    Command="{Binding AddSystemMessageCommand}" ToolTip="Add a system message"/>
                            <Button Content="{DynamicResource StrApply}" BorderThickness="0" Margin="5 0 0 0" Padding="3 0"
                                    Command="{Binding ApplySystemMessagesCommand}" ToolTip="Apply system messages"/>
                        </StackPanel>
                    </Grid>
                    <Border MinHeight="10"
                            BorderThickness="1" BorderBrush="{DynamicResource BoxBorder}" Padding="5">
                        <ItemsControl ItemsSource="{Binding ViewModel.SystemMessages}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <TextBox Padding="5 3" Margin="0 1"  Text="{Binding Value}" TextWrapping="Wrap" AcceptsReturn="True"/>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </Border>
                </StackPanel>

                <StackPanel Margin="0 30 0 5">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>

                        <TextBlock>
                            <Run Text="{DynamicResource StrEnableChatContext}"/>
                            <Run Text=":"/>
                        </TextBlock>
                        <CheckBox Grid.Column="1" VerticalAlignment="Center" IsChecked="{Binding ConfigurationService.Configuration.EnableChatContext}"/>
                    </Grid>
                </StackPanel>
                <StackPanel Margin="0 5 0 5">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock>
                            <Run Text="{DynamicResource StrEnableTitleGeneration}"/>
                            <Run Text=":"/>
                        </TextBlock>
                        <CheckBox Grid.Column="1" VerticalAlignment="Center" IsChecked="{Binding ConfigurationService.Configuration.EnableTitleGeneration}"/>
                    </Grid>
                </StackPanel>
                <StackPanel Margin="0 5 0 5">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock>
                            <Run Text="{DynamicResource StrWindowAlwaysOnTop}"/>
                            <Run Text=":"/>
                        </TextBlock>
                        <CheckBox Grid.Column="1" VerticalAlignment="Center" IsChecked="{Binding ConfigurationService.Configuration.WindowAlwaysOnTop}"/>
                    </Grid>
                </StackPanel>
                <StackPanel Margin="0 5 0 5">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock>
                            <Run Text="{DynamicResource StrDisableChatAnimation}"/>
                            <Run Text=":"/>
                        </TextBlock>
                        <CheckBox Grid.Column="1" VerticalAlignment="Center" IsChecked="{Binding ConfigurationService.Configuration.DisableChatAnimation}"/>
                    </Grid>
                </StackPanel>

                <StackPanel Margin="0 30 0 5">
                    <TextBlock>
                        <Run Text="{DynamicResource StrHotkeyTips}"/>
                        <Run Text=":"/>
                    </TextBlock>
                    <Grid Margin="5">
                        <Grid.Resources>
                            <Style TargetType="TextBlock">
                                <Setter Property="Margin" Value="0 5 0 0"/>
                            </Style>
                        </Grid.Resources>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        
                        <UniformGrid Grid.Column="0" Columns="1" Margin="0 0 20 0">
                            <TextBlock>Ctrl+H:</TextBlock>
                            <TextBlock>Ctrl+Shift+H:</TextBlock>
                            <TextBlock>Ctrl+Enter:</TextBlock>
                            <TextBlock>Ctrl+Shift+Enter:</TextBlock>
                            <TextBlock>Ctrl+R:</TextBlock>
                            <TextBlock>Ctrl+T/N:</TextBlock>
                            <TextBlock>Ctrl+W:</TextBlock>
                            <TextBlock>Ctrl+J:</TextBlock>
                            <TextBlock>Ctrl+K:</TextBlock>
                            <TextBlock>Ctrl+Tab:</TextBlock>
                            <TextBlock>Ctrl+Shift+Tab:</TextBlock>
                        </UniformGrid>
                        <UniformGrid Grid.Column="1" Columns="1">
                            <TextBlock>
                                <Run Text="{DynamicResource StrHideApplication}"/>
                            </TextBlock>
                            <TextBlock>
                                <Run Text="{DynamicResource StrShowApplication}"/>
                                <Run>(</Run>
                                <Run Text="{DynamicResource StrGlobalHotkey}"/>
                                <Run>)</Run>
                            </TextBlock>
                            <TextBlock>
                                <Run Text="{DynamicResource StrSendMessage}"/>
                                <Run>(</Run>
                                <Run Text="{DynamicResource StrInputBox}"/>
                                <Run>)</Run>
                            </TextBlock>
                            <TextBlock>
                                <Run Text="{DynamicResource StrCancelSendingMessage}"/>
                                <Run>(</Run>
                                <Run Text="{DynamicResource StrInputBox}"/>
                                <Run>)</Run>
                            </TextBlock>
                            <TextBlock>
                                <Run Text="{DynamicResource StrResetChat}"/>
                            </TextBlock>
                            <TextBlock>
                                <Run Text="{DynamicResource StrCreateNewSession}"/>
                            </TextBlock>
                            <TextBlock>
                                <Run Text="{DynamicResource StrRemoveCurrentSession}"/>
                            </TextBlock>
                            <TextBlock>
                                <Run Text="{DynamicResource StrSwitchToNextSession}"/>
                            </TextBlock>
                            <TextBlock>
                                <Run Text="{DynamicResource StrSwitchToPreviousSession}"/>
                            </TextBlock>
                            <TextBlock>
                                <Run Text="{DynamicResource StrCycleSwitchToNextSession}"/>
                            </TextBlock>
                            <TextBlock>
                                <Run Text="{DynamicResource StrCycleSwitchToPreviousSession}"/>
                            </TextBlock>
                        </UniformGrid>
                    </Grid>
                </StackPanel>

                <StackPanel Margin="0 5 0 5">
                    <TextBlock>
                        <Run Text="{DynamicResource StrColorMode}"/>
                        <Run Text=":"/>
                    </TextBlock>
                    <ListBox BorderThickness="0" d:ItemsSource="{d:SampleData ItemCount=5}"
                             ItemsSource="{Binding ColorModeService.ColorModes}" SelectedItem="{Binding ColorModeService.CurrentMode}">
                    </ListBox>
                </StackPanel>

                <StackPanel Margin="0 5 0 5">
                    <TextBlock>
                        <Run Text="{DynamicResource StrLanguage}"/>
                        <Run Text=":"/>
                    </TextBlock>
                    <ListBox BorderThickness="0" d:ItemsSource="{d:SampleData ItemCount=5}"
                             ItemsSource="{Binding LanguageService.Languages}" SelectedItem="{Binding LanguageService.CurrentLanguage}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock>
                                    <Run Text="{Binding NativeName,Mode=OneWay}"/>
                                </TextBlock>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </StackPanel>
            </StackPanel>
        </ScrollViewer>

        <Button Grid.Row="1" Content="{DynamicResource StrSave}" Command="{Binding SaveConfigurationCommand}" ToolTip="Save configuration"
                HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="20 10" Padding="10,5" utils:UiUtils.CornerRadius="3"/>
    </Grid>
</Page>
