<?xml version="1.0" encoding="utf-8"?>
<Page
    x:Class="VDownload.Core.Views.Authentication.AuthenticationView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:VDownload.Core.Views.Authentication"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ctuc="using:CommunityToolkit.WinUI.UI.Controls"
    xmlns:ctc="using:CommunityToolkit.WinUI.Controls"
    xmlns:ct="using:CommunityToolkit.WinUI"
    xmlns:i="using:Microsoft.Xaml.Interactivity" 
    xmlns:ic="using:Microsoft.Xaml.Interactions.Core"
    mc:Ignorable="d"
    Background="{ThemeResource ViewBackgroundColor}">
    <i:Interaction.Behaviors>
        <ic:EventTriggerBehavior EventName="Loaded">
            <ic:InvokeCommandAction Command="{Binding NavigationCommand}"/>
        </ic:EventTriggerBehavior>
    </i:Interaction.Behaviors>
    <Grid Padding="20"
          RowSpacing="20">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <TextBlock x:Uid="/AuthenticationViewResources/Header"
                   Grid.Row="0"
                   FontSize="28"
                   FontWeight="SemiBold"/>
        <StackPanel Grid.Row="1"
                    Spacing="10">
            <ctc:SettingsCard Header="Twitch">
                <i:Interaction.Behaviors>
                    <ic:DataTriggerBehavior Binding="{Binding TwitchButtonState, Converter={StaticResource ObjectToStringConverter}}"
                                            ComparisonCondition="NotEqual"
                                            Value="Loading">
                        <ic:ChangePropertyAction PropertyName="Description"
                                                 Value="{Binding TwitchDescription}"/>
                        <ic:ChangePropertyAction PropertyName="Content">
                            <ic:ChangePropertyAction.Value>
                                <Button Command="{Binding TwitchAuthenticationCommand}"
                                        IsEnabled="{Binding TwitchButtonEnable}">
                                    <Button.Content>
                                        <ctuc:SwitchPresenter Value="{Binding TwitchButtonState, Converter={StaticResource ObjectToStringConverter}}">
                                            <ctuc:Case Value="SignIn">
                                                <TextBlock x:Uid="/AuthenticationViewResources/AuthenticationButtonSignIn"/>
                                            </ctuc:Case>
                                            <ctuc:Case Value="SignOut">
                                                <TextBlock x:Uid="/AuthenticationViewResources/AuthenticationButtonSignOut"/>
                                            </ctuc:Case>
                                        </ctuc:SwitchPresenter>
                                    </Button.Content>
                                </Button>
                            </ic:ChangePropertyAction.Value>
                        </ic:ChangePropertyAction>
                    </ic:DataTriggerBehavior>
                    <ic:DataTriggerBehavior Binding="{Binding TwitchButtonState, Converter={StaticResource ObjectToStringConverter}}"
                                            ComparisonCondition="Equal"
                                            Value="Loading">
                        <ic:ChangePropertyAction x:Uid="/AuthenticationViewResources/AuthenticationDescriptionLoading"
                                                 PropertyName="Description"/>
                        <ic:ChangePropertyAction PropertyName="Content">
                            <ic:ChangePropertyAction.Value>
                                <ProgressRing Width="20" 
                                              Height="20"/>
                            </ic:ChangePropertyAction.Value>
                        </ic:ChangePropertyAction>
                    </ic:DataTriggerBehavior>
                </i:Interaction.Behaviors>
                <ctc:SettingsCard.HeaderIcon>
                    <BitmapIcon ShowAsMonochrome="False" 
                                UriSource="{StaticResource ImageSourcesTwitch}"/>
                </ctc:SettingsCard.HeaderIcon>
            </ctc:SettingsCard>
        </StackPanel>
    </Grid>
</Page>
