<UserControl
    x:Class="CubeKit.UI.Controls.Settings.SettingsBlockControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:CubeKit.UI.Controls.Settings"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <UserControl.Resources>
        <local:InverseBooleanConverter x:Key="InverseBooleanConverter" />
        <local:NullToTrueConverter x:Key="NullToFalseConverter" Inverse="True" />
        <local:NullToTrueConverter x:Key="NullToTrueConverter" Inverse="False" />
        <local:StringNullOrWhiteSpaceToTrueConverter x:Key="StringNullOrWhiteSpaceToFalseConverter" Inverse="True" />
        <local:StringNullOrWhiteSpaceToTrueConverter x:Key="StringNullOrWhiteSpaceToTrueConverter" Inverse="False" />

        <Style x:Key="TextBlockGroupHeaderStyle" TargetType="TextBlock">
            <Setter Property="Margin" Value="0,8,0,4" />
            <Setter Property="FontSize" Value="16" />
            <Setter Property="TextWrapping" Value="Wrap" />
            <Setter Property="FontWeight" Value="Bold" />
        </Style>

        <Style x:Key="GridSettingsBlockStyle" TargetType="Grid">
            <Setter Property="Background" Value="{ThemeResource ExpanderHeaderBackground}" />
            <Setter Property="BorderBrush" Value="{ThemeResource ExpanderHeaderBorderBrush}" />
            <Setter Property="BorderThickness" Value="{ThemeResource ExpanderHeaderBorderThickness}" />
            <Setter Property="HorizontalAlignment" Value="Stretch" />
            <Setter Property="MinHeight" Value="{StaticResource ExpanderMinHeight}" />
            <Setter Property="Padding" Value="{StaticResource ExpanderContentPadding}" />
            <Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
        </Style>

        <Style x:Key="ButtonSettingsBlockStyle" TargetType="Button" BasedOn="{StaticResource DefaultButtonStyle}">
            <Setter Property="Background" Value="{ThemeResource ExpanderHeaderBackground}" />
            <Setter Property="BorderBrush" Value="{ThemeResource ExpanderHeaderBorderBrush}" />
            <Setter Property="BorderThickness" Value="{ThemeResource ExpanderHeaderBorderThickness}" />
            <Setter Property="HorizontalAlignment" Value="Stretch" />
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="Padding" Value="{StaticResource ExpanderContentPadding}" />
            <Setter Property="MinHeight" Value="{StaticResource ExpanderMinHeight}" />
            <Setter Property="CornerRadius" Value="{ThemeResource ControlCornerRadius}" />
        </Style>
    </UserControl.Resources>

    <Grid>
        <!-- Expander -->
        <Grid x:Name="ExpanderPreGrid" x:Load="{x:Bind ExpandableContent, Mode=OneWay, Converter={StaticResource NullToFalseConverter}}">
            <Grid x:Name="ExpanderGrid" x:Load="{x:Bind IsClickable, Mode=OneWay, Converter={StaticResource InverseBooleanConverter}}">
                <Expander HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" Expanding="Expander_Expanding" Collapsed="Expander_Collapsed">
                    <Expander.Header>
                        <local:SettingsDisplayControl Icon="{x:Bind Icon, Mode=OneWay}" 
                                                      Margin="0,16"
                                                      AdditionalDescriptionContent="{x:Bind AdditionalDescriptionContent, Mode=OneWay}" 
                                                      Title="{x:Bind Title, Mode=OneWay}" 
                                                      Description="{x:Bind Description, Mode=OneWay}" 
                                                      SettingsActionableElement="{x:Bind SettingsActionableElement, Mode=OneWay}"/>
                    </Expander.Header>

                    <ContentPresenter Margin="-16" HorizontalAlignment="Stretch" Content="{x:Bind ExpandableContent, Mode=OneWay}" />
                </Expander>
            </Grid>
        </Grid>
        <!-- Button -->
        <Grid x:Name="ButtonPreGrid" x:Load="{x:Bind ExpandableContent, Mode=OneWay, Converter={StaticResource NullToTrueConverter}}">
            <Grid x:Name="ButtonGrid" x:Load="{x:Bind IsClickable, Mode=OneWay}">
                <Button x:Name="ActionableButton" Style="{StaticResource ButtonSettingsBlockStyle}" Click="ActionableButton_Click">
                    <local:SettingsDisplayControl Icon="{x:Bind Icon, Mode=OneWay}" 
                                                  AdditionalDescriptionContent="{x:Bind AdditionalDescriptionContent, Mode=OneWay}" 
                                                  Title="{x:Bind Title, Mode=OneWay}" 
                                                  Description="{x:Bind Description, Mode=OneWay}" 
                                                  SettingsActionableElement="{x:Bind SettingsActionableElement, Mode=OneWay}"/>
                </Button>
            </Grid>
        </Grid>
        <!-- Grid -->
        <Grid x:Name="StaticPreGrid" x:Load="{x:Bind ExpandableContent, Mode=OneWay, Converter={StaticResource NullToTrueConverter}}">
            <Grid x:Name="StaticGrid" x:Load="{x:Bind IsClickable, Mode=OneWay, Converter={StaticResource InverseBooleanConverter}}" Style="{StaticResource GridSettingsBlockStyle}">
                <local:SettingsDisplayControl Icon="{x:Bind Icon, Mode=OneWay}" 
                                              AdditionalDescriptionContent="{x:Bind AdditionalDescriptionContent, Mode=OneWay}" 
                                              Title="{x:Bind Title, Mode=OneWay}" 
                                              Description="{x:Bind Description, Mode=OneWay}" 
                                              SettingsActionableElement="{x:Bind SettingsActionableElement, Mode=OneWay}"/>
            </Grid>
        </Grid>
    </Grid>
</UserControl>
