<Window x:Class="ArkBot.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:tb="http://www.hardcodet.net/taskbar" 
        xmlns:local="clr-namespace:ArkBot"
        xmlns:layout="clr-namespace:ArkBot.Layout"
        xmlns:controls="clr-namespace:ArkBot.Controls"
        xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
        xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
        xmlns:xcpt="http://schemas.xceed.com/wpf/xaml/themes"
        xmlns:xctt="http://schemas.xceed.com/wpf/xaml/toolkit/themes"
        xmlns:localThemes="http://schemas.xceed.com/wpf/xaml/avalondock/themes"
        xmlns:s="clr-namespace:System;assembly=mscorlib"
        xmlns:sw="clr-namespace:System.Windows;assembly=mscorlib"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:prism="http://prismlibrary.com/"
        mc:Ignorable="d"
        x:Name="mainWindow"
        Title="ARK Bot" MinWidth="600" MinHeight="500" Width="800" Height="800" WindowStartupLocation="CenterScreen" Icon="basket_empty.ico">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Closing">
            <prism:InvokeCommandAction Command="{Binding ClosingCommand}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <Window.Resources>
        <!--<local:ActiveDocumentConverter x:Key="ActiveDocumentConverter"/>-->
        <xcad:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
    </Window.Resources>
    <Window.InputBindings>
        <!--<KeyBinding Command="{Binding Command}" Gesture="CTRL+Q" />-->
    </Window.InputBindings>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Menu Grid.Row="0">
            <MenuItem Header="File">
                <MenuItem Header="Open Web App" Command="{Binding OpenWebAppCommand }" />
                <Separator />
                <MenuItem Header="Exit" Command="{Binding ExitCommand}" />
            </MenuItem>
            <MenuItem Header="Options">
                <MenuItem Header="Reload partial config" Command="{Binding ReloadPartialConfig}" />
                <Separator />
                <MenuItem Header="Manually trigger server update" ItemsSource="{Binding ManuallyUpdateServers}">
                    <MenuItem.ItemContainerStyle>
                        <Style TargetType="{x:Type MenuItem}">
                            <Setter Property="Header" Value="{Binding Header}"/>
                            <Setter Property="Command" Value="{Binding Command}"/>
                            <Setter Property="CommandParameter" Value="{Binding CommandParameter}"/>
                        </Style>
                    </MenuItem.ItemContainerStyle>
                </MenuItem>
                <MenuItem Header="Manually trigger cluster update" ItemsSource="{Binding ManuallyUpdateClusters}">
                    <MenuItem.ItemContainerStyle>
                        <Style TargetType="{x:Type MenuItem}">
                            <Setter Property="Header" Value="{Binding Header}"/>
                            <Setter Property="Command" Value="{Binding Command}"/>
                            <Setter Property="CommandParameter" Value="{Binding CommandParameter}"/>
                        </Style>
                    </MenuItem.ItemContainerStyle>
                </MenuItem>
                <!--<MenuItem Header="Skip savegame extraction next restart" IsChecked="{Binding SkipExtractNextRestart, Mode=TwoWay}" IsCheckable="True"/>-->
            </MenuItem>
            <MenuItem Header="View">
                <MenuItem Header="Console" IsChecked="{Binding Console.IsVisible, Mode=TwoWay}" IsCheckable="True"/>
                <MenuItem Header="Configuration" IsChecked="{Binding Configuration.IsVisible, Mode=TwoWay}" IsCheckable="True"/>
                <MenuItem Header="About" IsChecked="{Binding About.IsVisible, Mode=TwoWay}" IsCheckable="True"/>
            </MenuItem>

        </Menu>
        <xcad:DockingManager x:Name="dockManager" Grid.Row="1" AnchorablesSource="{Binding Panes}" GridSplitterWidth="7" GridSplitterHeight="7" AllowMixedOrientation="True">
            <xcad:DockingManager.Theme>
                <xcad:MetroTheme/>
            </xcad:DockingManager.Theme>
            <xcad:DockingManager.DocumentHeaderTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Image Source="{Binding IconSource}" Margin="0,0,4,0"/>
                        <TextBlock Text="{Binding Title}" />
                    </StackPanel>
                </DataTemplate>
            </xcad:DockingManager.DocumentHeaderTemplate>
            <xcad:DockingManager.LayoutItemTemplateSelector>
                <layout:PaneTemplateSelector>
                    <layout:PaneTemplateSelector.ConsoleTemplate>
                        <DataTemplate>
                            <controls:Console ConsoleOutput="{Binding Model}"  Margin="3" />
                        </DataTemplate>
                    </layout:PaneTemplateSelector.ConsoleTemplate>
                    <layout:PaneTemplateSelector.ConfigurationTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="30" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <StackPanel Grid.Row="0" Orientation="Horizontal" Margin="3">
                                    <Button Content="Save" MinWidth="100" Command="{Binding SaveConfig}" />
                                </StackPanel>
                                <controls:Configuration Model="{Binding}" SelectedObject="{Binding Config}" IsReadOnly="False" Margin="3" Grid.Row="1" />
                            </Grid>
                        </DataTemplate>
                    </layout:PaneTemplateSelector.ConfigurationTemplate>
                    <layout:PaneTemplateSelector.AboutTemplate>
                        <DataTemplate>
                            <controls:About Model="{Binding}" Margin="3" />
                        </DataTemplate>
                    </layout:PaneTemplateSelector.AboutTemplate>
                </layout:PaneTemplateSelector>
            </xcad:DockingManager.LayoutItemTemplateSelector>
            <xcad:DockingManager.LayoutItemContainerStyleSelector>
                <layout:PaneStyleSelector>
                    <layout:PaneStyleSelector.ConsoleStyle>
                        <Style TargetType="{x:Type xcad:LayoutItem}">
                            <Setter Property="Title" Value="{Binding Model.Title}"/>
                            <Setter Property="Visibility" Value="{Binding Model.IsVisible, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter={x:Static Visibility.Hidden}}"/>
                            <Setter Property="ContentId" Value="{Binding Model.ContentId}"/>
                            <Setter Property="IsSelected" Value="{Binding Model.IsSelected, Mode=TwoWay}"/>
                            <Setter Property="IsActive" Value="{Binding Model.IsActive, Mode=TwoWay}"/>
                            <Setter Property="CanClose" Value="False" />
                            <Setter Property="ToolTip" Value="{Binding Model.FilePath}"/>
                            <Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}"/>
                            <Setter Property="IconSource" Value="{Binding Model.IconSource}"/>
                        </Style>
                    </layout:PaneStyleSelector.ConsoleStyle>
                    <layout:PaneStyleSelector.ConfigurationStyle>
                        <Style TargetType="{x:Type xcad:LayoutItem}">
                            <Setter Property="Title" Value="{Binding Model.Title}"/>
                            <Setter Property="Visibility" Value="{Binding Model.IsVisible, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter={x:Static Visibility.Hidden}}"/>
                            <Setter Property="ContentId" Value="{Binding Model.ContentId}"/>
                            <Setter Property="IsSelected" Value="{Binding Model.IsSelected, Mode=TwoWay}"/>
                            <Setter Property="IsActive" Value="{Binding Model.IsActive, Mode=TwoWay}"/>
                            <Setter Property="CanClose" Value="False" />
                        </Style>
                    </layout:PaneStyleSelector.ConfigurationStyle>
                    <layout:PaneStyleSelector.AboutStyle>
                        <Style TargetType="{x:Type xcad:LayoutItem}">
                            <Setter Property="Title" Value="{Binding Model.Title}"/>
                            <Setter Property="Visibility" Value="{Binding Model.IsVisible, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter={x:Static Visibility.Hidden}}"/>
                            <Setter Property="ContentId" Value="{Binding Model.ContentId}"/>
                            <Setter Property="IsSelected" Value="{Binding Model.IsSelected, Mode=TwoWay}"/>
                            <Setter Property="IsActive" Value="{Binding Model.IsActive, Mode=TwoWay}"/>
                            <Setter Property="CanClose" Value="False" />
                        </Style>
                    </layout:PaneStyleSelector.AboutStyle>
                </layout:PaneStyleSelector>
            </xcad:DockingManager.LayoutItemContainerStyleSelector>
            <xcad:DockingManager.LayoutUpdateStrategy>
                <layout:LayoutInitializer/>
            </xcad:DockingManager.LayoutUpdateStrategy>
            <xcad:LayoutRoot>
                <xcad:LayoutPanel Orientation="Horizontal">
                    <xcad:LayoutAnchorablePaneGroup Orientation="Horizontal" DockMinWidth="200">
                        <xcad:LayoutAnchorablePane Name="ToolsPane">
                        </xcad:LayoutAnchorablePane>
                    </xcad:LayoutAnchorablePaneGroup>
                    <xcad:LayoutDocumentPaneGroup Orientation="Horizontal" DockWidth="5*" DockMinWidth="500">
                        <xcad:LayoutDocumentPane>
                        </xcad:LayoutDocumentPane>
                    </xcad:LayoutDocumentPaneGroup>
                </xcad:LayoutPanel>
            </xcad:LayoutRoot>
        </xcad:DockingManager>

        <tb:TaskbarIcon
            Grid.Row="0" 
            IconSource="basket_empty.ico"
            ToolTipText="ARK Bot"
            DoubleClickCommand="{Binding TaskIconDoubleClickCommand}"
            >
            <!-- Set a simple context menu  -->
            <tb:TaskbarIcon.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Show/Hide" Command="{Binding ShowOrHideCommand}"/>
                    <MenuItem Header="Exit" Command="{Binding ExitCommand}"/>
                </ContextMenu>
            </tb:TaskbarIcon.ContextMenu>
        </tb:TaskbarIcon>
    </Grid>
</Window>
