<Page x:Class="SergechevExam.ProductList"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:SergechevExam"
      mc:Ignorable="d" 
      d:DesignHeight="450" d:DesignWidth="800"
      Title="ProductList">

    <Page.Resources>
        <BitmapImage x:Key="defaultImage" UriSource="/Resources/nolog.png"></BitmapImage>
    </Page.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>

        <TextBlock Text="Список товаров" FontSize="18" FontWeight="Bold" VerticalAlignment="Center" Margin="5"></TextBlock>

        <Button Name="openShoppingCart" Content="Корзина" Width="150" Height="50" Grid.Row="0" Margin="5" Visibility="Collapsed" Click="openShoppingCart_Click"></Button>

        <ListView Name="productList" Grid.Row="1" Background="Transparent" HorizontalContentAlignment="Stretch">
            <ListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Name="addToCart" Header="Добавить в корзину" Click="addToCart_Click"></MenuItem>
                </ContextMenu>
            </ListView.ContextMenu>

            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel></StackPanel>
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>

            <ListView.ItemTemplate>
                <DataTemplate>
                    <DockPanel>
                        <Image Source="{Binding Photo_Product, TargetNullValue={StaticResource defaultImage}, FallbackValue={StaticResource defaultImage}}" DockPanel.Dock="Left" Width="150"></Image>
                        <StackPanel DockPanel.Dock="Top">
                            <TextBlock Text="{Binding Name_Product}"></TextBlock>
                            <TextBlock Text="{Binding Description_Product}"></TextBlock>

                            <WrapPanel>
                                <TextBlock Text="Производитель:" Margin="0,0,5,0"></TextBlock>
                                <TextBlock Text="{Binding Manufacturer.Name_Manufacturer}"></TextBlock>
                            </WrapPanel>

                            <WrapPanel>
                                <TextBlock Text="Цена:" Margin="0,0,5,0"></TextBlock>
                                <TextBlock Uid="{Binding Code_Product}" Name="oldPrice" Margin="0,0,5,0" Text="{Binding Price_Product}" Visibility="Collapsed" TextDecorations="Strikethrough" Loaded="oldPrice_Loaded"></TextBlock>
                                <TextBlock Uid="{Binding Code_Product}" Name="mainPrice" Loaded="mainPrice_Loaded"></TextBlock>
                            </WrapPanel>
                        </StackPanel>

                        <TextBlock Uid="{Binding Code_Product}" Name="discount" Visibility="Collapsed" Text="{Binding Discount_Product}" Loaded="discount_Loaded" HorizontalAlignment="Right" DockPanel.Dock="Top" VerticalAlignment="Center"></TextBlock>
                    </DockPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
        
    </Grid>
</Page>
