<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"
        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>
	<Grid Margin="0,-2,-0.4,2">
        <TextBlock Margin="10,10,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Text="Liczba zadań: ">
            <Run Text="{Binding Path=ListaZadań.Count, Mode=OneWay}" />
        </TextBlock>
        <ListBox x:Name="lbListaZadań" Margin="10,35,10,200" ItemsSource="{Binding Path=ListaZadań}">
            <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>
							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}" Foreground="{Binding Path=CzyZadaniePozostajeNiezrealizowanePoPlanowanymTerminie, Mode=OneWay, Converter={StaticResource czyPoTerminieToBrush}}" />,
							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="{x:Type 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>
        </ListBox>
		<local: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=SelectedIndex}" />
		<Button Content="Usuń zadanie" 
				HorizontalAlignment="Left" VerticalAlignment="Bottom" 
				Margin="10,0,0,165" Width="100" Height="25" 
				Style="{StaticResource stylPrzycisku}" 
				Command="{Binding ElementName=questionYesNo, Path=Show}" 
				CommandParameter="Czy jesteś pewien, że chcesz usunąć niezrealizowane zadanie?" />
		<GroupBox Header="Nowe 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" HorizontalAlignment="Left" Margin="10,85,0,0" VerticalAlignment="Top" Width="120">
					<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}">
				</DatePicker>
				<local:NotificationDialogBox x:Name="notificationDialogBox" 
											 Caption="ZadaniaWPF" CommandBefore="{Binding Path=DodajZadanie}">
					<local:NotificationDialogBox.CommandParameter>
						<MultiBinding Converter="{StaticResource twórzZadanie}">
							<Binding ElementName="tbOpis" Path="Text" />
							<Binding ElementName="dpTerminRealizacji" Path="SelectedDate" />
							<Binding ElementName="cbPriorytet" Path="Text" />							
						</MultiBinding>
					</local:NotificationDialogBox.CommandParameter>
				</local:NotificationDialogBox>
				<Button Content="Dodaj zadanie" 
						Margin="0,83,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"
						Click="Button_Click">					
				</Button>				
			</Grid>	
		</GroupBox>
		<Button Content="Sortuj wg priorytetów" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="120,0,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,0,0,165" Width="120" Height="25" Style="{StaticResource stylPrzycisku}" Command="{Binding Path=SortujZadania}" CommandParameter="False" />
		<!--
		<local:SimpleMessageDialogBox x:Name="simpleMessageDialogBox" Caption="ZadaniaWPF" />
		<Button Content="O..." HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="395,0,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" />
		-->
		<local:FileSavedNotificationDialogBox
			x:Name="saveConfirmation"
			Caption="ZadaniaWPF"			
			CommandBefore="{Binding EksportujZadaniaDoPlikuTekstowego}"
			CommandParameter="{Binding ElementName=saveFileDialogBox, Path=FilePath}" />
		<local:SaveFileDialogBox 
			x:Name="saveFileDialogBox"
			Caption="Zapisz do pliku tekstowego" 
			Filter="Pliki tekstowe (*.txt)|*.txt|Wszystkie pliki (*.*)|*.*" 
			FilterIndex="0" DefaultExt="txt" Margin="0,1,0,-1"
			CommandFileOk="{Binding ElementName=saveConfirmation, Path=Show}" />
		<Button 
			Content="Eksportuj..." 
			HorizontalAlignment="Right" VerticalAlignment="Bottom" 
			Margin="0,0,10,165" Width="90" Height="25" 
			Style="{StaticResource stylPrzycisku}" 
			Command="{Binding Show, ElementName=saveFileDialogBox}" />
		<local:CustomContentDialogBox 
			x:Name="dodajZadanieDialogBox" 
			Caption="Dodaj zadanie"
			WindowWidth="440" WindowHeight="160"
			CommandTrue="{Binding Path=DodajZadanie}">
			<local:CustomContentDialogBox.CommandParameter>
						<MultiBinding Converter="{StaticResource twórzZadanie}">
							<Binding ElementName="tbOpis1" Path="Text" />
							<Binding ElementName="dpTerminRealizacji1" Path="SelectedDate" />
							<Binding ElementName="cbPriorytet1" Path="Text" />							
						</MultiBinding>
			</local:CustomContentDialogBox.CommandParameter>
			<Grid>
				<Label Content="Opis:" Margin="10,5,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"/>
				<TextBox x:Name="tbOpis1" Height="23" Margin="10,30,10,0" VerticalAlignment="Top" />
				<Label Content="Priorytet:" Margin="10,60,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"/>
				<ComboBox x:Name="cbPriorytet1" HorizontalAlignment="Left" Margin="10,85,0,0" VerticalAlignment="Top" Width="120">
					<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="dpTerminRealizacji1" Margin="160,85,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" SelectedDate="{x:Static s:DateTime.Now}">
				</DatePicker>				
				<Button Content="Dodaj zadanie" 
						Margin="0,83,9.8,0" HorizontalAlignment="Right" VerticalAlignment="Top" 
						Width="100" Height="25" 						
						Style="{StaticResource stylPrzycisku}" 
						Click="Button_Click"
						local:CustomContentDialogBox.CustomContentDialogResult="True" >
				</Button>
			</Grid>	
		</local:CustomContentDialogBox>
		<Button 
			Content="Dodaj zadanie..." 
			HorizontalAlignment="Left" VerticalAlignment="Bottom"
			Margin="10,0,0,130" Width="100" Height="25" 
			Style="{StaticResource stylPrzycisku}"
			Command="{Binding ElementName=dodajZadanieDialogBox, Path=Show}" />
	</Grid>
</Window>
