<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="OwlCore.Wpf.AbstractUI.Themes.AbstractMultiChoiceUIElementStyle"
    xmlns:behaviors="http://schemas.microsoft.com/xaml/behaviors"
    xmlns:abstractUI="clr-namespace:OwlCore.AbstractUI.ViewModels;assembly=OwlCore"
    xmlns:convertvis="clr-namespace:OwlCore.Wpf.Converters.Bools.Visible"
    xmlns:controls="clr-namespace:OwlCore.Wpf.AbstractUI.Controls"
    xmlns:themes="clr-namespace:OwlCore.Wpf.AbstractUI.Themes">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/OwlCore.Wpf;component/AbstractUI/Themes/AbstractUIResources.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <DataTemplate x:Key="DefaultAbstractMultipleChoiceComboBoxTemplate" DataType="abstractUI:AbstractMultiChoiceUIElementViewModel">
        <ComboBox ItemsSource="{Binding Items}" SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}">
            <ComboBox.ItemTemplate>
                <DataTemplate DataType="abstractUI:AbstractMultiChoiceItemViewModel">
                    <TextBlock Text="{Binding Title}" />
                </DataTemplate>
            </ComboBox.ItemTemplate>
            <behaviors:Interaction.Triggers>
                <behaviors:EventTrigger EventName="SelectionChanged">
                    <behaviors:InvokeCommandAction Command="{Binding ItemSelectedCommand}" />
                </behaviors:EventTrigger>
            </behaviors:Interaction.Triggers>
        </ComboBox>
    </DataTemplate>

    <DataTemplate x:Key="DefaultAbstractMultipleChoiceRadioButtonTemplate" DataType="abstractUI:AbstractMultiChoiceUIElementViewModel">
        <ItemsControl ItemsSource="{Binding Items}">
            <ItemsControl.ItemTemplate>
                <DataTemplate DataType="abstractUI:AbstractMultiChoiceItemViewModel">
                    <RadioButton Command="{Binding ItemSelectedCommand}" Content="{Binding Title}" GroupName="{Binding GroupId}" IsChecked="{Binding IsSelected, Mode=TwoWay}" />
                </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Vertical"  />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>
    </DataTemplate>

    <DataTemplate x:Key="DefaultAbstractMultipleChoiceTemplate" DataType="abstractUI:AbstractMultiChoiceUIElementViewModel">
        <StackPanel>
            <TextBlock Text="{Binding Title}" FontSize="{StaticResource DefaultAbstractUITitleFontSize}" ToolTipService.ToolTip="{Binding TooltipText}" />

            <TextBlock Text="{Binding Subtitle}" FontSize="{StaticResource DefaultAbstractUISubtitleFontSize}"
                       FontWeight="{StaticResource DefaultAbstractUISubtitleFontWeight}"
                       Opacity="{StaticResource DefaultAbstractUISubtitleOpacity}"
                       Visibility="{Binding Path=Subtitle, TargetNullValue=Collapsed}"/>

            <ContentControl Content="{Binding}" Margin="0,5,0,0">
                <ContentControl.ContentTemplateSelector>
                    <themes:AbstractMultiChoiceTypeTemplateSelector ComboBoxTemplate="{StaticResource DefaultAbstractMultipleChoiceComboBoxTemplate}"
                                                                    RadioButtonTemplate="{StaticResource DefaultAbstractMultipleChoiceRadioButtonTemplate}"/>
                </ContentControl.ContentTemplateSelector>
            </ContentControl>

        </StackPanel>
    </DataTemplate>

    <Style TargetType="controls:AbstractMultiChoicePresenter">
        <Style.Setters>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="controls:AbstractMultiChoicePresenter">
                        <ContentControl ContentTemplate="{StaticResource DefaultAbstractMultipleChoiceTemplate}"
                                        Content="{Binding}"
                                        HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style.Setters>
    </Style>

</ResourceDictionary>
