<UserControl x:Class="BeWo.View.Controls.MultiAddServGroupOfPeopleSelectionControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:localsearch="clr-namespace:BeWo.View.Search"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <Style x:Key="MultiSupportConceptSelectionControlStyle" TargetType="{x:Type ListBoxItem}">
            <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorLevel=1, AncestorType={x:Type ItemsControl}, Mode=FindAncestor}}" />
            <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorLevel=1, AncestorType={x:Type ItemsControl}, Mode=FindAncestor}}" />
            <Setter Property="Margin" Value="0,2,0,0" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Grid>
                            <Border x:Name="ItemBorder" CornerRadius="5" MinHeight="25" Background="#FF000000">
                                <Border.OpacityMask>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#19000000" Offset="0" />
                                        <GradientStop Color="#26000000" Offset="1" />
                                    </LinearGradientBrush>
                                </Border.OpacityMask>
                            </Border>
                            <Border x:Name="ItemContent"  MinHeight="25">
                                <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="3,2,1,2" OpacityMask="{x:Null}" SnapsToDevicePixels="True">
                                    <Grid Margin="3,0,0,0">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="Auto"/>
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="*"/>
                                            <RowDefinition Height="Auto"/>
                                        </Grid.RowDefinitions>
                                        <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal">
                                            <TextBlock FontSize="14" Foreground="#FFD2D2D2" 
                                                       x:Name="customerName" Text="{Binding Path=Customer.Name}" 
                                                       VerticalAlignment="Center" TextWrapping="Wrap"/>
                                        </StackPanel>
                                        <StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal">
                                            <TextBlock FontSize="12" Foreground="#FFA0A0A0" x:Name="groupName" 
                                                       Tag="{Binding}" Margin="0 2" Text="{Binding GroupName}" 
                                                       VerticalAlignment="Center" TextWrapping="Wrap" />

                                            <TextBlock FontSize="12" Foreground="#FFA0A0A0" x:Name="groupAppointmentDayOfWeek" 
                                                       Tag="{Binding}" Margin="3 2" Text="{Binding AppointmentDayOfWeek}" 
                                                       VerticalAlignment="Center" TextWrapping="Wrap" HorizontalAlignment="Right" Visibility="Collapsed" />
                                        </StackPanel>
                                        <Button Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" x:Name="btnRemoveCustomer" 
                                                Width="20" Height="20" ToolTip="Den Klienten aus der Gruppe entfernen" 
                                                Tag="{Binding}" Style="{DynamicResource CloseButtonStyle}" 
                                                Click="btnRemoveCustomer_Click" Margin="3,0,3,0" HorizontalAlignment="Right" />
                                    </Grid>
                                </Grid>
                            </Border>
                        </Grid>

                        <ControlTemplate.Triggers>
                            <DataTrigger Binding="{Binding Path=IsArchived}" Value="True">
                                <Setter Property="Foreground" TargetName="groupName" Value="#FF808080" />
                                <Setter Property="Foreground" TargetName="groupAppointmentDayOfWeek" Value="#FF808080" />
                            </DataTrigger>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="OpacityMask" TargetName="ItemBorder">
                                    <Setter.Value>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#33000000" Offset="0" />
                                            <GradientStop Color="#66000000" Offset="1" />
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <Trigger Property="ListBoxItem.IsSelected" Value="True">
                                <Setter Property="OpacityMask" TargetName="ItemBorder">
                                    <Setter.Value>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#99000000" Offset="0" />
                                            <GradientStop Color="#CC000000" Offset="1" />
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="ListBoxItem.IsSelected" Value="True" />
                                    <Condition Property="Selector.IsSelectionActive" Value="False" />
                                </MultiTrigger.Conditions>
                                <Setter Property="OpacityMask" TargetName="ItemBorder">
                                    <Setter.Value>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#99000000" Offset="0" />
                                            <GradientStop Color="#B2000000" Offset="1" />
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <EventSetter Event="MouseDoubleClick" Handler="DoubleClickHandler" />
        </Style>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Label Grid.Row="0" Grid.Column="0" Content="Gruppenauswahl" FontSize="12" FontWeight="Bold" />
            <StackPanel Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal" Margin="3">
                <Label Content="Gruppe:" FontSize="12" FontWeight="Bold"/>
                <Label x:Name="LabelGroupName" FontSize="12"/>
            </StackPanel>
            <StackPanel Grid.Column="1" Orientation="Horizontal">
                <Button HorizontalAlignment="Right" Click="btnAddGroup_Click" Height="21" Width="45" Margin="0,5,0,0" ToolTip="Gruppe hinzufügen">
                    <StackPanel Orientation="Horizontal">
                        <Grid Width="18" HorizontalAlignment="Center" VerticalAlignment="Center">
                            <Line X1="4" X2="12" Y1="8" Y2="8" Fill="{x:Null}" Stroke="#FFFFFFFF" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeThickness="2" HorizontalAlignment="Center" VerticalAlignment="Center" Width="16" Height="16" />
                            <Line X1="8" X2="8" Y1="4" Y2="12" Fill="{x:Null}" Stroke="#FFFFFFFF" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeThickness="2" HorizontalAlignment="Center" VerticalAlignment="Center" Width="16" Height="16" />
                        </Grid>
                        <Image Width="20" Source="/BeWoPlaner;component/Ressources/Icons/UserGroupHome24bw.png" />
                    </StackPanel>
                </Button>
                <Button HorizontalAlignment="Right" Click="btnAddCustomer_Click" Height="21" Width="45" Margin="3,5,0,0" ToolTip="Neuen Klienten hinzufügen" >
                    <StackPanel Orientation="Horizontal">
                        <Grid Width="18" HorizontalAlignment="Center" VerticalAlignment="Center">
                            <Line X1="4" X2="12" Y1="8" Y2="8" Fill="{x:Null}" Stroke="#FFFFFFFF" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeThickness="2" HorizontalAlignment="Center" VerticalAlignment="Center" Width="16" Height="16" />
                            <Line X1="8" X2="8" Y1="4" Y2="12" Fill="{x:Null}" Stroke="#FFFFFFFF" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeThickness="2" HorizontalAlignment="Center" VerticalAlignment="Center" Width="16" Height="16" />
                        </Grid>
                        <Image Width="20" Source="/BeWoPlaner;component/Ressources/Icons/AnonymousUserDisabled.png" />
                    </StackPanel>
                </Button>
            </StackPanel>
        </Grid>
        <ListBox Background="{DynamicResource CustomerListBrush}" Padding="2,0,2,2" Grid.Row="1" x:Name="ListBoxCustomers" 
                 IsSynchronizedWithCurrentItem="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" 
                 ItemContainerStyle="{DynamicResource MultiSupportConceptSelectionControlStyle}" SelectionMode="Single" 
                 SelectionChanged="listBoxCustomers_SelectionChanged">
            <ListBox.Template>
                <ControlTemplate TargetType="{x:Type ListBox}">
                    <Border x:Name="Bd" SnapsToDevicePixels="True" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}">
                        <ScrollViewer Focusable="False" Padding="{TemplateBinding Padding}" HorizontalScrollBarVisibility="Disabled">
                            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </ListBox.Template>
        </ListBox>
        <Popup x:Name="PopupCustomers" StaysOpen="False" Placement="MousePoint" Width="400" Grid.Row="2" Height="400">
            <localsearch:CustomerSearchView x:Name="SearchView" ItemSelected="CustomerSearchView_ItemSelected" />
        </Popup>
        <Popup x:Name="PopupAdditionalServiceGroupsOfPeople" StaysOpen="False" Placement="MousePoint" Width="400" Grid.Row="1" Height="400" >
            <localsearch:AddServGroupOfPeopleSearchView x:Name="AddServGroupSearchView" ItemSelected="AdditionalServiceGroupOfPeopleSearchView_ItemSelected" />
        </Popup>
    </Grid>
</UserControl>
