<Window x:Class="ZadaniaWPF.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:ZadaniaWPF"
        xmlns:mw="clr-namespace:ZadaniaWPF.ModelWidoku"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:s="clr-namespace:System;assembly=mscorlib"
        xmlns:jm="clr-namespace:JacekMatulewski.WpfUtils"
        mc:Ignorable="d"
        Title="ZadaniaWPF" Height="500" Width="500">
    <Window.DataContext>
        <mw:Zadania />
    </Window.DataContext>
    <Window.Resources>
        <Style x:Key="stylPrzycisku" TargetType="Button">
            <Setter Property="FontSize" Value="10" />
            <Setter Property="Margin" Value="5" />
            <Setter Property="Width" Value="85" />
            <Setter Property="Height" Value="20" />
            <Setter Property="HorizontalAlignment" Value="Right" />
            <Setter Property="VerticalAlignment" Value="Top" />
        </Style>
        <BooleanToVisibilityConverter x:Key="boolToVisibility" />
        <local:PriorytetZadaniaToString x:Key="priorytetToString" />
        <local:PriorytetZadaniaToBrush x:Key="priorytetToBrush" />
        <local:BoolToBrushConverter x:Key="czyZrealizowaneToBrush" />
        <local:BoolToBrushConverter x:Key="czyPoTerminieToBrush" KolorDlaFałszu="Green" KolorDlaPrawdy="Red" />
        <local:BoolToTextDecorationConverter x:Key="czyZrealizowaneToTextDecoration" />
        <local:ZadanieConverter x:Key="twórzZadanie" />
        <Style TargetType="{x:Type DatePickerTextBox}">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate>
                        <TextBox Text="{Binding Path=SelectedDate, 
                                 StringFormat={}{0:dd MMMM yyyy}, ConverterCulture=pl-PL, RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}}"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <!--
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Closed">
            <i:InvokeCommandAction Command="{Binding Zapisz}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    -->
    <DockPanel LastChildFill="True">

        <Grid DockPanel.Dock="Bottom" Background="LightBlue" DataContext="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext.Zapis}">
            <jm:ConditionalMessageDialogBox 
                x:Name="questionYesNo" 
                Caption="ZadaniaWPF" Icon="Question" Buttons="YesNo"
                IsDialogBypassed="{Binding ElementName=lbListaZadań, 
                                   Path=SelectedValue.CzyZrealizowane}"
                DialogBypassButton="Yes"
                CommandYes="{Binding Path=UsuńZadanie}" 
                CommandParameter="{Binding ElementName=lbListaZadań, Path=SelectedValue.Id}" />
            <!--CommandParameter="{Binding ElementName=lbListaZadań, Path=SelectedIndex}" />-->
            <Button Content="Usuń zadanie" 
                HorizontalAlignment="Left" VerticalAlignment="Bottom" 
                Margin="10,10,0,165" Width="100" Height="25" 
                Style="{StaticResource stylPrzycisku}" 
                Command="{Binding ElementName=questionYesNo, Path=Show}" 
                CommandParameter="Czy jesteś pewien, że chcesz usunąć niezrealizowane zadanie?" />
            <Button Content="Sortuj wg priorytetów" 
                HorizontalAlignment="Left" VerticalAlignment="Bottom" 
                Margin="120,10,0,165" Width="130" Height="25" 
                Style="{StaticResource stylPrzycisku}" 
                Command="{Binding Path=SortujZadania}" CommandParameter="True" />
            <Button Content="Sortuj wg terminów" 
                HorizontalAlignment="Left" VerticalAlignment="Bottom" 
                Margin="260,10,0,165" Width="120" Height="25" 
                Style="{StaticResource stylPrzycisku}" 
                Command="{Binding Path=SortujZadania}" CommandParameter="False" />
            <jm:SimpleMessageDialogBox x:Name="simpleMessageDialogBox" Caption="ZadaniaWPF" />
            <Button Content="O..." HorizontalAlignment="Right" VerticalAlignment="Bottom" 
                Margin="395,10,10,165" Width="60" Height="25" 
                Style="{StaticResource stylPrzycisku}" 
                Command="{Binding ElementName=simpleMessageDialogBox, Path=Show}" 
                CommandParameter="ZadaniaWPF&#x0a;(c) Jacek Matulewski 2015&#x0a;WWW: http://www.fizyka.umk.pl/~jacek" />

            <GroupBox Header="Dodaj zadanie" Margin="10,0,10,10" MinWidth="420" 
                  Height="140" VerticalAlignment="Bottom">
                <Grid>
                    <Label Content="Opis:" Margin="10,5,0,0" 
                       HorizontalAlignment="Left" VerticalAlignment="Top"/>
                    <TextBox x:Name="tbOpis" Height="23" 
                         Margin="10,30,10,0" VerticalAlignment="Top" />
                    <Label Content="Priorytet:" Margin="10,60,0,0" 
                       HorizontalAlignment="Left" VerticalAlignment="Top"/>
                    <ComboBox x:Name="cbPriorytet" Margin="10,85,0,0" Width="120"
                          HorizontalAlignment="Left" VerticalAlignment="Top">
                        <ComboBoxItem>Mniej ważne</ComboBoxItem>
                        <ComboBoxItem IsSelected="True">Ważne</ComboBoxItem>
                        <ComboBoxItem>Krytyczne</ComboBoxItem>
                    </ComboBox>
                    <Label Content="Termin realizacji:" Margin="160,60,0,0" 
                       HorizontalAlignment="Left" VerticalAlignment="Top"/>
                    <DatePicker x:Name="dpTerminRealizacji" Margin="160,85,0,0" 
                    HorizontalAlignment="Left" VerticalAlignment="Top" 
                    SelectedDate="{x:Static s:DateTime.Now}" />
                    <jm:NotificationDialogBox x:Name="notificationDialogBox" 
                                             Caption="ZadaniaWPF" CommandBefore="{Binding Path=DodajZadanie}">
                        <jm:NotificationDialogBox.CommandParameter>
                            <MultiBinding Converter="{StaticResource twórzZadanie}">
                                <Binding ElementName="tbOpis" Path="Text" />
                                <Binding ElementName="dpTerminRealizacji" Path="SelectedDate" />
                                <Binding ElementName="cbPriorytet" Path="Text" />
                            </MultiBinding>
                        </jm:NotificationDialogBox.CommandParameter>
                    </jm:NotificationDialogBox>
                    <Button Content="Dodaj zadanie" Margin="0,81,9.8,0" 
                        HorizontalAlignment="Right" VerticalAlignment="Top" 
                        Width="100" Height="25" 
                        Style="{StaticResource stylPrzycisku}" 
                        Command="{Binding ElementName=notificationDialogBox, Path=Show}"
                        CommandParameter="Zadanie zostało dodane" />
                </Grid>
            </GroupBox>
        </Grid>

        <Grid Background="LightGreen" DataContext="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext.Odczyt}">
            <TextBlock Margin="10,10,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Text="Liczba zadań: ">
            <Run Text="{Binding Path=Zadania.Count, Mode=OneWay}" />
            </TextBlock>
            <ListBox x:Name="lbListaZadań" Margin="10,35,10,10" 
                 ItemsSource="{Binding Path=Zadania}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Vertical" Margin="3">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding Path=Opis, Mode=OneWay}" 
                                       FontSize="20"
                                       Foreground="{Binding CzyZrealizowane, 
                                                    Converter={StaticResource czyZrealizowaneToBrush}}" 
                                                    TextDecorations="{Binding Path=CzyZrealizowane, Mode=OneWay, 
                                                    Converter={StaticResource czyZrealizowaneToTextDecoration}}" />
                                <Button Content="Zrealizowane" Command="{Binding Path=OznaczJakoZrealizowane}"
                                    Style="{StaticResource stylPrzycisku}"
                                    Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, 
                                                         Mode=OneWay, Converter={StaticResource boolToVisibility}}" />
                                <Button Content="Niezrealizowane" Command="{Binding Path=OznaczJakoNiezrealizowane}"
                                    Style="{StaticResource stylPrzycisku}"
                                    Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, 
                                                         Mode=OneWay, Converter={StaticResource boolToVisibility}}" />
                            </StackPanel>
                            <TextBlock>
                            <!--Id: <Run Text="{Binding Path=Id, Mode=OneWay}" />,-->
                            Priorytet: <Run Text="{Binding Path=Priorytet, Mode=OneWay, Converter={StaticResource priorytetToString}}" 
                                            Foreground="{Binding Path=Priorytet, Mode=OneWay, Converter={StaticResource priorytetToBrush}}" />,
                            Termin: <Run Text="{Binding Path=PlanowanyTerminRealizacji, Mode=OneWay, StringFormat={}{0:dd MMMM yyyy}, ConverterCulture=pl-PL}"  />,
                            Utworzone: <Run Text="{Binding Path=DataUtworzenia, Mode=OneWay, StringFormat={}{0:dd MMMM yyyy}, ConverterCulture=pl-PL}" />
                            </TextBlock>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="Control.Margin" Value="3" />
                        <Setter Property="Control.BorderBrush" Value="Black" />
                        <Setter Property="Control.BorderThickness" Value="1" />
                        <Style.Triggers>
                            <Trigger Property="Control.IsMouseOver" Value="True">
                                <Setter Property="Control.Background" Value="LightGray" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </ListBox.ItemContainerStyle>
                <i:Interaction.Behaviors>
                    <local:PrzesunięcieWDółListyPoDodaniuElementu />
                </i:Interaction.Behaviors>
            </ListBox>
        </Grid>

    </DockPanel>
</Window>
