<local:ContextWindow
        x:Class="Elwig.Windows.PaymentAdjustmentWindow"
        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"
        Title="Auszahlung anpassen - Elwig" Height="600" Width="1000" MinHeight="560" MinWidth="850">
    <Window.Resources>
        <ctrl:UnitConverter x:Key="CurrencyConverter" Precision="2" Unit="€"/>
        <ctrl:UnitConverter x:Key="WeightConverter" Precision="0" Unit="kg"/>
        <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="Left"/>
            <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="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="2*" MinWidth="300"/>
            <ColumnDefinition Width="5"/>
            <ColumnDefinition Width="1*" MinWidth="380"/>
        </Grid.ColumnDefinitions>

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

        <Grid Grid.Row="1">
            <DataGrid x:Name="MemberList" AutoGenerateColumns="False" HeadersVisibility="Column" IsReadOnly="True" GridLinesVisibility="None" SelectionMode="Single"
                      CanUserDeleteRows="False" CanUserResizeRows="False" CanUserAddRows="False" Margin="10,10,5,10"
                      SelectionChanged="MemberList_SelectionChanged">
                <DataGrid.Resources>
                    <Style TargetType="{x:Type DataGridRow}">
                        <Style.Setters>
                            <Setter Property="Background" Value="{Binding Path=Background}"></Setter>
                            <Setter Property="Foreground" Value="{Binding Path=Foreground}"></Setter>
                        </Style.Setters>
                    </Style>
                </DataGrid.Resources>
                <DataGrid.Columns>
                    <DataGridTextColumn Header="MgNr." Binding="{Binding MgNr, StringFormat='{}{0} '}" Width="45">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Right"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Nachname" Binding="{Binding Name}" Width="100"/>
                    <DataGridTextColumn Header="Vorname" Binding="{Binding GivenName}" Width="90"/>
                    <DataGridTextColumn Header="GA" Binding="{Binding BusinessShares, StringFormat='{}{0:N0} '}" Width="35">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Right"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Abs." Binding="{Binding ModAbs, Converter={StaticResource CurrencyConverter}, StringFormat='{}{0} '}" Width="65">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Right"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Rel." Binding="{Binding ModRel, StringFormat='{}{0:P2} '}" Width="65">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Right"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Ü.-/U.-Lfrg." Binding="{Binding OverUnder, Converter={StaticResource WeightConverter},StringFormat='{}{0} '}" Width="70">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Right"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Strafe GA" Binding="{Binding PenaltyBs, Converter={StaticResource CurrencyConverter}, StringFormat='{}{0} '}" Width="65">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Right"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Pönale FB" Binding="{Binding PenaltyAc, Converter={StaticResource CurrencyConverter}, StringFormat='{}{0} '}" Width="65">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Right"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Nachz." Binding="{Binding Adjust, StringFormat='{}{0:N0} '}" Width="45">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Right"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Nachz.Betr." Binding="{Binding AdjustAmount, Converter={StaticResource CurrencyConverter}, StringFormat='{}{0} '}" Width="70">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Right"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Weitere" Binding="{Binding CustomAmount, Converter={StaticResource CurrencyConverter}, StringFormat='{}{0} '}" Width="65">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Right"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Gesamt" Binding="{Binding Total, Converter={StaticResource CurrencyConverter}, StringFormat='{}{0} '}" Width="65">
                        <DataGridTextColumn.CellStyle>
                            <Style>
                                <Setter Property="TextBlock.TextAlignment" Value="Right"/>
                            </Style>
                        </DataGridTextColumn.CellStyle>
                    </DataGridTextColumn>
                </DataGrid.Columns>
            </DataGrid>
        </Grid>

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

        <Grid Grid.Column="2" Grid.Row="1">
            <GroupBox Header="Benutzerdefinierte Zu-/Abschläge" Margin="5,10,10,10" Height="270" Width="365"
                      VerticalAlignment="Top" HorizontalAlignment="Left">
                <Grid>
                    <Label Content="Mitglied:" Margin="10,10,10,10"/>
                    <TextBox x:Name="MgNrInput" Width="48" Margin="70,10,10,10" HorizontalAlignment="Left" TextAlignment="Right"
                             TextChanged="MgNrInput_TextChanged" LostFocus="MgNrInput_LostFocus"/>
                    <ComboBox x:Name="MemberInput" Margin="123,10,40,10" IsEditable="True"
                              ItemTemplate="{StaticResource MemberAdminNameTemplate}" TextSearch.TextPath="AdministrativeName"
                              SelectionChanged="MemberInput_SelectionChanged"
                              VerticalAlignment="Top" Height="25" FontSize="14"/>
                    <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="Vor MwSt." Margin="70,37.5,10,10"/>
                    <Label Content="Betrag:" Margin="10,60,10,10"/>
                    <ctrl:UnitTextBox x:Name="CustomModAbsInput" Width="80" Margin="70,60,10,10" Unit="€"
                                      TextChanged="CustomModAbsInput_TextChanged"/>
                    <ctrl:UnitTextBox x:Name="CustomModRelInput" Width="60" Margin="155,60,10,10" Unit="%"
                                      TextChanged="CustomModRelInput_TextChanged"/>

                    <Label Content="Freitext:" Margin="10,90,10,10"/>
                    <TextBox x:Name="CustomModCommentInput" Margin="70,90,10,10"/>

                    <Label Content="Nach MwSt." Margin="70,117.5,10,10"/>
                    <Label Content="Betrag:" Margin="10,140,10,10"/>
                    <ctrl:UnitTextBox x:Name="CustomAmountInput" Width="80" Margin="70,140,10,10" Unit="€"
                                      TextChanged="CustomAmountInput_TextChanged"/>

                    <Label Content="Freitext:" Margin="10,170,10,10"/>
                    <TextBox x:Name="CustomCommentInput" Margin="70,170,10,10"/>

                    <Button x:Name="SaveCustomButton" Content="Speichern" Margin="0,0,125,10" Width="120"
                            HorizontalAlignment="Center" VerticalAlignment="Bottom"
                            Click="CustomButton_Click"/>
                    <Button x:Name="RemoveCustomButton" Content="Entfernen" Margin="125,0,0,10" Width="120"
                            HorizontalAlignment="Center" VerticalAlignment="Bottom"
                            Click="CustomButton_Click"/>
                </Grid>
            </GroupBox>

            <GroupBox Header="Automatische Nachzeichnung der Geschäftsanteile" Margin="5,10,10,10" Height="180" Width="365"
                      VerticalAlignment="Bottom" HorizontalAlignment="Left">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="28*"/>
                    </Grid.ColumnDefinitions>
                    <Label Content="Absoluter Freibetrag:" Margin="10,10,0,0" Grid.ColumnSpan="2"/>
                    <ctrl:UnitTextBox x:Name="AllowanceKgInput" Unit="kg" Margin="128,10,0,0" Width="70"
                           TextChanged="KgInput_TextChanged" Grid.Column="1"/>
                    <ctrl:UnitTextBox x:Name="AllowanceBsInput" Unit="GA" Margin="203,10,0,0" Width="60"
                           TextChanged="PercentInput_TextChanged" Grid.Column="1"/>

                    <Label Content="Relativer Freibetrag:" Margin="10,40,0,0" Grid.ColumnSpan="2"/>
                    <ctrl:UnitTextBox x:Name="AllowanceKgPerBsInput" Unit="kg/GA" Margin="128,40,0,0" Width="87"
                           TextChanged="KgInput_TextChanged" Grid.Column="1"/>
                    <ctrl:UnitTextBox x:Name="AllowancePercentInput" Unit="%" Margin="220,40,0,0" Width="60"
                           TextChanged="PercentInput_TextChanged" Grid.Column="1"/>

                    <Label Content="Nur mind. nachz.:" Margin="10,70,0,0" Grid.ColumnSpan="2"/>
                    <ctrl:UnitTextBox x:Name="MinBsInput" Unit="GA" Margin="128,70,0,0" Width="50"
                           TextChanged="BsInput_TextChanged" Grid.Column="1"/>

                    <Button x:Name="SeasonButton" Content="GA-Wert" Margin="0,0,10,42" Width="120"
                            HorizontalAlignment="Right" VerticalAlignment="Bottom"
                            Click="SeasonButton_Click" Grid.Column="1"/>
                    <Button x:Name="AutoAdjustBsButton" Content="Nachzeichnen" Margin="0,0,135,10" Width="120"
                            HorizontalAlignment="Right" VerticalAlignment="Bottom"
                            Click="AutoAdjustBsButton_Click" Grid.Column="1"/>
                    <Button x:Name="UnAdjustBsButton" Content="Rückgängig" Margin="0,0,10,10" Width="120"
                            HorizontalAlignment="Right" VerticalAlignment="Bottom"
                            Click="UnAdjustBsButton_Click" Grid.Column="1"/>
                </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="*"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="1.25*"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="130"/>
                        </Grid.ColumnDefinitions>
                    </Grid>
                </ItemsPanelTemplate>
            </StatusBar.ItemsPanel>
            <StatusBarItem Grid.Column="0" HorizontalContentAlignment="Stretch">
                <DockPanel>
                    <TextBlock Text="Strafe GA: "/>
                    <TextBlock x:Name="PenaltyBusinessShares" Text="-"/>
                </DockPanel>
            </StatusBarItem>
            <Separator Grid.Column="1"/>
            <StatusBarItem Grid.Column="2" HorizontalContentAlignment="Stretch">
                <DockPanel>
                    <TextBlock Text="Pönale FB: "/>
                    <TextBlock x:Name="PenaltyAreaCommitments" Text="-"/>
                </DockPanel>
            </StatusBarItem>
            <Separator Grid.Column="3"/>
            <StatusBarItem Grid.Column="4" HorizontalContentAlignment="Stretch">
                <DockPanel>
                    <TextBlock Text="Nachz.: "/>
                    <TextBlock x:Name="AutoBusinessShareAdjustment" Text="-"/>
                </DockPanel>
            </StatusBarItem>
            <Separator Grid.Column="5"/>
            <StatusBarItem Grid.Column="6" HorizontalContentAlignment="Stretch">
                <DockPanel>
                    <TextBlock Text="Weitere: "/>
                    <TextBlock x:Name="CustomModifiers" Text="-"/>
                </DockPanel>
            </StatusBarItem>
            <Separator Grid.Column="7"/>
            <StatusBarItem Grid.Column="8" HorizontalContentAlignment="Stretch">
                <DockPanel>
                    <TextBlock Text="Gesamt: "/>
                    <TextBlock x:Name="TotalModifiers" Text="-"/>
                </DockPanel>
            </StatusBarItem>
            <Separator Grid.Column="9"/>
            <StatusBarItem Grid.Column="10" HorizontalContentAlignment="Stretch">
                <DockPanel>
                    <TextBlock Text="Nicht-Lieferanten: "/>
                    <TextBlock x:Name="NonDeliveries" Text="-"/>
                </DockPanel>
            </StatusBarItem>
        </StatusBar>
    </Grid>
</local:ContextWindow>
