<UserControl
    x:Class="NixExampleWinUI.Views.ColorSwatch"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:helpers="using:NixExampleWinUI.Helpers"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:viewmodels="using:NixExampleWinUI.ViewModels" d:DataContext="{d:DesignInstance Type=viewmodels:ColorSwatchViewModel}"
    mc:Ignorable="d">

    <UserControl.Resources>
        <helpers:NullableBooleanToVisibilityConverter x:Key="NullableBooleanToVisibilityConverter"/>
        <helpers:ReferenceWhiteToStringConverter x:Key="ReferenceWhiteToStringConverter"/>
    </UserControl.Resources>

    <RelativePanel Name="BackgroundPanel" 
                   RequestedTheme="{x:Bind ViewModel.ColorTheme, Mode=OneWay}">
        <Rectangle x:Name="ColorRectangle"
                   Margin="0,0,0,0" 
                   RadiusX="6" 
                   RadiusY="6"
                   VerticalAlignment="Stretch"
                   HorizontalAlignment="Stretch"
                   RelativePanel.AlignTopWithPanel="True"
                   RelativePanel.AlignLeftWithPanel="True"
                   RelativePanel.AlignRightWithPanel="True"
                   RelativePanel.AlignBottomWithPanel="True"
                   Fill="{x:Bind ViewModel.FillBrush, Mode=OneWay}">
        </Rectangle>
        <TextBlock x:Name="ValueLabel"
                   Margin="16,0,0,16"
                   RelativePanel.AlignLeftWithPanel="True"
                   RelativePanel.AlignBottomWithPanel="True"
                   RelativePanel.AlignRightWithPanel="True"
                   Style="{StaticResource BodyTextBlockStyle}" 
                   FontSize="16"
                   Text="{x:Bind ViewModel.LabValueText, Mode=OneWay}"/>
        <TextBlock x:Name="HeaderLabel"
                   Margin="16,0,0,0"
                   RelativePanel.AlignLeftWith="ValueLabel"
                   RelativePanel.AlignRightWith="ValueLabel"
                   RelativePanel.Above="ValueLabel"
                   Style="{StaticResource BodyStrongTextBlockStyle}"
                   FontSize="16"
                   Text="{x:Bind ViewModel.LabHeaderText, Mode=OneWay}"/>

        <StackPanel x:Name="ButtonStack"
                    Orientation="Horizontal"
                    RelativePanel.AlignTopWithPanel="True"
                    RelativePanel.AlignRightWithPanel="True"
                    Margin="16,16,16,16">            
            <Button x:Name="CopyButton"
                Visibility="{x:Bind ViewModel.IsDataAvailable, Mode=OneWay, Converter={StaticResource NullableBooleanToVisibilityConverter}}"
                    Margin="0,0,3,0"
                Click="CopyButton_Click">
                <ToolTipService.ToolTip>
                    <ToolTip x:Uid="ColorSwatch_CopyButton_ToolTip"/>
                </ToolTipService.ToolTip>
                <Button.Content>
                    <FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xEF3C;"/>
                </Button.Content>
            </Button>
            <Button x:Name="InfoButton"
                Visibility="{x:Bind ViewModel.IsDataAvailable, Mode=OneWay, Converter={StaticResource NullableBooleanToVisibilityConverter}}"
                Click="InfoButton_Click">
                <ToolTipService.ToolTip>
                    <ToolTip x:Uid="ColorSwatch_InfoButton_ToolTip"/>
                </ToolTipService.ToolTip>
                <Button.Content>
                    <FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="&#xE946;"/>
                </Button.Content>
            </Button>            
        </StackPanel>

        <ComboBox x:Name="ReferenceComboBox"
                  FontWeight="Normal"
                  Margin="16,16,16,16"
                  RelativePanel.AlignLeftWithPanel="True"
                  RelativePanel.AlignTopWith="ButtonStack"
                  RelativePanel.AlignBottomWith="ButtonStack"
                  VerticalAlignment="Stretch"
                  ItemsSource="{x:Bind ViewModel.MeasurementData.SupportedReferences, Mode=OneWay}"
                  SelectedItem="{x:Bind ViewModel.SelectedReference, Mode=TwoWay}"
                  Visibility="{x:Bind ViewModel.IsDataAvailable, Mode=OneWay, Converter={StaticResource NullableBooleanToVisibilityConverter}}">
            <ToolTipService.ToolTip>
                <ToolTip x:Uid="ColorSwatch_ComboBox_ToolTip"/>
            </ToolTipService.ToolTip>
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Converter={StaticResource ReferenceWhiteToStringConverter}}"/>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
    </RelativePanel>
</UserControl>
