<UserControl
    x:Class="AppFramework.Views.TenantDetailsView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:convert="clr-namespace:AppFramework.Converters"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:extensions="clr-namespace:AppFramework.Extensions"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Width="800"
    Height="550"
    mc:Ignorable="d">
    <UserControl.Resources>
        <convert:InverseBoolToVisibilityConverter x:Key="InverseBoolToVisibilityConverter" />
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>

        <Border
            Grid.RowSpan="3"
            CornerRadius="0"
            Opacity="1"
            Style="{StaticResource BorderStyle}" />

        <TextBlock
            Margin="15"
            FontSize="18"
            FontWeight="Bold"
            Text="{extensions:Translate CreateNewTenant}" />

        <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
            <StackPanel Grid.Row="1" Margin="20,10">
                <!--  租户名称  -->
                <TextBlock Margin="0,5" Text="{extensions:Translate TenancyName}" />

                <TextBox IsEnabled="{Binding IsNewTenant}" Text="{Binding Model.TenancyName}" />

                <!--  姓名  -->
                <TextBlock Margin="0,5" Text="{extensions:Translate Name}" />
                <TextBox Text="{Binding Model.Name}" />

                <!--  使用主机数据库  -->
                <StackPanel
                    Margin="0,5"
                    Orientation="Horizontal"
                    Visibility="{Binding IsNewTenant, Converter={StaticResource InverseBoolToVisibilityConverter}}">
                    <TextBlock Text="{extensions:Translate UseHostDatabase}" />
                    <CheckBox Margin="5,0" IsChecked="{Binding UseHostDatabase}" />
                </StackPanel>

                <!--  连接字符串  -->
                <StackPanel Margin="0,5" Visibility="{Binding UseHostDatabase, Converter={StaticResource InverseBoolToVisibilityConverter}}">
                    <TextBlock Text="{extensions:Translate DatabaseConnectionString}" />
                    <TextBox Text="{Binding Model.ConnectionString}" />

                    <!--  连接字符串更改警告  -->
                    <StackPanel
                        Margin="0,5"
                        Orientation="Horizontal"
                        Visibility="{Binding IsNewTenant, Converter={StaticResource InverseBoolToVisibilityConverter}}">
                        <TextBlock Text="{extensions:Translate TenantDatabaseConnectionStringChangeWarningMessage}" />
                    </StackPanel>
                </StackPanel>

                <StackPanel Margin="0,5" Visibility="{Binding IsNewTenant, Converter={StaticResource InverseBoolToVisibilityConverter}}">
                    <!--  管理员邮箱  -->
                    <TextBlock Text="{extensions:Translate AdminEmailAddress}" />
                    <TextBox Margin="0,5" Text="{Binding Model.AdminEmailAddress}" />

                    <!--  设置随机密码  -->
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{extensions:Translate SetRandomPassword}" />
                        <CheckBox Margin="5,0" IsChecked="{Binding IsSetRandomPassword}" />
                    </StackPanel>

                    <StackPanel
                        Margin="0,5"
                        Orientation="Vertical"
                        Visibility="{Binding IsSetRandomPassword, Converter={StaticResource boolToVisibility}}">

                        <!--  管理员密码  -->
                        <TextBlock Margin="0,5" Text="{extensions:Translate AdminPassword}" />
                        <TextBox Text="{Binding AdminPassword}" />

                        <!--  管理员密码重复  -->
                        <TextBlock Margin="0,5" Text="{extensions:Translate AdminPasswordRepeat}" />
                        <TextBox Text="{Binding AdminPasswordRepeat}" />
                    </StackPanel>
                </StackPanel>

                <TextBlock Margin="0,5" Text="{extensions:Translate Edition}" />
                <ComboBox ItemsSource="{Binding Editions}" SelectedItem="{Binding SelectedEdition}">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding DisplayText}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <StackPanel Orientation="Vertical" Visibility="{Binding IsSubscriptionFieldVisible, Converter={StaticResource InverseBoolToVisibilityConverter}}">

                    <!--  无限时间订阅  -->
                    <StackPanel Margin="0,5" Orientation="Horizontal">
                        <TextBlock Text="{extensions:Translate UnlimitedTimeSubscription}" />
                        <CheckBox Margin="5,0" IsChecked="{Binding IsUnlimitedTimeSubscription}" />
                    </StackPanel>

                    <!--  选择到期时间  -->
                    <!--<controls:ExtendedDatePicker
                    Format="{extensions:Translate DateFormatShort}"
                    HasBorder="False"
                    HorizontalOptions="FillAndExpand"
                    IsVisible="{Binding IsUnlimitedTimeSubscription, Converter={StaticResource InverseBooleanConverter}}"
                    MinimumDate="{Binding Today}"
                    NullableDate="{Binding Model.SubscriptionEndDateUtc}"
                    Placeholder="{extensions:Translate SelectDate}"
                    XAlign="Start" />-->

                    <!--  试用期  -->
                    <StackPanel
                        Margin="0,5"
                        Orientation="Horizontal"
                        Visibility="{Binding IsUnlimitedTimeSubscription, Converter={StaticResource InverseBoolToVisibilityConverter}}">
                        <TextBlock Text="{extensions:Translate IsInTrialPeriod}" />
                        <CheckBox Margin="5,0" IsChecked="{Binding Model.IsInTrialPeriod}" />
                    </StackPanel>

                    <StackPanel
                        Margin="0,5"
                        Orientation="Horizontal"
                        Visibility="{Binding IsSelectedEditionFree, Converter={StaticResource InverseBoolToVisibilityConverter}}">
                        <TextBlock Text="{extensions:Translate FreeEditionsCannotHaveTrialVersions}" />
                    </StackPanel>

                    <!--  下一次登录修改密码？  -->
                    <StackPanel Margin="0,5" Orientation="Horizontal">
                        <TextBlock Text="{extensions:Translate ShouldChangePasswordOnNextLogin}" />
                        <CheckBox Margin="5,0" IsChecked="{Binding Model.ShouldChangePasswordOnNextLogin}" />
                    </StackPanel>

                    <!--  发送激活邮件  -->
                    <StackPanel Margin="0,5" Orientation="Horizontal">
                        <TextBlock Text="{extensions:Translate EmailActivation}" />
                        <CheckBox Margin="5,0" IsChecked="{Binding Model.SendActivationEmail}" />
                    </StackPanel>

                    <!--  是否激活  -->
                    <StackPanel Margin="0,5" Orientation="Horizontal">
                        <TextBlock Text="{extensions:Translate Active}" />
                        <CheckBox Margin="5,0" IsChecked="{Binding Model.IsActive}" />
                    </StackPanel>
                </StackPanel>
            </StackPanel>
        </ScrollViewer>


        <StackPanel
            Grid.Row="2"
            Margin="0,0,15,15"
            HorizontalAlignment="Right"
            Orientation="Horizontal">
            <Button
                Margin="0,0,10,0"
                Padding="10,5"
                Command="{Binding CancelCommand}"
                Content="{extensions:Translate Cancel}" />
            <Button
                Padding="10,5"
                Command="{Binding SaveCommand}"
                Content="{extensions:Translate Save}" />
        </StackPanel>
    </Grid>
</UserControl>
