<?xml version="1.0" encoding="utf-8"?>
<UserControl
    x:Class="Sonex.Client.Controls.Filters.SqlFilterBuilder"
    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:tk="using:CommunityToolkit.WinUI.Controls"
    mc:Ignorable="d">

    <Grid x:Name="RootGrid" >
        <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>

        <Border Grid.Row="2" CornerRadius="10" Padding="0" BorderThickness="1"  Background="{StaticResource CardBackgroundFillColorDefaultBrush}" BorderBrush="{StaticResource CardStrokeColorDefaultBrush}">
            <Grid >
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
                <!--<StackPanel x:Name="RowsPanel" Grid.Row="1" Spacing="12" Orientation="Vertical" Padding="12" />-->
                <tk:WrapPanel x:Name="RowsPanel" Grid.Row="0" HorizontalSpacing="12" VerticalSpacing="12" Padding="12" Background="{StaticResource SolidBackgroundFillColorTertiaryBrush}">
                    <StackPanel x:Name="ActionButtonsPanel"
                                Orientation="Horizontal"
                                Spacing="4"
                                VerticalAlignment="Top">
                        <Button x:Name="AddRuleButton"
                                Height="30"
                                MinHeight="30"
                                Width="30"
                                MinWidth="30"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                Padding="0,0"
                                Click="AddRuleButton_Click">
                            <FontIcon Glyph="&#xE710;" FontSize="12" />
                        </Button>

                        <Button x:Name="ClearButton"
                                Height="30"
                                MinHeight="30"
                                Width="50"
                                MinWidth="50"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                Padding="0,0"
                                Visibility="Collapsed"
                                Click="ClearButton_Click">
                            <TextBlock Text="Clear" FontSize="14" />
                        </Button>

                        <Button x:Name="ApplyButton"
                                Height="30"
                                MinHeight="30"
                                Width="30"
                                MinWidth="30"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                Padding="0,0"
                                Click="ApplyButton_Click">
                            <FontIcon Glyph="&#xE721;" FontSize="14" />
                        </Button>
                    </StackPanel>
                </tk:WrapPanel>

            </Grid>
        </Border>


    </Grid>
</UserControl>
