<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:ui="using:FluentAvalonia.UI.Controls"
             xmlns:ic="clr-namespace:FluentIcons.Avalonia.Fluent;assembly=FluentIcons.Avalonia.Fluent"
             xmlns:ext="clr-namespace:GalaxyBudsClient.Interface.MarkupExtensions"
             xmlns:controls="clr-namespace:GalaxyBudsClient.Interface.Controls"
             xmlns:pages="clr-namespace:GalaxyBudsClient.Interface.ViewModels.Pages"
             xmlns:converters="clr-namespace:GalaxyBudsClient.Interface.Converters"
             xmlns:i18N="clr-namespace:GalaxyBudsClient.Generated.I18N"
             xmlns:config="clr-namespace:GalaxyBudsClient.Model.Config"
             xmlns:platform="clr-namespace:GalaxyBudsClient.Platform;assembly=GalaxyBudsClient.Platform"
             mc:Ignorable="d" d:DesignWidth="900" d:DesignHeight="1200"
             x:Class="GalaxyBudsClient.Interface.Pages.SettingsPage"
             x:CompileBindings="True"
             x:DataType="pages:SettingsPageViewModel">
    <Design.DataContext>
        <pages:SettingsPageViewModel />
    </Design.DataContext>

    <ScrollViewer>
        <StackPanel Spacing="8" Margin="{StaticResource AppPageMargin}">
            <DockPanel>
                <Image Source="{OnPlatform '/Resources/icon.ico', Android='/Resources/Android/Orange/android/res/mipmap-xxxhdpi/ic_launcher.png'}"
                       DockPanel.Dock="Left"
                       Height="78"
                       RenderOptions.BitmapInterpolationMode="HighQuality" />

                <StackPanel Spacing="{StaticResource SettingsSubtitleTextSpacing}" Margin="12 0">
                    <TextBlock Text="Galaxy Buds Manager"
                               Theme="{StaticResource BoldTitleTextBlockStyle}" />

                    <TextBlock Text="{Binding CurrentVersion}"
                               Theme="{StaticResource BodyTextBlockStyle}" />

                    <TextBlock Text="GPL-3.0"
                               Theme="{StaticResource CaptionTextBlockStyle}" />

                    <TextBlock Theme="{StaticResource CaptionTextBlockStyle}"
                               Text="https://github.com/timschneeb/GalaxyBudsClient"
                               Foreground="{DynamicResource TextFillColorSecondaryBrush}"
                               Cursor="Hand">
                        <Interaction.Behaviors>
                            <EventTriggerBehavior EventName="PointerPressed">
                                <ext:OpenLinkAction TargetUri="https://github.com/timschneeb/GalaxyBudsClient" />
                            </EventTriggerBehavior>
                        </Interaction.Behaviors>
                    </TextBlock>
                </StackPanel>
            </DockPanel>

            <controls:SettingsGroup Margin="0,4,0,0">
                <controls:SettingsSymbolItem Content="{ext:Translate {x:Static i18N:Keys.DevicesSettingsLink}}"
                                             Description="{ext:Translate {x:Static i18N:Keys.DevicesSettingsLinkDesc}}"
                                             Symbol="BluetoothConnected"
                                             ActionSymbol="ChevronRight"
                                             IsClickEnabled="True"
                                             IsEnabled="{Binding CanManageDevices}"
                                             Click="OnManageDevicesClicked" />
            </controls:SettingsGroup>

            <ui:SettingsExpander Header="{ext:Translate {x:Static i18N:Keys.SettingsAppearance}}" IsExpanded="True">
                <ui:SettingsExpander.IconSource>
                    <ic:SymbolIconSource Symbol="PaintBrush" />
                </ui:SettingsExpander.IconSource>

                <controls:SettingsComboBoxItem Name="AppTheme"
                                               Content="{ext:Translate {x:Static i18N:Keys.SettingsDarkmode}}"
                                               Description="{ext:Translate {x:Static i18N:Keys.SettingsDarkmodeDescription}}"
                                               Symbol="DarkTheme"
                                               ItemsSource="{Binding ., Source={ext:ThemesBindingSource}}"
                                               SelectedValue="{Binding Theme, Source={x:Static config:Settings.Data}}">
                    <Interaction.Behaviors>
                        <ext:RequiresDesktopBehavior />
                        <ext:LocalizationAwareComboBoxBehavior />
                    </Interaction.Behaviors>
                </controls:SettingsComboBoxItem>

                <controls:SettingsSliderItem
                    Content="{ext:Translate {x:Static i18N:Keys.SettingsBlurstrength}}"
                    Description="{ext:Translate {x:Static i18N:Keys.SettingsBlurstrengthDescription}}"
                    TickPlacement="None"
                    Symbol="Blur"
                    Maximum="255"
                    IsEnabled="{Binding Theme, Source={x:Static config:Settings.Data}, Converter={x:Static converters:FuncConverters.IsBlurDarkModeSet}}"
                    Value="{Binding BlurStrength, Source={x:Static config:Settings.Data}}">
                    <Interaction.Behaviors>
                        <ext:RequiresDesktopBehavior />
                    </Interaction.Behaviors>
                </controls:SettingsSliderItem>

                <controls:SettingsColorItem Name="AppAccent"
                                            Content="{ext:Translate {x:Static i18N:Keys.SettingsAccent}}"
                                            Description="{ext:Translate {x:Static i18N:Keys.SettingsAccentDescription}}"
                                            Symbol="Color"
                                            Color="{Binding AccentColor, Source={x:Static config:Settings.Data}, Converter={StaticResource ColorUintConverter}}" />

                <controls:SettingsComboBoxItem Name="AppLanguage"
                                               Content="{ext:Translate {x:Static i18N:Keys.SettingsLocalizationDisable}}"
                                               Description="{ext:Translate {x:Static i18N:Keys.SettingsLocalizationDescription}}"
                                               Symbol="LocalLanguage"
                                               ItemsSource="{Binding Source={ext:LocalesBindingSource}}"
                                               SelectedValue="{Binding Locale, Source={x:Static config:Settings.Data}}" />
                
                <controls:SettingsComboBoxItem Name="ColorOverride"
                                               Content="{ext:Translate {x:Static i18N:Keys.SettingsColorOverride}}"
                                               Description="{ext:Translate {x:Static i18N:Keys.SettingsColorOverrideDescription}}"
                                               Symbol="ColorFill"
                                               IsEnabled="{Binding RealisticEarbudImages, Source={x:Static config:Settings.Data}}"
                                               ItemsSource="{Binding ., Source={ext:DeviceColorBindingSource}}"
                                               SelectedValue="{Binding ColorOverride, Source={x:Static config:Settings.Data}}" />

                <controls:SettingsSwitchItem Content="{ext:Translate {x:Static i18N:Keys.SettingsRealisticEarbudIcons}}"
                                             Description="{ext:Translate {x:Static i18N:Keys.SettingsRealisticEarbudIconsDescription}}"
                                             Symbol="ImageSparkle"
                                             IsChecked="{Binding RealisticEarbudImages, Source={x:Static config:Settings.Data}}" />

                <controls:SettingsSwitchItem Content="{ext:Translate {x:Static i18N:Keys.SettingsNavSidebar}}"
                                             Description="{ext:Translate {x:Static i18N:Keys.SettingsNavSidebarDescription}}"
                                             Symbol="LayoutColumnOneThirdLeft"
                                             IsChecked="{Binding ShowSidebar, Source={x:Static config:Settings.Data}}" />

            </ui:SettingsExpander>

            <ui:SettingsExpander Header="{ext:Translate {x:Static i18N:Keys.SettingsTraySettings}}"
                                 IsExpanded="True"
                                 IsVisible="{x:Static platform:PlatformUtils.SupportsTrayIcon}">
                <ui:SettingsExpander.IconSource>
                    <ic:SymbolIconSource Symbol="ChatSettings" />
                </ui:SettingsExpander.IconSource>

                <controls:SettingsSwitchItem
                    Name="TrayIcon"
                    Content="{ext:Translate {x:Static i18N:Keys.SettingsMinimizeTray}}"
                    Description="{ext:Translate {x:Static i18N:Keys.SettingsMinimizeTrayDescription}}"
                    Symbol="ArrowMinimize"
                    IsChecked="{Binding MinimizeToTray, Source={x:Static config:Settings.Data}}" />

                <controls:SettingsComboBoxItem
                    Name="DynamicTrayIcon"
                    Content="{ext:Translate {x:Static i18N:Keys.SettingsDynTrayMode}}"
                    Description="{ext:Translate {x:Static i18N:Keys.SettingsDynTrayModeDescription}}"
                    IsEnabled="{Binding MinimizeToTray, Source={x:Static config:Settings.Data}}"
                    ItemsSource="{Binding Source={ext:DynamicTrayIconModesBindingSource}}"
                    SelectedValue="{Binding DynamicTrayIconMode, Source={x:Static config:Settings.Data}}">
                    <Interaction.Behaviors>
                        <ext:LocalizationAwareComboBoxBehavior />
                    </Interaction.Behaviors>
                </controls:SettingsComboBoxItem>

                <controls:SettingsSwitchItem
                    Content="{ext:Translate {x:Static i18N:Keys.SettingsAutostart}}"
                    Description="{ext:Translate {x:Static i18N:Keys.SettingsAutostartDescription}}"
                    Symbol="KeyboardShiftUppercase"
                    IsEnabled="{Binding MinimizeToTray, Source={x:Static config:Settings.Data}}"
                    IsChecked="{Binding IsAutoStartEnabled}"
                    IsVisible="{x:Static platform:PlatformUtils.SupportsAutoboot}" />

            </ui:SettingsExpander>


            <ui:SettingsExpander Header="{ext:Translate {x:Static i18N:Keys.SettingsConnpopup}}">
                <ui:SettingsExpander.IconSource>
                    <ic:SymbolIconSource Symbol="Badge" />
                </ui:SettingsExpander.IconSource>

                <Interaction.Behaviors>
                    <ext:RequiresDesktopBehavior />
                </Interaction.Behaviors>
                
                <controls:SettingsSwitchItem
                    Content="{ext:Translate {x:Static i18N:Keys.SettingsCpopupEnable}}"
                    Description="{ext:Translate {x:Static i18N:Keys.SettingsCpopupEnableDescription}}"
                    IsChecked="{Binding PopupEnabled, Source={x:Static config:Settings.Data}}" />

                <controls:SettingsSwitchItem
                    Content="{ext:Translate {x:Static i18N:Keys.SettingsCpopupCompact}}"
                    Description="{ext:Translate {x:Static i18N:Keys.SettingsCpopupCompactDescription}}"
                    Symbol="ArrowMinimizeVertical"
                    IsChecked="{Binding PopupCompact, Source={x:Static config:Settings.Data}}" />

                <controls:SettingsComboBoxItem Name="PopupPosition"
                                               Content="{ext:Translate {x:Static i18N:Keys.SettingsCpopupPosition}}"
                                               Description="{ext:Translate {x:Static i18N:Keys.SettingsCpopupPositionDescription}}"
                                               Symbol="LayoutCellFourFocusBottomLeft"
                                               ItemsSource="{Binding Source={ext:PopupPlacementBindingSource}}"
                                               SelectedValue="{Binding PopupPlacement, Source={x:Static config:Settings.Data}}">
                    <Interaction.Behaviors>
                        <ext:LocalizationAwareComboBoxBehavior />
                    </Interaction.Behaviors>
                </controls:SettingsComboBoxItem>

                <controls:SettingsSymbolItem Content="{ext:Translate {x:Static i18N:Keys.SettingsCpopupDemo}}"
                                             IsClickEnabled="True"
                                             Symbol="SendBeaker">
                    <Interaction.Behaviors>
                        <EventTriggerBehavior EventName="Click">
                            <ext:EventDispatcherAction Event="ShowBatteryPopup" />
                        </EventTriggerBehavior>
                    </Interaction.Behaviors>

                </controls:SettingsSymbolItem>
            </ui:SettingsExpander>


            <ui:SettingsExpander Header="{ext:Translate {x:Static i18N:Keys.SettingsCrowdsourcing}}">
                <ui:SettingsExpander.IconSource>
                    <ic:SymbolIconSource Symbol="Lightbulb" />
                </ui:SettingsExpander.IconSource>
                
                <controls:SettingsSwitchItem
                    Content="{ext:Translate {x:Static i18N:Keys.SettingsCrowdAllow}}"
                    Description="{ext:Translate {x:Static i18N:Keys.SettingsCrowdAllowDescription}}"
                    IsChecked="{Binding !ExperimentsDisabled, Source={x:Static config:Settings.Data}}">
                    <Interaction.Behaviors>
                        <ext:RequiresDesktopBehavior />
                    </Interaction.Behaviors>
                </controls:SettingsSwitchItem>

                <controls:SettingsSwitchItem
                    Content="{ext:Translate {x:Static i18N:Keys.SettingsCrowdCrashreport}}"
                    Description="{ext:Translate {x:Static i18N:Keys.SettingsCrowdCrashreportDescription}}"
                    IsChecked="{Binding !DisableCrashReporting, Source={x:Static config:Settings.Data}}" />

            </ui:SettingsExpander>


            <ui:SettingsExpander Header="{ext:Translate {x:Static i18N:Keys.CreditsHeader}}">
                <ui:SettingsExpander.IconSource>
                    <ic:SymbolIconSource Symbol="PeopleTeam" />
                </ui:SettingsExpander.IconSource>

                <controls:SettingsSymbolItem Content="{ext:Translate {x:Static i18N:Keys.CreditsGithub}}"
                                             ActionIconSource="Open"
                                             IsClickEnabled="True">
                    <Interaction.Behaviors>
                        <EventTriggerBehavior EventName="Click">
                            <ext:OpenLinkAction TargetUri="https://github.com/timschneeb/GalaxyBudsClient" />
                        </EventTriggerBehavior>
                    </Interaction.Behaviors>
                </controls:SettingsSymbolItem>

                <controls:SettingsSymbolItem Content="{ext:Translate {x:Static i18N:Keys.CreditsDeveloper}}"
                                             Description="@thepbone" />
                <controls:SettingsSymbolItem Content="{ext:Translate {x:Static i18N:Keys.CreditsContributor}}"
                                             Description="{StaticResource ContributorCreditsString}" />
                <controls:SettingsSymbolItem Content="{ext:Translate {x:Static i18N:Keys.CreditsTranslator}}"
                                             Description="{StaticResource TranslatorCreditsString}" />
            </ui:SettingsExpander>

            <ui:SettingsExpander Name="DevSettings"
                                 Header="{ext:Translate {x:Static i18N:Keys.SettingsDevmode}}"
                                 Description="{ext:Translate {x:Static i18N:Keys.SettingsDevmodeDescription}}"
                                 ActionIconSource="Open"
                                 IsClickEnabled="True">
                <Interaction.Behaviors>
                    <ext:RequiresDesktopBehavior />
                </Interaction.Behaviors>
                
                <ui:SettingsExpander.IconSource>
                    <ic:SymbolIconSource Symbol="Beaker" />
                </ui:SettingsExpander.IconSource>
            </ui:SettingsExpander>
            
            <ui:SettingsExpander Header="{ext:Translate {x:Static i18N:Keys.CreditsSponsor}}"
                                 Description="{ext:Translate {x:Static i18N:Keys.CreditsKofi}}"
                                 ActionIconSource="Open"
                                 IsClickEnabled="True">

                <Interaction.Behaviors>
                    <EventTriggerBehavior EventName="Click">
                        <ext:OpenLinkAction TargetUri="https://ko-fi.com/thepbone" />
                    </EventTriggerBehavior>
                </Interaction.Behaviors>

                <ui:SettingsExpander.IconSource>
                    <ic:SymbolIconSource Symbol="Heart" />
                </ui:SettingsExpander.IconSource>
            </ui:SettingsExpander>

        </StackPanel>
    </ScrollViewer>

</UserControl>