<UserControl x:Class="MyPad.Views.Regions.StatusBarView"
             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:i="http://schemas.microsoft.com/xaml/behaviors"
             xmlns:p="http://prismlibrary.com/"
             xmlns:m="http://metro.mahapps.com/winfx/xaml/controls"
             xmlns:mi="http://metro.mahapps.com/winfx/xaml/iconpacks"
             xmlns:le="http://wpflocalizeextension.codeplex.com"
             xmlns:qc="http://QuickConverter.CodePlex.com/"
             xmlns:ge="clr-namespace:SourceChord.GridExtra;assembly=GridExtra.Wpf"
             mc:Ignorable="d"
             p:ViewModelLocator.AutoWireViewModel="True"
             d:DesignHeight="450" d:DesignWidth="800">

    <UserControl.Resources>
        <Style TargetType="{x:Type StatusBarItem}" BasedOn="{StaticResource Common.StatusBarItem}">
            <Setter Property="Padding" Value="0"/>
            <Style.Resources>
                <Style TargetType="{x:Type m:TransitioningContentControl}">
                    <Setter Property="Margin" Value="5 0"/>
                </Style>
                <Style TargetType="{x:Type Button}" BasedOn="{StaticResource Common.Button}">
                    <Setter Property="Focusable" Value="False"/>
                    <Setter Property="Padding" Value="5 0"/>
                    <Setter Property="Foreground" Value="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type StatusBar}}, Mode=OneWay}"/>
                    <Setter Property="Background" Value="{Binding Background, RelativeSource={RelativeSource AncestorType={x:Type StatusBar}}, Mode=OneWay}"/>
                    <Setter Property="FontStyle"  Value="{DynamicResource {x:Static SystemFonts.StatusFontStyleKey}}"/>
                    <Setter Property="FontWeight" Value="{DynamicResource {x:Static SystemFonts.StatusFontWeightKey}}"/>
                    <Setter Property="BorderThickness" Value="0"/>
                    <Style.Resources>
                        <!-- ボタンが押された状態の背景色を上書きする -->
                        <SolidColorBrush x:Key="MahApps.Brushes.Gray7" Color="{DynamicResource MahApps.Colors.Highlight}"/>
                        <!-- マウスオーバー時の背景色を上書きする -->
                        <SolidColorBrush x:Key="MahApps.Brushes.Gray8" Color="{DynamicResource MahApps.Colors.Highlight}"/>
                    </Style.Resources>
                </Style>
                <Style TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource Common.ToggleButton}">
                    <Setter Property="Focusable" Value="False"/>
                    <Setter Property="Padding" Value="5 0"/>
                    <Setter Property="Foreground" Value="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type StatusBar}}, Mode=OneWay}"/>
                    <Setter Property="Background" Value="{Binding Background, RelativeSource={RelativeSource AncestorType={x:Type StatusBar}}, Mode=OneWay}"/>
                    <Setter Property="FontStyle"  Value="{DynamicResource {x:Static SystemFonts.StatusFontStyleKey}}"/>
                    <Setter Property="FontWeight" Value="{DynamicResource {x:Static SystemFonts.StatusFontWeightKey}}"/>
                    <Setter Property="BorderThickness" Value="0"/>
                    <Setter Property="m:ControlsHelper.MouseOverBorderBrush" Value="{DynamicResource MahApps.Brushes.Highlight}"/>
                    <Style.Triggers>
                        <!-- チェック状態時の背景色を上書きする -->
                        <Trigger Property="IsChecked" Value="True">
                            <Setter Property="Background" Value="{Binding Background, RelativeSource={RelativeSource AncestorType={x:Type StatusBar}}, Mode=OneWay}"/>
                            <Setter Property="BorderBrush" Value="{Binding Background, RelativeSource={RelativeSource AncestorType={x:Type StatusBar}}, Mode=OneWay}"/>
                        </Trigger>
                        <!-- マウスオーバー時の背景色を上書きする -->
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="{DynamicResource MahApps.Brushes.Highlight}"/>
                        </Trigger>
                        <!-- チェック状態かつマウスオーバー時の背景色を上書きする -->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" Value="True"/>
                                <Condition Property="IsChecked" Value="True"/>
                            </MultiTrigger.Conditions>
                            <Setter Property="Background" Value="{DynamicResource MahApps.Brushes.Highlight}"/>
                        </MultiTrigger>
                    </Style.Triggers>
                </Style>
            </Style.Resources>
        </Style>

        <Style TargetType="{x:Type StatusBar}" BasedOn="{StaticResource Common.StatusBar}">
            <Setter Property="Background" Value="{DynamicResource MahApps.Brushes.AccentBase}"/>
            <Style.Triggers>
                <!-- WindowTitleBrush に追従する処理を打ち消す -->
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding IsVisible, RelativeSource={RelativeSource Self}, Mode=OneWay}" Value="True"/>
                        <Condition Binding="{Binding IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Mode=OneWay}" Value="True"/>
                    </MultiDataTrigger.Conditions>
                    <Setter Property="Background" Value="{DynamicResource MahApps.Brushes.AccentBase}"/>
                </MultiDataTrigger>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding IsVisible, RelativeSource={RelativeSource Self}, Mode=OneWay}" Value="True"/>
                        <Condition Binding="{Binding IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Mode=OneWay}" Value="False"/>
                    </MultiDataTrigger.Conditions>
                    <Setter Property="Background" Value="{DynamicResource MahApps.Brushes.AccentBase}"/>
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>

        <Storyboard x:Key="QuietlyAnimation">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="CurrentContentPresentationSite">
                <SplineDoubleKeyFrame KeyTime="00:00:00"   Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PreviousContentPresentationSite">
                <SplineDoubleKeyFrame KeyTime="00:00:00"   Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <Storyboard x:Key="BlinkingAnimation">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="CurrentContentPresentationSite">
                <SplineDoubleKeyFrame KeyTime="00:00:00"    Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="0"/>
                <EasingDoubleKeyFrame KeyTime="00:00:00.5"  Value="1">
                    <EasingDoubleKeyFrame.EasingFunction>
                        <SineEase/>
                    </EasingDoubleKeyFrame.EasingFunction>
                </EasingDoubleKeyFrame>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PreviousContentPresentationSite">
                <SplineDoubleKeyFrame KeyTime="00:00:00"    Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>

    <StatusBar>
        <StatusBar.ItemsPanel>
            <ItemsPanelTemplate>
                <Grid ge:GridEx.ColumnDefinition="Auto, *, Auto, Auto, Auto, Auto, Auto"/>
            </ItemsPanelTemplate>
        </StatusBar.ItemsPanel>
        <StatusBarItem Grid.Column="0">
            <Button>
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <i:InvokeCommandAction Command="{Binding SwitchPomodoroTimerCommand, Mode=OneTime}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <Button.Content>
                    <Grid ge:GridEx.ColumnDefinition="Auto, 3, Auto">
                        <Border Grid.ColumnSpan="3" Visibility="{qc:Binding '$P ? Visibility.Collapsed : Visibility.Visible', P={Binding SharedProperties.IsInPomodoro.Value, Mode=OneWay}}">
                            <mi:Material Kind="TimerOutline"/>
                        </Border>
                        <Border Grid.Column="0" Visibility="{qc:MultiBinding '$P0 ## $P1 ? Visibility.Visible : Visibility.Collapsed', P0={Binding SharedProperties.IsInPomodoro.Value, Mode=OneWay}, P1={Binding SharedProperties.IsPomodoroWorking.Value, Mode=OneWay}}">
                            <mi:Material Kind="Draw"/>
                        </Border>
                        <Border Grid.Column="0" Visibility="{qc:MultiBinding '$P0 ## !$P1 ? Visibility.Visible : Visibility.Collapsed', P0={Binding SharedProperties.IsInPomodoro.Value, Mode=OneWay}, P1={Binding SharedProperties.IsPomodoroWorking.Value, Mode=OneWay}}">
                            <mi:VaadinIcons Kind="Coffee"/>
                        </Border>
                        <Border Grid.Column="2" Visibility="{qc:Binding '$P ? Visibility.Visible : Visibility.Collapsed', P={Binding SharedProperties.IsInPomodoro.Value, Mode=OneWay}}">
                            <m:TransitioningContentControl
                                Content="{Binding SharedProperties.PomodoroTimer.Value, Mode=OneWay}"
                                Transition="Custom" CustomVisualStatesName="Transition0">
                                <m:TransitioningContentControl.CustomVisualStates>
                                    <VisualState x:Name="Transition0" Storyboard="{StaticResource QuietlyAnimation}"/>
                                </m:TransitioningContentControl.CustomVisualStates>
                            </m:TransitioningContentControl>
                        </Border>
                    </Grid>
                </Button.Content>
            </Button>
        </StatusBarItem>
        <StatusBarItem Grid.Column="1">
            <m:TransitioningContentControl
                DataContext="{Binding ActiveTextEditor.Value, Mode=OneWay}"
                Content="{qc:MultiBinding '$P0 == 0 ? string.Empty : $P0 + \' chars (\' + $P1 + \' lines) selected\'', P0={Binding SelectionLength, Mode=OneWay}, P1={Binding SelectionLineCount, Mode=OneWay}}"
                Transition="Custom" CustomVisualStatesName="Transition1">
                <m:TransitioningContentControl.CustomVisualStates>
                    <VisualState x:Name="Transition1" Storyboard="{StaticResource QuietlyAnimation}"/>
                </m:TransitioningContentControl.CustomVisualStates>
            </m:TransitioningContentControl>
        </StatusBarItem>
        <StatusBarItem Grid.Column="2">
            <Button>
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <i:InvokeCommandAction Command="{Binding GoToLineCommand, Mode=OneTime}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <Button.Content>
                    <m:TransitioningContentControl
                        DataContext="{Binding ActiveTextEditor.Value, Mode=OneWay}"
                        Content="{qc:MultiBinding '\'Ln \' + $P0 + \', Col \' + $P1 + \' (\' + $P2 + \')\'', P0={Binding Line, Mode=OneWay}, P1={Binding Column, Mode=OneWay}, P2={Binding CharName, Mode=OneWay}}"
                        Transition="Custom" CustomVisualStatesName="Transition2">
                        <m:TransitioningContentControl.CustomVisualStates>
                            <VisualState x:Name="Transition2" Storyboard="{StaticResource QuietlyAnimation}"/>
                        </m:TransitioningContentControl.CustomVisualStates>
                    </m:TransitioningContentControl>
                </Button.Content>
            </Button>
        </StatusBarItem>
        <StatusBarItem Grid.Column="3">
            <Button>
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <i:InvokeCommandAction Command="{Binding ChangeEncodingCommand, Mode=OneTime}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <Button.Content>
                    <m:TransitioningContentControl
                        DataContext="{Binding ActiveTextEditor.Value, Mode=OneWay}"
                        Content="{qc:Binding '$P.EncodingName', P={Binding Encoding, Mode=OneWay}}"
                        Transition="Custom" CustomVisualStatesName="Transition3">
                        <m:TransitioningContentControl.CustomVisualStates>
                            <VisualState x:Name="Transition3" Storyboard="{StaticResource BlinkingAnimation}"/>
                        </m:TransitioningContentControl.CustomVisualStates>
                    </m:TransitioningContentControl>
                </Button.Content>
            </Button>
        </StatusBarItem>
        <StatusBarItem Grid.Column="4">
            <Button>
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <i:InvokeCommandAction Command="{Binding ChangeSyntaxCommand, Mode=OneTime}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <Button.Content>
                    <m:TransitioningContentControl
                        DataContext="{Binding ActiveTextEditor.Value, Mode=OneWay}"
                        Content="{qc:Binding '$P?.Name ?? \'Plain Text\'', P={Binding SyntaxDefinition, Mode=OneWay}}"
                        Transition="Custom" CustomVisualStatesName="Transition4">
                        <m:TransitioningContentControl.CustomVisualStates>
                            <VisualState x:Name="Transition4" Storyboard="{StaticResource BlinkingAnimation}"/>
                        </m:TransitioningContentControl.CustomVisualStates>
                    </m:TransitioningContentControl>
                </Button.Content>
            </Button>
        </StatusBarItem>
        <StatusBarItem Grid.Column="5">
            <ToggleButton IsChecked="{Binding ActiveTextEditor.Value.OverstrikeMode, Mode=TwoWay}">
                <ToggleButton.Content>
                    <m:TransitioningContentControl
                        DataContext="{Binding ActiveTextEditor.Value, Mode=OneWay}"
                        Content="{qc:Binding '$P ? \'OVER\' : \'INS\'', P={Binding OverstrikeMode, Mode=OneWay}}"
                        Transition="Custom" CustomVisualStatesName="Transition5">
                        <m:TransitioningContentControl.CustomVisualStates>
                            <VisualState x:Name="Transition5" Storyboard="{StaticResource BlinkingAnimation}"/>
                        </m:TransitioningContentControl.CustomVisualStates>
                    </m:TransitioningContentControl>
                </ToggleButton.Content>
            </ToggleButton>
        </StatusBarItem>
        <StatusBarItem Grid.Column="6">
            <ResizeGrip IsHitTestVisible="False" Visibility="Hidden"/>
        </StatusBarItem>
    </StatusBar>

</UserControl>
