<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:vm="clr-namespace:GitLab.UI.ViewModels"
             xmlns:converters="clr-namespace:GitCredentialManager.UI.Converters;assembly=gcmcore"
             mc:Ignorable="d" d:DesignWidth="420"
             x:Class="GitLab.UI.Views.CredentialsView"
             x:Name="view">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceInclude Source="/UI/Assets/Images.axaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Design.DataContext>
        <vm:CredentialsViewModel/>
    </Design.DataContext>
    <DockPanel>
        <StackPanel DockPanel.Dock="Top" Margin="0,0,0,15">
            <!--
                Only show the GitLab logo when this is GitLab.com,
                otherwise show just the logo type "GitLab".
            -->
            <StackPanel Orientation="Horizontal"
                        HorizontalAlignment="Center"
                        Margin="0,0,0,10">
                <Image Source="{DynamicResource GitLabLogo}"
                       Height="46" VerticalAlignment="Center" Margin="0,0,8,0"
                       IsVisible="{Binding Url, Converter={x:Static StringConverters.IsNullOrEmpty}}"/>
                <Image Source="{DynamicResource GitLabLogoType}"
                       Height="24" VerticalAlignment="Center"/>
            </StackPanel>
            <TextBlock Text="Sign in"
                       HorizontalAlignment="Center"
                       FontSize="16"
                       FontWeight="Light"
                       Margin="0,0,0,5" />
            <StackPanel IsVisible="{Binding Url, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
                        Margin="0,10,0,0">
                <TextBlock Text="{Binding Url}" HorizontalAlignment="Center"/>
            </StackPanel>
        </StackPanel>

        <WrapPanel DockPanel.Dock="Bottom" HorizontalAlignment="Center" VerticalAlignment="Center"
                   IsVisible="{Binding Url, Converter={x:Static StringConverters.IsNullOrEmpty}}"
                   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 IsEnabled="{Binding ShowBrowserLogin}"
                     IsVisible="{Binding $self.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"/>
                </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="_patUserNameTextBox"
                             Watermark="Username or email (optional)" Margin="0,0,0,10"
                             Text="{Binding TokenUserName}"/>
                    <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>
