<UserControl x:Class="WWWings_GUI_SL5.Views.FlugauswahlView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    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:u="clr-namespace:WWWings_GUI_SL5.Utilities"
             
    xmlns:m="clr-namespace:WWWings_GUI_SL5.ModelExtensions"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" 
             
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">

  <UserControl.Resources>
    <DataTemplate DataType="m:Flughafen">
      <TextBlock Text="{Binding Name}" Margin="3" 
                 VerticalAlignment="Center"/>
    </DataTemplate>
    
    <DataTemplate DataType="m:Flughafen" x:Key="FlughafenMitBildTemplate">
      <StackPanel Orientation="Horizontal" Width="100" Background="#01ffffff">
        <TextBlock Text="{Binding Name}" Margin="3" VerticalAlignment="Center" >
        </TextBlock>
        <ToolTipService.ToolTip>
            <Grid Width="300">
              <Image Source="{Binding Bild}" Stretch="Uniform"/>
              <Grid VerticalAlignment="Bottom" HorizontalAlignment="Center" 
                    Margin="0,0,0,5" Background="#a0ffffff">
                <TextBlock Text="{Binding Name}"  FontSize="16" 
                           Foreground="Black" Margin="5,2" />
              </Grid>
            </Grid>
        </ToolTipService.ToolTip>
      </StackPanel>
    </DataTemplate>

    <u:IndexSelectConverter x:Key="StyleSelector">
      <u:IndexSelectConverter.Values>
        <Style TargetType="ListBox">
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate>
                <TextBlock Text="Kein Flug verfügbar"/>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
        </Style>
      </u:IndexSelectConverter.Values>
    </u:IndexSelectConverter>
    
  </UserControl.Resources>
  
  <Grid x:Name="LayoutRoot" Background="White">
    <Grid.RowDefinitions>
      <RowDefinition Height="0" />
      <RowDefinition Height="Auto" />
      <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*" />
      <ColumnDefinition Width="*" />
      <ColumnDefinition Width="*" />
      <ColumnDefinition Width="100" />
    </Grid.ColumnDefinitions>

    <!-- Zeile 0 -->
    <sdk:Label Content="Abflugort" Grid.Row="0" Grid.Column="0" Margin="3"/>
    <sdk:Label Content="Zielort" Grid.Row="0" Grid.Column="1" Margin="3"/>
    <!-- Zeile 1 -->
    <ComboBox ItemsSource="{Binding Path=Flughäfen}" 
              SelectedItem="{Binding Path=Abflugort, Mode=TwoWay}"
              ItemTemplate="{StaticResource FlughafenMitBildTemplate}"  Margin="3" Grid.Row="1" Grid.Column="0" MinWidth="120"              />
    <ComboBox ItemsSource="{Binding Path=Flughäfen}" 
              SelectedItem="{Binding Path=Zielort, Mode=TwoWay}"
              ItemTemplate="{StaticResource FlughafenMitBildTemplate}" MinWidth="120"  Margin="3" Grid.Row="1" Grid.Column="1"/>

    <Button Content="Flüge suchen" Command="{Binding FlügeSuchenCommand}" Grid.Row="1" Grid.Column="3" Margin="3"  />
    <!-- Zeile 2 -->
    <ListBox ItemsSource="{Binding VerfügbareFlüge}" 
             SelectedItem="{Binding AusgewählterFlug, Mode=TwoWay}" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4" Margin="3"
             Style="{Binding VerfügbareFlüge.Count, Converter={StaticResource StyleSelector}}">
      <ListBox.ItemTemplate>
        <DataTemplate>
          <StackPanel Orientation="Horizontal">
            <StackPanel.Resources>
              <Style TargetType="TextBlock">
                <Setter Property="Margin" Value="5,0,0,0"/>
              </Style>
            </StackPanel.Resources>
            <TextBlock Text="ID:" />
            <TextBlock Text="{Binding ID}" Width="80" />
            <TextBlock Text="Datum:"/>
            <TextBlock Text="{Binding Datum, StringFormat=g}" Width="100"/>
            <TextBlock Text="Freie Plätze:"/>
            <TextBlock Text="{Binding FreiePlaetze}" Name="TBFreiePlätze" Width="80" />
          </StackPanel>
        </DataTemplate>
      </ListBox.ItemTemplate>

    </ListBox>
  </Grid>
</UserControl>
