<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}">
    <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" />
                            <Button Content="Niezrealizowane" Command="{Binding Path=OznaczJakoNiezrealizowane}" 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>
            <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" />
            <AppBarButton Label="Usuń" Icon="Delete" Command="{Binding UsuńZadanie}" />
        </CommandBar>
    </Page.BottomAppBar>
</Page>

