<Window x:Class="WPF.Framework.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:WPF.Framework" xmlns:viewmodels="clr-namespace:WPF.Framework.ViewModels" xmlns:converters="clr-namespace:WPF.Framework.Converters"
        mc:Ignorable="d"
        Title="Приятный шелест" Height="450" Width="800"
        Icon="Resources/Icon.ico">
    <Window.DataContext>
        <viewmodels:AgentsViewModel/>
    </Window.DataContext>
    <Window.Resources>
        <converters:ListSortDirectionToStringConverter x:Key="ListSortDirectionToStringConverter"/>
    </Window.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>

        <Grid Grid.Row="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="2*"/>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="1*"/>
            </Grid.ColumnDefinitions>
            <StackPanel Orientation="Horizontal"
                        Margin="10">
                <Image Source="Resources/Приятный шелест.png" 
                       MaxWidth="50"
                       Margin="0 0 10 0"/>
                <TextBlock Text="Список агентов"
                           VerticalAlignment="Center"
                           FontSize="24"/>
            </StackPanel>
            <TextBox Grid.Column="1"
                     VerticalAlignment="Center"
                     Margin="5"
                     Padding="2"
                     Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}"/>
            <Button Grid.Column="2"
                    Padding="4 2"
                    VerticalAlignment="Center"
                    Content="{Binding CurrentListSortDirection, Converter={StaticResource ListSortDirectionToStringConverter}, FallbackValue='/\\'}"
                    Command="{Binding ListDirectionCommand}">
            </Button>
            <ComboBox Grid.Column="3"
                      VerticalAlignment="Center"
                      Margin="5"
                      SelectedIndex="0"
                      SelectedValue="{Binding CurrentSortingAgentProperty}"
                      ItemsSource="{Binding AgentsSortingDictionary}"
                      SelectedValuePath="Key"
                      DisplayMemberPath="Value"/>
            <ComboBox Grid.Column="4"
                      VerticalAlignment="Center"
                      Margin="5"
                      SelectedIndex="0"
                      SelectedValue="{Binding CurrentAgentTypeFilter}"
                      ItemsSource="{Binding AgentTypesFilterDictionary}"
                      SelectedValuePath="Key"
                      DisplayMemberPath="Value"/>
        </Grid>

        <Grid Grid.Row="1">
            <ListBox x:Name="ListBox"
                     ItemsSource="{Binding AgentsCollectionView}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="1*"/>
                                <ColumnDefinition Width="5*"/>
                                <ColumnDefinition Width="auto"/>
                            </Grid.ColumnDefinitions>
                                <Image Grid.Column="0"
                                   Source="{Binding Logo, FallbackValue='Resource/no_picture.png', TargetNullValue='Resource/no_picture.png'}"
                                   Width="150"/>
                                <StackPanel Grid.Column="1"
                                            Margin="10">
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding AgentType.Title, StringFormat='{}{0} | '}"/>
                                        <TextBlock Text="{Binding Title}"/>
                                    </StackPanel>
                                    <TextBlock Text="{Binding ProductSaledLastYear, StringFormat='{}{0} продаж за год', FallbackValue='Продажи не найдены'}"/>
                                    <TextBlock Text="{Binding Phone}"/>
                                    <TextBlock Text="{Binding Priority, StringFormat='Приоритетность: {0}'}"/>
                                </StackPanel>
                            <TextBlock Grid.Column="2"
                                       Text="{Binding Discount, StringFormat='{}{0} %', FallbackValue='Скидка не найдена'}"
                                       FontSize="24"
                                       HorizontalAlignment="Right"/>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>

        <Grid Grid.Row="2"
              Margin="5">
            <StackPanel Orientation="Horizontal">
                <Button Content="Назад"/>
                <TextBlock Text="{Binding CurrentPage, StringFormat='  {0} из', FallbackValue='  {0} из'}"/>
                <TextBlock  Text="{Binding ItemsSource.Count, ElementName=ListBox, StringFormat=' {}{0}', FallbackValue=' {0}  '}"/>
                <Button Content="Вперед"/>
            </StackPanel>
        </Grid>
    </Grid>
</Window>
