<Window x:Class="wpf_app.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_app"
        mc:Ignorable="d"
        Title="Нагеев шоп" Height="450" Width="950">
    
    <Window.Resources>
        <BitmapImage
            x:Key='defaultImage'
            UriSource="./img/defaultPicture.jpg"/>
    </Window.Resources>

    <Grid ShowGridLines="False">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition />
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>


        <Image 
            Source="assets/nagievlogo2.jpg"
            Grid.Row="0"
            Grid.RowSpan="2"
            Stretch="Fill"/>

        <ListBox
            x:Name="productsListBox"
            Grid.Row="1"
            Grid.Column="1"
            Background="White"
            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            ItemsSource="{Binding ProductList}"
            MouseDoubleClick="productsListBox_MouseDoubleClick">
            

            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel
                        HorizontalAlignment="Center"/>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Border
                        BorderThickness="1"
                        BorderBrush="Black"
                        CornerRadius="5">
                        <Grid
                            Margin="10"
                            Width="300"
                            HorizontalAlignment="Stretch">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="64"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Image
                                Width="64"
                                Height="64"
                                Source="{Binding ImageBitmap,TargetNullValue={StaticResource defaultImage}}"/>
                            <StackPanel
                                Grid.Column="1"
                                Margin="5"
                                Orientation="Vertical"
                                VerticalAlignment="Center">
                                <TextBlock
                                    Text="{Binding Company}"/>
                                <TextBlock
                                    Text="{Binding Title}"/>
                            </StackPanel>
                            <WrapPanel
                                Grid.Column="2"
                                VerticalAlignment="Center"
                                HorizontalAlignment="Right">
                                <Label
                                    Content="Цена:"/>
                                <TextBlock
                                    Grid.Column="2"
                                    HorizontalAlignment="Right"
                                    VerticalAlignment="Center"
                                    Text="{Binding Price}"/>
                            </WrapPanel>
                        </Grid>
                    </Border>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <StackPanel 
            Orientation="Vertical"
            Grid.RowSpan="3"
            Grid.Row="2"
            VerticalAlignment="Bottom">
            <Button 
            x:Name="ExitButton"
            Content="Выход" 
            Click="ExitButton_Click"
            Height="50"/>
        </StackPanel>

        

        <WrapPanel
            Orientation="Horizontal"
            Grid.Column="1"
            MinHeight="50"
            Margin="0 5 0 0">
            <Label
                Content="Категория:"
                VerticalAlignment="Center"/>

            <ComboBox
                Name="CategoryFilterComboBox"
                SelectionChanged="CategoryFilterComboBox_SelectionChanged"
                VerticalAlignment="Center"
                MinWidth="100"
                SelectedIndex="0"
                ItemsSource="{Binding CategoryList}">

                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <Label
                            Content="{Binding title}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>

            <Label
                Content="Цена"/>
            <ComboBox
                Name ="PriceFilterComboBox"
                SelectionChanged="PriceFilterComboBox_SelectionChanged"
                VerticalAlignment="Center"
                MinWidth="100"
                SelectedIndex="0"
                ItemsSource="{Binding ProductPrices}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <Label
                            Content="{Binding title}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>

            <Label
                Content="Компания"/>
            <ComboBox
                Name ="CompanyFilterComboBox"
                SelectionChanged="CompanyFilterComboBox_SelectionChanged"
                VerticalAlignment="Center"
                MinWidth="100"
                SelectedIndex="0"
                ItemsSource="{Binding ProductCompanies}">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <Label
                            Content="{Binding title}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>

            <Label 
                Content="Поиск" 
                VerticalAlignment="Center"/>
            <TextBox
                Width="180"
                VerticalAlignment="Center"
                x:Name="SearchFilterTextBox"
                KeyUp="SearchFilterTextBox_KeyUp"/>

            <Label 
                Content="Цена:" 
                VerticalAlignment="Center"/>
            <RadioButton
                GroupName="Price"
                Tag="1"
                Content="по возрастанию"
                IsChecked="True"
                Checked="RadioButton_Checked"
                VerticalAlignment="Center"/>
            <RadioButton
                GroupName="Price"
                Tag="2"
                Content="по убыванию"
                Checked="RadioButton_Checked"
                VerticalAlignment="Center"/>
        </WrapPanel>
    </Grid>
</Window>
