<Page
    x:Class="ZadaniaUA.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ZadaniaUA"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:mw="using:ZadaniaUA.ModelWidoku"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
    DataContext="{StaticResource modelWidoku}">
    <!--
    <Page.DataContext>
        <mw:Zadania />
    </Page.DataContext>
    -->
    <Page.Resources>
        <Style x:Key="stylPrzycisku" TargetType="Button">
			<Setter Property="FontSize" Value="13" />
			<Setter Property="Margin" Value="0,0,5,0" />
			<Setter Property="Width" Value="150" />
		</Style>
        <local:BooleanToVisibilityConverter x:Key="czyZrealizowaneToVisibility" />
        <local:BooleanToVisibilityConverter x:Key="czyNiezrealizowaneToVisibility" OdwróćZależność="True" />
        <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:DateConverter x:Key="dataToString" />        
    </Page.Resources>
    <Grid>
        <TextBlock Margin="15,10,0,10" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="20" Text="Liczba zadań: ">
            <Run Text="{Binding Path=ListaZadań.Count, Mode=OneWay}" />
        </TextBlock>
        <ListBox x:Name="lbListaZadań" Margin="10,35,10,10" ItemsSource="{Binding Path=ListaZadań}"
                 Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" SelectedIndex="{Binding WybranyIndeksZadania, Mode=TwoWay}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical" Margin="3">
                        <TextBlock Text="{Binding Path=Opis, Mode=OneWay}" FontSize="30" Foreground="{Binding CzyZrealizowane, Converter={StaticResource czyZrealizowaneToBrush}}" />
                        <StackPanel Orientation="Horizontal">                            
                            <Button Content="Zrealizowane" Command="{Binding Path=OznaczJakoZrealizowane}" Style="{StaticResource stylPrzycisku}" Visibility="{Binding Path=CzyZrealizowane, Mode=OneWay, Converter={StaticResource czyNiezrealizowaneToVisibility}}" Background="Red" />
                            <!--
                            <local:NotificationDialogBox x:Name="notificationDialogBox1" Caption="Zadania" 
                                                         CommandBefore="{Binding Path=OznaczJakoZrealizowane}" />
                            <Button Content="Zrealizowane" Command="{Binding ElementName=notificationDialogBox1, Path=Show}" CommandParameter="Zadanie oznaczone jako zrealizowane"
                                    Style="{StaticResource stylPrzycisku}" Visibility="{Binding Path=CzyZrealizowane, Mode=OneWay, Converter={StaticResource czyNiezrealizowaneToVisibility}}" Background="Red" />
                            -->
                            <Button Content="Niezrealizowane" Command="{Binding Path=OznaczJakoNiezrealizowane}" Style="{StaticResource stylPrzycisku}" Visibility="{Binding Path=CzyZrealizowane, Mode=OneWay, Converter={StaticResource czyZrealizowaneToVisibility}}" Background="Green" />
                            <!--
                            <local:NotificationDialogBox x:Name="notificationDialogBox2" Caption="Zadania" 
                                                         CommandBefore="{Binding Path=OznaczJakoNiezrealizowane}" />
                            <Button Content="Niezrealizowane" Command="{Binding ElementName=notificationDialogBox2, Path=Show}" CommandParameter="Zadanie oznaczone jako niezrealizowane"
                                    Style="{StaticResource stylPrzycisku}" Visibility="{Binding Path=CzyZrealizowane, Mode=OneWay, Converter={StaticResource czyZrealizowaneToVisibility}}" Background="Green" />
                            -->
                            <TextBlock Margin="10,0,10,0" Foreground="{ThemeResource ApplicationForegroundThemeBrush}" FontSize="13">
                                Priorytet: <Run Text="{Binding Path=Priorytet, Mode=OneWay, Converter={StaticResource priorytetToString}}" Foreground="{Binding Path=Priorytet, Mode=OneWay, Converter={StaticResource priorytetToBrush}}" /><LineBreak />
                                Termin: <Run Text="{Binding Path=PlanowanyTerminRealizacji, Mode=OneWay, Converter={StaticResource dataToString}}" Foreground="{Binding Path=CzyZadaniePozostajeNiezrealizowanePoPlanowanymTerminie, Mode=OneWay, Converter={StaticResource czyPoTerminieToBrush}}" /><LineBreak />
                                Utworzone: <Run Text="{Binding Path=DataUtworzenia, Mode=OneWay, Converter={StaticResource dataToString}}"  />
                            </TextBlock>
                        </StackPanel>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
			<ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Setter Property="Control.Margin" Value="3" />
                    <Setter Property="Control.BorderBrush" Value="{ThemeResource ApplicationForegroundThemeBrush}" />
                    <Setter Property="Control.BorderThickness" Value="1" />
                </Style>
            </ListBox.ItemContainerStyle>
        </ListBox>  
    </Grid>    
    <Page.BottomAppBar>
        <CommandBar>
            <CommandBar.Resources>
                <local:SimpleMessageDialogBox x:Name="simpleMessageDialogBox" Caption="Zadania" />                
                <local:NotificationDialogBox x:Name="notificationDialogBox1" Caption="Zadania" 
                                             CommandBefore="{Binding Source={StaticResource modelWidoku}, Path=UsuńZadanie}" />
                <local:MessageDialogBox
                    x:Name="questionYesNo" 
                    Caption="Zadania" Buttons="YesNo"
                    CommandYes="{Binding Source={StaticResource modelWidoku}, Path=UsuńZadanie}" />
                <local:CustomContentDialogBox 
                    x:Name="dodajZadanieDialogBox" Caption="Zadania" DialogContentDataContext="{StaticResource modelWidoku}"
                    DialogHeight="400" PrimaryButtonText="Dodaj" SecondaryButtonText="Anuluj"
                    CommandPrimary="{Binding Source={StaticResource modelWidoku}, Path=DodajZadanie}">
                    <local:CustomContentDialogBox.Resources>
                        <local:PriorytetZadaniaToIndex x:Key="priorytetToIndex" />
                    </local:CustomContentDialogBox.Resources>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="1*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="100" />
                            <RowDefinition Height="100" />
                            <RowDefinition Height="150" />
                        </Grid.RowDefinitions>
                        <TextBox x:Name="tbOpis" Grid.Row="0" Grid.ColumnSpan="2" Header="Opis:" Margin="10"
                            Text="{Binding Path=OpisNowegoZadania, Mode=TwoWay}"/>
                        <ComboBox Grid.Row="1" Grid.Column="0" Grid.RowSpan="2" x:Name="cbPriorytet" Header="Priorytet:" Margin="10"
                            SelectedIndex="{Binding Path=PriorytetNowegoZadania, Mode=TwoWay, Converter={StaticResource priorytetToIndex}}">
                            <ComboBoxItem>Mniej ważne</ComboBoxItem>
                            <ComboBoxItem IsSelected="True">Ważne</ComboBoxItem>
                            <ComboBoxItem>Krytyczne</ComboBoxItem>
                        </ComboBox>
                        <DatePicker Grid.Row="1" Grid.Column="1" x:Name="dpTerminRealizacji" Header="Termin realizacji:" Margin="10" Language="pl-PL" MonthFormat="{}{month.full}" 
                    Date="{Binding Path=PlanowanyTerminRealizacjiNowegoZadania, Mode=TwoWay}" />
                    </Grid>
                </local:CustomContentDialogBox>
            </CommandBar.Resources>
            <AppBarButton Label="Sortuj" Icon="Sort">
                <AppBarButton.Flyout>
                    <MenuFlyout>
                        <MenuFlyoutItem Text="Sortuj wg priorytów" Command="{Binding SortujZadania}" CommandParameter="True" />
                        <MenuFlyoutItem Text="Sortuj wg terminów" Command="{Binding SortujZadania}" CommandParameter="False" />
                    </MenuFlyout>
                </AppBarButton.Flyout>
            </AppBarButton>            
            <!--<AppBarButton Label="Dodaj" Icon="Add" Click="AppBarButton_Click"/>-->
            <AppBarButton Label="Dodaj" Icon="Add" Command="{Binding ElementName=dodajZadanieDialogBox, Path=Show}" />
            <!--
            <AppBarButton Label="Usuń" Icon="Delete" Command="{Binding ElementName=notificationDialogBox1, Path=Show}" CommandParameter="Zadanie zostało usunięte" />
            -->
            <AppBarButton Label="Usuń" Icon="Delete" Command="{Binding ElementName=questionYesNo, Path=Show}" CommandParameter="Czy jesteś pewien, że chcesz usunąć zadanie?" />
            <AppBarButton Label="O..." Icon="Document" Command="{Binding ElementName=simpleMessageDialogBox, Path=Show}" CommandParameter="ZadaniaUA&#x0a;(c) Jacek Matulewski 2015&#x0a;WWW: http://www.fizyka.umk.pl/~jacek" />
        </CommandBar>        
    </Page.BottomAppBar>
</Page>

