<?xml version="1.0" encoding="utf-8"?>
<Page
    x:Class="TodoXaml.Views.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TodoXaml.Views"
    xmlns:titem="using:TodoXaml.Models"
    xmlns:conv="using:TodoXaml.Converters"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Page.Resources>
        <conv:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
        <local:PriorityToBrushConverter x:Key="PriorityToBrushConverter"/>
        <conv:PriorityToIndexConverter x:Key="PriorityToIndexConverter"/>
    </Page.Resources>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="500" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <!-- BAL OLDAL: lista -->
        <StackPanel Background="{ThemeResource AppBarBackgroundThemeBrush}"
                    Grid.Column="0" Margin="20">
            <CommandBar VerticalContentAlignment="Center"
                        Background="{ThemeResource AppBarBackgroundThemeBrush}"
                        DefaultLabelPosition="Right">
                <CommandBar.Content>
                    <TextBlock Margin="12,0,0,0"
                               Style="{ThemeResource SubtitleTextBlockStyle}"
                               Text="To-Dos" />
                </CommandBar.Content>
                <AppBarButton Icon="Add"
                              Label="Add"
                              Click="OnAddClicked"/>
            </CommandBar>

            <ListView x:Name="TodoListView"
                      ItemsSource="{x:Bind Todos}"
                      Margin="0,20,0,0"
                      SelectionMode="Single"
                      Background="{ThemeResource AppBarBackgroundThemeBrush}">
                <ListView.ItemTemplate>
                    <DataTemplate x:DataType="titem:TodoItem">
                        <Grid Margin="10">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <StackPanel>
                                <TextBlock Text="{x:Bind Title, Mode=OneWay}"
                                           FontWeight="SemiBold"
                                           Foreground="{x:Bind Priority, Converter={StaticResource PriorityToBrushConverter}}"/>
                                <TextBlock Text="{x:Bind Description, Mode=OneWay}"
                                           Opacity="0.7"/>
                                <TextBlock Text="{x:Bind Deadline.ToString('yyyy.MM.dd', x:Null)}"
                                           FontSize="12"/>
                            </StackPanel>
                            <SymbolIcon Grid.Column="1"
                                        Symbol="Accept"
                                        VerticalAlignment="Center"
                                        Visibility="{x:Bind IsDone, Converter={StaticResource BoolToVisibilityConverter}}"/>
                        </Grid>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </StackPanel>

        <!-- JOBB OLDAL: fejléc + űrlap -->
        <Grid Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <TextBlock Grid.Row="0"
                       Text="To-Do item"
                       FontSize="25"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Center"
                       Margin="20,0,0,0"/>

            <ScrollViewer Grid.Row="1"
                          Margin="8,0,8,8"
                          Visibility="{x:Bind IsFormVisible, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}">
                <StackPanel Spacing="15"
                            Padding="10,15,10,15"
                            BorderThickness="1"
                            BorderBrush="LightGray">

                    <TextBox Header="Title"
                             Text="{x:Bind NewItem.Title, Mode=TwoWay}"/>

                    <TextBox Header="Description"
                             AcceptsReturn="True"
                             Height="160"
                             TextWrapping="Wrap"
                             ScrollViewer.VerticalScrollBarVisibility="Auto"
                             Text="{x:Bind NewItem.Description, Mode=TwoWay}"/>

                    <DatePicker Header="Deadline"
                                Language="en-US"
                                HorizontalAlignment="Left"
                                Date="{x:Bind NewItem.Deadline, Mode=TwoWay}"/>

                    <ComboBox Header="Priority"
          SelectedIndex="{x:Bind NewItem.Priority, Mode=TwoWay, Converter={StaticResource PriorityToIndexConverter}}">
                        <ComboBoxItem Content="Low"/>
                        <ComboBoxItem Content="Normal"/>
                        <ComboBoxItem Content="High"/>
                    </ComboBox>

                    <CheckBox Content="Is Done"
                              IsChecked="{x:Bind NewItem.IsDone, Mode=TwoWay}"/>

                    <Button Content="Save"
                            HorizontalAlignment="Right"
                            Style="{StaticResource AccentButtonStyle}"
                            Click="OnSaveClicked"/>
                </StackPanel>
            </ScrollViewer>
        </Grid>
    </Grid>
</Page>