<Window x:Class="EarTrumpet.UI.Views.FullWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Event="clr-namespace:EarTrumpet.Extensions.EventBinding"
        xmlns:Theme="clr-namespace:EarTrumpet.UI.Themes"
        xmlns:b="clr-namespace:EarTrumpet.UI.Behaviors"
        xmlns:ctl="clr-namespace:EarTrumpet.UI.Controls"
        xmlns:resx="clr-namespace:EarTrumpet.Properties"
        xmlns:views="clr-namespace:EarTrumpet.UI.Views"
        xmlns:vm="clr-namespace:EarTrumpet.UI.ViewModels"
        Name="WindowRoot"
        Title="{x:Static resx:Resources.FullWindowTitleText}"
        MinWidth="{StaticResource WindowAndItemSize}"
        Theme:AcrylicBrush.Background="AcrylicColor_Settings"
        Theme:Options.Source="App"
        b:FrameworkElementEx.DisplaySettingsChanged="{Binding DisplaySettingsChanged}"
        b:FrameworkElementEx.FlowDirection="Auto"
        Background="Transparent"
        Closing="{Event:Binding OnClosing}"
        LocationChanged="{Event:Binding OnLocationChanged}"
        PreviewKeyDown="{Event:Binding OnPreviewKeyDown}"
        SizeChanged="{Event:Binding OnSizeChanged}"
        SizeToContent="WidthAndHeight"
        Style="{StaticResource DialogWindowStyle}"
        TextOptions.TextFormattingMode="Display"
        UseLayoutRounding="True"
        WindowStartupLocation="CenterOwner">
    <Window.Resources>
        <DataTemplate DataType="{x:Type vm:DeviceViewModel}">
            <views:DeviceView Width="{StaticResource WindowAndItemSize}" Device="{Binding}" />
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <Border Name="AcrylicBackgroundActive" Theme:Brush.Background="AcrylicBackground" />
        <Border Name="AcrylicBackgroundWhileDragging">
            <Border.Style>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="Theme:Brush.Background" Value="AcrylicBackgroundFallback" />
                    <Setter Property="Opacity" Value="0" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=WindowRoot, Path=(Theme:AcrylicBrush.IsSuppressed)}" Value="True">
                            <DataTrigger.EnterActions>
                                <BeginStoryboard Name="IsSuppressed_Enter_AnimationsOn">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                                         From="0"
                                                         To="1"
                                                         Duration="00:00:00" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.EnterActions>
                            <DataTrigger.ExitActions>
                                <BeginStoryboard Name="IsSuppressed_Exit_AnimationsOn">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames BeginTime="0:0:0"
                                                                       Storyboard.TargetProperty="Opacity"
                                                                       Duration="0:00:00.25">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0" Value="1" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="1" />
                                            <EasingDoubleKeyFrame KeyTime="0:0:0.25" Value="0" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.ExitActions>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>
        </Border>
        <Border Name="AcrylicBackgroundInactive">
            <Border.Style>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="Theme:Brush.Background" Value="AcrylicBackgroundFallback" />
                    <Setter Property="Opacity" Value="1" />
                    <Style.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding Source={StaticResource ThemeManager}, Path=AnimationsEnabled}" Value="True" />
                                <Condition Binding="{Binding ElementName=WindowRoot, Path=IsActive}" Value="True" />
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.EnterActions>
                                <StopStoryboard BeginStoryboardName="IsActive_Exit_AnimationsOff" />
                                <StopStoryboard BeginStoryboardName="IsActive_Enter_AnimationsOff" />
                                <BeginStoryboard Name="IsActive_Enter_AnimationsOn">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                                         From="1"
                                                         To="0"
                                                         Duration="00:00:00.15" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiDataTrigger.EnterActions>
                            <MultiDataTrigger.ExitActions>
                                <StopStoryboard BeginStoryboardName="IsActive_Enter_AnimationsOff" />
                                <StopStoryboard BeginStoryboardName="IsActive_Exit_AnimationsOff" />
                                <BeginStoryboard Name="IsActive_Exit_AnimationsOn">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                                         From="0"
                                                         To="1"
                                                         Duration="00:00:00.15" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiDataTrigger.ExitActions>
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding Source={StaticResource ThemeManager}, Path=AnimationsEnabled}" Value="False" />
                                <Condition Binding="{Binding ElementName=WindowRoot, Path=IsActive}" Value="True" />
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.EnterActions>
                                <StopStoryboard BeginStoryboardName="IsActive_Enter_AnimationsOn" />
                                <StopStoryboard BeginStoryboardName="IsActive_Exit_AnimationsOn" />
                                <BeginStoryboard Name="IsActive_Enter_AnimationsOff">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                                         From="1"
                                                         To="0"
                                                         Duration="00:00:00" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiDataTrigger.EnterActions>
                            <MultiDataTrigger.ExitActions>
                                <StopStoryboard BeginStoryboardName="IsActive_Exit_AnimationsOn" />
                                <StopStoryboard BeginStoryboardName="IsActive_Enter_AnimationsOn" />
                                <BeginStoryboard Name="IsActive_Exit_AnimationsOff">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                                         From="0"
                                                         To="1"
                                                         Duration="00:00:00" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiDataTrigger.ExitActions>
                        </MultiDataTrigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>
        </Border>
        <DockPanel x:Name="ContentRoot">
            <DockPanel DockPanel.Dock="Top">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Padding="12,8,12,8"
                               Text="{Binding ElementName=WindowRoot, Path=Title}"
                               TextAlignment="Left" />
                    <Button x:Name="CloseButton"
                            Grid.Column="2"
                            Style="{StaticResource CloseButtonStyle}" />
                </Grid>
            </DockPanel>
            <Grid>
                <ScrollViewer x:Name="BaseVisual"
                              HorizontalScrollBarVisibility="Auto"
                              VerticalScrollBarVisibility="Auto">
                    <Grid Name="ContentGrid">
                        <Border Width="{StaticResource WindowAndItemSize}"
                                VerticalAlignment="Center"
                                Theme:Brush.Background="FlyoutBackground">
                            <Border.Style>
                                <Style TargetType="Border">
                                    <Setter Property="Visibility" Value="Collapsed" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding AllDevices.Count}" Value="0">
                                            <Setter Property="Visibility" Value="Visible" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Border.Style>
                            <TextBlock Margin="{StaticResource NoItemsPaneMargin}"
                                       HorizontalAlignment="Center"
                                       FontSize="{StaticResource {x:Static SystemFonts.MessageFontSizeKey}}"
                                       Text="{x:Static resx:Resources.NoDevicesPanelContent}"
                                       TextWrapping="Wrap" />
                        </Border>
                        <Grid>
                            <Grid.Style>
                                <Style TargetType="Grid">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding AllDevices.Count}" Value="0">
                                            <Setter Property="Visibility" Value="Collapsed" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Grid.Style>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <ItemsControl IsTabStop="False" ItemsSource="{Binding AllDevices}">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Horizontal" />
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                            </ItemsControl>
                            <Border Grid.Row="1" Theme:Brush.Background="Background">
                                <Border.Style>
                                    <Style TargetType="{x:Type Border}">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding IsManyDevicesMode}" Value="True">
                                                <Setter Property="Height" Value="12" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Border.Style>
                            </Border>
                        </Grid>
                    </Grid>
                </ScrollViewer>
                <ctl:AppPopup IsOpen="{Binding Dialog.IsVisible, Mode=TwoWay}"
                              PlacementTarget="{Binding Dialog.Source}"
                              Style="{StaticResource AppPopup}">
                    <ContentControl Content="{Binding Dialog.Focused}" />
                </ctl:AppPopup>
            </Grid>
        </DockPanel>
        <Border Name="LightDismissBorder"
                Theme:Brush.Background="Background"
                PreviewMouseDown="{Event:Binding OnLightDismissBorderPreviewMouseDown}">
            <Border.Style>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="Visibility" Value="Collapsed" />
                    <Style.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding Dialog.IsVisible}" Value="True" />
                                <Condition Binding="{Binding Source={StaticResource ThemeManager}, Path=AnimationsEnabled}" Value="True" />
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.EnterActions>
                                <StopStoryboard BeginStoryboardName="EnterLightDismiss_AnimationsOff" />
                                <StopStoryboard BeginStoryboardName="ExitLightDismiss_AnimationsOff" />
                                <BeginStoryboard Name="EnterLightDismiss_AnimationsOn">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                                         From="0"
                                                         To="1"
                                                         Duration="00:00:00.15" />
                                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiDataTrigger.EnterActions>
                            <MultiDataTrigger.ExitActions>
                                <StopStoryboard BeginStoryboardName="EnterLightDismiss_AnimationsOff" />
                                <StopStoryboard BeginStoryboardName="ExitLightDismiss_AnimationsOff" />
                                <BeginStoryboard Name="ExitLightDismiss_AnimationsOn">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                                         From="1"
                                                         To="0"
                                                         Duration="00:00:00.15" />
                                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00.15" Value="{x:Static Visibility.Collapsed}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiDataTrigger.ExitActions>
                        </MultiDataTrigger>

                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding Dialog.IsVisible}" Value="True" />
                                <Condition Binding="{Binding Source={StaticResource ThemeManager}, Path=AnimationsEnabled}" Value="False" />
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.EnterActions>
                                <StopStoryboard BeginStoryboardName="EnterLightDismiss_AnimationsOn" />
                                <StopStoryboard BeginStoryboardName="ExitLightDismiss_AnimationsOn" />
                                <BeginStoryboard Name="EnterLightDismiss_AnimationsOff">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiDataTrigger.EnterActions>
                            <MultiDataTrigger.ExitActions>
                                <StopStoryboard BeginStoryboardName="EnterLightDismiss_AnimationsOn" />
                                <StopStoryboard BeginStoryboardName="ExitLightDismiss_AnimationsOn" />
                                <BeginStoryboard Name="ExitLightDismiss_AnimationsOff">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Collapsed}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </MultiDataTrigger.ExitActions>
                        </MultiDataTrigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>
            <Border Margin="0,0,0,14" Opacity="0.8">
                <Border.Effect>
                    <BlurEffect KernelType="Gaussian"
                                Radius="{StaticResource WindowBlurRadius}"
                                RenderingBias="Performance" />
                </Border.Effect>
                <Border.Background>
                    <VisualBrush AlignmentX="Left"
                                 AlignmentY="Top"
                                 Stretch="UniformToFill"
                                 Visual="{Binding ElementName=ContentRoot}" />
                </Border.Background>
            </Border>
        </Border>
    </Grid>
</Window>
