<UserControl x:Class="MassiveKnob.View.Settings.BaseSettingsInputOutputView"
             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:settings="clr-namespace:MassiveKnob.ViewModel.Settings"
             xmlns:viewModel="clr-namespace:MassiveKnob.ViewModel"
             xmlns:massiveKnob="clr-namespace:MassiveKnob"
             xmlns:helpers="clr-namespace:MassiveKnob.Helpers"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="800"
             d:DataContext="{d:DesignInstance Type=settings:BaseSettingsInputOutputViewModelDesignTime, IsDesignTimeCreatable=True}">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../../Style.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <DataTemplate x:Key="ActionDropdownItem">
                <StackPanel Orientation="Vertical" d:DataContext="{d:DesignInstance Type=viewModel:ActionViewModel}">
                    <TextBlock Text="{Binding Name}" />
                    <TextBlock Text="{Binding Description}" Style="{StaticResource ComboBoxDescription}" Visibility="{Binding DescriptionVisibility}" />
                </StackPanel>
            </DataTemplate>

            <DataTemplate x:Key="ActionSelectedItem">
                <TextBlock Text="{Binding Name}" d:DataContext="{d:DesignInstance Type=viewModel:ActionViewModel}" />
            </DataTemplate>
        </ResourceDictionary>
    </UserControl.Resources>

    <StackPanel Orientation="Vertical" SnapsToDevicePixels="True" UseLayoutRounding="True"  TextOptions.TextFormattingMode="Display">
        <ItemsControl ItemsSource="{Binding InputOutputs}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical" Style="{StaticResource Content}">
                        <TextBlock Text="{Binding DisplayName}" Style="{StaticResource SubHeader}"></TextBlock>

                        <StackPanel Orientation="Vertical">
                            <ComboBox 
                ItemsSource="{Binding Actions}" 
                SelectedItem="{Binding SelectedAction}" 
                IsSynchronizedWithCurrentItem="False" 
                ItemTemplateSelector="{helpers:ComboBoxTemplateSelector 
                                        SelectedItemTemplate={StaticResource ActionSelectedItem},
                                        DropdownItemsTemplate={StaticResource ActionDropdownItem}}" />

                            <ContentControl Focusable="False" Content="{Binding ActionSettingsControl}" Style="{StaticResource SettingsControl}" />

                            <Grid Margin="0,24,0,0" Visibility="{Binding DigitalToAnalogVisibility}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                </Grid.RowDefinitions>

                                <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Text="{x:Static massiveKnob:Strings.DigitalToAnalogDescription}" TextWrapping="Wrap" />

                                <TextBlock Grid.Row="1" Grid.Column="0" Margin="0,8,8,8" VerticalAlignment="Center" Text="{x:Static massiveKnob:Strings.DigitalToAnalogOn}" />
                                <Slider Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Value="{Binding DigitalToAnalogOn}" Minimum="0" Maximum="100" />

                                <TextBlock Grid.Row="2" Grid.Column="0" Margin="0,8,8,8" VerticalAlignment="Center" Text="{x:Static massiveKnob:Strings.DigitalToAnalogOff}" />
                                <Slider Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" Value="{Binding DigitalToAnalogOff}" Minimum="0" Maximum="100" />
                            </Grid>
                        </StackPanel>
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </StackPanel>
</UserControl>
