<Page x:Class="Cashier.MenuPage"
      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:Cashier"
      mc:Ignorable="d" 
      d:DesignHeight="450" d:DesignWidth="800"
      Title="{Binding ElementName=TabCashier, Path=SelectedItem.Header}">

    <Grid>
        <TabControl x:Name="TabCashier" TabStripPlacement="Left">
            <TabItem Name="BtnPayment" Header="Продажа">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="2*"/>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <TextBlock Margin="5" VerticalAlignment="Bottom" HorizontalAlignment="Right">Код продукта</TextBlock>
                        <TextBox x:Name="TxtProductCode" Grid.Column="1" VerticalContentAlignment="Center" Padding="5,0,0,0" VerticalAlignment="Bottom" Height="30" Margin="5,5,20,5"></TextBox>
                        <TextBlock Margin="5" VerticalAlignment="Top" HorizontalAlignment="Right" Grid.Row="1">Количество</TextBlock>
                        <TextBox x:Name="TxtAmountProduct" Grid.Column="1" VerticalAlignment="Top" VerticalContentAlignment="Center" Padding="5,0,0,0" Grid.Row="1" Height="30" Margin="5,5,20,5"></TextBox>
                        <Button Grid.RowSpan="2" Grid.Row="1" Grid.ColumnSpan="2" Height="30" Margin="100,0,100,0" VerticalAlignment="Center" 
                                Name="BtnAddInOrder" Click="BtnAddInOrder_Click">Добавить</Button>
                    </Grid>
                    <Grid Grid.Column="1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="7*"/>
                            <RowDefinition/>
                            <RowDefinition Height="2*"/>
                        </Grid.RowDefinitions>
                        <DataGrid AutoGenerateColumns="False" Name="ProductInOrderList" Margin="5" ColumnWidth="SizeToHeader" Grid.ColumnSpan="2" CanUserAddRows="False">
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="Название"  Binding="{Binding ProductInStore.NameProduct}">
                                    <DataGridTextColumn.ElementStyle>
                                        <Style TargetType="TextBlock">
                                            <Setter Property="TextWrapping" Value="Wrap"></Setter>
                                        </Style>
                                    </DataGridTextColumn.ElementStyle>
                                </DataGridTextColumn>
                                <DataGridTextColumn Header="Кол-во" Binding="{Binding AmountProduct}"></DataGridTextColumn>
                                <DataGridTextColumn Header="Стоимость" Binding="{Binding Cost, StringFormat={}{0:F2}}"></DataGridTextColumn>
                                <DataGridTemplateColumn Width="Auto">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <Button x:Name="BtnDeleteInOrder" Click="BtnDeleteInOrder_Click" Width="30" Height="30">X</Button>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                            </DataGrid.Columns>
                        </DataGrid>
                        <TextBlock Text="Общая стоимость" Grid.Row="1" VerticalAlignment="Center" Margin="5"></TextBlock>
                        <TextBlock x:Name="TxtTotalCost" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Margin="5"></TextBlock>
                        <ComboBox Grid.Row="2" Height="30" Margin="5" Name="CmbTypeOfPayment" SelectedIndex="0"></ComboBox>
                        <Button x:Name="BtnCreateOrder" Grid.Row="2" Grid.Column="1" Height="30" Margin="10" Click="BtnCreateOrder_Click">Оплатить</Button>
                    </Grid>
                </Grid>
            </TabItem>
            <TabItem Header="Товары">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="50"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <TextBlock VerticalAlignment="Center" Margin="30,0,20,0">Поиск</TextBlock>
                        <TextBox Grid.Column="1" Name="TxtSearch" TextChanged="TxtSearch_TextChanged" VerticalContentAlignment="Center" Padding="5,0,0,0" Margin="5,10,350,10"></TextBox>
                    </Grid>
                    <ListView x:Name="ProductInStoreList" Grid.Row="1" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <Border BorderBrush="Gray" BorderThickness="1" Margin="5">
                                    <Grid Width="300" Height="120">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition/>
                                            <ColumnDefinition/>
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition/>
                                            <RowDefinition/>
                                            <RowDefinition/>
                                        </Grid.RowDefinitions>
                                        <TextBlock Text="{Binding NameProduct}" TextWrapping="Wrap" Grid.ColumnSpan="2" TextAlignment="Center" Margin="5"></TextBlock>
                                        <TextBlock Text="{Binding BarCode,StringFormat={}Код: {0}}" Grid.Row="1" Margin="5" HorizontalAlignment="Left"></TextBlock>
                                        <TextBlock Text="{Binding PriceOfOne, StringFormat={}{0:F2} руб.}" Grid.Row="1" Margin="5" HorizontalAlignment="Right" Grid.Column="1"></TextBlock>
                                    </Grid>
                                </Border>
                               
                            </DataTemplate>
                        </ListView.ItemTemplate>
                        <ListView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel></WrapPanel>
                            </ItemsPanelTemplate>
                        </ListView.ItemsPanel>
                    </ListView>
                </Grid>
            </TabItem>
        </TabControl>
    </Grid>
</Page>
