<local:AdministrationWindow
        x:Class="Elwig.Windows.DeliveryScheduleAdminWindow"
        AutomationProperties.AutomationId="DeliveryScheduleAdminWindow"
        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:local="clr-namespace:Elwig.Windows"
        xmlns:vm="clr-namespace:Elwig.ViewModels"
        xmlns:ctrl="clr-namespace:Elwig.Controls"
        Title="Leseplanung - Elwig" Height="600" Width="850" MinHeight="450" MinWidth="800"
        Loaded="Window_Loaded">
    <Window.DataContext>
        <vm:DeliveryScheduleAdminViewModel/>
    </Window.DataContext>
    <Window.Resources>
        <Style TargetType="Label">
            <Setter Property="HorizontalAlignment" Value="Left"/>
            <Setter Property="VerticalAlignment" Value="Top"/>
            <Setter Property="Padding" Value="2,4,2,4"/>
            <Setter Property="Height" Value="25"/>
        </Style>
        <Style TargetType="TextBox">
            <Setter Property="HorizontalAlignment" Value="Stretch"/>
            <Setter Property="VerticalAlignment" Value="Top"/>
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="Padding" Value="2"/>
            <Setter Property="Height" Value="25"/>
            <Setter Property="TextWrapping" Value="NoWrap"/>
        </Style>
        <Style TargetType="ctrl:UnitTextBox">
            <Setter Property="HorizontalAlignment" Value="Stretch"/>
            <Setter Property="VerticalAlignment" Value="Top"/>
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="Padding" Value="2"/>
            <Setter Property="Height" Value="25"/>
            <Setter Property="TextWrapping" Value="NoWrap"/>
        </Style>
        <Style TargetType="ComboBox">
            <Setter Property="Height" Value="25"/>
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="HorizontalAlignment" Value="Stretch"/>
            <Setter Property="VerticalAlignment" Value="Top"/>
        </Style>
        <Style TargetType="ctrl:CheckComboBox">
            <Setter Property="Height" Value="25"/>
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="HorizontalAlignment" Value="Stretch"/>
            <Setter Property="VerticalAlignment" Value="Top"/>
        </Style>
        <Style TargetType="Button">
            <Setter Property="FontSize" Value="14"/>
            <Setter Property="Padding" Value="9,3"/>
            <Setter Property="Height" Value="27"/>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="19"/>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="24"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*" MinWidth="350"/>
            <ColumnDefinition Width="5"/>
            <ColumnDefinition Width="1*" MinWidth="400"/>
        </Grid.ColumnDefinitions>

        <Menu Grid.ColumnSpan="3" BorderThickness="0,0,0,1" BorderBrush="LightGray" Background="White">
        </Menu>

        <Grid Grid.Row="1" Margin="5,0,0,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="35"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="42"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <TextBox x:Name="SearchInput" Text="{Binding SearchQuery, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding EnableSearchInputs}"
                     Grid.ColumnSpan="3" Margin="5,5,174,0" IsReadOnly="False"
                     TextChanged="SearchInput_TextChanged">
                <TextBox.ToolTip>
                    <TextBlock>
                        <Bold>Strg+F</Bold><LineBreak/><LineBreak/>
                        Lesepläne filtern und durchsuchen. Die Filter sind beliebig kombinierbar.<LineBreak/>
                        Groß- und Kleinschreibung ist in den meisten Fällen egal.<LineBreak/>
                        <LineBreak/>
                        Filtern nach:<LineBreak/>
                        <Bold>Sorte</Bold>: z.B. GV, ZW, rr, sa, !gv (ausgenommen GV), ...<LineBreak/>
                        <Bold>Rot/Weiß</Bold>: z.B. r, Rot, w, weiß, ...<LineBreak/>
                        <Bold>Zweigstelle</Bold>: z.B. musterort, ...<LineBreak/>
                        <Bold>Datum</Bold>: z.B. 1.9., 15.9.-10.10., -15.10.2020, ...<LineBreak/>
                        <Bold>Beschreibung</Bold>: z.B. Bio, ...
                    </TextBlock>
                </TextBox.ToolTip>
            </TextBox>
            <ctrl:IntegerUpDown x:Name="SeasonInput" Text="{Binding FilterSeasonString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding EnableSearchInputs}"
                                Grid.ColumnSpan="3" Height="25" Width="56" FontSize="14" Minimum="1900" Maximum="9999"
                                Margin="5,5,113,0" VerticalAlignment="Top" HorizontalAlignment="Right"
                                TextChanged="SeasonInput_TextChanged"/>
            <CheckBox x:Name="OnlyUpcomingInput" Content="Nur zukünftige" IsChecked="{Binding FilterOnlyUpcoming, Mode=TwoWay}" IsEnabled="{Binding EnableSearchInputs}"
                      HorizontalAlignment="Right" Margin="0,10,10,0" VerticalAlignment="Top" Grid.Column="0" Grid.ColumnSpan="3"
                      Checked="OnlyUpcomingInput_Changed" Unchecked="OnlyUpcomingInput_Changed"/>

            <DataGrid x:Name="DeliveryScheduleList" AutoGenerateColumns="False" HeadersVisibility="Column" IsReadOnly="True" GridLinesVisibility="None" SelectionMode="Single"
                      ItemsSource="{Binding DeliverySchedules, Mode=TwoWay}" SelectedItem="{Binding SelectedDeliverySchedule, Mode=TwoWay}"
                      CanUserDeleteRows="False" CanUserResizeRows="False" CanUserAddRows="False"
                      SelectionChanged="DeliveryScheduleList_SelectionChanged"
                      Margin="5,0,5,0" Grid.Row="1" FontSize="14" Grid.ColumnSpan="3">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Datum" Binding="{Binding Date, StringFormat='dd.MM.yy'}" Width="70">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Center"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Z." Binding="{Binding ZwstId}" Width="25">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Center"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Beschreibung" Binding="{Binding Description}" Width="200"/>
                    <DataGridTextColumn Header="Max. Mg." Binding="{Binding MaxWeight, StringFormat='{}{0:N0} kg'}" Width="80">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Right"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                </DataGrid.Columns>
            </DataGrid>

            <Button x:Name="NewDeliveryScheduleButton" Content="Neu" Visibility="{Binding ControlButtonsVisibility}"
                    HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="5,5,2.5,10" Grid.Column="0" Grid.Row="2"
                    Click="NewDeliveryScheduleButton_Click">
                <Button.ToolTip>
                    <TextBlock FontWeight="Bold">Alt+Einfg</TextBlock>
                </Button.ToolTip>
            </Button>
            <Button x:Name="EditDeliveryScheduleButton" Content="Bearbeiten" IsEnabled="False" Visibility="{Binding ControlButtonsVisibility}"
                    HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="2.5,5,2.5,10" Grid.Column="1" Grid.Row="2"
                    Click="EditDeliveryScheduleButton_Click">
                <Button.ToolTip>
                    <TextBlock FontWeight="Bold">Strg+B</TextBlock>
                </Button.ToolTip>
            </Button>
            <Button x:Name="DeleteDeliveryScheduleButton" Content="Löschen" IsEnabled="False" Visibility="{Binding ControlButtonsVisibility}"
                    HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="2.5,5,5,10" Grid.Column="2" Grid.Row="2"
                    Click="DeleteDeliveryScheduleButton_Click">
                <Button.ToolTip>
                    <TextBlock FontWeight="Bold">Alt+Entf</TextBlock>
                </Button.ToolTip>
            </Button>

            <Button x:Name="SaveButton" Content="Speichern" IsEnabled="False" Visibility="{Binding EditingButtonsVisibility}"
                    HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="5,5,2.5,10" Grid.Column="0" Grid.Row="2"
                    Click="SaveButton_Click">
                <Button.ToolTip>
                    <TextBlock FontWeight="Bold">Strg+S</TextBlock>
                </Button.ToolTip>
            </Button>
            <Button x:Name="ResetButton" Content="Zurücksetzen" IsEnabled="False" Visibility="{Binding EditingButtonsVisibility}"
                    HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="2.5,5,2.5,10" Grid.Column="1" Grid.Row="2"
                    Click="ResetButton_Click">
                <Button.ToolTip>
                    <TextBlock FontWeight="Bold">Strg+Z</TextBlock>
                </Button.ToolTip>
            </Button>
            <Button x:Name="CancelButton" Content="Abbrechen" IsEnabled="False" Visibility="{Binding EditingButtonsVisibility}" IsCancel="True"
                    HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="2.5,5,5,10" Grid.Column="2" Grid.Row="2"
                    Click="CancelButton_Click">
                <Button.ToolTip>
                    <TextBlock FontWeight="Bold">Esc</TextBlock>
                </Button.ToolTip>
            </Button>
        </Grid>

        <GridSplitter Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>

        <Grid Grid.Column="2" Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="1.5*"/>
                <RowDefinition/>
            </Grid.RowDefinitions>

            <GroupBox Header="Leseplan" Margin="5,5,5,5">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="110"/>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>

                    <Label Content="Datum/Zwst.:" Margin="10,10,0,10"/>
                    <TextBox x:Name="DateInput" Text="{Binding DateString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Margin="0,10,10,10" Width="77" Grid.Column="1" Grid.ColumnSpan="2" HorizontalAlignment="Left" TextAlignment="Right"
                             TextChanged="ScheduleDateInput_TextChanged" LostFocus="DateInput_LostFocus"/>
                    <ComboBox x:Name="BranchInput" SelectedItem="{Binding Branch, Mode=TwoWay}" ItemsSource="{Binding BranchSource, Mode=TwoWay}"
                              DisplayMemberPath="Name" TextSearch.TextPath="Name"
                              Margin="82,10,10,10" Width="150" Grid.Column="1" Grid.ColumnSpan="2" HorizontalAlignment="Left"/>

                    <Label Content="Beschreibung:" Margin="10,40,0,10"/>
                    <TextBox x:Name="DescriptionInput" Text="{Binding Description, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Margin="0,40,10,10" Grid.Column="1" Grid.ColumnSpan="2"
                             TextChanged="TextBox_TextChanged"/>

                    <Label Content="Max. Menge:" Margin="10,70,0,10"/>
                    <ctrl:UnitTextBox x:Name="MaxWeightInput" Unit="kg" Text="{Binding MaxWeightString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                      Margin="0,70,10,10" Grid.Column="1" Grid.ColumnSpan="2" Width="68" HorizontalAlignment="Left"
                                      TextChanged="MaxWeightInput_TextChanged"/>

                    <CheckBox x:Name="CancelledInput" Content="Abgesagt" IsChecked="{Binding IsCancelled, Mode=TwoWay}"
                              Grid.Column="1" Grid.ColumnSpan="2" Margin="80,75,0,0" VerticalAlignment="Top" HorizontalAlignment="Left"
                              Checked="CheckBox_Changed" Unchecked="CheckBox_Changed"/>

                    <Label Content="Sorten:" Margin="10,100,0,10"/>
                    <ctrl:CheckComboBox x:Name="MainWineVarietiesInput" SelectedItems="{Binding MainVarieties}" ItemsSource="{Binding MainVarietiesSource, Mode=TwoWay}"
                                        Grid.Column="1" Grid.ColumnSpan="2" Margin="0,100,10,10"
                                        Delimiter=", " AllItemsSelectedContent="Alle Sorten" ListDisplayMemberPath="SortId" TextSearch.TextPath="Name">
                        <ctrl:CheckComboBox.ItemTemplateSelector>
                            <ctrl:WineVarietyTemplateSelector/>
                        </ctrl:CheckComboBox.ItemTemplateSelector>
                    </ctrl:CheckComboBox>

                    <Label Content="Weitere Sorten:" Margin="10,130,0,10"/>
                    <ctrl:CheckComboBox x:Name="OtherWineVarietiesInput" SelectedItems="{Binding OtherVarieties}" ItemsSource="{Binding OtherVarietiesSource, Mode=TwoWay}"
                                        Grid.Column="1" Grid.ColumnSpan="2" Margin="0,130,10,10"
                                        Delimiter=", " AllItemsSelectedContent="Alle Sorten" ListDisplayMemberPath="SortId" TextSearch.TextPath="Name">
                        <ctrl:CheckComboBox.ItemTemplateSelector>
                            <ctrl:WineVarietyTemplateSelector/>
                        </ctrl:CheckComboBox.ItemTemplateSelector>
                    </ctrl:CheckComboBox>

                    <Label Content="Attribut/Bewirt.:" Margin="10,160,0,10"/>
                    <ComboBox x:Name="AttributeInput" SelectedItem="{Binding AttributeObj, Mode=TwoWay}" ItemsSource="{Binding AttributeSource, Mode=TwoWay}"
                              Grid.Column="1" Margin="0,160,5,10"
                              DisplayMemberPath="Name"/>
                    <ComboBox x:Name="CultivationInput" SelectedItem="{Binding CultivationObj, Mode=TwoWay}" ItemsSource="{Binding CultivationSource, Mode=TwoWay}"
                              Grid.Column="2" Margin="0,160,10,10"
                              DisplayMemberPath="Name"/>
                </Grid>
            </GroupBox>

            <GroupBox Header="Anmeldungen" Margin="5,5,5,5" Grid.Row="1" Width="249" Height="98"
                      VerticalAlignment="Top" HorizontalAlignment="Left">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="100"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>

                    <Label Content="ab frühestens:" Margin="10,10,0,10"/>
                    <TextBox x:Name="AncmtFromDateInput" Text="{Binding AncmtFromDateString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Width="77" Margin="0,10,10,10" Grid.Column="1" HorizontalAlignment="Left" TextAlignment="Right"
                             TextChanged="DateInput_TextChanged" LostFocus="DateInput_LostFocus"/>
                    <TextBox x:Name="AncmtFromTimeInput" Text="{Binding AncmtFromTimeString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Width="44" Margin="83,10,10,10" Grid.Column="1" HorizontalAlignment="Left"
                             TextChanged="TimeInput_TextChanged" LostFocus="TimeInput_LostFocus"/>

                    <Label Content="bis spätestens:" Margin="10,40,0,10"/>
                    <TextBox x:Name="AncmtToDateInput" Text="{Binding AncmtToDateString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Width="77" Margin="0,40,10,10" Grid.Column="1" HorizontalAlignment="Left" TextAlignment="Right"
                             TextChanged="DateInput_TextChanged" LostFocus="DateInput_LostFocus"/>
                    <TextBox x:Name="AncmtToTimeInput" Text="{Binding AncmtToTimeString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Width="44" Margin="83,40,10,10" Grid.Column="1" HorizontalAlignment="Left"
                             TextChanged="TimeInput_TextChanged" LostFocus="TimeInput_LostFocus"/>
                </Grid>
            </GroupBox>
        </Grid>

        <StatusBar Grid.Row="2" Grid.ColumnSpan="3" BorderThickness="0,1,0,0" BorderBrush="Gray">
            <StatusBar.ItemsPanel>
                <ItemsPanelTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="150"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="200"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="1*"/>
                        </Grid.ColumnDefinitions>
                    </Grid>
                </ItemsPanelTemplate>
            </StatusBar.ItemsPanel>
            <StatusBarItem>

            </StatusBarItem>
        </StatusBar>
    </Grid>
</local:AdministrationWindow>
