<local:AdministrationWindow
        x:Class="Elwig.Windows.DeliveryAncmtAdminWindow"
        AutomationProperties.AutomationId="DeliveryAncmtWindow"
        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:Elwig.Windows"
        xmlns:vm="clr-namespace:Elwig.ViewModels"
        xmlns:ctrl="clr-namespace:Elwig.Controls"
        Title="Anmeldungen - Elwig" Height="700" Width="980" MinWidth="600" MinHeight="400"
        Loaded="Window_Loaded">
    <Window.DataContext>
        <vm:DeliveryAncmtAdminViewModel/>
    </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.25*" MinWidth="250"/>
            <ColumnDefinition Width="5"/>
            <ColumnDefinition Width="1*" MinWidth="300"/>
        </Grid.ColumnDefinitions>

        <Menu Grid.ColumnSpan="3" BorderThickness="0,0,0,1" BorderBrush="LightGray" Background="White">
            <MenuItem Header="Anmeldeliste">
                <MenuItem x:Name="Menu_DeliveryAncmtList_SaveSelected" Header="...von ausgewähltem Leseplan speichern... (Excel)"
                          Click="Menu_DeliveryAncmtList_SaveSelected_Click">
                    <MenuItem.Icon>
                        <TextBlock FontFamily="Segoe MDL2 Assets" FontSize="16" Text="&#xE9F9;"/>
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem x:Name="Menu_DeliveryAncmtList_ShowSelected" Header="...von ausgewähltem Leseplan anzeigen (PDF)"
                          Click="Menu_DeliveryAncmtList_ShowSelected_Click" InputGestureText="Strg+P">
                    <MenuItem.Icon>
                        <TextBlock FontFamily="Segoe MDL2 Assets" FontSize="16" Text="&#xE8FF;"/>
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem x:Name="Menu_DeliveryAncmtList_SavePdfSelected" Header="...von ausgewähltem Leseplan speichern... (PDF)"
                          Click="Menu_DeliveryAncmtList_SavePdfSelected_Click">
                    <MenuItem.Icon>
                        <TextBlock FontFamily="Segoe MDL2 Assets" FontSize="16" Text="&#xEA90;"/>
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem x:Name="Menu_DeliveryAncmtList_PrintSelected" Header="...von ausgewähltem Leseplan drucken"
                          Click="Menu_DeliveryAncmtList_PrintSelected_Click" InputGestureText="Strg+Shift+P">
                    <MenuItem.Icon>
                        <TextBlock FontFamily="Segoe MDL2 Assets" FontSize="16" Text="&#xE749;"/>
                    </MenuItem.Icon>
                </MenuItem>
            </MenuItem>
        </Menu>

        <Grid Grid.Row="1" Margin="5,0,0,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="42"/>
                <RowDefinition Height="1*" MinHeight="100"/>
                <RowDefinition Height="5"/>
                <RowDefinition Height="1*" MinHeight="100"/>
                <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,10,174,0" IsReadOnly="False"
                     TextChanged="SearchInput_TextChanged">
                <TextBox.ToolTip>
                    <TextBlock>
                        <Bold>Strg+F</Bold><LineBreak/><LineBreak/>
                        Anmeldungen 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>Mitglied</Bold>: z.B. 1234, 987, ...<LineBreak/>
                        <Bold>Zweigstelle</Bold>: z.B. musterort, ...<LineBreak/>
                        <Bold>Attribut</Bold>: z.B. kabinett, !kabinett (alle außer kabinett), ...<LineBreak/>
                        <Bold>Bewirtschaftung</Bold>: z.B. bio, !kip (alle außer KIP), ...<LineBreak/>
                        <Bold>Menge</Bold>: z.B. &lt;500kg, &gt;6000kg, ...<LineBreak/>
                        <Bold>Datum</Bold>: z.B. 1.9., 15.9.-10.10., -15.10.2020, ...
                    </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,10,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,7,10,0" VerticalAlignment="Top" Grid.Column="0" Grid.ColumnSpan="3"
                      Checked="OnlyUpcomingInput_Changed" Unchecked="OnlyUpcomingInput_Changed"/>
            <CheckBox x:Name="FromAllSchedulesInput" Content="Alle Lesepläne" IsChecked="{Binding FilterFromAllSchedules, Mode=TwoWay}" IsEnabled="{Binding EnableSearchInputs}"
                      HorizontalAlignment="Right" Margin="0,24,13.5,0" VerticalAlignment="Top" Grid.Column="0" Grid.ColumnSpan="3"
                      Checked="FromAllSchedulesInput_Changed" Unchecked="FromAllSchedulesInput_Changed"/>

            <ListBox x:Name="DeliveryScheduleList" SelectedItem="{Binding SelectedDeliverySchedule, Mode=TwoWay}" ItemsSource="{Binding DeliverySchedules, Mode=TwoWay}"
                     Grid.Row="1" Grid.ColumnSpan="3" Margin="5,0,5,5" VerticalAlignment="Stretch" IsEnabled="{Binding EnableSearchInputs}"
                     SelectionChanged="DeliveryScheduleList_SelectionChanged">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Date, StringFormat='ddd.'}" Width="24"/>
                            <TextBlock Text="{Binding Date, StringFormat='dd.MM.'}" Width="32"/>
                            <TextBlock Text="{Binding ZwstId}" Width="25" TextAlignment="Center"/>
                            <TextBlock Text="{Binding Description}" Width="200" TextDecorations="{Binding TextDecoration}"/>
                            <TextBlock TextAlignment="Right">
                                <TextBlock Text="{Binding AnnouncedWeight, StringFormat='{}{0:N0}'}" Width="42" TextAlignment="Right"/> kg
                                / <TextBlock Text="{Binding MaxWeight, StringFormat='{}{0:N0}'}" Width="42" TextAlignment="Right"/> kg
                                (<TextBlock Text="{Binding Percent, StringFormat='{}{0:N0}'}" Width="20" TextAlignment="Right"/>%)
                            </TextBlock>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

            <GridSplitter Grid.Row="2" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>

            <DataGrid x:Name="DeliveryAncmtList" AutoGenerateColumns="False" HeadersVisibility="Column" IsReadOnly="True" GridLinesVisibility="None" SelectionMode="Single"
                      ItemsSource="{Binding DeliveryAncmts, Mode=TwoWay}" SelectedItem="{Binding SelectedDeliveryAncmt, Mode=TwoWay}"
                      CanUserDeleteRows="False" CanUserResizeRows="False" CanUserAddRows="False"
                      SelectionChanged="DeliveryAncmtList_SelectionChanged"
                      Margin="5,5,5,0" Grid.Row="3" FontSize="14" Grid.ColumnSpan="3">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Datum" Binding="{Binding Schedule.Date, StringFormat='{}{0:dd.MM.yy}'}" Width="60">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Center"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="MgNr." Binding="{Binding MgNr, StringFormat='{}{0} '}" Width="50">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Right"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Mitglied" Binding="{Binding Member.AdministrativeName}" Width="160"/>
                    <DataGridTextColumn Header="Sorte" Binding="{Binding SortId}" Width="50">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.Foreground" Value="{Binding Variety.Color}"/>
                                <Setter Property="TextBlock.TextAlignment" Value="Center"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Menge" Binding="{Binding Weight, StringFormat='{}{0:N0} kg'}" Width="75">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Right"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Angemeldet" Binding="{Binding CreatedAt, StringFormat='{}{0:HH:mm, dd.MM.}'}" Width="100">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Center"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                </DataGrid.Columns>
            </DataGrid>

            <Button x:Name="NewDeliveryAncmtButton" Content="Neu" Visibility="{Binding ControlButtonsVisibility}"
                    HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="5,5,2.5,10" Grid.Column="0" Grid.Row="4"
                    Click="NewDeliveryAncmtButton_Click">
                <Button.ToolTip>
                    <TextBlock FontWeight="Bold">Alt+Einfg</TextBlock>
                </Button.ToolTip>
            </Button>
            <Button x:Name="EditDeliveryAncmtButton" Content="Bearbeiten" IsEnabled="False" Visibility="{Binding ControlButtonsVisibility}"
                    HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="2.5,5,2.5,10" Grid.Column="1" Grid.Row="4"
                    Click="EditDeliveryAncmtButton_Click">
                <Button.ToolTip>
                    <TextBlock FontWeight="Bold">Strg+B</TextBlock>
                </Button.ToolTip>
            </Button>
            <Button x:Name="DeleteDeliveryAncmtButton" Content="Löschen" IsEnabled="False" Visibility="{Binding ControlButtonsVisibility}"
                    HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="2.5,5,5,10" Grid.Column="2" Grid.Row="4"
                    Click="DeleteDeliveryAncmtButton_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="4"
                    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="4"
                    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="4"
                    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="2*"/>
                <RowDefinition Height="3*"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <GroupBox Header="Mitglied" Grid.Row="0" Margin="5,5,5,5">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="70"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>

                    <Label Content="Mitglied:" Margin="10,10,0,0" Grid.Column="0"/>
                    <TextBox x:Name="MgNrInput" Text="{Binding MgNrString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Width="48" Grid.Row="1" Grid.Column="1" Margin="0,10,0,0" HorizontalAlignment="Left" TextAlignment="Right"
                             TextChanged="MgNrInput_TextChanged" LostFocus="MgNrInput_LostFocus" KeyUp="Input_KeyUp"/>
                    <ComboBox x:Name="MemberInput" SelectedItem="{Binding Member, Mode=TwoWay}" ItemsSource="{Binding MemberSource, Mode=TwoWay}"
                              Grid.Column="1" Margin="53,10,40,10" IsEditable="True"
                              ItemTemplate="{StaticResource MemberAdminNameTemplate}" TextSearch.TextPath="AdministrativeName"
                              SelectionChanged="MemberInput_SelectionChanged" KeyUp="Input_KeyUp"/>
                    <Button x:Name="MemberReferenceButton" Grid.Column="1" Height="25" Width="25" FontFamily="Segoe MDL2 Assets" Content="&#xEE35;" Padding="0,0,0,0"
                            Margin="10,10,10,10" VerticalAlignment="Top" HorizontalAlignment="Right" ToolTip="Zu Mitglied springen"
                            Click="MemberReferenceButton_Click"/>

                    <Label Content="Wohnort:" Margin="10,38,0,0" Grid.Column="0"/>
                    <TextBox x:Name="MemberAddressField" Text="{Binding MemberAddress}"
                             Grid.Column="1" Margin="0,40,10,10" FontSize="12" Height="22"
                             IsReadOnly="True" IsTabStop="False"/>
                </Grid>
            </GroupBox>

            <GroupBox Header="Anmeldung" Grid.Row="1" Margin="5,5,5,5">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="70"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>

                    <Label Content="Leseplan:" Margin="10,10,0,0" Grid.Column="0"/>
                    <ComboBox x:Name="DeliveryScheduleInput" SelectedItem="{Binding DeliverySchedule, Mode=TwoWay}" ItemsSource="{Binding DeliveryScheduleSource, Mode=TwoWay}"
                              Grid.Column="1" Margin="0,10,10,10"
                              TextSearch.TextPath="Name"
                              SelectionChanged="DeliveryScheduleInput_SelectionChanged">
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Date, StringFormat='ddd.'}" Width="28"/>
                                    <TextBlock Text="{Binding Date, StringFormat='dd.MM.'}" Width="35"/>
                                    <TextBlock Text="{Binding ZwstId}" Width="30" TextAlignment="Center"/>
                                    <TextBlock Text="{Binding Description}" TextDecorations="{Binding TextDecoration}"/>
                                </StackPanel>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>

                    <Label Content="Sorte:" Margin="10,40,0,0" Grid.Column="0"/>
                    <TextBox x:Name="SortIdInput" Text="{Binding SortId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="{Binding WineVariety.Color}"
                             Width="36" Grid.Row="1" Grid.Column="1" Margin="0,40,0,0" HorizontalAlignment="Left"
                             TextChanged="SortIdInput_TextChanged" LostFocus="SortIdInput_LostFocus" KeyUp="Input_KeyUp"/>
                    <ComboBox x:Name="WineVarietyInput" SelectedItem="{Binding WineVariety, Mode=TwoWay}" ItemsSource="{Binding WineVarietySource, Mode=TwoWay}"
                              Grid.Column="1" Margin="41,40,10,10"
                              TextSearch.TextPath="Name"
                              SelectionChanged="WineVarietyInput_SelectionChanged" KeyUp="Input_KeyUp">
                        <ComboBox.ItemTemplateSelector>
                            <ctrl:WineVarietyTemplateSelector/>
                        </ComboBox.ItemTemplateSelector>
                    </ComboBox>

                    <Label Content="Menge:" Margin="10,70,0,0" Grid.Column="0"/>
                    <ctrl:UnitTextBox x:Name="WeightInput" Unit="kg" Text="{Binding WeightString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                      Grid.Column="1" Margin="0,70,10,10" Width="61" HorizontalAlignment="Left"
                                      TextChanged="WeightInput_TextChanged" KeyUp="Input_KeyUp"/>
                </Grid>
            </GroupBox>

            <Button x:Name="DeliveryScheduleButton" Content="Leseplanung"
                    Grid.Row="2" Margin="10,10,10,10" Width="120" HorizontalAlignment="Right" VerticalAlignment="Bottom"
                    Click="DeliveryScheduleButton_Click"/>
        </Grid>

        <StatusBar Grid.Row="2" Grid.ColumnSpan="3" BorderThickness="0,1,0,0" BorderBrush="Gray">
            <StatusBar.ItemsPanel>
                <ItemsPanelTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="0.5*" MinWidth="120"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="1.75*" MinWidth="150"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="2*"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="2*"/>
                        </Grid.ColumnDefinitions>
                    </Grid>
                </ItemsPanelTemplate>
            </StatusBar.ItemsPanel>
            <StatusBarItem>
                <TextBlock>
                    Anmeldungen: <Run Text="{Binding StatusAncmts}"/>
                </TextBlock>
            </StatusBarItem>
            <Separator Grid.Column="1"/>
            <StatusBarItem Grid.Column="2">
                <TextBlock ToolTip="{Binding StatusWeightToolTip}">
                    Menge: <Run Text="{Binding StatusWeight}"/>
                </TextBlock>
            </StatusBarItem>
            <Separator Grid.Column="3"/>
            <StatusBarItem Grid.Column="4">
                <TextBlock>
                    Anmldg. erstellt: <Run Text="{Binding StatusAncmtCreated}"/>
                </TextBlock>
            </StatusBarItem>
            <Separator Grid.Column="5"/>
            <StatusBarItem Grid.Column="6">
                <TextBlock>
                    Anmldg. geändert: <Run Text="{Binding StatusAncmtModified}"/>
                </TextBlock>
            </StatusBarItem>
        </StatusBar>
    </Grid>
</local:AdministrationWindow>
