<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:controls="clr-namespace:GitHub.UI.Controls"
             xmlns:vm="clr-namespace:GitHub.UI.ViewModels"
             xmlns:converters="clr-namespace:GitCredentialManager.UI.Converters;assembly=gcmcore"
             mc:Ignorable="d" d:DesignWidth="420"
             x:Class="GitHub.UI.Views.CredentialsView">
    <Design.DataContext>
        <vm:CredentialsViewModel/>
    </Design.DataContext>
    <DockPanel>
        <StackPanel DockPanel.Dock="Top" Margin="0,0,0,15">
            <!-- TODO: replace with GitHub logo -->
            <TextBlock Text="GitHub"
                       HorizontalAlignment="Center"
                       FontSize="20"
                       FontWeight="Bold"/>
            <TextBlock Text="Sign in"
                       HorizontalAlignment="Center"
                       FontSize="24"
                       FontWeight="Light"
                       Margin="0,0,0,10" />
            <controls:HorizontalShadowDivider/>
            <StackPanel IsVisible="{Binding EnterpriseUrl, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
                        Margin="0,10,0,0">
                <TextBlock Text="GitHub Enterprise" HorizontalAlignment="Center"/>
                <TextBlock Text="{Binding EnterpriseUrl}"
                           HorizontalAlignment="Center"/>
            </StackPanel>
        </StackPanel>

        <WrapPanel DockPanel.Dock="Bottom" HorizontalAlignment="Center" VerticalAlignment="Center"
                   Margin="0,20,0,0">
            <TextBlock Text="Don't have an account?" Margin="0,0,5,0" />
            <Button Content="Sign up"
                    Command="{Binding SignUpCommand}"
                    Classes="hyperlink"/>
        </WrapPanel>

        <TabControl x:Name="_authModesTabControl"
                    VerticalContentAlignment="Center"
                    AutoScrollToSelectedItem="True">
            <TabControl.Styles>
                <Style Selector="TabItem">
                    <Setter Property="MinHeight" Value="30" />
                </Style>
                <Style Selector="DockPanel > ItemsPresenter > WrapPanel">
                    <Setter Property="HorizontalAlignment" Value="Center"/>
                </Style>
            </TabControl.Styles>

            <TabItem IsVisible="{Binding $self.IsEnabled}">
                <TabItem.IsEnabled>
                    <MultiBinding Converter="{x:Static converters:BoolConvertersEx.Or}">
                        <Binding Path="ShowBrowserLogin" />
                        <Binding Path="ShowDeviceLogin" />
                    </MultiBinding>
                </TabItem.IsEnabled>
                <TabItem.Header>
                    <TextBlock Text="{Binding OAuthModeTitle}" FontSize="12" />
                </TabItem.Header>
                <StackPanel Margin="0,10">
                    <Button x:Name="_signInBrowserButton"
                            Content="Sign in with your browser"
                            IsDefault="True"
                            Command="{Binding SignInBrowserCommand}"
                            IsVisible="{Binding ShowBrowserLogin}"
                            HorizontalAlignment="Center"
                            Margin="0,0,0,10"
                            Classes="accent"/>
                    <Button x:Name="_signInDeviceButton"
                            Content="Sign in with a code"
                            Command="{Binding SignInDeviceCommand}"
                            IsVisible="{Binding ShowDeviceLogin}"
                            HorizontalAlignment="Center"
                            Margin="0,10,0,10"/>
                </StackPanel>
            </TabItem>

            <TabItem IsEnabled="{Binding ShowTokenLogin}"
                     IsVisible="{Binding $self.IsEnabled}">
                <TabItem.Header>
                    <TextBlock Text="Token" FontSize="12" />
                </TabItem.Header>
                <StackPanel Margin="0,10">
                    <TextBox x:Name="_tokenTextBox"
                             Watermark="Personal access token" Margin="0,0,0,10"
                             PasswordChar="●"
                             Text="{Binding Token}"/>
                    <Button Content="Sign in"
                            IsDefault="True"
                            Command="{Binding SignInTokenCommand}"
                            HorizontalAlignment="Center"
                            Classes="accent"/>
                </StackPanel>
            </TabItem>

            <TabItem IsEnabled="{Binding ShowBasicLogin}"
                     IsVisible="{Binding $self.IsEnabled}">
                <TabItem.Header>
                    <TextBlock Text="Password" FontSize="12" />
                </TabItem.Header>
                <StackPanel Margin="0,10">
                    <TextBox x:Name="_userNameTextBox"
                             Watermark="Username or email" Margin="0,0,0,10"
                             Text="{Binding UserName}"/>
                    <TextBox x:Name="_passwordTextBox"
                             Watermark="Password" Margin="0,0,0,10"
                             PasswordChar="●"
                             Text="{Binding Password}"/>
                    <Button Content="Sign in"
                            IsDefault="True"
                            Command="{Binding SignInBasicCommand}"
                            HorizontalAlignment="Center"
                            Classes="accent"/>
                </StackPanel>
            </TabItem>
        </TabControl>
    </DockPanel>
</UserControl>
