<controls:EnhancedPage
    x:Class="Pixeval.Pages.Login.LoginPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:app="using:Pixeval.AppManagement"
    xmlns:controls="using:Pixeval.Controls"
    xmlns:controls2="using:CommunityToolkit.WinUI.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:fluent="using:FluentIcons.WinUI"
    xmlns:local="using:Pixeval.Pages.Login"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:pixeval="using:Pixeval"
    Loaded="LoginPage_OnLoaded"
    Unloaded="LoginPage_OnUnloaded"
    mc:Ignorable="d">
    <controls2:DockPanel>
        <controls2:TitleBar
            Title="{x:Bind app:AppInfo.AppIdentifier}"
            VerticalAlignment="Top"
            controls2:DockPanel.Dock="Top"
            DisplayMode="Tall"
            Window="{x:Bind Window}">
            <controls2:TitleBar.Icon>
                <ImageIcon Source="ms-appx:///Assets/Images/logo.svg" />
            </controls2:TitleBar.Icon>
        </controls2:TitleBar>
        <controls2:DockPanel
            Padding="50"
            HorizontalSpacing="20"
            KeyboardAcceleratorPlacementMode="Hidden">
            <controls2:DockPanel
                MinWidth="300"
                controls2:DockPanel.Dock="Right"
                LastChildFill="False">
                <ContentControl
                    HorizontalAlignment="Stretch"
                    controls2:DockPanel.Dock="Top"
                    IsEnabled="{x:Bind _viewModel.IsEnabled, Mode=OneWay}">
                    <controls2:SwitchPresenter
                        x:Name="SwitchPresenter"
                        Width="350"
                        HorizontalAlignment="Stretch"
                        Value="{x:Bind local:LoginPage.RefreshToken}">
                        <controls2:Case Value="{x:Bind local:LoginPage.RefreshToken}">
                            <controls2:DockPanel
                                VerticalAlignment="Top"
                                LastChildFill="False"
                                VerticalSpacing="10">
                                <TextBox
                                    x:Uid="/LoginPage/RefreshTokenBox"
                                    controls2:DockPanel.Dock="Top"
                                    IsSpellCheckEnabled="False"
                                    Text="{x:Bind _viewModel.RefreshToken, Mode=TwoWay}" />
                                <controls2:DockPanel controls2:DockPanel.Dock="Top" HorizontalSpacing="10">
                                    <Button
                                        x:Uid="/LoginPage/SubmitButton"
                                        Height="33"
                                        controls2:DockPanel.Dock="Right"
                                        Click="TokenLogin_OnClicked"
                                        IsEnabled="{x:Bind _viewModel.IsEnabled, Mode=OneWay}" />
                                    <ToggleSwitch x:Uid="/LoginPage/DisableDomainFrontingToggleSwitch" IsOn="{x:Bind _viewModel.EnableDomainFronting, Mode=TwoWay}" />
                                </controls2:DockPanel>
                                <HyperlinkButton
                                    x:Uid="/LoginPage/BrowserButton"
                                    controls2:DockPanel.Dock="Top"
                                    Click="SwitchPresenterButton_OnClicked"
                                    Tag="{x:Bind local:LoginPage.Browser}" />
                                <HyperlinkButton
                                    x:Uid="/LoginPage/WebViewButton"
                                    controls2:DockPanel.Dock="Top"
                                    Click="SwitchPresenterButton_OnClicked"
                                    Tag="{x:Bind local:LoginPage.WebView}" />
                            </controls2:DockPanel>
                        </controls2:Case>
                        <controls2:Case Value="{x:Bind local:LoginPage.Browser}">
                            <controls2:DockPanel
                                VerticalAlignment="Top"
                                LastChildFill="False"
                                VerticalSpacing="10">
                                <InfoBar
                                    x:Uid="/LoginPage/BrowserLoginTip"
                                    controls2:DockPanel.Dock="Top"
                                    IsClosable="False"
                                    IsOpen="True"
                                    Severity="Informational" />
                                <controls2:DockPanel
                                    controls2:DockPanel.Dock="Top"
                                    HorizontalSpacing="10"
                                    LastChildFill="False">
                                    <Button
                                        x:Uid="/LoginPage/BrowserHelp"
                                        controls2:DockPanel.Dock="Right"
                                        Content="{fluent:SymbolIcon Symbol=Question}"
                                        IsTabStop="False" />
                                    <Button
                                        x:Uid="/LoginPage/SubmitButton"
                                        Height="33"
                                        controls2:DockPanel.Dock="Right"
                                        Click="BrowserLogin_OnClicked" />
                                    <!--<ToggleSwitch x:Uid="/LoginPage/DisableDomainFrontingToggleSwitch" IsOn="{x:Bind _viewModel.EnableDomainFronting, Mode=TwoWay}" />-->
                                </controls2:DockPanel>
                                <HyperlinkButton
                                    x:Uid="/LoginPage/RefreshTokenButton"
                                    controls2:DockPanel.Dock="Top"
                                    Click="SwitchPresenterButton_OnClicked"
                                    Tag="{x:Bind local:LoginPage.RefreshToken}" />
                                <HyperlinkButton
                                    x:Uid="/LoginPage/WebViewButton"
                                    controls2:DockPanel.Dock="Top"
                                    Click="SwitchPresenterButton_OnClicked"
                                    Tag="{x:Bind local:LoginPage.WebView}" />
                            </controls2:DockPanel>
                        </controls2:Case>
                        <controls2:Case Value="{x:Bind local:LoginPage.WebView}">
                            <controls2:DockPanel
                                VerticalAlignment="Top"
                                LastChildFill="False"
                                VerticalSpacing="10">
                                <controls2:DockPanel.KeyboardAccelerators>
                                    <KeyboardAccelerator Key="Enter" Invoked="WebViewLogin_OnClicked" />
                                </controls2:DockPanel.KeyboardAccelerators>
                                <InfoBar
                                    x:Uid="/LoginPage/WebViewLoginTip"
                                    controls2:DockPanel.Dock="Top"
                                    IsClosable="False"
                                    IsOpen="True"
                                    Severity="Informational" />
                                <TextBox
                                    x:Uid="/LoginPage/UserNameBox"
                                    controls2:DockPanel.Dock="Top"
                                    IsSpellCheckEnabled="False"
                                    Text="{x:Bind _viewModel.UserName, Mode=TwoWay}" />
                                <PasswordBox
                                    x:Uid="/LoginPage/PasswordBox"
                                    controls2:DockPanel.Dock="Top"
                                    Password="{x:Bind _viewModel.Password, Mode=TwoWay}" />
                                <controls2:DockPanel controls2:DockPanel.Dock="Top" HorizontalSpacing="10">
                                    <Button
                                        x:Uid="/LoginPage/WebViewHelp"
                                        controls2:DockPanel.Dock="Right"
                                        Content="{fluent:SymbolIcon Symbol=Question}"
                                        IsTabStop="False" />
                                    <SplitButton
                                        x:Uid="/LoginPage/SubmitButton"
                                        Height="33"
                                        controls2:DockPanel.Dock="Right"
                                        Click="WebViewLogin_OnClicked">
                                        <SplitButton.Flyout>
                                            <MenuFlyout>
                                                <MenuFlyoutItem x:Uid="/LoginPage/SubmitWithNewAccountButton" Click="WebViewLoginNewAccount_OnClicked" />
                                            </MenuFlyout>
                                        </SplitButton.Flyout>
                                    </SplitButton>
                                    <ToggleSwitch x:Uid="/LoginPage/DisableDomainFrontingToggleSwitch" IsOn="{x:Bind _viewModel.EnableDomainFronting, Mode=TwoWay}" />
                                </controls2:DockPanel>
                                <HyperlinkButton
                                    x:Uid="/LoginPage/RefreshTokenButton"
                                    controls2:DockPanel.Dock="Top"
                                    Click="SwitchPresenterButton_OnClicked"
                                    Tag="{x:Bind local:LoginPage.RefreshToken}" />
                                <HyperlinkButton
                                    x:Uid="/LoginPage/BrowserButton"
                                    controls2:DockPanel.Dock="Top"
                                    Click="SwitchPresenterButton_OnClicked"
                                    Tag="{x:Bind local:LoginPage.Browser}" />
                            </controls2:DockPanel>
                        </controls2:Case>
                    </controls2:SwitchPresenter>
                </ContentControl>
                <Button
                    HorizontalAlignment="Right"
                    controls2:DockPanel.Dock="Bottom"
                    Click="ButtonBase_OnClick"
                    Content="{fluent:SymbolIcon Symbol=LocalLanguage}"
                    ToolTipService.ToolTip="{x:Bind pixeval:SettingsPageResources.AppLanguageEntryHeader}">
                    <Button.ContextFlyout>
                        <MenuFlyout x:Name="MenuFlyout" Placement="TopEdgeAlignedRight" />
                    </Button.ContextFlyout>
                </Button>
            </controls2:DockPanel>
            <Grid>
                <StackPanel
                    Grid.Column="0"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Spacing="25">
                    <Image
                        Width="100"
                        Height="100"
                        Source="../../Assets/Images/logo400.png" />
                    <ProgressRing
                        Width="30"
                        Height="30"
                        Visibility="{x:Bind _viewModel.ProcessingRingVisible, Mode=OneWay}" />
                    <TextBlock
                        HorizontalAlignment="Center"
                        Style="{StaticResource CaptionTextBlockStyle}"
                        Text="{x:Bind local:LoginPhaseEnumExtension.GetResource(_viewModel.LoginPhase), Mode=OneWay}" />
                </StackPanel>
                <Border
                    Grid.Column="0"
                    Child="{x:Bind _viewModel.WebView, Mode=OneWay}"
                    CornerRadius="{ThemeResource ControlCornerRadius}"
                    Visibility="{x:Bind controls:C.ToVisibilityNegation(_viewModel.IsFinished), Mode=OneWay}" />
            </Grid>
        </controls2:DockPanel>
    </controls2:DockPanel>
</controls:EnhancedPage>
