<UserControl xmlns="https://github.com/avaloniaui"
             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"
             xmlns:layerBrushes="clr-namespace:Artemis.Core.LayerBrushes;assembly=Artemis.Core"
             xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
             xmlns:settings="clr-namespace:Artemis.UI.Screens.Settings"
             xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
             xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
             xmlns:behaviors="clr-namespace:Artemis.UI.Shared.Behaviors;assembly=Artemis.UI.Shared"
             mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="2400"
             x:Class="Artemis.UI.Screens.Settings.GeneralTabView"
             x:DataType="settings:GeneralTabViewModel">

    <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
        <StackPanel Margin="15" MaxWidth="1000">
            <TextBlock Classes="h4">General settings</TextBlock>
            <TextBlock>
                Here you can change the general settings op the application, for plugin and device specific settings, see the other tabs.
            </TextBlock>
            <!-- General settings -->
            <TextBlock Classes="card-title">
                General
            </TextBlock>
            <Border Classes="card" VerticalAlignment="Stretch" Margin="0,0,5,0">
                <StackPanel>
                    <StackPanel IsVisible="{CompiledBinding IsAutoRunSupported}">
                        <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                            <StackPanel Grid.Column="0">
                                <TextBlock>Auto-run on startup</TextBlock>
                            </StackPanel>
                            <ToggleSwitch Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" IsChecked="{CompiledBinding UIAutoRun.Value}" MinWidth="0" Margin="0 -10" OnContent="Yes"
                                          OffContent="No" />
                        </Grid>
                        <Border Classes="card-separator" />

                        <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                            <StackPanel Grid.Column="0">
                                <TextBlock>Hide window on auto-run</TextBlock>
                            </StackPanel>
                            <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
                                <ToggleSwitch IsChecked="{CompiledBinding !UIShowOnStartup.Value}" IsEnabled="{CompiledBinding UIAutoRun.Value}" MinWidth="0" Margin="0 -10" OnContent="Yes"
                                              OffContent="No" />
                            </StackPanel>
                        </Grid>
                        <Border Classes="card-separator" />
                        
                        <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                            <StackPanel Grid.Column="0">
                                <TextBlock>Associate with Artemis links</TextBlock>
                                <TextBlock Classes="subtitle" TextWrapping="Wrap">
                                    Open Artemis when navigating to artemis:// links, allows opening workshop entries from your browser.
                                </TextBlock>
                            </StackPanel>
                            <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
                                <ToggleSwitch IsChecked="{CompiledBinding UIUseProtocol.Value}" OnContent="Yes" OffContent="No" MinWidth="0" Margin="0 -10" />
                            </StackPanel>
                        </Grid>
                        <Border Classes="card-separator"/>
                        
                        <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto" IsVisible="{CompiledBinding IsWindows11}">
                            <StackPanel Grid.Column="0">
                                <TextBlock>Enable Mica effect</TextBlock>
                                <TextBlock Classes="subtitle" TextWrapping="Wrap">
                                    The Mica effect is the semi-transparent effect used by the application window, the colors are based on your wallpaper.
                                </TextBlock>
                            </StackPanel>
                            <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
                                <ToggleSwitch IsChecked="{CompiledBinding EnableMica.Value}" OnContent="Yes" OffContent="No" MinWidth="0" Margin="0 -10" />
                            </StackPanel>
                        </Grid>
                        <Border Classes="card-separator" IsVisible="{CompiledBinding IsWindows11}"/>
                        
                        <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                            <StackPanel Grid.Column="0">
                                <TextBlock>Startup delay</TextBlock>
                                <TextBlock Classes="subtitle" TextWrapping="Wrap">
                                    Set the amount of seconds to wait before auto-running Artemis.
                                </TextBlock>
                                <TextBlock Classes="subtitle" TextWrapping="Wrap">
                                    If some devices don't work because Artemis starts before the manufacturer's software, try increasing this value.
                                </TextBlock>
                            </StackPanel>
                            <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Orientation="Horizontal">
                                <controls:NumberBox IsEnabled="{CompiledBinding UIAutoRun.Value}" Width="120">
                                    <Interaction.Behaviors>
                                        <behaviors:LostFocusNumberBoxBindingBehavior Value="{CompiledBinding UIAutoRunDelay.Value}" />
                                    </Interaction.Behaviors>
                                </controls:NumberBox>
                                <TextBlock VerticalAlignment="Center" TextAlignment="Right" Width="30">sec</TextBlock>
                            </StackPanel>
                        </Grid>
                        <Border Classes="card-separator" />
                    </StackPanel>

                    <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                        <StackPanel Grid.Column="0">
                            <TextBlock>
                                Log level
                            </TextBlock>
                            <TextBlock Classes="subtitle" TextWrapping="Wrap">
                                Sets the logging level, a higher logging level will result in more log files.
                            </TextBlock>
                        </StackPanel>
                        <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
                            <shared:EnumComboBox Width="150" Value="{CompiledBinding CoreLoggingLevel.Value}" />
                        </StackPanel>
                    </Grid>
                    <Border Classes="card-separator" />

                    <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                        <StackPanel Grid.Column="0" VerticalAlignment="Center">
                            <TextBlock>
                                Logs
                            </TextBlock>
                            <TextBlock Classes="subtitle">
                                Opens the directory where logs are stored.
                            </TextBlock>
                        </StackPanel>
                        <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
                            <Button Command="{CompiledBinding ShowLogs}" Width="150" Content="Show logs" />
                        </StackPanel>
                    </Grid>
                </StackPanel>
            </Border>

            <!-- Web server settings -->
            <TextBlock Classes="card-title">
                Web server
            </TextBlock>
            <Border Classes="card" VerticalAlignment="Stretch" Margin="0,0,5,0">
                <StackPanel>
                    <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                        <StackPanel Grid.Column="0">
                            <TextBlock>Enable web server</TextBlock>
                            <TextBlock Classes="subtitle" TextWrapping="Wrap">
                                Artemis runs a local web server that can be used to externally interact with the application.
                            </TextBlock>
                            <TextBlock Classes="subtitle" TextWrapping="Wrap">
                                This web server can only be accessed by applications running on your own computer, e.g. supported games.
                            </TextBlock>
                        </StackPanel>
                        <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
                            <ToggleSwitch IsChecked="{CompiledBinding WebServerEnabled.Value}" OnContent="Yes" OffContent="No" MinWidth="0" Margin="0 -10" />
                        </StackPanel>
                    </Grid>
                    <Border Classes="card-separator" />

                    <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                        <StackPanel Grid.Column="0">
                            <TextBlock>
                                Web server port
                            </TextBlock>
                            <TextBlock Classes="subtitle" TextWrapping="Wrap">
                                If the webserver does not work you can try changing the port to one that is available.
                            </TextBlock>
                        </StackPanel>
                        <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
                            <controls:NumberBox Width="150">
                                <Interaction.Behaviors>
                                    <behaviors:LostFocusNumberBoxBindingBehavior Value="{CompiledBinding WebServerPort.Value}" />
                                </Interaction.Behaviors>
                            </controls:NumberBox>
                        </StackPanel>
                    </Grid>
                </StackPanel>
            </Border>

            <!-- Update settings -->
            <StackPanel>
                <TextBlock Classes="card-title">
                    Updating
                </TextBlock>
                <Border Classes="card" VerticalAlignment="Stretch" Margin="0,0,5,0">
                    <StackPanel>
                        <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                            <StackPanel Grid.Column="0">
                                <TextBlock>
                                    Check for updates
                                </TextBlock>
                                <TextBlock Classes="subtitle" TextWrapping="Wrap">
                                    If enabled, we'll check for updates on startup and periodically while running.
                                </TextBlock>
                            </StackPanel>
                            <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
                                <ToggleSwitch IsChecked="{CompiledBinding UICheckForUpdates.Value}" MinWidth="0" OnContent="Yes" OffContent="No" />
                            </StackPanel>
                        </Grid>
                        <Border Classes="card-separator" />

                        <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                            <StackPanel Grid.Column="0">
                                <TextBlock>
                                    Auto-install updates
                                </TextBlock>
                                <TextBlock Classes="subtitle" TextWrapping="Wrap">
                                    If enabled, new updates will automatically be installed.
                                </TextBlock>
                            </StackPanel>
                            <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
                                <ToggleSwitch IsEnabled="{CompiledBinding UICheckForUpdates.Value}" IsChecked="{CompiledBinding UIAutoUpdate.Value}" MinWidth="0" OnContent="Yes" OffContent="No" />
                            </StackPanel>
                        </Grid>
                        <Border Classes="card-separator" />

                        <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                            <StackPanel Grid.Column="0" VerticalAlignment="Center">
                                <TextBlock>
                                    Update
                                </TextBlock>
                                <TextBlock Classes="subtitle">
                                    Use the button on the right to check for updates now.
                                </TextBlock>
                            </StackPanel>
                            <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
                                <Button Command="{CompiledBinding CheckForUpdate}" Width="150" Content="Check now" />
                            </StackPanel>
                        </Grid>
                    </StackPanel>
                </Border>
            </StackPanel>

            <!-- Profile editor settings -->
            <TextBlock Classes="card-title">
                Profile editor
            </TextBlock>
            <Border Classes="card" VerticalAlignment="Stretch" Margin="0,0,5,0">
                <StackPanel>
                    <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                        <StackPanel Grid.Column="0">
                            <TextBlock>
                                Show condition data model values
                            </TextBlock>
                            <TextBlock Classes="subtitle" TextWrapping="Wrap">
                                While selecting a condition target, show the current values of the data model.
                            </TextBlock>
                        </StackPanel>
                        <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
                            <ToggleSwitch IsChecked="{CompiledBinding ProfileEditorShowDataModelValues.Value}" MinWidth="0" OnContent="Yes" OffContent="No" />
                        </StackPanel>
                    </Grid>
                    <Border Classes="card-separator" />

                    <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                        <StackPanel Grid.Column="0">
                            <TextBlock>
                                Default brush
                            </TextBlock>
                            <TextBlock Classes="subtitle" TextWrapping="Wrap">
                                Sets the default brush that is applied to new layers
                            </TextBlock>
                        </StackPanel>
                        <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
                            <StackPanel.Styles>
                                <Style Selector="ComboBox.brush /template/ ContentControl#ContentPresenter">
                                    <Setter Property="ContentTemplate">
                                        <Setter.Value>
                                            <DataTemplate DataType="{x:Type layerBrushes:LayerBrushDescriptor}">
                                                <StackPanel Orientation="Horizontal">
                                                    <avalonia:MaterialIcon Kind="{CompiledBinding Icon}" Height="20" Width="20" VerticalAlignment="Center" Margin="0 0 5 0" />
                                                    <TextBlock Text="{CompiledBinding DisplayName}" VerticalAlignment="Center" />
                                                </StackPanel>
                                            </DataTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </StackPanel.Styles>
                            <ComboBox Classes="brush"
                                      Width="200"
                                      HorizontalAlignment="Left"
                                      ItemsSource="{CompiledBinding LayerBrushDescriptors}"
                                      SelectedItem="{CompiledBinding SelectedLayerBrushDescriptor}">
                                <ComboBox.ItemTemplate>
                                    <DataTemplate DataType="{x:Type layerBrushes:LayerBrushDescriptor}">
                                        <Grid ColumnDefinitions="30,*" RowDefinitions="Auto,Auto">
                                            <avalonia:MaterialIcon Grid.Row="0"
                                                                   Grid.RowSpan="2"
                                                                   Kind="{CompiledBinding Icon}"
                                                                   Height="20"
                                                                   Width="20"
                                                                   VerticalAlignment="Center"
                                                                   HorizontalAlignment="Left" />
                                            <TextBlock Grid.Row="0" Grid.Column="1" Text="{CompiledBinding DisplayName}" TextWrapping="Wrap" MaxWidth="350" />
                                            <TextBlock Classes="subtitle" Grid.Row="1" Grid.Column="1" Text="{CompiledBinding Description}" TextWrapping="Wrap" MaxWidth="350" />
                                        </Grid>
                                    </DataTemplate>
                                </ComboBox.ItemTemplate>
                            </ComboBox>
                        </StackPanel>
                    </Grid>
                </StackPanel>
            </Border>

            <!-- Rendering settings -->
            <TextBlock Classes="card-title">
                Rendering
            </TextBlock>
            <Border Classes="card" VerticalAlignment="Stretch" Margin="0,0,5,0">
                <StackPanel>
                    <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                        <StackPanel Grid.Column="0">
                            <TextBlock>
                                Preferred render method
                            </TextBlock>
                            <TextBlock Classes="subtitle" TextWrapping="Wrap">
                                Software-based rendering is done purely on the CPU while Vulkan uses GPU-acceleration.
                            </TextBlock>
                        </StackPanel>
                        <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
                            <ComboBox Width="150"
                                      SelectedItem="{CompiledBinding CorePreferredGraphicsContext.Value}"
                                      ItemsSource="{CompiledBinding GraphicsContexts}" />
                        </StackPanel>
                    </Grid>
                    <Border Classes="card-separator" />

                    <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                        <StackPanel Grid.Column="0">
                            <TextBlock>
                                Render scale
                            </TextBlock>
                            <TextBlock Classes="subtitle" TextWrapping="Wrap">
                                Sets the resolution Artemis renders at, higher scale means more CPU-usage, especially on large surfaces.
                            </TextBlock>
                        </StackPanel>
                        <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
                            <ComboBox Width="150"
                                      SelectedItem="{CompiledBinding SelectedRenderScale}"
                                      ItemsSource="{CompiledBinding RenderScales}">
                                <ComboBox.ItemTemplate>
                                    <DataTemplate x:DataType="settings:RenderSettingViewModel">
                                        <TextBlock Text="{CompiledBinding Display}" />
                                    </DataTemplate>
                                </ComboBox.ItemTemplate>
                            </ComboBox>
                        </StackPanel>
                    </Grid>
                    <Border Classes="card-separator" />

                    <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                        <StackPanel Grid.Column="0">
                            <TextBlock>
                                Target frame rate
                            </TextBlock>
                            <TextBlock Classes="subtitle" TextWrapping="Wrap">
                                Sets the FPS Artemis tries to render at, higher FPS means more CPU-usage but smoother animations.
                            </TextBlock>
                            <TextBlock Classes="subtitle" TextWrapping="Wrap">
                                The options past 45 FPS are mostly useless unless you are using a custom device.
                            </TextBlock>
                        </StackPanel>
                        <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
                            <ComboBox Width="150"
                                      SelectedItem="{CompiledBinding SelectedTargetFrameRate}"
                                      ItemsSource="{CompiledBinding TargetFrameRates}">
                                <ComboBox.ItemTemplate>
                                    <DataTemplate x:DataType="settings:RenderSettingViewModel">
                                        <TextBlock Text="{CompiledBinding Display}" />
                                    </DataTemplate>
                                </ComboBox.ItemTemplate>
                            </ComboBox>
                        </StackPanel>
                    </Grid>
                </StackPanel>
            </Border>

            <!-- Tools -->
            <TextBlock Classes="card-title">
                Tools
            </TextBlock>
            <Border Classes="card" VerticalAlignment="Stretch" Margin="0,0,5,0">
                <StackPanel>
                    <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                        <StackPanel Grid.Column="0" VerticalAlignment="Center">
                            <TextBlock>
                                Setup wizard
                            </TextBlock>
                            <TextBlock Classes="subtitle">
                                Opens the startup wizard usually shown when Artemis first starts.
                            </TextBlock>
                        </StackPanel>
                        <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
                            <Button Command="{CompiledBinding ShowSetupWizard}" Width="150" Content="Show wizard" />
                        </StackPanel>
                    </Grid>
                    <Border Classes="card-separator" />

                    <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                        <StackPanel Grid.Column="0" VerticalAlignment="Center">
                            <TextBlock>
                                Debugger
                            </TextBlock>
                            <TextBlock Classes="subtitle">
                                Use the debugger to see the raw image Artemis is rendering on the surface.
                            </TextBlock>
                        </StackPanel>
                        <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
                            <Button Command="{CompiledBinding ShowDebugger}" Width="150" Content="Show debugger" />
                        </StackPanel>
                    </Grid>
                    <Border Classes="card-separator" />

                    <Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
                        <StackPanel Grid.Column="0" VerticalAlignment="Center">
                            <TextBlock>
                                Application files
                            </TextBlock>
                            <TextBlock Classes="subtitle">
                                Opens the directory where application files like plugins and settings are stored.
                            </TextBlock>
                        </StackPanel>
                        <StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
                            <Button Command="{CompiledBinding ShowDataFolder}" Width="150" Content="Show app files" />
                        </StackPanel>
                    </Grid>
                </StackPanel>
            </Border>
        </StackPanel>
    </ScrollViewer>

</UserControl>