<UserControl
    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:s="https://github.com/canton7/Stylet"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    xmlns:utilities="clr-namespace:Artemis.UI.Utilities"
    xmlns:DataModelConditions="clr-namespace:Artemis.UI.Screens.ProfileEditor.Conditions"
    x:Class="Artemis.UI.Screens.ProfileEditor.Conditions.DataModelConditionListPredicateView"
    mc:Ignorable="d"
    d:DesignHeight="450" d:DesignWidth="800"
    d:DataContext="{d:DesignInstance IsDesignTimeCreatable=False, Type={x:Type DataModelConditions:DataModelConditionListPredicateViewModel}}">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/Artemis.UI;component/ResourceDictionaries/DataModelConditions.xaml" />
                <ResourceDictionary>
                    <utilities:BindingProxy x:Key="DataContextProxy" Data="{Binding}" />
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid Margin="0 0 0 3">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Button Grid.Row="0"
                Grid.Column="0"
                ToolTip="Delete the predicate"
                Style="{StaticResource MaterialDesignIconForegroundButton}"
                HorizontalAlignment="Left"
                Foreground="#E74C4C"
                Width="25"
                Height="25"
                Command="{s:Action Delete}">
            <materialDesign:PackIcon Kind="Close" Width="18" Height="18" />
        </Button>

        <!-- Left side, always a property -->
        <ContentControl Grid.Row="0" 
                        Grid.Column="1"
                        s:View.Model="{Binding LeftSideSelectionViewModel}"
                        VerticalContentAlignment="Stretch" 
                        HorizontalContentAlignment="Stretch"
                        IsTabStop="False" />

        <!-- Operator -->
        <Button Grid.Row="0"
                Grid.Column="2"
                Style="{StaticResource DataModelConditionButtonLeftClickMenu}"
                Background="#7B7B7B"
                BorderBrush="#7B7B7B"
                Content="{Binding SelectedOperator.Description}"
                IsEnabled="{Binding CanSelectOperator}"
                Click="PropertyButton_OnClick">
            <Button.ContextMenu>
                <ContextMenu ItemsSource="{Binding Operators}">
                    <ContextMenu.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <materialDesign:PackIcon Kind="{Binding Icon}" VerticalAlignment="Center" Margin="0 0 15 0" />
                                <TextBlock Text="{Binding Description}" VerticalAlignment="Center" />
                            </StackPanel>
                        </DataTemplate>
                    </ContextMenu.ItemTemplate>
                    <ContextMenu.ItemContainerStyle>
                        <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MaterialDesignMenuItem}">
                            <Setter Property="Command" Value="{Binding Data.SelectOperatorCommand, Source={StaticResource DataContextProxy}}" />
                            <Setter Property="CommandParameter" Value="{Binding}" />
                            <Setter Property="CommandTarget" Value="{Binding}" />
                        </Style>
                    </ContextMenu.ItemContainerStyle>
                </ContextMenu>
            </Button.ContextMenu>
        </Button>

        <!-- Right side, either a selection or an input -->
        <ContentControl Grid.Row="0" 
                        Grid.Column="3"
                        s:View.Model="{Binding RightSideSelectionViewModel}"
                        VerticalContentAlignment="Stretch" 
                        HorizontalContentAlignment="Stretch"
                        IsTabStop="False" />
        <ContentControl Grid.Row="0" 
                        Grid.Column="3"
                        s:View.Model="{Binding RightSideInputViewModel}"
                        VerticalContentAlignment="Stretch" 
                        HorizontalContentAlignment="Stretch"
                        IsTabStop="False" />
    </Grid>
</UserControl>