<Window x:Class="TimeScheduler.MainWindow"
        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:local="clr-namespace:TimeScheduler"
        xmlns:c="clr-namespace:TimeScheduler.Common"
        xmlns:vm="clr-namespace:TimeScheduler.ViewModel"
        xmlns:domain="clr-namespace:TimeScheduler.Domain.Impl"
        mc:Ignorable="d" Language="de"
        Title="TimeSchedule" Height="350" Width="525">
  <Window.DataContext>
    <vm:MainViewModel/>
  </Window.DataContext>
  <Window.Resources>
    <c:BindingProxy x:Key="proxy" Data="{Binding}"/>
  </Window.Resources>
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="200"/>
      <ColumnDefinition Width="5"/>
      <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>

    </Grid.RowDefinitions>

    <DockPanel Grid.Column="0">
      <DatePicker DockPanel.Dock="Top" Margin="5" SelectedDate="{Binding Path=SelectedDate}"/>
      <ListBox x:Name="lbTimeElements" Margin="5" HorizontalContentAlignment="Stretch"
               ItemsSource="{Binding TimeItems}" SelectedItem="{Binding SelectedTimeItem}">
        <ListBox.ContextMenu>
          <ContextMenu>
            <MenuItem Command="{Binding AddNewCommand}" Header="Neues Element"/>
            <MenuItem Command="{Binding DeleteCommand}" Header="Lösche selektiertes Element"/>
          </ContextMenu>
        </ListBox.ContextMenu>
        <ListBox.ItemContainerStyle>
          <Style TargetType="ListBoxItem">
            <Setter Property="Background">
              <Setter.Value>
                <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                  <GradientStop Color="White" Offset="0"/>
                  <GradientStop Color="#FF00a0FF" Offset="0.5"/>
                </LinearGradientBrush>
              </Setter.Value>
            </Setter>
            <Setter Property="Template">
              <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                  <Border x:Name="showSelection" BorderBrush="Black" BorderThickness="2" Margin="1,2,1,0">
                    <Border Background="{TemplateBinding Background}" Margin="5" CornerRadius="10" Padding="5">
                      <Grid>
                        <ContentPresenter />
                        <Path x:Name="currentItemAdorner" Visibility="Collapsed" Fill="#FF00C000" Width="10" Height="10" 
                              VerticalAlignment="Top" HorizontalAlignment="Right"
                              Data="M 0,0 L 10,5 L0,10 Z"/>
                      </Grid>
                    </Border>
                  </Border>
                  <ControlTemplate.Triggers>
                    <Trigger Property="IsSelected" Value="true">
                      <Setter TargetName="showSelection" Property="Background" Value="Blue"/>
                    </Trigger>
                    <DataTrigger Binding="{Binding IsCurrentItem}" Value="true">
                      <Setter TargetName="currentItemAdorner" Property="Visibility" Value="Visible"/>
                    </DataTrigger>
                  </ControlTemplate.Triggers>
                </ControlTemplate>
              </Setter.Value>
            </Setter>
            <Setter Property="ContentTemplate">
              <Setter.Value>
                <DataTemplate DataType="{x:Type domain:TimeItem}">
                  <DataTemplate.Resources>
                    <Style TargetType="TextBlock">
                      <Setter Property="Margin" Value="2"/>
                    </Style>
                  </DataTemplate.Resources>
                  <StackPanel>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                      <TextBlock Text="{Binding Description}"/>
                      <TextBlock Text=" - "/>
                      <TextBlock Text="{Binding CostUnit}"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                      <TextBlock Text="{Binding From,StringFormat=t}" HorizontalAlignment="Right"/>
                      <TextBlock Text=" - "/>
                      <TextBlock Text="{Binding Till,StringFormat=t}" HorizontalAlignment="Right"/>
                    </StackPanel>
                  </StackPanel>
                </DataTemplate>
              </Setter.Value>
            </Setter>
            <Style.Triggers>
              <DataTrigger Binding="{Binding ItemType}" Value="Break">
                <Setter Property="Background">
                  <Setter.Value>
                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                      <GradientStop Color="White" Offset="0"/>
                      <GradientStop Color="GreenYellow" Offset="0.5"/>
                    </LinearGradientBrush>
                  </Setter.Value>
                </Setter>
              </DataTrigger>
              <DataTrigger Binding="{Binding ItemType}" Value="Holiday">
                <Setter Property="Background">
                  <Setter.Value>
                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                      <GradientStop Color="White" Offset="0"/>
                      <GradientStop Color="#FF99B4D1" Offset="0.5"/>
                    </LinearGradientBrush>
                  </Setter.Value>
                </Setter>
              </DataTrigger>
              <DataTrigger Binding="{Binding ItemType}" Value="Ill">
                <Setter Property="Background">
                  <Setter.Value>
                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                      <GradientStop Color="White" Offset="0"/>
                      <GradientStop Color="Red" Offset="0.5"/>
                    </LinearGradientBrush>
                  </Setter.Value>
                </Setter>
              </DataTrigger>
            </Style.Triggers>
          </Style>
        </ListBox.ItemContainerStyle>
      </ListBox>
    </DockPanel>

    <GridSplitter Grid.Column="1" ResizeBehavior="PreviousAndNext" ResizeDirection="Columns" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>

    <ContentControl Grid.Column="2" Margin="5" Content="{Binding SelectedTimeItem}">
      <ContentControl.ContentTemplate>
        <DataTemplate DataType="{x:Type domain:TimeItem}">
          <Grid>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="Auto"/>
              <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto"/>
              <RowDefinition Height="Auto"/>
              <RowDefinition Height="Auto"/>
              <RowDefinition Height="Auto"/>
              <RowDefinition Height="Auto"/>
              <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid.Resources>
              <Style TargetType="TextBlock">
                <Setter Property="Margin" Value="15,10"/>
              </Style>
              <Style TargetType="TextBox">
                <Setter Property="Margin" Value="15,10"/>
              </Style>
              <Style TargetType="DatePicker">
                <Setter Property="Margin" Value="15,10"/>
              </Style>
              <Style TargetType="DatePickerTextBox">
                <Setter Property="Margin" Value="15,10"/>
              </Style>
              <Style TargetType="ComboBox">
                <Setter Property="Margin" Value="15,10"/>
              </Style>
            </Grid.Resources>

            <TextBlock Grid.Column="0" Grid.Row="0" Text="Beschreibung:"/>
            <TextBox Grid.Column="1" Grid.Row="0" Text="{Binding Path=Description,UpdateSourceTrigger=PropertyChanged}"/>

            <TextBlock Grid.Column="0" Grid.Row="1" Text="Von:"/>
            <DatePickerTextBox Grid.Column="1" Grid.Row="1" Text="{Binding From,StringFormat=g,UpdateSourceTrigger=PropertyChanged}"/>

            <TextBlock Grid.Column="0" Grid.Row="2" Text="Bis:"/>
            <DatePickerTextBox Grid.Column="1" Grid.Row="2" Text="{Binding Till,StringFormat=g,UpdateSourceTrigger=PropertyChanged}"/>

            <TextBlock Grid.Column="0" Grid.Row="3" Text="Kostenstelle:"/>
            <ComboBox Grid.Column="1" Grid.Row="3" DisplayMemberPath="Value" SelectedValuePath="Key" 
                      ItemsSource="{Binding Source={StaticResource proxy},Path=Data.CostUnits}" SelectedValue="{Binding CostUnit}"/>

            <TextBlock Grid.Column="0" Grid.Row="4" Text="Typ:"/>
            <ComboBox Grid.Column="1" Grid.Row="4" DisplayMemberPath="Value" SelectedValuePath="Key"
                      ItemsSource="{Binding Source={StaticResource proxy},Path=Data.ItemTypes}" SelectedValue="{Binding ItemType}"/>

          </Grid>
        </DataTemplate>
      </ContentControl.ContentTemplate>
    </ContentControl>
  </Grid>
</Window>
