<Window
    x:Class="FileTime.GuiApp.App.Views.MainWindow"
    xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:appCoreModels="using:FileTime.App.Core.Models"
    xmlns:cloudDrives="clr-namespace:FileTime.GuiApp.App.CloudDrives;assembly=FileTime.GuiApp.App.Abstractions"
    xmlns:corevm="using:FileTime.App.Core.ViewModels"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity"
    xmlns:ia="clr-namespace:Avalonia.Xaml.Interactions.Core;assembly=Avalonia.Xaml.Interactions"
    xmlns:interactions="using:FileTime.Core.Interactions"
    xmlns:itemPreview="clr-namespace:FileTime.App.Core.ViewModels.ItemPreview;assembly=FileTime.App.Core"
    xmlns:itemPreviewInterface="clr-namespace:FileTime.App.Core.ViewModels.ItemPreview;assembly=FileTime.App.Core.Abstraction"
    xmlns:local="using:FileTime.GuiApp.App.Views"
    xmlns:local1="clr-namespace:FileTime.Providers.Local;assembly=FileTime.Providers.Local.Abstractions"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sizePreview="clr-namespace:FileTime.App.ContainerSizeScanner;assembly=FileTime.App.ContainerSizeScanner"
    xmlns:vm="using:FileTime.GuiApp.App.ViewModels"
    Title="FileTime"
    MinWidth="1000"
    MinHeight="800"
    d:DataContext="vm:MainWindowDesignViewModel"
    d:DesignHeight="450"
    d:DesignWidth="800"
    x:CompileBindings="True"
    x:DataType="vm:IMainWindowViewModelBase"
    Background="Transparent"
    Closed="Window_OnClosed"
    Closing="Window_OnClosing"
    ExtendClientAreaToDecorationsHint="True"
    FontFamily="{Binding MainFont^, Mode=OneWay}"
    Icon="/Assets/filetime.ico"
    KeyDown="OnKeyDown"
    Opened="OnWindowOpened"
    RequestedThemeVariant="Dark"
    TransparencyLevelHint="{Binding TransparencyLevelHint}"
    mc:Ignorable="d">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceInclude Source="avares://FileTime.GuiApp.App/Resources/SolarizedDarkTheme.axaml" />
                <ResourceInclude Source="avares://FileTime.GuiApp.App/Resources/Brushes.axaml" />
                <ResourceInclude Source="avares://FileTime.GuiApp.App/Resources/Converters.axaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Window.Styles>
        <StyleInclude Source="avares://FileTime.GuiApp.App/Resources/Styles.axaml" />
    </Window.Styles>

    <Grid>
        <Grid
            x:DataType="vm:IMainWindowViewModel"
            Background="{DynamicResource AppBackgroundBrush}"
            IsVisible="{Binding Loading, Converter={x:Static BoolConverters.Not}, FallbackValue=False}">

            <Grid
                ColumnDefinitions="250,*"
                RowDefinitions="Auto,*">

                <Grid PointerPressed="HeaderPointerPressed">
                    <Rectangle Fill="#01000000" />
                    <TextBlock
                        Margin="15,10"
                        Text="{Binding Title.Value}" />
                </Grid>

                <Grid
                    Grid.Column="1"
                    PointerPressed="HeaderPointerPressed">
                    <Rectangle Fill="#01000000" />

                    <Grid ColumnDefinitions="*, Auto">
                        <StackPanel
                            Margin="20,10"
                            Orientation="Horizontal">
                            <local:PathPresenter DataContext="{Binding AppState.SelectedTab.Value.CurrentLocation^.FullName.Path, Converter={StaticResource PathPreformatter}}" />
                            <TextBlock
                                Foreground="{StaticResource AccentBrush}"
                                Text="{Binding AppState.SelectedTab.Value.CurrentSelectedItem.Value.DisplayNameText}" />
                        </StackPanel>
                        <StackPanel
                            Grid.Column="1"
                            Margin="{Binding IconStatusPanelMargin, Mode=OneTime}"
                            Orientation="Vertical">
                            <Image
                                Width="20"
                                Height="20"
                                Margin="10,0,0,0"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Center"
                                IsVisible="{Binding AdminElevationManager.IsAdminInstanceRunning}"
                                Source="{SvgImage /Assets/material/security.svg}" />
                            <Image
                                Width="20"
                                Height="20"
                                Margin="10,0,0,0"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Center"
                                IsVisible="{Binding ClipboardService.Content.Count, Converter={StaticResource EqualsConverter}, ConverterParameter=1}"
                                Source="{SvgImage /Assets/material/clipboard-outline.svg}" />
                            <Image
                                Width="20"
                                Height="20"
                                Margin="10,0,0,0"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Center"
                                IsVisible="{Binding ClipboardService.Content.Count, Converter={StaticResource GreaterThanConverter}, ConverterParameter=1}"
                                Source="{SvgImage /Assets/material/clipboard-multiple-outline.svg}" />
                        </StackPanel>
                    </Grid>
                </Grid>

                <Grid
                    Grid.Row="1"
                    RowDefinitions="Auto,Auto,Auto,Auto">

                    <Border
                        Margin="10"
                        Padding="0,10"
                        Background="{DynamicResource ContainerBackgroundBrush}"
                        CornerRadius="10">
                        <Grid RowDefinitions="Auto,Auto">

                            <TextBlock
                                Margin="10,0,10,10"
                                Text="Drives" />

                            <ItemsRepeater
                                Grid.Row="1"
                                ItemsSource="{Binding AppState.RootDriveInfos}">
                                <ItemsRepeater.ItemTemplate>
                                    <DataTemplate x:DataType="local1:RootDriveInfo">
                                        <Grid
                                            Classes="SidebarContainerPresenter"
                                            PointerPressed="OnHasContainerPointerPressed">
                                            <Grid
                                                Margin="10,5"
                                                ColumnDefinitions="Auto,*,Auto"
                                                RowDefinitions="Auto,Auto">
                                                <Image
                                                    Grid.RowSpan="2"
                                                    Width="20"
                                                    Height="20"
                                                    HorizontalAlignment="Left"
                                                    VerticalAlignment="Center"
                                                    Source="{SvgImage /Assets/material/folder.svg}" />

                                                <StackPanel
                                                    Grid.Column="1"
                                                    HorizontalAlignment="Stretch"
                                                    VerticalAlignment="Center"
                                                    Orientation="Horizontal">

                                                    <TextBlock
                                                        Margin="5,0,0,0"
                                                        VerticalAlignment="Center"
                                                        Text="{Binding FullName}" />

                                                    <TextBlock
                                                        Margin="5,0,0,0"
                                                        VerticalAlignment="Center"
                                                        Classes="ExtraSmallText"
                                                        IsVisible="{Binding Label, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
                                                        Text="{Binding Label}" />
                                                </StackPanel>

                                                <StackPanel
                                                    Grid.Column="2"
                                                    HorizontalAlignment="Right"
                                                    VerticalAlignment="Center"
                                                    Orientation="Horizontal">

                                                    <TextBlock
                                                        VerticalAlignment="Center"
                                                        Classes="SmallText"
                                                        Text="{Binding Free, Converter={StaticResource FormatSizeConverter}}" />

                                                    <TextBlock
                                                        VerticalAlignment="Center"
                                                        Classes="SmallText"
                                                        Text=" / " />

                                                    <TextBlock
                                                        VerticalAlignment="Center"
                                                        Classes="SmallText"
                                                        Text="{Binding Size, Converter={StaticResource FormatSizeConverter}}" />
                                                </StackPanel>

                                                <ProgressBar
                                                    Grid.Row="1"
                                                    Grid.Column="1"
                                                    Grid.ColumnSpan="2"
                                                    MinWidth="100"
                                                    Margin="5,0,0,0"
                                                    HorizontalAlignment="Stretch"
                                                    Maximum="100"
                                                    Value="{Binding UsedPercentage}" />
                                            </Grid>
                                        </Grid>
                                    </DataTemplate>
                                </ItemsRepeater.ItemTemplate>
                            </ItemsRepeater>
                        </Grid>
                    </Border>

                    <Border
                        Grid.Row="1"
                        Margin="10"
                        Padding="0,10"
                        Background="{DynamicResource ContainerBackgroundBrush}"
                        CornerRadius="10"
                        IsVisible="{Binding AppState.Places.Count, Converter={StaticResource GreaterThanConverter}, ConverterParameter=0}">
                        <Grid RowDefinitions="Auto,Auto">

                            <TextBlock
                                Margin="10,0,10,10"
                                Text="Places" />

                            <ItemsRepeater
                                Grid.Row="1"
                                ItemsSource="{Binding AppState.Places}">
                                <ItemsRepeater.ItemTemplate>
                                    <DataTemplate x:DataType="vm:PlaceInfo">
                                        <Grid
                                            Classes="SidebarContainerPresenter"
                                            PointerPressed="OnHasContainerPointerPressed">
                                            <StackPanel
                                                Margin="10,5"
                                                HorizontalAlignment="Stretch"
                                                Orientation="Horizontal">
                                                <Image
                                                    Width="20"
                                                    Height="20"
                                                    VerticalAlignment="Center"
                                                    Source="{Binding Container, Converter={StaticResource ItemToImageConverter}}" />

                                                <TextBlock
                                                    Margin="5,0,0,0"
                                                    VerticalAlignment="Center"
                                                    Text="{Binding DisplayName}" />
                                            </StackPanel>
                                        </Grid>
                                    </DataTemplate>
                                </ItemsRepeater.ItemTemplate>
                            </ItemsRepeater>
                        </Grid>
                    </Border>

                    <Border
                        Grid.Row="2"
                        Margin="10"
                        Padding="0,10"
                        VerticalAlignment="Bottom"
                        Background="{DynamicResource ContainerBackgroundBrush}"
                        CornerRadius="10"
                        IsVisible="{Binding CloudDriveService.CloudDrives.Count, Converter={StaticResource GreaterThanConverter}, ConverterParameter=0}">
                        <Grid RowDefinitions="Auto,Auto">

                            <TextBlock
                                Margin="10,0,10,10"
                                Text="Cloud drives" />

                            <ItemsRepeater
                                Grid.Row="1"
                                ItemsSource="{Binding CloudDriveService.CloudDrives}">
                                <ItemsRepeater.ItemTemplate>
                                    <DataTemplate x:DataType="cloudDrives:CloudDrive">
                                        <Grid
                                            Classes="SidebarContainerPresenter"
                                            PointerPressed="OnHasContainerPointerPressed">
                                            <StackPanel
                                                Margin="10,5"
                                                HorizontalAlignment="Stretch"
                                                Orientation="Horizontal"
                                                ToolTip.Tip="{Binding Name}">
                                                <Image
                                                    Width="20"
                                                    Height="20"
                                                    VerticalAlignment="Center"
                                                    Source="{Binding Path, Converter={StaticResource ItemToImageConverter}}" />

                                                <TextBlock
                                                    Margin="5,0,0,0"
                                                    VerticalAlignment="Center"
                                                    Text="{Binding Name}" />
                                            </StackPanel>
                                        </Grid>
                                    </DataTemplate>
                                </ItemsRepeater.ItemTemplate>
                            </ItemsRepeater>
                        </Grid>
                    </Border>

                    <Border
                        Grid.Row="3"
                        Margin="10"
                        Padding="10"
                        VerticalAlignment="Bottom"
                        Background="{DynamicResource ContainerBackgroundBrush}"
                        CornerRadius="10">
                        <StackPanel>
                            <TextBlock Margin="0,0,0,10">Actions</TextBlock>
                            <StackPanel Orientation="Horizontal">
                                <Grid
                                    Classes="IconButton"
                                    Cursor="Hand"
                                    PointerPressed="SettingsButtonClicked">
                                    <Image
                                        Margin="5"
                                        HorizontalAlignment="Center"
                                        VerticalAlignment="Center"
                                        Source="{SvgImage /Assets/material/settings.svg}" />
                                </Grid>
                            </StackPanel>
                        </StackPanel>
                    </Border>

                </Grid>

                <Grid
                    Grid.Row="1"
                    Grid.Column="1"
                    RowDefinitions="Auto,40,*,Auto">

                    <Grid x:Name="CommandGroupsContainer">
                        <Grid.Transitions>
                            <Transitions>
                                <DoubleTransition
                                    Property="Height"
                                    Duration="0:0:.2" />
                            </Transitions>
                        </Grid.Transitions>
                        <i:Interaction.Behaviors>
                            <ia:DataTriggerBehavior
                                Binding="{Binding #CommandGroups.ItemCount}"
                                ComparisonCondition="GreaterThan"
                                Value="0">
                                <ia:ChangePropertyAction
                                    PropertyName="Height"
                                    TargetObject="CommandGroupsContainer"
                                    Value="180" />
                            </ia:DataTriggerBehavior>
                            <ia:DataTriggerBehavior
                                Binding="{Binding #CommandGroups.ItemCount}"
                                ComparisonCondition="LessThanOrEqual"
                                Value="0">
                                <ia:ChangePropertyAction
                                    PropertyName="Height"
                                    TargetObject="CommandGroupsContainer"
                                    Value="0" />
                            </ia:DataTriggerBehavior>
                        </i:Interaction.Behaviors>
                        <ItemsControl
                            x:Name="CommandGroups"
                            VerticalAlignment="Stretch"
                            ItemsSource="{Binding TimelineViewModel.ParallelCommandsGroups}">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Horizontal" />
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Grid
                                        VerticalAlignment="Stretch"
                                        ColumnDefinitions="300,10">
                                        <ScrollViewer>
                                            <ItemsControl ItemsSource="{Binding Commands}">
                                                <ItemsControl.ItemTemplate>
                                                    <DataTemplate>
                                                        <Border
                                                            Margin="0,0,10,0"
                                                            Padding="5"
                                                            VerticalAlignment="Top"
                                                            Background="{DynamicResource ContainerBackgroundColor}"
                                                            BorderThickness="1"
                                                            Classes.SelectedTimelineCommand="{Binding IsSelected}"
                                                            CornerRadius="10">
                                                            <Grid
                                                                ColumnDefinitions="*, *"
                                                                RowDefinitions="Auto, Auto">
                                                                <Grid
                                                                    Grid.ColumnSpan="2"
                                                                    ColumnDefinitions="*, Auto">
                                                                    <TextBlock Text="{Binding DisplayLabel.Value}" />

                                                                    <Button
                                                                        Grid.Column="1"
                                                                        Command="{Binding Cancel}">
                                                                        <Image
                                                                            Width="20"
                                                                            Height="20"
                                                                            HorizontalAlignment="Left"
                                                                            VerticalAlignment="Center"
                                                                            Source="{SvgImage /Assets/material/close-octagon.svg}" />
                                                                    </Button>
                                                                </Grid>

                                                                <StackPanel
                                                                    Grid.Row="1"
                                                                    Grid.Column="0"
                                                                    Margin="0,5,5,5">
                                                                    <TextBlock
                                                                        Text="{Binding DisplayDetailLabel.Value}"
                                                                        TextAlignment="Right" />

                                                                    <ProgressBar
                                                                        MinWidth="50"
                                                                        Margin="0,5,0,0"
                                                                        Maximum="100"
                                                                        Value="{Binding CurrentProgress.Value}" />
                                                                </StackPanel>
                                                                <StackPanel
                                                                    Grid.Row="1"
                                                                    Grid.Column="1"
                                                                    Margin="5,5,0,5">
                                                                    <TextBlock
                                                                        Text="{Binding TotalProgress.Value, StringFormat={}{0}%}"
                                                                        TextAlignment="Right" />

                                                                    <ProgressBar
                                                                        MinWidth="50"
                                                                        Margin="0,5,0,0"
                                                                        Maximum="100"
                                                                        Value="{Binding TotalProgress.Value}" />
                                                                </StackPanel>
                                                            </Grid>
                                                        </Border>
                                                    </DataTemplate>
                                                </ItemsControl.ItemTemplate>
                                            </ItemsControl>
                                        </ScrollViewer>

                                        <Rectangle
                                            Grid.Column="1"
                                            Width="1"
                                            Margin="0,10,0,10"
                                            HorizontalAlignment="Center"
                                            VerticalAlignment="Stretch"
                                            Fill="{DynamicResource ContentSeparatorBrush}" />
                                    </Grid>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </Grid>

                    <ItemsControl
                        Grid.Row="1"
                        ItemsSource="{Binding AppState.Tabs}">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Horizontal" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid RowDefinitions="Auto,1">
                                    <StackPanel
                                        Margin="20,0,20,0"
                                        Orientation="Horizontal">

                                        <TextBlock
                                            VerticalAlignment="Center"
                                            Text="{Binding TabNumber, StringFormat=({0})}" />

                                        <TextBlock
                                            Margin="5,0,0,0"
                                            VerticalAlignment="Center"
                                            Text="{Binding CurrentLocation.Value.Name, FallbackValue=Loading...}" />
                                    </StackPanel>

                                    <Rectangle
                                        Grid.Row="1"
                                        Fill="{DynamicResource ForegroundBrush}"
                                        IsVisible="{Binding IsSelected.Value}" />
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>

                    <Grid
                        Grid.Row="2"
                        Margin="20,0,0,0">
                        <Grid ColumnDefinitions="15*,10,40*,10,45*">

                            <ListBox
                                AutoScrollToSelectedItem="True"
                                Classes="ContentListView"
                                IsTabStop="True"
                                ItemsSource="{Binding AppState.SelectedTab.Value.ParentsChildren.Value}"
                                ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                                ScrollViewer.VerticalScrollBarVisibility="Visible">
                                <ListBox.ItemTemplate>
                                    <DataTemplate x:DataType="corevm:IItemViewModel">
                                        <local:ItemView
                                            HorizontalAlignment="Stretch"
                                            HorizontalContentAlignment="Stretch"
                                            ShowAttributes="False" />
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>

                            <Rectangle
                                Grid.Column="1"
                                Width="1"
                                Margin="0,10,0,10"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Stretch"
                                Fill="{DynamicResource ContentSeparatorBrush}" />

                            <Grid
                                Grid.Column="2"
                                RowDefinitions="Auto,*">
                                <Grid IsVisible="{Binding AppState.SelectedTab.Value.CurrentLocation.Value.IsLoading^, FallbackValue=False}">
                                    <Image
                                        Width="40"
                                        Height="40"
                                        Classes="LoadingAnimation"
                                        Source="{SvgImage /Assets/loading.svg}" />
                                </Grid>
                                <ListBox
                                    x:Name="CurrentItems"
                                    Grid.Row="1"
                                    AutoScrollToSelectedItem="True"
                                    Classes="ContentListView"
                                    IsTabStop="True"
                                    ItemsSource="{Binding AppState.SelectedTab.Value.CurrentItems.Value}"
                                    ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                                    ScrollViewer.VerticalScrollBarVisibility="Visible"
                                    SelectedItem="{Binding AppState.SelectedTab.Value.CurrentSelectedItem.Value}">
                                    <ListBox.ItemTemplate>
                                        <DataTemplate x:DataType="corevm:IItemViewModel">
                                            <local:ItemView
                                                HorizontalAlignment="Stretch"
                                                HorizontalContentAlignment="Stretch"
                                                PointerPressed="Child_OnPointerPressed" />
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>

                                <TextBlock
                                    x:Name="CurrentEmpty"
                                    Grid.Row="1"
                                    Margin="10"
                                    HorizontalAlignment="Center"
                                    FontWeight="Bold"
                                    Foreground="{DynamicResource ErrorBrush}"
                                    IsVisible="{Binding AppState.SelectedTab.Value.CurrentItems.Value.Count, Converter={StaticResource EqualsConverter}, ConverterParameter=0}">
                                    Empty
                                </TextBlock>
                            </Grid>

                            <Rectangle
                                Grid.Column="3"
                                Width="1"
                                Margin="0,10,0,10"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Stretch"
                                Fill="{DynamicResource ContentSeparatorBrush}" />

                            <Grid Grid.Column="4">
                                <Grid IsVisible="{Binding ItemPreviewService.ItemPreview.Value, Converter={x:Static ObjectConverters.IsNull}}">
                                    <Grid IsVisible="{Binding AppState.SelectedTab.Value.SelectedsChildren.Value, Converter={x:Static ObjectConverters.IsNotNull}, FallbackValue=False}">
                                        <Grid RowDefinitions="Auto, Auto, *">

                                            <Grid IsVisible="{Binding AppState.SelectedTab.Value.CurrentSelectedItemAsContainer.Value.Container.IsLoading^, FallbackValue=False}">
                                                <Image
                                                    Width="40"
                                                    Height="40"
                                                    Classes="LoadingAnimation"
                                                    Source="{SvgImage /Assets/loading.svg}" />
                                            </Grid>


                                            <ItemsRepeater
                                                Grid.Row="1"
                                                ItemsSource="{Binding AppState.SelectedTab.Value.CurrentLocation.Value.Exceptions}">
                                                <ItemsRepeater.ItemTemplate>
                                                    <DataTemplate>
                                                        <TextBlock
                                                            Margin="5,0,5,10"
                                                            Classes="ErrorText"
                                                            Text="{Binding Converter={StaticResource ExceptionToStringConverter}}" />
                                                    </DataTemplate>
                                                </ItemsRepeater.ItemTemplate>
                                            </ItemsRepeater>

                                            <ListBox
                                                x:Name="ChildItems"
                                                Grid.Row="2"
                                                AutoScrollToSelectedItem="True"
                                                Classes="ContentListView"
                                                IsVisible="{Binding AppState.SelectedTab.Value.SelectedsChildren.Value.Count, Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}"
                                                ItemsSource="{Binding AppState.SelectedTab.Value.SelectedsChildren.Value}">
                                                <ListBox.ItemTemplate>
                                                    <DataTemplate x:DataType="corevm:IItemViewModel">
                                                        <local:ItemView />
                                                    </DataTemplate>
                                                </ListBox.ItemTemplate>
                                            </ListBox>
                                        </Grid>

                                        <TextBlock
                                            x:Name="ChildEmpty"
                                            Margin="10"
                                            HorizontalAlignment="Center"
                                            FontWeight="Bold"
                                            Foreground="{DynamicResource ErrorBrush}"
                                            IsVisible="{Binding AppState.SelectedTab.Value.SelectedsChildren.Value.Count, Converter={StaticResource EqualsConverter}, ConverterParameter=0}">
                                            Empty
                                        </TextBlock>
                                    </Grid>

                                    <Grid
                                        IsVisible="{Binding AppState.SelectedTab.Value.CurrentSelectedItem.Value.BaseItem.Exceptions.Count, Converter={StaticResource GreaterThanConverter}, ConverterParameter=0, FallbackValue=False}"
                                        RowDefinitions="Auto, Auto">
                                        <TextBlock
                                            Margin="0,0,0,10"
                                            HorizontalAlignment="Center"
                                            Foreground="{DynamicResource ErrorBrush}"
                                            Text="There were some errors while opening container."
                                            TextWrapping="Wrap" />

                                        <ItemsRepeater
                                            Grid.Row="1"
                                            ItemsSource="{Binding AppState.SelectedTab.Value.CurrentSelectedItem.Value.BaseItem.Exceptions}">
                                            <ItemsRepeater.ItemTemplate>
                                                <DataTemplate>
                                                    <TextBlock
                                                        Margin="5,0,5,10"
                                                        Classes="ErrorText"
                                                        Text="{Binding Converter={StaticResource ExceptionToStringConverter}}" />
                                                </DataTemplate>
                                            </ItemsRepeater.ItemTemplate>
                                        </ItemsRepeater>
                                    </Grid>
                                </Grid>
                                <Grid
                                    DataContext="{Binding ItemPreviewService.ItemPreview.Value}"
                                    IsVisible="{Binding FallbackValue=false, Converter={x:Static ObjectConverters.IsNotNull}}">
                                    <Grid IsVisible="{Binding Name, FallbackValue=false, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static itemPreview:ElementPreviewViewModel.PreviewName}}">
                                        <Grid x:DataType="itemPreviewInterface:IElementPreviewViewModel">
                                            <TextBlock
                                                HorizontalAlignment="Center"
                                                IsVisible="{Binding Mode, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static appCoreModels:ItemPreviewMode.Unknown}, FallbackValue={x:Static appCoreModels:ItemPreviewMode.Unknown}}"
                                                Text="Don't know how to preview this item." />
                                            <TextBlock
                                                HorizontalAlignment="Center"
                                                IsVisible="{Binding Mode, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static appCoreModels:ItemPreviewMode.Empty}, FallbackValue={x:Static appCoreModels:ItemPreviewMode.Unknown}}"
                                                Text="Empty" />
                                            <Grid
                                                IsVisible="{Binding Mode, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static appCoreModels:ItemPreviewMode.Text}, FallbackValue={x:Static appCoreModels:ItemPreviewMode.Unknown}}"
                                                RowDefinitions="*, Auto">
                                                <ScrollViewer>
                                                    <TextBox
                                                        IsReadOnly="True"
                                                        Text="{Binding TextContent}" />
                                                </ScrollViewer>
                                                <TextBlock
                                                    Grid.Row="1"
                                                    Margin="5"
                                                    Text="{Binding TextEncoding, StringFormat=Encoding: {0}}" />
                                            </Grid>
                                        </Grid>
                                    </Grid>
                                    <Grid
                                        x:Name="SizeContainerPreview"
                                        IsVisible="{Binding Name, FallbackValue=false, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static sizePreview:ContainerPreview.PreviewName}}">
                                        <Grid
                                            x:DataType="sizePreview:ContainerPreview"
                                            RowDefinitions="Auto, Auto">
                                            <ItemsControl
                                                Margin="0,0,0,30"
                                                ItemsSource="{Binding TopItems}">
                                                <ItemsControl.ItemsPanel>
                                                    <ItemsPanelTemplate>
                                                        <StackPanel Orientation="Horizontal" />
                                                    </ItemsPanelTemplate>
                                                </ItemsControl.ItemsPanel>
                                                <ItemsControl.ItemTemplate>
                                                    <DataTemplate>
                                                        <Grid>
                                                            <Grid.Width>
                                                                <MultiBinding Converter="{StaticResource ItemSizeToSizeConverter}">
                                                                    <MultiBinding.Bindings>
                                                                        <Binding />
                                                                        <Binding
                                                                            ElementName="SizeContainerPreview"
                                                                            Path="DataContext" />
                                                                        <Binding
                                                                            ElementName="SizeContainerPreview"
                                                                            Path="Bounds.Width" />
                                                                    </MultiBinding.Bindings>
                                                                </MultiBinding>
                                                            </Grid.Width>

                                                            <Rectangle HorizontalAlignment="Stretch">
                                                                <Rectangle.Fill>
                                                                    <MultiBinding Converter="{StaticResource ItemSizeToBrushConverter}">
                                                                        <MultiBinding.Bindings>
                                                                            <Binding />
                                                                            <Binding
                                                                                ElementName="SizeContainerPreview"
                                                                                Path="DataContext" />
                                                                        </MultiBinding.Bindings>
                                                                    </MultiBinding>
                                                                </Rectangle.Fill>
                                                            </Rectangle>
                                                            <StackPanel
                                                                HorizontalAlignment="Left"
                                                                VerticalAlignment="Center">
                                                                <TextBlock
                                                                    Margin="5,5,5,2"
                                                                    Classes="SmallText"
                                                                    FontWeight="Bold"
                                                                    Text="{Binding Name}">
                                                                    <TextBlock.Foreground>
                                                                        <MultiBinding Converter="{StaticResource ItemSizeToForegroundBrushConverter}">
                                                                            <MultiBinding.Bindings>
                                                                                <Binding />
                                                                                <Binding
                                                                                    ElementName="SizeContainerPreview"
                                                                                    Path="DataContext" />
                                                                            </MultiBinding.Bindings>
                                                                        </MultiBinding>
                                                                    </TextBlock.Foreground>
                                                                </TextBlock>
                                                                <TextBlock
                                                                    Margin="5,2,5,5"
                                                                    Classes="SmallText"
                                                                    FontWeight="Bold"
                                                                    Text="{Binding Size.Value, Converter={StaticResource FormatSizeConverter}}">
                                                                    <TextBlock.Foreground>
                                                                        <MultiBinding Converter="{StaticResource ItemSizeToForegroundBrushConverter}">
                                                                            <MultiBinding.Bindings>
                                                                                <Binding />
                                                                                <Binding
                                                                                    ElementName="SizeContainerPreview"
                                                                                    Path="DataContext" />
                                                                            </MultiBinding.Bindings>
                                                                        </MultiBinding>
                                                                    </TextBlock.Foreground>
                                                                </TextBlock>
                                                            </StackPanel>
                                                        </Grid>
                                                    </DataTemplate>
                                                </ItemsControl.ItemTemplate>
                                            </ItemsControl>

                                            <ItemsControl
                                                Grid.Row="1"
                                                ItemsSource="{Binding TopItems}">
                                                <ItemsControl.ItemTemplate>
                                                    <DataTemplate>
                                                        <Grid
                                                            Margin="0,0,0,20"
                                                            ColumnDefinitions="Auto,*">
                                                            <TextBlock Text="{Binding Name}" />
                                                            <TextBlock
                                                                Grid.Column="1"
                                                                Margin="0,0,20,0"
                                                                HorizontalAlignment="Right"
                                                                Text="{Binding Size.Value, Converter={StaticResource FormatSizeConverter}}" />
                                                        </Grid>
                                                    </DataTemplate>
                                                </ItemsControl.ItemTemplate>
                                            </ItemsControl>
                                        </Grid>
                                    </Grid>
                                </Grid>
                            </Grid>
                        </Grid>

                        <ItemsRepeater
                            Margin="0,0,0,20"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Top"
                            IsVisible="{Binding AppState.PopupTexts.Count, Converter={StaticResource NotEqualsConverter}}"
                            ItemsSource="{Binding AppState.PopupTexts}">
                            <ItemsRepeater.Styles>
                                <Style Selector="TextBlock">
                                    <Style.Animations>
                                        <Animation Duration="0:0:1">
                                            <KeyFrame Cue="0%">
                                                <Setter Property="Opacity" Value="0.0" />
                                            </KeyFrame>
                                            <KeyFrame Cue="100%">
                                                <Setter Property="Opacity" Value="1.0" />
                                            </KeyFrame>
                                        </Animation>
                                    </Style.Animations>
                                </Style>
                            </ItemsRepeater.Styles>
                            <ItemsRepeater.ItemTemplate>
                                <DataTemplate x:DataType="x:String">
                                    <Border
                                        Margin="5"
                                        Padding="5"
                                        Background="{DynamicResource ContainerGradientBackgroundBrush}">
                                        <TextBlock
                                            HorizontalAlignment="Center"
                                            Foreground="{DynamicResource AccentComplementBrush}"
                                            Text="{Binding}" />
                                    </Border>
                                </DataTemplate>
                            </ItemsRepeater.ItemTemplate>
                        </ItemsRepeater>
                    </Grid>

                    <Grid
                        Grid.Row="3"
                        RowDefinitions="Auto, Auto">
                        <Grid>
                            <TextBlock
                                IsVisible="{Binding AppState.ContainerStatus.Value, Converter={x:Static ObjectConverters.IsNotNull}}"
                                Text="{Binding AppState.ContainerStatus.Value}" />
                        </Grid>
                        <Grid Grid.Row="1">
                            <Grid
                                IsVisible="{Binding AppState.ViewMode^, Converter={StaticResource EqualsConverter}, ConverterParameter=RapidTravel}"
                                RowDefinitions="1,Auto">

                                <Rectangle
                                    Height="1"
                                    Margin="10,0"
                                    HorizontalAlignment="Stretch"
                                    VerticalAlignment="Center"
                                    Fill="{DynamicResource ContentSeparatorBrush}" />

                                <StackPanel
                                    Grid.Row="1"
                                    Margin="30,10,10,10"
                                    Orientation="Horizontal">

                                    <TextBlock
                                        Margin="0,0,30,0"
                                        Text="Rapid travel mode" />

                                    <TextBlock Text="Filter " />

                                    <TextBlock Text="{Binding AppState.RapidTravelText.Value}" />
                                </StackPanel>
                            </Grid>

                            <Grid IsVisible="{Binding PossibleCommands.PossibleCommands.Count, Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="1" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>

                                <Rectangle
                                    Height="1"
                                    Margin="10,0"
                                    HorizontalAlignment="Stretch"
                                    VerticalAlignment="Center"
                                    Fill="{DynamicResource ContentSeparatorBrush}" />

                                <ItemsRepeater
                                    Grid.Row="1"
                                    ItemsSource="{Binding PossibleCommands.PossibleCommands}">
                                    <ItemsRepeater.ItemTemplate>
                                        <DataTemplate x:DataType="corevm:IPossibleCommandEntryViewModel">
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="200" />
                                                    <ColumnDefinition Width="*" />
                                                </Grid.ColumnDefinitions>

                                                <TextBlock Text="{Binding KeysText}" />
                                                <TextBlock
                                                    Grid.Column="1"
                                                    Text="{Binding Title}" />
                                            </Grid>
                                        </DataTemplate>
                                    </ItemsRepeater.ItemTemplate>
                                </ItemsRepeater>
                            </Grid>
                        </Grid>
                    </Grid>
                </Grid>
            </Grid>

            <Border
                x:Name="ReadInputContainer"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch"
                Background="{DynamicResource BarelyTransparentBackgroundColor}"
                IsVisible="{Binding DialogService.ReadInput.Value, Converter={x:Static ObjectConverters.IsNotNull}}">
                <Border
                    Padding="20"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Background="{DynamicResource ContainerBackgroundBrush}">
                    <Grid RowDefinitions="Auto,Auto,Auto">

                        <ItemsControl
                            x:Name="InputList"
                            ItemsSource="{Binding DialogService.ReadInput.Value.Inputs}"
                            KeyUp="InputList_OnKeyUp">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Grid
                                        x:Name="ItemRoot"
                                        MinWidth="500"
                                        Margin="10,5"
                                        ColumnDefinitions="250,*">
                                        <TextBlock
                                            HorizontalAlignment="Left"
                                            VerticalAlignment="Top"
                                            Text="{Binding Label}" />
                                        <Grid Grid.Column="1">
                                            <TextBox
                                                VerticalAlignment="Top"
                                                x:DataType="interactions:TextInputElement"
                                                IsVisible="{Binding Type, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static interactions:InputType.Text}}"
                                                Tag="InputItem"
                                                Text="{Binding Value, Mode=TwoWay}" />
                                            <TextBox
                                                VerticalAlignment="Top"
                                                x:DataType="interactions:PasswordInputElement"
                                                IsVisible="{Binding Type, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static interactions:InputType.Password}}"
                                                PasswordChar="{Binding PasswordChar}"
                                                Tag="InputItem"
                                                Text="{Binding Value, Mode=TwoWay}" />
                                            <ListBox
                                                x:DataType="interactions:IOptionsInputElement"
                                                Classes="RadioButtonListBox"
                                                IsVisible="{Binding Type, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static interactions:InputType.Options}}"
                                                ItemsSource="{Binding Options}"
                                                SelectedItem="{Binding Value}"
                                                Tag="InputItem" />
                                        </Grid>
                                    </Grid>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>

                        <ItemsControl
                            Grid.Row="1"
                            ItemsSource="{Binding DialogService.ReadInput.Value.Previews}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <local:ReadInputPreview />
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>

                        <StackPanel
                            DataContext="{Binding DialogService.ReadInput.Value}"
                            Grid.Row="2"
                            Margin="0,10,0,0"
                            Orientation="Horizontal">
                            <Button
                                Width="80"
                                HorizontalContentAlignment="Center"
                                Command="{Binding Process}"
                                Content="Ok" />
                            <Button
                                Width="80"
                                Margin="10,0,0,0"
                                HorizontalContentAlignment="Center"
                                Command="{Binding Cancel}"
                                Content="Cancel" />
                        </StackPanel>
                    </Grid>
                </Border>
            </Border>

            <Border
                DataContext="{Binding DialogService.LastMessageBox.Value}"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch"
                Background="{DynamicResource BarelyTransparentBackgroundColor}"
                IsVisible="{Binding Converter={x:Static ObjectConverters.IsNotNull}, FallbackValue=False}">
                <Border
                    Padding="20"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Background="{DynamicResource ContainerBackgroundBrush}">
                    <Grid RowDefinitions="Auto,Auto">

                        <TextBlock Text="{Binding Text}" />
                        <StackPanel
                            Grid.Row="1"
                            Margin="0,10,0,0"
                            Orientation="Horizontal">
                            <Button
                                Width="80"
                                HorizontalContentAlignment="Center"
                                Command="{Binding Ok}"
                                Content="{Binding OkText}" />
                            <Button
                                Width="80"
                                Margin="10,0,0,0"
                                HorizontalContentAlignment="Center"
                                Command="{Binding Cancel}"
                                Content="{Binding CancelText}"
                                IsVisible="{Binding ShowCancel}" />
                        </StackPanel>
                    </Grid>
                </Border>
            </Border>

            <Border
                DataContext="{Binding FrequencyNavigationService.CurrentModal}"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch"
                Background="{DynamicResource BarelyTransparentBackgroundColor}"
                IsVisible="{Binding ShowWindow.Value, FallbackValue=False}">
                <Grid
                    Margin="100"
                    Background="{DynamicResource ContainerBackgroundColor}">
                    <local:FrequencyNavigation IsVisible="{Binding ShowWindow^, FallbackValue=False}" />
                </Grid>
            </Border>

            <Border
                DataContext="{Binding CommandPaletteService.CurrentModal}"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Stretch"
                Background="{DynamicResource BarelyTransparentBackgroundColor}"
                IsVisible="{Binding ShowWindow.Value, FallbackValue=False}">
                <Grid
                    Margin="100"
                    Background="{DynamicResource ContainerBackgroundColor}">
                    <local:CommandPalette IsVisible="{Binding ShowWindow^, FallbackValue=False}" />
                </Grid>
            </Border>
        </Grid>

        <Grid
            Background="{DynamicResource AppLoadingBackgroundBrush}"
            IsVisible="{Binding Loading}">
            <StackPanel
                HorizontalAlignment="Center"
                VerticalAlignment="Center">
                <Image
                    Width="128"
                    Height="128"
                    Source="/Assets/filetime.ico" />
                <TextBlock
                    Margin="50"
                    HorizontalAlignment="Center"
                    Text="{Binding Title.Value}" />
                <TextBlock
                    Margin="50"
                    HorizontalAlignment="Center"
                    Foreground="Red"
                    Text="{Binding FatalError.Value}" />
            </StackPanel>
        </Grid>
    </Grid>
</Window>