<local:AdministrationWindow
        x:Class="Elwig.Windows.AreaComAdminWindow"
        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:ctrl="clr-namespace:Elwig.Controls"
        xmlns:vm="clr-namespace:Elwig.ViewModels"
        Title="{Binding Title}" Height="600" MinHeight="450" Width="1000" MinWidth="860"
        Loaded="Window_Loaded">
    <Window.DataContext>
        <vm:AreaComAdminViewModel/>
    </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="IsReadOnly" Value="True"/>
            <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="IsReadOnly" Value="True"/>
            <Setter Property="Height" Value="25"/>
            <Setter Property="TextWrapping" Value="NoWrap"/>
        </Style>
        <Style TargetType="ComboBox">
            <Setter Property="IsEnabled" Value="False"/>
            <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="*"/>
            <RowDefinition Height="24"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="3*" MinWidth="500"/>
            <ColumnDefinition Width="5"/>
            <ColumnDefinition Width="*" MinWidth="280"/>
        </Grid.ColumnDefinitions>

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

        <Grid Grid.Row="1" Grid.Column="0" 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}"
                     Grid.ColumnSpan="3" Margin="5,5,190,0" IsReadOnly="False"
                     TextChanged="SearchInput_TextChanged">
                <TextBox.ToolTip>
                    <TextBlock>
                        <Bold>Strg+F</Bold><LineBreak/><LineBreak/>
                        Flächenbindungen 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, ...<LineBreak/>
                        <Bold>Attribut</Bold>: z.B. Kabinett, dac, ...<LineBreak/>
                        <Bold>Flächenbindung</Bold>: z.B. GVK, GVD, ...<LineBreak/>
                        <Bold>Saison</Bold>: z.B. 2020, 2019... (in dieser Saison aktiv)
                    </TextBlock>
                </TextBox.ToolTip>
            </TextBox>
            <CheckBox x:Name="ActiveAreaCommitmentInput" Content="Nur laufende anzeigen (2020)" IsChecked="{Binding ShowOnlyActiveAreaComs}"
                      Checked="ActiveAreaCommitmentInput_Changed" Unchecked="ActiveAreaCommitmentInput_Changed"
                      HorizontalAlignment="Right" Margin="0,10,10,0" VerticalAlignment="Top" Grid.Column="1" Grid.ColumnSpan="2"/>

            <DataGrid x:Name="AreaCommitmentList" AutoGenerateColumns="False" HeadersVisibility="Column" IsReadOnly="True" GridLinesVisibility="None" SelectionMode="Single"
                      CanUserDeleteRows="False" CanUserResizeRows="False" CanUserAddRows="False" SelectionChanged="AreaCommitmentList_SelectionChanged" Grid.Column="0" Grid.Row="1"
                      Margin="5,0,5,0" FontSize="14" Grid.ColumnSpan="3" Background="#e2e2e2">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="FbNr." Binding="{Binding FbNr, StringFormat='{}{0} '}" Width="50">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Right"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Katastralgemeinde" Binding="{Binding Kg.AtKg.Name}" Width="130"/>
                    <DataGridTextColumn Header="Sorte" Binding="{Binding AreaComType.WineVar.SortId}" Width="50">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.Foreground" Value="{Binding AreaComType.WineVar.Color}"/>
                                <Setter Property="TextBlock.TextAlignment" Value="Center"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Fläche" Binding="{Binding Area, StringFormat='{}{0:N0} m² '}" Width="80">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Right"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Attribut"           Binding="{Binding AreaComType.WineAttr.Name}" Width="100"/>
                    <DataGridTextColumn Header="Ried"               Binding="{Binding Rd.Name}"       Width="130"/>
                    <DataGridTextColumn Header="Parzelle"           Binding="{Binding GstNr}"         Width="130"/>
                    <DataGridTextColumn Header="Bewirt."            Binding="{Binding WineCult.Name}" Width="60"/>
                    <DataGridTextColumn Header="Von"                Binding="{Binding YearFrom}"      Width="48"/>
                    <DataGridTextColumn Header="Bis"                Binding="{Binding YearTo}"        Width="48"/>
                </DataGrid.Columns>
            </DataGrid>

            <Button x:Name="NewAreaCommitmentButton" Content="Neu" Click="NewAreaCommitmentButton_Click"
                    HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="5,5,2.5,10" Grid.Column="0" Grid.Row="2">
                <Button.ToolTip>
                    <TextBlock FontWeight="Bold">Alt+Einfg</TextBlock>
                </Button.ToolTip>
            </Button>
            <Button x:Name="EditAreaCommitmentButton" Content="Bearbeiten" Click="EditAreaCommitmentButton_Click" IsEnabled="False"
                    HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="2.5,5,2.5,10" Grid.Column="1" Grid.Row="2">
                <Button.ToolTip>
                    <TextBlock FontWeight="Bold">Strg+B</TextBlock>
                </Button.ToolTip>
            </Button>
            <Button x:Name="DeleteAreaCommitmentButton" Content="Löschen" Click="DeleteAreaCommitmentButton_Click" IsEnabled="False"
                    HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="2.5,5,5,10" Grid.Column="2" Grid.Row="2">
                <Button.ToolTip>
                    <TextBlock FontWeight="Bold">Alt+Entf</TextBlock>
                </Button.ToolTip>
            </Button>

            <Button x:Name="SaveButton" Content="Speichern" Click="SaveButton_Click" IsEnabled="False" Visibility="Hidden"
                    HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="5,5,2.5,10" Grid.Column="0" Grid.Row="2">
                <Button.ToolTip>
                    <TextBlock FontWeight="Bold">Strg+S</TextBlock>
                </Button.ToolTip>
            </Button>
            <Button x:Name="ResetButton" Content="Zurücksetzen" Click="ResetButton_Click" IsEnabled="False" Visibility="Hidden"
                    HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="2.5,5,2.5,10" Grid.Column="1" Grid.Row="2">
                <Button.ToolTip>
                    <TextBlock FontWeight="Bold">Strg+Z</TextBlock>
                </Button.ToolTip>
            </Button>
            <Button x:Name="CancelButton" Content="Abbrechen" Click="CancelButton_Click" IsEnabled="False" Visibility="Hidden" IsCancel="True"
                    HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="2.5,5,5,10" Grid.Column="2" Grid.Row="2">
                <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.125*"/>
                <RowDefinition Height="1*"/>
            </Grid.RowDefinitions>

            <GroupBox Header="Vertrag" Grid.Column="2" Grid.Row="0" Grid.RowSpan="1" Margin="5,5,5,5">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="80"/>
                        <ColumnDefinition Width="48"/>
                        <ColumnDefinition Width="60"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <Label Content="MgNr.:" Margin="10,10,0,0" Grid.Column="0"/>
                    <TextBox x:Name="MgNrInput" Text="{Binding MgNrString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="False"
                             Margin="0,10,0,0" Width="48" HorizontalAlignment="Left" Grid.Column="1" TextAlignment="Right"/>

                    <Label Content="FbNr.:" Margin="10,10,0,0" Grid.Column="2"/>
                    <TextBox x:Name="FbNrInput" Text="{Binding FbNrString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Margin="0,10,10,0" Width="56" HorizontalAlignment="Left" Grid.Column="3" TextAlignment="Right"
                             TextChanged="FbNrInput_TextChanged" LostFocus="FbNrInput_LostFocus"/>

                    <Label Content="Zeitraum:" Margin="10,40,0,0" Grid.Column="0"/>
                    <TextBox x:Name="YearFromInput" Text="{Binding YearFromString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Margin="0,40,10,0" Width="40" HorizontalAlignment="Left" Grid.Column="1" Grid.ColumnSpan="2" TextAlignment="Right"
                             TextChanged="IntegerInput_TextChanged"/>
                    <Label Content="–" Grid.Column="1" Grid.ColumnSpan="3" Margin="45,40,0,0"/>
                    <TextBox x:Name="YearToInput" Text="{Binding YearToString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Margin="60,40,10,0" Width="40" HorizontalAlignment="Left" Grid.Column="1" Grid.ColumnSpan="3" TextAlignment="Right"
                             TextChanged="IntegerInput_TextChanged"/>

                    <Label Content="Vertragsart:" Margin="10,70,0,0" Grid.Column="0" Grid.ColumnSpan="2"/>
                    <ComboBox x:Name="AreaComTypeInput" SelectedItem="{Binding AreaComType, Mode=TwoWay}" ItemsSource="{Binding AreaComTypeSource, Mode=TwoWay}"
                              ItemTemplate="{StaticResource AreaCommitmentTypeTemplate}" TextSearch.TextPath="DisplayName"
                              HorizontalAlignment="Stretch" Margin="0,70,40,10" Grid.Column="1" Grid.ColumnSpan="3"/>
                    <Button x:Name="AreaComTypeDetailsButton" Content="&#xE712;" FontFamily="Segoe MDL2 Assets" FontSize="14" Padding="0,1,0,0"
                            Click="AreaComTypeDetailsButton_Click"
                            Grid.Column="3" VerticalAlignment="Top" HorizontalAlignment="Right" Width="25" Height="25" Margin="10,70,10,10"/>

                    <Label Content="Bewirt.-Art:" Margin="10,100,0,0" Grid.Column="0" Grid.ColumnSpan="2"/>
                    <ComboBox x:Name="WineCultivationInput" SelectedItem="{Binding WineCultObj, Mode=TwoWay}" ItemsSource="{Binding WineCultSource, Mode=TwoWay}"
                              DisplayMemberPath="Name" TextSearch.TextPath="Name"
                              HorizontalAlignment="Stretch" Margin="0,100,10,0" Grid.Column="1" Grid.ColumnSpan="3"/>

                    <Label Content="Anmerkung:" Margin="10,130,0,0" Grid.Column="0" Grid.ColumnSpan="2"/>
                    <TextBox x:Name="CommentInput" Text="{Binding Comment, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             TextChanged="TextBox_TextChanged"
                             HorizontalAlignment="Stretch" Margin="0,130,10,0" Grid.Column="1" Grid.ColumnSpan="3"/>
                </Grid>
            </GroupBox>

            <GroupBox Header="Lage" Grid.Column="2" Grid.Row="1" Grid.RowSpan="1" Margin="5,5,5,10">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="80"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <Label Content="KG:" Margin="10,10,0,0" Grid.Column="0"/>
                    <ComboBox x:Name="KgInput" SelectedItem="{Binding Kg, Mode=TwoWay}" ItemsSource="{Binding KgSource, Mode=TwoWay}"
                              ItemTemplate="{StaticResource KgNrTemplate}" TextSearch.TextPath="Name"
                              HorizontalAlignment="Stretch" Margin="0,10,40,10" Grid.Column="1"
                              SelectionChanged="KgInput_SelectionChanged"/>
                    <Button x:Name="KgDetailsButton" Content="&#xE712;" FontFamily="Segoe MDL2 Assets" FontSize="14" Padding="0,1,0,0"
                            Click="KgDetailsButton_Click"
                            Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Right" Width="25" Height="25" Margin="10,10,10,10"/>

                    <Label Content="Ried:" Margin="10,40,0,0" Grid.Column="0"/>
                    <ComboBox x:Name="RdInput" SelectedItem="{Binding RdObj, Mode=TwoWay}" ItemsSource="{Binding RdSource, Mode=TwoWay}"
                              DisplayMemberPath="Name" TextSearch.TextPath="Name" IsEditable="True"
                              HorizontalAlignment="Stretch" Margin="0,40,40,10" Grid.Column="1"
                              SelectionChanged="RdInput_SelectionChanged"/>
                    <Button x:Name="RdAddButton" Content="&#xE73E;" FontFamily="Segoe MDL2 Assets" FontSize="16" Padding="0,0,0,0" IsEnabled="False"
                            Click="RdAddButton_Click"
                            Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Right" Width="25" Height="25" Margin="10,40,10,10"/>

                    <Label Content="Parzelle(n):" Margin="10,70,0,0" Grid.Column="0"/>
                    <TextBox x:Name="GstNrInput" Text="{Binding GstNr, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Margin="0,70,10,0" Grid.Column="1" HorizontalAlignment="Stretch"
                             TextChanged="TextBox_TextChanged"/>

                    <Label Content="Fläche:" Margin="10,100,0,0" Grid.Column="0"/>
                    <ctrl:UnitTextBox x:Name="AreaInput" Unit="m²" Text="{Binding AreaString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                      TextChanged="IntegerInput_TextChanged"
                                      Grid.Column="1" Width="70" Margin="0,100,10,10" VerticalAlignment="Top" HorizontalAlignment="Left"/>
                </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="180"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="180"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                    </Grid>
                </ItemsPanelTemplate>
            </StatusBar.ItemsPanel>
            <StatusBarItem>
                <TextBlock>
                    Flächenbindungen: <Run Text="{Binding StatusAreaCommitments}"/>
                </TextBlock>
            </StatusBarItem>
            <Separator Grid.Column="1"/>
            <StatusBarItem Grid.Column="2">
                <TextBlock ToolTip="{Binding StatusAreaToolTip}">
                    Fläche: <Run Text="{Binding StatusArea}"/>
                </TextBlock>
            </StatusBarItem>
            <Separator Grid.Column="3"/>
            <StatusBarItem Grid.Column="4">
                <TextBlock>
                    Vertragsarten: <Run Text="{Binding StatusContracts}"/>
                </TextBlock>
            </StatusBarItem>
        </StatusBar>
    </Grid>
</local:AdministrationWindow>
