<local:ContextWindow
        x:Class="Elwig.Windows.MailWindow"
        AutomationProperties.AutomationId="MailWindow"
        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"
        mc:Ignorable="d"
        MinWidth="650" MinHeight="400" Height="600" Width="950"
        Closed="Window_Closed"
        Title="Rundschreiben - Elwig">
    <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>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="19"/>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="24"/>
        </Grid.RowDefinitions>

        <Menu BorderThickness="0,0,0,1" BorderBrush="LightGray" Background="White">
            <MenuItem Header="Hilfe">
                <MenuItem x:Name="Menu_Help_Log" Header="Ausgangs-Protokoll anzeigen"
                          Click="Menu_Help_Log_Click">
                    <MenuItem.Icon>
                        <TextBlock FontFamily="Segoe MDL2 Assets" FontSize="16" Text="&#xF168;"/>
                    </MenuItem.Icon>
                </MenuItem>
            </MenuItem>
        </Menu>

        <TabControl x:Name="TabControl" BorderThickness="0" Grid.Row="1"
                    PreviewDragOver="Document_PreviwDragOver" AllowDrop="True" Drop="Document_Drop">
            <TabItem Header="Dokumente" Visibility="Collapsed">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="320"/>
                    </Grid.ColumnDefinitions>

                    <Grid Height="200" VerticalAlignment="Top" HorizontalAlignment="Stretch">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="25"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="30"/>
                        </Grid.RowDefinitions>

                        <Label Content="Verfügbare Dokumente"
                               Grid.Column="0" Margin="10,8,10,10"/>
                        <ListBox x:Name="AvaiableDocumentsList"
                                 Grid.Column="0" Margin="10,30,10,10"
                                 SelectionChanged="AvaiableDocumentsList_SelectionChanged"/>

                        <Button x:Name="DocumentAddButton" Content="&#xF0AF;" FontFamily="Segoe MDL2 Assets" FontSize="14"
                                Grid.Column="1" Margin="0,0,0,30" VerticalAlignment="Center" Height="25" IsEnabled="False"
                                Click="DocumentAddButton_Click"/>
                        <Button x:Name="DocumentRemoveButton" Content="&#xE74D;" FontFamily="Segoe MDL2 Assets" FontSize="16" Padding="1.5,0,0,0"
                                Grid.Column="1" Margin="0,30,0,0" VerticalAlignment="Center" Height="25" IsEnabled="False"
                                Click="DocumentRemoveButton_Click"/>

                        <Label Content="Ausgewählte Dokumente"
                               Grid.Column="2" Margin="10,8,10,10"/>
                        <ListBox x:Name="SelectedDocumentsList" DisplayMemberPath="Name"
                                 Grid.Column="2" Margin="10,30,10,37"
                                 SelectionChanged="SelectedDocumentsList_SelectionChanged">
                            <ListBox.InputBindings>
                                <KeyBinding Key="Delete" Command="{Binding Path=DeleteCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MailWindow}}}"/>
                            </ListBox.InputBindings>
                        </ListBox>
                        <Button x:Name="SelectDocumentButton" Content="Durchsuchen..."
                                Grid.Column="2" VerticalAlignment="Bottom" Margin="10,10,10,10" Height="22"
                                Click="SelectDocumentButton_Click"/>
                    </Grid>

                    <GroupBox x:Name="DocumentBox" Header="Dokument" Margin="10,170,10,47" HorizontalAlignment="Stretch">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="70"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>

                            <CheckBox x:Name="DocumentNonDeliverersInput" Content="Auch Nicht-Lieferanten miteinbeziehen"
                                      Margin="10,10,10,10" Grid.Column="1"/>

                            <Label x:Name="DocumentFooterLabel" Content="Fußtext:" Margin="10,40,0,10"/>
                            <TextBox x:Name="DeliveryConfirmationFooterInput" Grid.Column="1"
                                     Margin="0,40,10,10" Height="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                                     AcceptsReturn="True" VerticalScrollBarVisibility="Visible" TextWrapping="Wrap"
                                     TextChanged="DocumentInput_TextChanged"/>
                            <TextBox x:Name="CreditNoteFooterInput" Grid.Column="1"
                                     Margin="0,10,10,10" Height="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                                     AcceptsReturn="True" VerticalScrollBarVisibility="Visible" TextWrapping="Wrap"
                                     TextChanged="DocumentInput_TextChanged"/>
                        </Grid>
                    </GroupBox>

                    <TextBox x:Name="PostalLocation" Grid.Column="1" TextChanged="PostalLocation_TextChanged"
                             Margin="10,30,10,10" Width="120" HorizontalAlignment="Left"/>
                    <Label Content=", am" Margin="130,30,10,10" FontSize="14" Grid.Column="1"/>
                    <TextBox x:Name="PostalDate" Grid.Column="1" Text="01.01.2020"
                             Margin="162,30,10,10" Width="78" HorizontalAlignment="Left"
                             TextChanged="Date_TextChanged" LostFocus="Date_LostFocus"/>

                    <GroupBox Header="Adressaten" Margin="10,70,10,47" Grid.Column="1">
                        <Grid>
                            <RadioButton GroupName="Recipients" x:Name="RecipientsActiveMembersInput" Content="aktive Mitglieder"
                                         Margin="10,10,10,10" VerticalAlignment="Top" HorizontalAlignment="Left"
                                         Checked="RecipientsInput_Changed" Unchecked="RecipientsInput_Changed"/>
                            <RadioButton GroupName="Recipients" x:Name="RecipientsAreaComMembersInput" Content="Mitglieder mit Flächenbindung"
                                         Margin="10,30,10,10" VerticalAlignment="Top" HorizontalAlignment="Left"
                                         Checked="RecipientsInput_Changed" Unchecked="RecipientsInput_Changed"/>
                            <RadioButton GroupName="Recipients" x:Name="RecipientsDeliveryAncmtMembersInput" Content="Mitglieder mit Anmeldung"
                                         Margin="10,50,10,10" VerticalAlignment="Top" HorizontalAlignment="Left"
                                         Checked="RecipientsInput_Changed" Unchecked="RecipientsInput_Changed"/>
                            <RadioButton GroupName="Recipients" x:Name="RecipientsDeliveryMembersInput" Content="Lieferanten der Saison"
                                         Margin="10,70,10,10" VerticalAlignment="Top" HorizontalAlignment="Left"
                                         Checked="RecipientsInput_Changed" Unchecked="RecipientsInput_Changed"/>
                            <RadioButton GroupName="Recipients" x:Name="RecipientsNonDeliveryMembersInput" Content="Nicht-Lieferanten der Saison"
                                         Margin="10,90,10,10" VerticalAlignment="Top" HorizontalAlignment="Left"
                                         Checked="RecipientsInput_Changed" Unchecked="RecipientsInput_Changed"/>
                            <RadioButton GroupName="Recipients" x:Name="RecipientsCustomInput" Content="Benutzerdefiniert"
                                         Margin="10,110,10,10" VerticalAlignment="Top" HorizontalAlignment="Left"
                                         Checked="RecipientsInput_Changed" Unchecked="RecipientsInput_Changed"/>

                            <Label Content="Zwst.:" x:Name="MemberBranchLabel" Margin="10,140,0,10"/>
                            <ctrl:CheckComboBox x:Name="MemberBranchInput" AllItemsSelectedContent="Alle Stammzweigstellen" Delimiter=", " DisplayMemberPath="Name"
                                                Margin="50,140,10,10" VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="25"
                                                SelectionChanged="MemberInput_SelectionChanged"/>

                            <Label Content="Gem.:" x:Name="MemberKgLabel" Margin="10,170,0,10"/>
                            <ctrl:CheckComboBox x:Name="MemberKgInput" AllItemsSelectedContent="Alle Stammgemeinden" Delimiter=", " DisplayMemberPath="Name"
                                                IsSelectAllActive="True" SelectAllContent="Alle Stammgemeinden"
                                                Margin="50,170,10,10" VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="25"
                                                SelectionChanged="MemberInput_SelectionChanged"/>

                            <Label Content="Bio-Betrieb:" x:Name="MemberOrganicLabel" Margin="10,200,0,10"/>
                            <RadioButton x:Name="MemberOrganicYesInput" Content="Ja" GroupName="MemberOrganic"
                                         Margin="80,205,10,10" VerticalAlignment="Top" HorizontalAlignment="Left"
                                         Checked="MemberInput_Checked"/>
                            <RadioButton x:Name="MemberOrganicNoInput" Content="Nein" GroupName="MemberOrganic"
                                         Margin="125,205,10,10" VerticalAlignment="Top" HorizontalAlignment="Left"
                                         Checked="MemberInput_Checked"/>
                            <RadioButton x:Name="MemberOrganicIndifferentInput" Content="Egal" GroupName="MemberOrganic"
                                         Margin="180,205,10,10" VerticalAlignment="Top" HorizontalAlignment="Left"
                                         Checked="MemberInput_Checked"/>

                            <Label Content="Funktionär:" x:Name="MemberFunktionärLabel" Margin="10,230,0,10"/>
                            <RadioButton x:Name="MemberFunktionärYesInput" Content="Ja" GroupName="MemberFunktionär"
                                         Margin="80,235,10,10" VerticalAlignment="Top" HorizontalAlignment="Left"
                                         Checked="MemberInput_Checked"/>
                            <RadioButton x:Name="MemberFunktionärNoInput" Content="Nein" GroupName="MemberFunktionär"
                                         Margin="125,235,10,10" VerticalAlignment="Top" HorizontalAlignment="Left"
                                         Checked="MemberInput_Checked"/>
                            <RadioButton x:Name="MemberFunktionärIndifferentInput" Content="Egal" GroupName="MemberFunktionär"
                                         Margin="180,235,10,10" VerticalAlignment="Top" HorizontalAlignment="Left"
                                         Checked="MemberInput_Checked"/>

                            <Label Content="Vtrg.:" x:Name="MemberAreaComLabel" Margin="10,260,0,10"/>
                            <ctrl:CheckComboBox x:Name="MemberAreaComInput" AllItemsSelectedContent="Alle Vertragsarten" Delimiter=", " DisplayMemberPath="VtrgId"
                                                IsSelectAllActive="True" SelectAllContent="Alle Vertragsarten"
                                                Margin="50,260,10,10" VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="25"
                                                SelectionChanged="MemberInput_SelectionChanged"/>

                            <Label Content="Tag:" x:Name="MemberDeliveryAncmtLabel" Margin="10,260,0,10"/>
                            <ctrl:CheckComboBox x:Name="MemberDeliveryAncmtInput" AllItemsSelectedContent="Alle Lesepläne" Delimiter=", " DisplayMemberPath="Identifier"
                                                IsSelectAllActive="True" SelectAllContent="Alle Lesepläne"
                                                Margin="50,260,10,10" VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="25"
                                                SelectionChanged="MemberInput_SelectionChanged"/>

                            <ctrl:CheckComboBox x:Name="MemberCustomInput" AllItemsSelectedContent="Alle Mitglieder" Delimiter=", " DisplayMemberPath="AdministrativeName"
                                                IsSelectAllActive="True" SelectAllContent="Alle Mitglieder"
                                                Margin="10,140,10,10" VerticalAlignment="Top" HorizontalAlignment="Stretch" Height="25"
                                                SelectionChanged="MemberInput_SelectionChanged"/>
                        </Grid>
                    </GroupBox>

                    <Button x:Name="ContinueButton" Content="Weiter" Grid.Column="1"
                            Margin="10,10,10,10" Height="27" Width="100" Padding="9,3" FontSize="14"
                            VerticalAlignment="Bottom" HorizontalAlignment="Right"
                            Click="ContinueButton_Click"/>
                </Grid>
            </TabItem>

            <TabItem Header="Absenden" Visibility="Collapsed">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="1.5*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="80"/>
                    </Grid.RowDefinitions>

                    <GroupBox Header="Post" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,10,5,10" Grid.Column="0">
                        <Grid>
                            <GroupBox Header="Zusenden an..." Margin="10,10,10,10" Height="150" Width="220" VerticalAlignment="Top" HorizontalAlignment="Left">
                                <StackPanel>
                                    <RadioButton x:Name="PostalAllInput" Margin="10,10,10,2.5" Click="PostalInput_Changed">
                                        <TextBlock>
                                            ...alle (<Run Text="{Binding Path=PostalAllCount, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MailWindow}}}"/>)
                                        </TextBlock>
                                    </RadioButton>
                                    <RadioButton x:Name="PostalWishInput" Margin="10,2.5,10,2.5" Click="PostalInput_Changed" IsChecked="True">
                                        <TextBlock>
                                            ...Mitglieder, die Zusendung<LineBreak/>
                                            per Post wünschen (<Run Text="{Binding Path=PostalWishCount, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MailWindow}}}"/>)
                                        </TextBlock>
                                    </RadioButton>
                                    <RadioButton x:Name="PostalNoEmailInput" Margin="10,2.5,10,2.5" Click="PostalInput_Changed">
                                        <TextBlock>
                                            ...Mitglieder, die keine<LineBreak/>
                                            E-Mail erhalten würden (<Run Text="{Binding Path=PostalNoEmailCount, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MailWindow}}}"/>)
                                        </TextBlock>
                                    </RadioButton>
                                    <RadioButton x:Name="PostalNobodyInput" Margin="10,2.5,10,10" Content="...niemanden (0)"  Click="PostalInput_Changed"/>
                                </StackPanel>
                            </GroupBox>

                            <GroupBox Header="Sortieren nach" Margin="10,180,10,10" Width="180" Height="80" VerticalAlignment="Top" HorizontalAlignment="Left">
                                <StackPanel Margin="5,5,0,5">
                                    <RadioButton GroupName="Order" x:Name="OrderMgNrInput" Content="Mitgliedsnummer" Click="OrderInput_Changed" IsChecked="True"/>
                                    <RadioButton GroupName="Order" x:Name="OrderNameInput" Content="Name" Click="OrderInput_Changed"/>
                                    <RadioButton GroupName="Order" x:Name="OrderPlzInput" Content="PLZ, Ort, Name" Click="OrderInput_Changed"/>
                                </StackPanel>
                            </GroupBox>

                            <CheckBox x:Name="DoublePagedInput" Margin="20,270,10,10" Content="Doppelseitig drucken"
                                      VerticalAlignment="Top" HorizontalAlignment="Left"
                                      Checked="DoublePagedInput_Changed" Unchecked="DoublePagedInput_Changed"/>

                            <TextBox x:Name="PostalSender1" TextChanged="PostalSender_TextChanged" IsEnabled="False"
                                     Margin="10,300,10,10"/>
                            <TextBox x:Name="PostalSender2" TextChanged="PostalSender_TextChanged"
                                     Margin="10,330,10,10"/>
                        </Grid>
                    </GroupBox>

                    <GroupBox Header="E-Mail" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5,10,10,10" Grid.Column="1">
                        <Grid>
                            <GroupBox Header="Zusenden an..." Margin="80,10,10,10" Width="220" Height="110" VerticalAlignment="Top" HorizontalAlignment="Left">
                                <StackPanel>
                                    <RadioButton x:Name="EmailAllInput" Margin="10,10,10,2.5" Checked="EmailInput_Changed">
                                        <TextBlock>
                                            ...alle mit E-Mail-Adressen (<Run Text="{Binding Path=EmailAllCount, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MailWindow}}}"/>)
                                        </TextBlock>
                                    </RadioButton>
                                    <RadioButton x:Name="EmailWishInput" Margin="10,2.5,10,2.5" IsChecked="True" Checked="EmailInput_Changed">
                                        <TextBlock>
                                            ...Mitglieder, die Zusendung<LineBreak/>
                                            per E-Mail wünschen (<Run Text="{Binding Path=EmailWishCount, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MailWindow}}}"/>)
                                        </TextBlock>
                                    </RadioButton>
                                    <RadioButton x:Name="EmailNobodyInput" Margin="10,2.5,10,10" Content="...niemanden (0)"  Checked="EmailInput_Changed"/>
                                </StackPanel>
                            </GroupBox>

                            <Label Content="Betreff:" Margin="10,130,10,10"/>
                            <TextBox x:Name="EmailSubjectInput" Margin="80,130,10,10"/>

                            <Label Content="Nachricht:" Margin="10,160,10,10"/>
                            <TextBox x:Name="EmailBodyInput"
                                     Margin="80,160,10,10" VerticalAlignment="Stretch" Height="Auto"
                                     TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" AcceptsReturn="True"/>
                        </Grid>
                    </GroupBox>

                    <Grid Grid.Row="1" Grid.ColumnSpan="2" Width="400" Height="59">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="0.7*"/>
                            <ColumnDefinition Width="10"/>
                            <ColumnDefinition Width="0.4*"/>
                            <ColumnDefinition Width="5"/>
                            <ColumnDefinition Width="0.6*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="5"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>

                        <Button x:Name="GenerateButton" Content="Generieren"
                                Grid.Row="0" Grid.Column="0" FontSize="14"
                                Click="GenerateButton_Click"/>
                        <Button x:Name="AbortButton" Content="Abbrechen" Visibility="Hidden" IsEnabled="False"
                                Grid.Row="0" Grid.Column="0" FontSize="14"
                                Click="AbortButton_Click"/>
                        <ProgressBar x:Name="ProgressBar"
                                     Grid.Row="2" Grid.Column="0" SnapsToDevicePixels="True"/>

                        <Button x:Name="PreviewButton" Content="Vorschau" IsEnabled="False"
                                Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="3" FontSize="14"
                                Click="PreviewButton_Click"/>
                        <Button x:Name="PrintButton" Content="Drucken" IsEnabled="False"
                                Grid.Row="2" Grid.Column="2" FontSize="14"
                                Click="PrintButton_Click"/>
                        <Button x:Name="EmailButton" Content="E-Mails verschicken" IsEnabled="False"
                                Grid.Row="2" Grid.Column="4" FontSize="14"
                                Click="EmailButton_Click"/>
                    </Grid>

                    <Button x:Name="BackButton" Content="Zurück" Grid.Row="1"
                            Margin="10,10,10,10" Height="27" Width="100" Padding="9,3" FontSize="14"
                            VerticalAlignment="Bottom" HorizontalAlignment="Left"
                            Click="BackButton_Click"/>
                </Grid>
            </TabItem>
        </TabControl>

        <StatusBar Grid.Row="2" BorderThickness="0,1,0,0" BorderBrush="Gray">
            <StatusBar.ItemsPanel>
                <ItemsPanelTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="1*"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="1*"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="1*"/>
                        </Grid.ColumnDefinitions>
                    </Grid>
                </ItemsPanelTemplate>
            </StatusBar.ItemsPanel>
            <StatusBarItem>
                <TextBlock>
                    Adressaten: <Run x:Name="StatusRecipients" Text="0"/>
                </TextBlock>
            </StatusBarItem>
            <Separator Grid.Column="1"/>
            <StatusBarItem Grid.Column="2">
                <TextBlock>
                    Adressaten (Post): <Run x:Name="StatusPostalRecipients" Text="0"/>
                </TextBlock>
            </StatusBarItem>
            <Separator Grid.Column="3"/>
            <StatusBarItem Grid.Column="4">
                <TextBlock>
                    Adressaten (E-Mail): <Run x:Name="StatusEmailRecipients" Text="0"/>
                </TextBlock>
            </StatusBarItem>
        </StatusBar>
    </Grid>
</local:ContextWindow>
