<?xml version="1.0" encoding="utf-8"?>
<Flyout
    x:Class="Sonex.Client.Controls.DataGridView.FilterFlyout"
    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"
    mc:Ignorable="d"
    Placement="Bottom"
    AreOpenCloseAnimationsEnabled="False">

    <!-- Styl kontenera flyout: szerokosc i wyglad spójny z DataGridView. -->
    <Flyout.FlyoutPresenterStyle>
        <Style TargetType="FlyoutPresenter">
            <Setter Property="Padding" Value="12" />
            <Setter Property="CornerRadius" Value="12" />
            <Setter Property="BorderBrush" Value="{ThemeResource SurfaceStrokeColorDefaultBrush}" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="Background" Value="{ThemeResource SolidBackgroundFillColorQuarternaryBrush}" />
            <Setter Property="Width" Value="500" />
            <Setter Property="MinWidth" Value="500" />
        </Style>
    </Flyout.FlyoutPresenterStyle>

    <!-- Uklad flyout: lista warunkow + panel akcji. -->
    <Grid>
        <Grid.Resources>
            <Thickness x:Key="ComparisonMenuFlyoutItemPlaceholderThemeThickness">36,0,0,0</Thickness>
            <Thickness x:Key="ComparisonMenuFlyoutItemDoublePlaceholderThemeThickness">64,0,0,0</Thickness>

            <Style x:Key="ComparisonMenuFlyoutItemStyle"
                   TargetType="MenuFlyoutItem"
                   BasedOn="{StaticResource DefaultMenuFlyoutItemStyle}">
                <Setter Property="FontSize" Value="12" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="MenuFlyoutItem">
                            <Grid x:Name="LayoutRoot"
                                  Padding="{TemplateBinding Padding}"
                                  Background="{TemplateBinding Background}"
                                  BorderBrush="{TemplateBinding BorderBrush}"
                                  BorderThickness="{TemplateBinding BorderThickness}"
                                  Margin="{StaticResource MenuFlyoutItemMargin}"
                                  CornerRadius="{TemplateBinding CornerRadius}">

                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal" />

                                        <VisualState x:Name="PointerOver">
                                            <VisualState.Setters>
                                                <Setter Target="LayoutRoot.Background" Value="{ThemeResource MenuFlyoutItemBackgroundPointerOver}" />
                                                <Setter Target="TextBlock.Foreground" Value="{ThemeResource MenuFlyoutItemForegroundPointerOver}" />
                                                <Setter Target="IconContent.Foreground" Value="{ThemeResource MenuFlyoutItemForegroundPointerOver}" />
                                                <Setter Target="KeyboardAcceleratorTextBlock.Foreground" Value="{ThemeResource MenuFlyoutItemKeyboardAcceleratorTextForegroundPointerOver}" />
                                            </VisualState.Setters>
                                        </VisualState>

                                        <VisualState x:Name="Pressed">
                                            <VisualState.Setters>
                                                <Setter Target="LayoutRoot.Background" Value="{ThemeResource MenuFlyoutItemBackgroundPressed}" />
                                                <Setter Target="TextBlock.Foreground" Value="{ThemeResource MenuFlyoutItemForegroundPressed}" />
                                                <Setter Target="IconContent.Foreground" Value="{ThemeResource MenuFlyoutItemForegroundPressed}" />
                                                <Setter Target="KeyboardAcceleratorTextBlock.Foreground" Value="{ThemeResource MenuFlyoutItemKeyboardAcceleratorTextForegroundPressed}" />
                                            </VisualState.Setters>
                                        </VisualState>

                                        <VisualState x:Name="Disabled">
                                            <VisualState.Setters>
                                                <Setter Target="LayoutRoot.Background" Value="{ThemeResource MenuFlyoutItemBackgroundDisabled}" />
                                                <Setter Target="TextBlock.Foreground" Value="{ThemeResource MenuFlyoutItemForegroundDisabled}" />
                                                <Setter Target="IconContent.Foreground" Value="{ThemeResource MenuFlyoutItemForegroundDisabled}" />
                                                <Setter Target="KeyboardAcceleratorTextBlock.Foreground" Value="{ThemeResource MenuFlyoutItemKeyboardAcceleratorTextForegroundDisabled}" />
                                            </VisualState.Setters>
                                        </VisualState>
                                    </VisualStateGroup>

                                    <VisualStateGroup x:Name="CheckPlaceholderStates">
                                        <VisualState x:Name="NoPlaceholder" />
                                        <VisualState x:Name="CheckPlaceholder">
                                            <VisualState.Setters>
                                                <Setter Target="TextBlock.Margin" Value="{StaticResource ComparisonMenuFlyoutItemPlaceholderThemeThickness}" />
                                            </VisualState.Setters>
                                        </VisualState>
                                        <VisualState x:Name="IconPlaceholder">
                                            <VisualState.Setters>
                                                <Setter Target="TextBlock.Margin" Value="{StaticResource ComparisonMenuFlyoutItemPlaceholderThemeThickness}" />
                                                <Setter Target="IconRoot.Visibility" Value="Visible" />
                                            </VisualState.Setters>
                                        </VisualState>
                                        <VisualState x:Name="CheckAndIconPlaceholder">
                                            <VisualState.Setters>
                                                <Setter Target="TextBlock.Margin" Value="{StaticResource ComparisonMenuFlyoutItemDoublePlaceholderThemeThickness}" />
                                                <Setter Target="IconRoot.Margin" Value="{StaticResource ComparisonMenuFlyoutItemPlaceholderThemeThickness}" />
                                                <Setter Target="IconRoot.Visibility" Value="Visible" />
                                            </VisualState.Setters>
                                        </VisualState>
                                    </VisualStateGroup>

                                    <VisualStateGroup x:Name="PaddingSizeStates">
                                        <VisualState x:Name="DefaultPadding" />
                                        <VisualState x:Name="NarrowPadding">
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="LayoutRoot"
                                                                               Storyboard.TargetProperty="Padding">
                                                    <DiscreteObjectKeyFrame KeyTime="0"
                                                                            Value="{StaticResource MenuFlyoutItemThemePaddingNarrow}" />
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>

                                    <VisualStateGroup x:Name="KeyboardAcceleratorTextVisibility">
                                        <VisualState x:Name="KeyboardAcceleratorTextCollapsed" />
                                        <VisualState x:Name="KeyboardAcceleratorTextVisible">
                                            <VisualState.Setters>
                                                <Setter Target="KeyboardAcceleratorTextBlock.Visibility" Value="Visible" />
                                            </VisualState.Setters>
                                        </VisualState>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>

                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>

                                <Viewbox x:Name="IconRoot"
                                         HorizontalAlignment="Left"
                                         VerticalAlignment="Center"
                                         Width="24"
                                         Height="16"
                                         Visibility="Collapsed">
                                    <ContentPresenter x:Name="IconContent"
                                                      Content="{TemplateBinding Icon}"
                                                      Foreground="{TemplateBinding Foreground}" />
                                </Viewbox>

                                <TextBlock x:Name="TextBlock"
                                           Text="{TemplateBinding Text}"
                                           FontSize="{TemplateBinding FontSize}"
                                           TextTrimming="{ThemeResource MenuFlyoutItemTextTrimming}"
                                           Foreground="{TemplateBinding Foreground}"
                                           HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                           VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />

                                <TextBlock x:Name="KeyboardAcceleratorTextBlock"
                                           Grid.Column="1"
                                           Style="{ThemeResource CaptionTextBlockStyle}"
                                           Text="{TemplateBinding KeyboardAcceleratorTextOverride}"
                                           MinWidth="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.KeyboardAcceleratorTextMinWidth}"
                                           Margin="24,4,0,0"
                                           Foreground="{ThemeResource MenuFlyoutItemKeyboardAcceleratorTextForeground}"
                                           TextAlignment="Right"
                                           HorizontalAlignment="Right"
                                           VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                           Visibility="Collapsed"
                                           AutomationProperties.AccessibilityView="Raw" />
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>


        <!-- Lista wierszy warunkow filtrowania (z przewijaniem dla dlugich zestawow). -->
        <ScrollViewer Grid.Row="0" MaxHeight="500" VerticalScrollMode="Auto" HorizontalScrollMode="Disabled" >
            <StackPanel x:Name="RowsPanel" Spacing="6"/>
        </ScrollViewer>

        <!-- Przyciski akcji dla calego zestawu warunkow. -->
        <Grid Grid.Row="1" Margin="0,10,0,0" ColumnSpacing="8">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Button Grid.Column="0" x:Name="ClearRulesButton" Content="Clear" Height="28" MinHeight="28" MaxHeight="28" FontSize="12" Click="ClearRulesButton_Click">
                
            </Button>
            <Button Grid.Column="2" x:Name="AddRuleButton" Content="Add Rule" Height="28" MinHeight="28" MaxHeight="28" FontSize="12" Click="AddRuleButton_Click" />
            <Button Grid.Column="3" x:Name="ApplyButton" Style="{StaticResource AccentButtonStyle}" Content="Apply" Height="28" MinHeight="28" MaxHeight="28" FontSize="12" Click="ApplyButton_Click" />
        </Grid>
    </Grid>
</Flyout>
