<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:treeItem1="clr-namespace:Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem"
    xmlns:converters="clr-namespace:Artemis.UI.Converters"
    xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
    x:Class="Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem.LayerView"
    mc:Ignorable="d"
    d:DesignHeight="450" d:DesignWidth="800"
    d:DataContext="{d:DesignInstance {x:Type treeItem1:LayerViewModel}}">
    <UserControl.Resources>
        <converters:InverseBooleanConverter x:Key="InverseBooleanConverter" />
        <shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
    </UserControl.Resources>
    <!-- Capture clicks on full tree view item -->
    <StackPanel Margin="-10" Background="Transparent" ContextMenuOpening="{s:Action ContextMenuOpening}">
        <StackPanel.ContextMenu>
            <ContextMenu>
                <MenuItem Header="Duplicate" Command="{s:Action DuplicateElement}" InputGestureText="Ctrl+D">
                    <MenuItem.Icon>
                        <materialDesign:PackIcon Kind="ContentDuplicate" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Copy" Command="{s:Action CopyElement}" InputGestureText="Ctrl+C">
                    <MenuItem.Icon>
                        <materialDesign:PackIcon Kind="ContentCopy" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Paste" Command="{s:Action PasteElement}" InputGestureText="Ctrl+V">
                    <MenuItem.Icon>
                        <materialDesign:PackIcon Kind="ContentPaste" />
                    </MenuItem.Icon>
                </MenuItem>
                <Separator />
                <MenuItem Header="View adaption hints" Command="{s:Action OpenAdaptionHints}">
                    <MenuItem.Icon>
                        <materialDesign:PackIcon Kind="AutoFix" />
                    </MenuItem.Icon>
                </MenuItem>
                <Separator />
                <MenuItem Header="Rename" Command="{s:Action RenameElement}" InputGestureText="F2">
                    <MenuItem.Icon>
                        <materialDesign:PackIcon Kind="RenameBox" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Delete" Command="{s:Action DeleteElement}" InputGestureText="Del">
                    <MenuItem.Icon>
                        <materialDesign:PackIcon Kind="TrashCan" />
                    </MenuItem.Icon>
                </MenuItem>
            </ContextMenu>
        </StackPanel.ContextMenu>
        <Grid Margin="10">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Button Grid.Column="0"
                    Style="{StaticResource MaterialDesignFloatingActionMiniDarkButton}"
                    ToolTip="{Binding BrokenState}"
                    Visibility="{Binding BrokenState, Converter={StaticResource NullToVisibilityConverter}}"
                    Foreground="White"
                    Background="#E74C4C"
                    BorderBrush="#E74C4C"
                    Width="18"
                    Height="18"
                    Margin="0 0 5 0"
                    Command="{s:Action ShowBrokenStateExceptions}">
                <materialDesign:PackIcon Kind="AlertCircle" Height="12" Width="12" />
            </Button>
            <materialDesign:PackIcon Grid.Column="1" Kind="Layers" Width="16" VerticalAlignment="Center" />
            <shared:ArtemisIcon Grid.Column="2"
                                VerticalAlignment="Center"
                                Icon="{Binding Layer.LayerBrush.Descriptor.Icon}"
                                Width="16"
                                Margin="5 0 0 0"
                                ToolTip="{Binding Layer.LayerBrush.Descriptor.DisplayName, Mode=OneWay}"
                                Visibility="{Binding ShowIcons, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}"
                                Background="Transparent" />
            <TextBlock Grid.Column="3" Text="{Binding Layer.Name}" VerticalAlignment="Center" Margin="5 0 0 0" />
            <ToggleButton Grid.Column="4"
                          Style="{StaticResource MaterialDesignFlatToggleButton}"
                          Width="18"
                          Height="18"
                          IsChecked="{Binding ProfileElement.Suspended, Converter={StaticResource InverseBooleanConverter}}"
                          Command="{s:Action SuspendedToggled}"
                          VerticalAlignment="Center" Padding="-25">
                <ToggleButton.ToolTip>
                    <TextBlock>
                        Toggle suspended state <LineBreak />
                        <Bold>Shift+click</Bold> to toggle focus
                    </TextBlock>
                </ToggleButton.ToolTip>
                <materialDesign:PackIcon Kind="Eye" Height="13" Width="13" />
            </ToggleButton>
        </Grid>
    </StackPanel>
</UserControl>