<UserControl x:Class="Artemis.UI.Shared.Input.DataModelStaticView"
             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:input="clr-namespace:Artemis.UI.Shared.Input"
             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:s="https://github.com/canton7/Stylet"
             xmlns:shared="clr-namespace:Artemis.UI.Shared"
             mc:Ignorable="d"
             d:DesignHeight="450" d:DesignWidth="800"
             d:DataContext="{d:DesignInstance input:DataModelStaticViewModel}">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/Artemis.UI.Shared;component/ResourceDictionaries/DataModelConditions.xaml" />
                <ResourceDictionary>
                    <shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
                    <Style x:Key="DataModelConditionButtonCornerToggle" BasedOn="{StaticResource DataModelConditionButton}" TargetType="Button">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding DisplaySwitchButton}" Value="True">
                                <Setter Property="materialDesign:ButtonAssist.CornerRadius" Value="0 2 2 0" />
                            </DataTrigger>
                            <DataTrigger Binding="{Binding DisplaySwitchButton}" Value="False">
                                <Setter Property="materialDesign:ButtonAssist.CornerRadius" Value="2" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <StackPanel Orientation="Horizontal" Visibility="{Binding InputViewModel, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">
            <Button Style="{StaticResource MaterialDesignFlatDarkBgButton}"
                    Background="{Binding SwitchButtonBrush}"
                    BorderBrush="{Binding SwitchButtonBrush}"
                    Height="22"
                    Padding="0"
                    Width="22"
                    FontSize="12"
                    materialDesign:ButtonAssist.CornerRadius="2 0 0 2"
                    Margin="3 0 -3 0"
                    HorizontalAlignment="Left"
                    ToolTip="Switch to data model value"
                    Command="{s:Action SwitchToDynamic}"
                    Visibility="{Binding DisplaySwitchButton, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
                <materialDesign:PackIcon Kind="SwapHorizontal" />
            </Button>
            <Button Style="{StaticResource DataModelConditionButtonCornerToggle}"
                    Background="{Binding ButtonBrush}"
                    BorderBrush="{Binding ButtonBrush}"
                    Command="{s:Action ActivateInputViewModel}"
                    HorizontalAlignment="Left"
                    IsEnabled="{Binding IsEnabled}"
                    ToolTip="Click to edit value">
                <Grid>
                    <StackPanel Visibility="{Binding Value, Converter={StaticResource NullToVisibilityConverter}}" Orientation="Horizontal">
                        <ContentControl s:View.Model="{Binding DisplayViewModel}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
                    </StackPanel>

                    <TextBlock FontStyle="Italic" Visibility="{Binding Value, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}">
                        <Run Text="« " /><Run Text="{Binding Placeholder}" /><Run Text=" »" />
                    </TextBlock>
                </Grid>
            </Button>
        </StackPanel>
        
        <Border BorderBrush="{Binding ButtonBrush}"
                Background="{DynamicResource MaterialDesignPaper}"
                Visibility="{Binding InputViewModel, Converter={StaticResource NullToVisibilityConverter}}"
                CornerRadius="3"
                Padding="3"
                Margin="0 -3"
                HorizontalAlignment="Left"
                MinWidth="140">
            <ContentControl s:View.Model="{Binding InputViewModel}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
        </Border>
    </Grid>
</UserControl>