<UserControl x:Class="Filtration.ThemeEditor.Views.ThemeComponentControl"
             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:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
             xmlns:commonConverters="clr-namespace:Filtration.Common.Converters;assembly=Filtration.Common"
             xmlns:themeEditor="clr-namespace:Filtration.ObjectModel.ThemeEditor;assembly=Filtration.ObjectModel"
             xmlns:views="clr-namespace:Filtration.ThemeEditor.Views"
             mc:Ignorable="d" 
             d:DataContext="{d:DesignInstance Type=themeEditor:ThemeComponent}"
             d:DesignHeight="100" d:DesignWidth="200">
    <UserControl.Resources>
        <commonConverters:BooleanVisibilityConverter x:Key="BooleanVisibilityConverter" />
    </UserControl.Resources>
    <Grid Width="200">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="25" />
        </Grid.RowDefinitions>
        <Grid.Resources>
            <DataTemplate x:Key="EditableComponentNameTemplate">
                <StackPanel>
                    <TextBlock Text="{Binding UsageCount, StringFormat='Usages: {0}'}"
                               FontSize="10"
                               HorizontalAlignment="Right"
                               Visibility="{Binding Path=DataContext.EditEnabled, RelativeSource={RelativeSource AncestorType={x:Type views:ThemeEditorView}}, Converter={StaticResource BooleanVisibilityConverter}}">
                        <TextBlock.Style>
                            <Style TargetType="TextBlock">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding UsageCount}" Value="0">
                                        <Setter Property="Foreground" Value="Red" />
                                    </DataTrigger>
                                </Style.Triggers>
                                <Setter Property="Foreground" Value="SteelBlue" />
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>
                    <TextBox Text="{Binding ComponentName}" />
                </StackPanel>
            </DataTemplate>
            <DataTemplate x:Key="ViewOnlyComponentNameTemplate">
                <TextBlock Text="{Binding ComponentName}" ToolTip="{Binding ComponentName}" />
            </DataTemplate>
        </Grid.Resources>
        <ContentControl Grid.Row="1" Content="{Binding}">
            <ContentControl.Style>
                <Style TargetType="ContentControl">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=DataContext.IsMasterTheme, RelativeSource={RelativeSource AncestorType={x:Type views:ThemeEditorView}}}" Value="true">
                            <Setter Property="ContentTemplate" Value="{StaticResource EditableComponentNameTemplate}" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=DataContext.IsMasterTheme, RelativeSource={RelativeSource AncestorType={x:Type views:ThemeEditorView}}}" Value="false">
                            <Setter Property="ContentTemplate" Value="{StaticResource ViewOnlyComponentNameTemplate}" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ContentControl.Style>
        </ContentControl>
        <xctk:ColorPicker Grid.Row="2" SelectedColor="{Binding Color}" />
    </Grid>
</UserControl>
