<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Apollon.WPF.Views.Components" 
             xmlns:custom="clr-namespace:LoadingSpinnerControl;assembly=LoadingSpinnerControl"
             xmlns:ViewModels="clr-namespace:Apollon.WPF.ViewModels" x:Class="Apollon.WPF.Views.Components.AddEditDetails"
             mc:Ignorable="d">
    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>        
    </UserControl.Resources>    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="55"/>
            <RowDefinition Height="55"/>
            <RowDefinition Height="55"/>
            <RowDefinition Height="55"/>
            <RowDefinition Height="55"/>
            <RowDefinition Height="55"/>
            <RowDefinition Height="55"/>
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="180"/>
            <ColumnDefinition Width="400"/>
        </Grid.ColumnDefinitions>

        <TextBlock Text="Veranstalter: "                       
                   Style="{StaticResource ModalTextBlock}"/>

        <TextBlock Grid.Row="1"
                   Text="Turniername: "
                   Style="{StaticResource ModalTextBlock}"/>

        <TextBlock Grid.Row="2"                   
                   Text="Wettkampfart: "                    
                   Style="{StaticResource ModalTextBlock}"/>

        <TextBlock Grid.Row="3"
                   Text="Startdatum: "
                   Style="{StaticResource ModalTextBlock}"/>

        <TextBlock Grid.Row="4"
                   Text="Enddatum: "
                   Style="{StaticResource ModalTextBlock}"/>

        <TextBlock Grid.Row="5"
                   Text="Veranstaltungsort: "
                   Style="{StaticResource ModalTextBlock}"/>

        <TextBlock Grid.Row="6"
                   Text="Durchgänge: "
                   Style="{StaticResource ModalTextBlock}"/>

        <TextBox Grid.Column="1"
                 Text="{Binding Organisation}"
                 FontFamily="Arial"
                 FontSize="16"
                 Height="30"
                 Width="300"
                 Background="LightGray"
                 VerticalContentAlignment="Center"
                 HorizontalAlignment="Left"/>

        <TextBox Grid.Row="1"
                 Grid.Column="1"
                 Text="{Binding TournamentName, UpdateSourceTrigger=PropertyChanged}"
                 FontFamily="Arial"                     
                 FontSize="16"
                 Height="30"
                 Width="300"
                 HorizontalAlignment="Left"
                 VerticalContentAlignment="Center"                     
                 Background="LightGray"/>

        <StackPanel Grid.Column="1"
               Grid.RowSpan="2">
            <Image 
               Height="80"
               Width="80"
               HorizontalAlignment="Right"
               Source="{Binding Logo, TargetNullValue={x:Null}}"/>
            <Button Style="{StaticResource ModernButton}"
                    Content="Logo wählen"
                    Height="20"
                    Width="80"
                    HorizontalAlignment="Right"
                    FontSize="10"
                    Command="{Binding ChooseLogoCommand}"/>                  
        </StackPanel>
        

        <ComboBox Grid.Row="2"                                     
                  Text="{Binding Competition}"
                  IsReadOnly="False"
                  IsEditable="True"
                  Grid.Column="1"
                  Height="30"
                  Width="200"
                  FontSize="16"
                  VerticalContentAlignment="Center"
                  HorizontalAlignment="Left"
                  ItemsSource="{Binding CompetitionList}"
                  DisplayMemberPath="CompetitionName"
                  SelectedValuePath="CompetitionName"
                  SelectedValue="{Binding CurrentCompetition.CompetitionName}"
                  SelectedItem="{Binding CurrentCompetition}">                    
        </ComboBox>
        
        <Image x:Name="CompetitionImage"                 
               Grid.Row="2"
               Grid.Column="1"
               Grid.RowSpan="3"
               Height="80"
               Width="80"
               HorizontalAlignment="Right"
               Margin="0 0 60 0"
               Source="{Binding CompetitionImage, TargetNullValue={x:Null}}" />

        <DatePicker SelectedDateFormat="Long"
                    Grid.Row="3"
                    SelectedDate="{Binding StartDate}"
                    Grid.Column="1"                        
                    Height="30"
                    FontSize="14"                        
                    HorizontalAlignment="Left"/>

        <DatePicker SelectedDateFormat="Long"
                    Grid.Row="4"
                    SelectedDate="{Binding EndDate}"
                    Grid.Column="1"                        
                    Height="30"
                    FontSize="14"                        
                    HorizontalAlignment="Left"/>

        <TextBox Grid.Row="5"
                 Grid.Column="1"
                 Text="{Binding Location}"
                 FontFamily="Arial"                     
                 FontSize="16"
                 Height="30"
                 Width="300"
                 HorizontalAlignment="Left"
                 VerticalContentAlignment="Center"
                 Background="LightGray"/>
        <TextBox Grid.Row="6"
                 Grid.Column="1"
                 Text="{Binding Rounds}"
                 FontFamily="Arial"                     
                 FontSize="16"
                 Height="30"
                 Width="50"
                 VerticalContentAlignment="Center"
                 HorizontalAlignment="Left"
                 Background="LightGray"/>

        <TextBlock Text="{Binding ErrorMessage}"
                   Grid.Row="7"
                   Grid.ColumnSpan="2"
                   TextAlignment="Center"
                   FontSize="14"
                   Foreground="Red"
                   Visibility="{Binding HasErrorMessage, Converter={StaticResource BooleanToVisibilityConverter}}"/>

        <Grid Grid.Row="7"
              Grid.ColumnSpan="2"
              Margin="0 30 0 0"
              Width="450"
              HorizontalAlignment="Center">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="35"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>

            <Button Content="Speichern"
                    Command="{Binding SubmitCommand}"
                    Style="{StaticResource ModernButton}"
                    Width="120"
                    Height="35" 
                    FontSize="16"
                    IsEnabled="{Binding CanSubmit}"
                    ToolTip="Turniername muss angegeben werden!"
                    ToolTipService.ShowOnDisabled="True"
                    ToolTipService.BetweenShowDelay="1000"/>

            <Button Content="Abbrechen"
                    Command="{Binding CancelCommand}"
                    Style="{StaticResource ModernButton}"
                    Width="120"
                    Height="35"
                    FontSize="16"
                    Grid.Column="2"/>
            <custom:LoadingSpinner Grid.Column="1" 
                                   Diameter="25" 
                                   Thickness="2" 
                                   Color="{StaticResource BrushPrimary1}" 
                                   IsLoading="{Binding IsSubmitting}"/>
        </Grid>
    </Grid>
</UserControl>
