<UserControl x:Class="ModernFlyouts.Controls.BrightnessControl"
             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:ui="http://schemas.modernwpf.com/2019"
             xmlns:local="clr-namespace:ModernFlyouts.Controls"
             xmlns:rootui="clr-namespace:ModernFlyouts.UI"
             xmlns:toolkit="http://schemas.modernwpf.com/toolkit"
             xmlns:utils="clr-namespace:ModernFlyouts.Utilities"
             xmlns:display="clr-namespace:ModernFlyouts.Core.Display;assembly=ModernFlyouts.Core"
             mc:Ignorable="d" d:DesignWidth="354"
             MaxHeight="216" DataContext="{x:Static display:BrightnessManager.Instance}">
    
    <local:ContentScrollViewer x:Name="ContentScrollViewer"
                               ContentHeight="48"
                               ContentWidth="{x:Static rootui:UIManager.FlyoutWidth}"
                               VerticalSpacing="{x:Static rootui:UIManager.DefaultVerticalSpacing}">
        <ItemsControl ItemsSource="{Binding BrightnessControllers}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <ui:SimpleStackPanel Orientation="Vertical"
                        Spacing="{x:Static rootui:UIManager.DefaultVerticalSpacing}"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.Resources>
                <DataTemplate DataType="{x:Type display:BrightnessController}">
                    <Border Height="48" CornerRadius="{DynamicResource FlyoutCornerRadius}"
                            Background="{DynamicResource SystemControlBackgroundAltMediumLowBrush}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="48" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="48" />
                            </Grid.ColumnDefinitions>

                            <Grid>
                                <ui:FontIcon x:Name="BrightnessGlyph" Grid.Column="0" FontSize="16">
                                    <ui:FontIcon.Glyph>
                                        <Binding Path="Brightness">
                                            <Binding.Converter>
                                                <toolkit:DoubleToObjectConverter GreaterThan="50"
                                                TrueValue="{x:Static utils:CommonGlyphs.Brightness}"
                                                FalseValue="{x:Static utils:CommonGlyphs.LowerBrightness}" />
                                            </Binding.Converter>
                                        </Binding>
                                    </ui:FontIcon.Glyph>
                                </ui:FontIcon>
                                <Border Background="{DynamicResource SystemControlBackgroundBaseMediumLowBrush}"
                                        Width="16" Height="16" CornerRadius="8" Margin="16,16,0,0"
                                        VerticalAlignment="Center" HorizontalAlignment="Center"
                                        ToolTip="{Binding AssociatedDisplayMonitor.DisplayName}">
                                    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center"
                                        Text="{Binding AssociatedDisplayMonitor.Index}" />
                                </Border>
                            </Grid>

                            <Slider x:Name="BrightnessSlider" Maximum="{Binding Maximum}"
                                    Minimum="{Binding Minimum}" Grid.Column="1" VerticalAlignment="Center" Margin="8,0"
                                    SmallChange="0.01" Value="{Binding Brightness}" IsMoveToPointEnabled="True" />

                            <TextBlock x:Name="textVal" Grid.Column="2" HorizontalAlignment="Center" Margin="6"
                                       Style="{DynamicResource SubtitleTextBlockStyle}"
                                       Text="{Binding Brightness, StringFormat={}{0:#0}}" VerticalAlignment="Center" />
                        </Grid>
                    </Border>
                </DataTemplate>
            </ItemsControl.Resources>
        </ItemsControl>
    </local:ContentScrollViewer>

</UserControl>
