<UserControl x:Class="Filtration.Views.ItemFilterScriptView"
             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:views="clr-namespace:Filtration.Views"
             xmlns:attachedProperties="clr-namespace:Filtration.Views.AttachedProperties"
             xmlns:viewModels="clr-namespace:Filtration.ViewModels"
             xmlns:userControls="clr-namespace:Filtration.UserControls"
             mc:Ignorable="d" 
             d:DataContext="{d:DesignInstance Type=viewModels:ItemFilterScriptViewModel}"
             d:DesignHeight="300" d:DesignWidth="600">
    <UserControl.InputBindings>
        <KeyBinding Command="{Binding CopyBlockCommand}" Modifiers="Control" Key="C" />
        <KeyBinding Command="{Binding PasteBlockCommand}" Modifiers="Control" Key="V" />
        <KeyBinding Command="{Binding CopyBlockStyleCommand}" Modifiers="Shift+Control" Key="C" />
        <KeyBinding Command="{Binding PasteBlockStyleCommand}" Modifiers="Shift+Control" Key="V" />
    </UserControl.InputBindings>
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <!-- ReSharper disable once Xaml.RedundantResource -->
                    <DataTemplate x:Key="ItemFilterBlockTemplate">
                        <views:ItemFilterBlockView Margin="0,2,0,2" />
                    </DataTemplate>
                    <!-- ReSharper disable once Xaml.RedundantResource -->
                    <DataTemplate x:Key="ItemFilterSectionTemplate">
                        <views:ItemFilterSectionView Margin="0,2,0,2" />
                    </DataTemplate>
                    <views:BlockTemplateSelector x:Key="BlockTemplateSelector" />
                </ResourceDictionary>
                <ResourceDictionary Source="ExpanderStyle.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/> 
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Border Grid.Row="0" BorderThickness="1" BorderBrush="DarkGray"  Margin="5,5,5,0">
            <StackPanel Margin="2,2,2,2">
                <Expander Style="{StaticResource ExpanderRightAlignStyle}">
                    <Expander.Header>
                        <TextBlock Text="Script Description" VerticalAlignment="Center" /> 
                    </Expander.Header>
                    <Grid>
                        <TextBox Text="{Binding Description, UpdateSourceTrigger=PropertyChanged}" Margin="5" MaxLines="20" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" />
                    </Grid>
                </Expander>
            </StackPanel>
        </Border>
        <Border Grid.Row="1" BorderThickness="1" BorderBrush="DarkGray" Margin="5,5,5,5" Padding="2">
            <DockPanel LastChildFill="True">
                <userControls:AutoScrollingListBox ItemsSource="{Binding ItemFilterBlockViewModels}"
                                                   Margin="5,5,5,5"
                                                   Padding="5"
                                                   HorizontalContentAlignment="Stretch"
                                                   BorderThickness="0"
                                                   ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                                   VirtualizingStackPanel.VirtualizationMode="Recycling"
                                                   ItemTemplateSelector="{StaticResource BlockTemplateSelector}"
                                                   attachedProperties:SelectingItemAttachedProperty.SelectingItem="{Binding SectionBrowserSelectedBlockViewModel}"
                                                   SelectedItem="{Binding SelectedBlockViewModel}" x:Name="BlocksListBox">
                    <ListBox.InputBindings>
                        <KeyBinding Key="Delete" Command="{Binding DeleteBlockCommand}" />
                    </ListBox.InputBindings>
                    <ListBox.ItemContainerStyle>
                        <Style TargetType="ListBoxItem">
                            <Style.Triggers>
                                <Trigger Property="IsSelected" Value="True">
                                    <Setter Property="BorderThickness" Value="1"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </ListBox.ItemContainerStyle>
                    <ListBox.Resources>
                        <Style TargetType="ListBoxItem">
                            <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                        </Style>
                    </ListBox.Resources>
                </userControls:AutoScrollingListBox>
            </DockPanel>
        </Border>
    </Grid>
</UserControl>
