<ui:Page xmlns:props="clr-namespace:Ink_Canvas.Properties" x:Class="Ink_Canvas.Windows.SettingsViews.Pages.CloudStoragePage"
      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:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
      xmlns:ikw="http://schemas.inkore.net/lib/ui/wpf"
      xmlns:sys="clr-namespace:System;assembly=mscorlib"
      xmlns:controls="clr-namespace:Ink_Canvas.Controls;assembly=InkCanvas.Controls"
      mc:Ignorable="d"
      Title="{x:Static props:CloudStorageStrings.CloudStorage_Manage}">

    <ScrollViewer PanningMode="VerticalFirst">
        <Grid Margin="59,0,59,0">
            <FrameworkElement.Resources>
                <sys:Double x:Key="SettingsCardSpacing">4</sys:Double>
                <Style x:Key="SettingsSectionHeaderTextBlockStyle"
                    BasedOn="{StaticResource BodyStrongTextBlockStyle}"
                    TargetType="TextBlock">
                    <Style.Setters>
                        <Setter Property="Margin" Value="1,30,0,6" />
                    </Style.Setters>
                </Style>
            </FrameworkElement.Resources>

            <ikw:SimpleStackPanel MaxWidth="1000"
                HorizontalAlignment="Stretch"
                Spacing="{StaticResource SettingsCardSpacing}">

                <TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}"
                           Text="{x:Static props:CloudStorageStrings.CloudStorage_Manage}" />

                <ui:SettingsCard Header="{x:Static props:CloudStorageStrings.CloudStorage_UploadDelay}"
                                 Description="{x:Static props:CloudStorageStrings.CloudStorage_UploadDelayDesc}">
                    <ui:SettingsCard.HeaderIcon>
                        <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.QuietHours}" />
                    </ui:SettingsCard.HeaderIcon>
                    <ikw:SimpleStackPanel Orientation="Horizontal" Spacing="8" VerticalAlignment="Center">
                        <TextBox x:Name="TxtUniversalUploadDelayMinutes"
                                 Width="88"
                                 HorizontalContentAlignment="Right"
                                 TextChanged="TxtUniversalUploadDelayMinutes_TextChanged"
                                 PreviewTextInput="TxtUniversalUploadDelayMinutes_PreviewTextInput" />
                        <TextBlock Text="{x:Static props:CloudStorageStrings.CloudStorage_Minutes}" VerticalAlignment="Center" />
                    </ikw:SimpleStackPanel>
                </ui:SettingsCard>

                <ui:SettingsExpander Header="{x:Static props:CloudStorageStrings.CloudStorage_UploadProviders}"
                                     Description="{x:Static props:CloudStorageStrings.CloudStorage_UploadProvidersDesc}"
                                     IsExpanded="True">
                    <ui:SettingsExpander.HeaderIcon>
                        <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Cloud}" />
                    </ui:SettingsExpander.HeaderIcon>
                    <TextBlock Text="" />
                    <ui:SettingsExpander.Items>
                        <ui:SettingsCard Header="{x:Static props:CloudStorageStrings.CloudStorage_ProviderList}"
                                         Description="{x:Static props:CloudStorageStrings.CloudStorage_ProviderListDesc}">
                            <ItemsControl x:Name="LstUploadProviders">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Grid Margin="0,4">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*" />
                                                <ColumnDefinition Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <TextBlock Text="{Binding Name}"
                                                       VerticalAlignment="Center" />
                                            <ui:ToggleSwitch x:Name="ToggleProviderEnabled"
                                                             Grid.Column="1"
                                                             IsOn="{Binding IsEnabled, Mode=OneWay}"
                                                             Toggled="ToggleProviderEnabled_Toggled" />
                                        </Grid>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </ui:SettingsCard>
                    </ui:SettingsExpander.Items>
                </ui:SettingsExpander>

                <TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}"
                           Text="{x:Static props:CloudStorageStrings.CloudStorage_Dlass}" />

                <ui:SettingsExpander Header="{x:Static props:CloudStorageStrings.CloudStorage_UserToken}"
                                     Description="{x:Static props:CloudStorageStrings.CloudStorage_UserTokenDesc}"
                                     IsExpanded="True">
                    <ui:SettingsExpander.HeaderIcon>
                        <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.People}" />
                    </ui:SettingsExpander.HeaderIcon>
                    <TextBlock x:Name="TxtTokenStatus"
                               Text="{x:Static props:CloudStorageStrings.CloudStorage_TokenNotSet}"
                               Foreground="{DynamicResource TextFillColorSecondaryBrush}" />
                    <ui:SettingsExpander.Items>
                        <ui:SettingsCard Header="{x:Static props:CloudStorageStrings.CloudStorage_SavedTokens}"
                                         Description="{x:Static props:CloudStorageStrings.CloudStorage_SavedTokensDesc}">
                            <ComboBox x:Name="CmbSavedTokens"
                                      IsEditable="False"
                                      IsReadOnly="True"
                                      SelectionChanged="CmbSavedTokens_SelectionChanged" />
                        </ui:SettingsCard>
                        <ui:SettingsCard Header="{x:Static props:CloudStorageStrings.CloudStorage_NewToken}"
                                         Description="{x:Static props:CloudStorageStrings.CloudStorage_NewTokenDesc}">
                            <TextBox x:Name="TxtNewToken"
                                     MinWidth="260"
                                     MaxLength="500" />
                        </ui:SettingsCard>
                        <ui:SettingsCard Header="{x:Static props:CloudStorageStrings.CloudStorage_TokenActions}">
                            <WrapPanel Orientation="Horizontal">
                                <Button x:Name="BtnSaveToken"
                                        Content="{x:Static props:CloudStorageStrings.CloudStorage_SaveToken}"
                                        Margin="0,0,8,0"
                                        Click="BtnSaveToken_Click" />
                                <Button x:Name="BtnClearToken"
                                        Content="{x:Static props:CloudStorageStrings.CloudStorage_DeleteToken}"
                                        Margin="0,0,8,0"
                                        Click="BtnClearToken_Click" />
                                <Button x:Name="BtnOpenDlassDashboard"
                                        Content="{x:Static props:CloudStorageStrings.CloudStorage_OpenDlassDashboard}"
                                        Click="BtnOpenDlassDashboard_Click" />
                            </WrapPanel>
                        </ui:SettingsCard>
                    </ui:SettingsExpander.Items>
                </ui:SettingsExpander>

                <ui:SettingsCard Header="{x:Static props:CloudStorageStrings.CloudStorage_ConnectionStatus}"
                                 Description="{x:Static props:CloudStorageStrings.CloudStorage_ConnectionStatusDesc}">
                    <ui:SettingsCard.HeaderIcon>
                        <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Sync}" />
                    </ui:SettingsCard.HeaderIcon>
                    <ikw:SimpleStackPanel Orientation="Horizontal" Spacing="12" VerticalAlignment="Center">
                        <TextBlock x:Name="TxtConnectionStatus"
                                   Text="{x:Static props:CloudStorageStrings.CloudStorage_NotConnected}"
                                   VerticalAlignment="Center"
                                   Foreground="{DynamicResource TextFillColorSecondaryBrush}" />
                        <Button x:Name="BtnTestToken"
                                Content="{x:Static props:CloudStorageStrings.CloudStorage_TestConnection}"
                                Click="BtnTestToken_Click" />
                    </ikw:SimpleStackPanel>
                </ui:SettingsCard>

                <ui:SettingsCard Header="{x:Static props:CloudStorageStrings.CloudStorage_ClassSelection}"
                                 Description="{x:Static props:CloudStorageStrings.CloudStorage_ClassSelectionDesc}">
                    <ui:SettingsCard.HeaderIcon>
                        <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.People}" />
                    </ui:SettingsCard.HeaderIcon>
                    <ComboBox x:Name="CmbClassSelection"
                              IsEditable="False"
                              IsReadOnly="True"
                              SelectionChanged="CmbClassSelection_SelectionChanged" />
                </ui:SettingsCard>

                <controls:LabeledSettingsCard x:Name="ToggleSwitchAutoUploadNotes"
                        Header="{x:Static props:CloudStorageStrings.CloudStorage_AutoUploadNotes}"
                        Description="{x:Static props:CloudStorageStrings.CloudStorage_AutoUploadNotesDesc}"
                        Icon="{x:Static ui:SegoeFluentIcons.Upload}"
                        Toggled="ToggleSwitchAutoUploadNotes_Toggled" />

                <TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}"
                           Text="{x:Static props:CloudStorageStrings.CloudStorage_WebDav}" />

                <ui:SettingsExpander Header="{x:Static props:CloudStorageStrings.CloudStorage_WebDavSettings}"
                                     Description="{x:Static props:CloudStorageStrings.CloudStorage_WebDavSettingsDesc}"
                                     IsExpanded="True">
                    <ui:SettingsExpander.HeaderIcon>
                        <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Folder}" />
                    </ui:SettingsExpander.HeaderIcon>
                    <Border Background="#07aef0dc" CornerRadius="4" Padding="6,2" VerticalAlignment="Center">
                        <TextBlock Text="Beta" FontSize="10" FontWeight="SemiBold" Foreground="White" />
                    </Border>
                    <ui:SettingsExpander.Items>
                        <ui:SettingsCard Header="{x:Static props:CloudStorageStrings.CloudStorage_WebDavUrl}"
                                         Description="{x:Static props:CloudStorageStrings.CloudStorage_WebDavUrlDesc}">
                            <TextBox x:Name="TxtWebDavUrl" MinWidth="320" />
                        </ui:SettingsCard>
                        <ui:SettingsCard Header="{x:Static props:CloudStorageStrings.CloudStorage_Username}">
                            <TextBox x:Name="TxtWebDavUsername" MinWidth="320" />
                        </ui:SettingsCard>
                        <ui:SettingsCard Header="{x:Static props:CloudStorageStrings.CloudStorage_Password}">
                            <PasswordBox x:Name="TxtWebDavPassword" MinWidth="320" />
                        </ui:SettingsCard>
                        <ui:SettingsCard Header="{x:Static props:CloudStorageStrings.CloudStorage_RootDirectory}"
                                         Description="{x:Static props:CloudStorageStrings.CloudStorage_RootDirectoryDesc}">
                            <TextBox x:Name="TxtWebDavRootDirectory" MinWidth="320" />
                        </ui:SettingsCard>
                        <ui:SettingsCard Header="{x:Static props:CloudStorageStrings.CloudStorage_WebDavActions}">
                            <WrapPanel Orientation="Horizontal">
                                <Button Content="{x:Static props:CloudStorageStrings.CloudStorage_SaveWebDavSettings}"
                                        Margin="0,0,8,0"
                                        Click="BtnSaveWebDav_Click" />
                                <Button Content="{x:Static props:CloudStorageStrings.CloudStorage_Restore}"
                                        Click="BtnCancelWebDav_Click" />
                            </WrapPanel>
                        </ui:SettingsCard>
                    </ui:SettingsExpander.Items>
                </ui:SettingsExpander>

                <Rectangle Height="48" />
            </ikw:SimpleStackPanel>
        </Grid>
    </ScrollViewer>
</ui:Page>
