<Window x:Class="Ion.Sdk.DemoApp.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:views="clr-namespace:Ion.Sdk.DemoApp.Views"
        xmlns:system="clr-namespace:System;assembly=mscorlib"
        xmlns:converters="clr-namespace:Ion.Sdk.DemoApp.Views.Converters"
        xmlns:framework="clr-namespace:Ion.Sdk.DemoApp.Framework;assembly=Ion.Sdk.DemoApp.Shared"
        mc:Ignorable="d"
        Height="680"
        Width="1020"
        WindowStartupLocation="CenterScreen"
        x:Name="View">
    <Window.Resources>
        <converters:ViewInfoToViewConverter x:Key="ViewInfoToViewConverter" />
        <views:ProgressOperationModeToFriendlyNameConverter x:Key="ProgressOperationModeToFriendlyNameConverter" />
        <DataTemplate x:Key="Template.ExceptionHandler">
            <Grid>
                <Border Effect="{StaticResource Shadow.Popup}"
                        Background="{StaticResource Brush.Background}" />
                <Border BorderThickness="1"
                        BorderBrush="Black"
                        Opacity="0.20" />
                <Grid ClipToBounds="True"
                      Margin="1">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="*"
                                       MaxHeight="300" />
                    </Grid.RowDefinitions>
                    <Grid x:Name="HeaderGrid">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="auto" />
                        </Grid.ColumnDefinitions>
                        <Grid Margin="{StaticResource Margin.Content}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Viewbox Stretch="Uniform"
                                     Height="12"
                                     Margin="0 0 3 0">
                                <Path Data="{StaticResource Geometry.Warning}"
                                      Fill="{StaticResource Brush.Validation.Critical}"
                                      Stretch="Uniform" />
                            </Viewbox>
                            <TextBlock Grid.Column="1"
                                       Style="{StaticResource TextBlock.Content}"
                                       Margin="{StaticResource Margin.Text}"
                                       Foreground="{StaticResource Brush.Foreground.Strong}"
                                       Text="{Binding Path=Model.Message}" />
                        </Grid>
                        <StackPanel Orientation="Horizontal"
                                    Grid.Column="1">
                            <ToggleButton x:Name="ShowMoreToggleButton"
                                          IsChecked="{Binding Path=IsShowingDetails}"
                                          Style="{StaticResource ToggleButton.Classic}"
                                          Margin="{StaticResource Margin.Button}"
                                          Foreground="{StaticResource Brush.Foreground}"
                                          HorizontalContentAlignment="Center"
                                          Padding="{StaticResource Margin.Text}"
                                          BorderThickness="0"
                                          Height="Auto"
                                          Content="Show more" />
                            <Button Margin="{StaticResource Margin.Button}"
                                    Style="{StaticResource Button.Circle}"
                                    Content="Close"
                                    ContentTemplate="{StaticResource Button.Template.Close}"
                                    Command="{Binding Path=CloseCommand}" />
                        </StackPanel>
                    </Grid>
                    <Grid x:Name="DetailsGrid"
                          Grid.Row="1"
                          Visibility="{Binding ElementName=ShowMoreToggleButton, Path=IsChecked, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
                        <Border Background="{StaticResource Brush.White}">
                            <ScrollViewer VerticalScrollBarVisibility="Visible">
                                <TextBox Style="{StaticResource TextBox.Undefined}"
                                         Margin="{StaticResource Margin.Text}"
                                         Text="{Binding Path=DetailsText, Mode=OneWay}"
                                         TextWrapping="Wrap"
                                         IsReadOnly="True" />
                            </ScrollViewer>
                        </Border>
                    </Grid>
                </Grid>
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="Template.Message">
            <Grid>
                <Border Effect="{StaticResource Shadow.Popup}"
                        Background="{StaticResource Brush.Background}" />
                <Border BorderThickness="1"
                        BorderBrush="Black"
                        SnapsToDevicePixels="True"
                        Opacity="0.20" />
                <Grid ClipToBounds="True"
                      Margin="1">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*"
                                       MinHeight="75"
                                       MaxHeight="200" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <StackPanel x:Name="HeaderPanel"
                                    Orientation="Horizontal"
                                    Margin="{StaticResource Margin.Text.Horizontal}">
                            <StackPanel.Resources>
                                <DataTemplate DataType="{x:Type framework:Message}">
                                    <Viewbox Stretch="Uniform"
                                             Height="12"
                                             Margin="3 0">
                                        <Path Data="{StaticResource Geometry.Info}"
                                              Fill="{StaticResource Brush.Accent.Strong}"
                                              Stretch="Uniform" />
                                    </Viewbox>
                                </DataTemplate>
                                <DataTemplate DataType="{x:Type framework:CriticalMessage}">
                                    <Viewbox Stretch="Uniform"
                                             Height="12"
                                             Margin="3 0">
                                        <Path Data="{StaticResource Geometry.Warning}"
                                              Fill="{StaticResource Brush.Validation.Critical}"
                                              Stretch="Uniform" />
                                    </Viewbox>
                                </DataTemplate>
                            </StackPanel.Resources>
                            <StackPanel.Style>
                                <Style TargetType="StackPanel">
                                    <Setter Property="Visibility"
                                            Value="Visible" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding ElementName=Subject, Path=Text}"
                                                     Value="">
                                            <Setter Property="Visibility"
                                                    Value="Collapsed" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </StackPanel.Style>
                            <ContentControl x:Name="Icon"
                                            Content="{Binding Path=Model}"></ContentControl>
                            <TextBlock x:Name="Subject"
                                       Style="{StaticResource TextBlock.Content}"
                                       Margin="{StaticResource Margin.Text}"
                                       Foreground="{StaticResource Brush.Foreground.Strong}"
                                       Text="{Binding Path=Model.Subject}" />
                        </StackPanel>
                        <Button Grid.Column="1"
                                Margin="{StaticResource Margin.Button}"
                                Style="{StaticResource Button.Circle}"
                                Content="Close"
                                ContentTemplate="{StaticResource Button.Template.Close}"
                                Command="{Binding Path=CloseCommand}" />
                    </Grid>
                    <Border Grid.Row="1"
                            Background="{StaticResource Brush.White}">
                        <ScrollViewer>
                            <TextBox Style="{StaticResource TextBox.Undefined}"
                                     Margin="5"
                                     Text="{Binding Path=Model.Text, Mode=OneWay}"
                                     TextWrapping="Wrap"
                                     IsReadOnly="True" />
                        </ScrollViewer>
                    </Border>
                    <Grid Grid.Row="2">
                        <Grid.Style>
                            <Style TargetType="Grid">
                                <Setter Property="Visibility"
                                        Value="Visible" />
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Path=MessageCount}"
                                                 Value="1">
                                        <Setter Property="Visibility"
                                                Value="Collapsed" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Grid.Style>
                        <StackPanel Orientation="Horizontal"
                                    HorizontalAlignment="Center">
                            <Button Style="{StaticResource Button.ToolBar}"
                                    ToolTip="Show previous message"
                                    Command="{Binding Path=ShowPreviousMessageCommand, Mode=OneWay}">
                                <Button.ContentTemplate>
                                    <DataTemplate>
                                        <Viewbox Stretch="Uniform"
                                                 Height="6">
                                            <Path Data="{StaticResource Geometry.ArrowHead.Left}"
                                                  Stretch="Uniform"
                                                  Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}" />
                                        </Viewbox>
                                    </DataTemplate>
                                </Button.ContentTemplate>
                            </Button>
                            <TextBlock Margin="{StaticResource Margin.Text.Horizontal}"
                                       VerticalAlignment="Center"
                                       Style="{StaticResource TextBlock.Content}"
                                       FontSize="{StaticResource Font.Size.Small}">
                                <Run Text="{Binding Path=Index, Mode=OneWay}" />
                                <Run Text="of" />
                                <Run Text="{Binding Path=MessageCount, Mode=OneWay}" /></TextBlock>
                            <Button Style="{StaticResource Button.ToolBar}"
                                    ToolTip="Show next message"
                                    Command="{Binding Path=ShowNextMessageCommand, Mode=OneWay}">
                                <Button.ContentTemplate>
                                    <DataTemplate>
                                        <Viewbox Stretch="Uniform"
                                                 Height="6">
                                            <Path Data="{StaticResource Geometry.ArrowHead.Right}"
                                                  Stretch="Uniform"
                                                  Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}" />
                                        </Viewbox>
                                    </DataTemplate>
                                </Button.ContentTemplate>
                            </Button>
                        </StackPanel>
                    </Grid>
                </Grid>
            </Grid>
        </DataTemplate>
    </Window.Resources>
    <Window.Style>
        <Style TargetType="Window">
            <Setter Property="Title"
                    Value="Ion SDK DemoApp" />
            <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding Path=ActiveView}"
                                   Value="{x:Static views:PadfxBrowser.ViewInfo}" />
                        <Condition Binding="{Binding ElementName=ActiveView, Path=Content.File, Converter={StaticResource NotNullToBooleanConverter}}"
                                   Value="True" />
                    </MultiDataTrigger.Conditions>
                    <Setter Property="Title"
                            Value="{Binding ElementName=ActiveView, Path=Content.File, StringFormat=Ion SDK DemoApp - {0}}" />
                </MultiDataTrigger>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding Path=ActiveView}"
                                   Value="{x:Static views:PadfxBrowser.ViewInfo}" />
                        <Condition Binding="{Binding ElementName=ActiveView, Path=Content.File}"
                                   Value="{x:Null}" />
                        <Condition Binding="{Binding ElementName=ActiveView, Path=Content.Workspace, Converter={StaticResource NotNullToBooleanConverter}}"
                                   Value="True" />
                    </MultiDataTrigger.Conditions>
                    <Setter Property="Title"
                            Value="{Binding ElementName=ActiveView, Path=Content.Workspace.Name, StringFormat=Ion SDK DemoApp - {0}}" />
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Style>
    <Grid Background="{StaticResource Brush.Background}">
        <TabControl x:Name="ViewsTabControl"
                    Style="{StaticResource TabControl.Classic}"
                    ItemsSource="{Binding Path=AvailableViews, Mode=OneWay}"
                    SelectionChanged="ViewsTabControl_OnSelectionChanged"
                    SelectedIndex="0">
            <TabControl.ItemTemplate>
                <DataTemplate DataType="framework:IAppViewInfo">
                    <TextBlock Style="{StaticResource TextBlock.Content}"
                               VerticalAlignment="Center"
                               Foreground="{StaticResource Brush.Accent.Strong}"
                               FontWeight="SemiBold"
                               Text="{Binding Path=Name}" />
                </DataTemplate>
            </TabControl.ItemTemplate>
            <TabControl.ContentTemplate>
                <DataTemplate DataType="framework:IAppViewInfo">
                    <Grid  Background="{StaticResource Brush.White}">
                        <ContentPresenter x:Name="ViewPresenter"
                                          Margin="0 2 0 0"
                                          Content="{Binding Converter={StaticResource ViewInfoToViewConverter}}" />
                    </Grid>
                </DataTemplate>
            </TabControl.ContentTemplate>
        </TabControl>
        <Grid x:Name="ProgressGrid"
              Style="{StaticResource Element.FadeInOut}"
              Tag="{Binding Path=IsBusy}"
              DataContext="{Binding Path=ActiveView.Progress, Mode=OneWay}">
            <Grid Margin="{StaticResource Margin.Content}"
                  VerticalAlignment="Center"
                  HorizontalAlignment="Center">
                <Border Background="{StaticResource Brush.White}"
                        Effect="{StaticResource Shadow.Popup}"
                        SnapsToDevicePixels="True" />
                <Border BorderThickness="1"
                        BorderBrush="Black"
                        Opacity="0.10"
                        SnapsToDevicePixels="True" />
                <Grid Margin="1 5 1 1">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <TextBlock Text="{Binding Path=OperationType, Converter={StaticResource ProgressOperationModeToFriendlyNameConverter}}"
                               Margin="5" />
                    <TextBlock Margin="5"
                               HorizontalAlignment="Right">
                        <TextBlock.Style>
                            <Style TargetType="{x:Type TextBlock}">
                                <Setter Property="Visibility"
                                        Value="Collapsed" />
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Path=IsIndeterminate}"
                                                 Value="False">
                                        <Setter Property="Visibility"
                                                Value="Visible" />
                                        <Setter Property="Text"
                                                Value="{Binding Path=PercentComplete, StringFormat='({0:##}%)'}" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Path=PercentComplete}" Value="0">
                                        <Setter Property="Visibility" Value="Collapsed" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style></TextBlock>
                    <ProgressBar Grid.Row="1"
                                 SnapsToDevicePixels="True"
                                 Style="{StaticResource ProgressBar.Classic}"
                                 Width="200"
                                 Height="3"
                                 IsIndeterminate="{Binding Path=IsIndeterminate}"
                                 Maximum="{Binding Path=Maximum}"
                                 Minimum="{Binding Path=Minimum}"
                                 Value="{Binding Path=Value}" />
                </Grid>
            </Grid>
        </Grid>
        <Border x:Name="MessageOverlay"
                Style="{StaticResource Border.Overlay}"
                Tag="{Binding ElementName=View, Path=MessagingService.IsShowingMessage, Mode=OneWay}" />
        <ContentControl x:Name="MessageServiceContent"
                        DataContext="{Binding ElementName=View, Path=MessagingService}"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Top"
                        Margin="0 10 0 0"
                        Width="400"
                        Style="{StaticResource ContentControl.Dialog}"
                        Tag="{Binding Path=IsShowingMessage, Mode=OneWay}"
                        Content="{Binding}"
                        ContentTemplate="{StaticResource Template.Message}" />
        <Border x:Name="Overlay"
                Style="{StaticResource Border.Overlay}"
                Tag="{Binding ElementName=View, Path=ExceptionHandler.IsShowingException, Mode=OneWay}" />
        <ContentControl x:Name="ExceptionHandlerContent"
                        DataContext="{Binding ElementName=View, Path=ExceptionHandler}"
                        Margin="10"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Top"
                        Width="550"
                        Style="{StaticResource ContentControl.Dialog}"
                        Tag="{Binding Path=IsShowingException, Mode=OneWay}"
                        Content="{Binding}"
                        ContentTemplate="{StaticResource Template.ExceptionHandler}" />
    </Grid>
</Window>
