<mde:MaterialWindow x:Class="Artemis.UI.Screens.Scripting.ScriptsDialogView"
                    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:local="clr-namespace:Artemis.UI.Screens.Scripting"
                    xmlns:mde="https://spiegelp.github.io/MaterialDesignExtensions/winfx/xaml"
                    xmlns:svgc="http://sharpvectors.codeplex.com/svgc/"
                    xmlns:s="https://github.com/canton7/Stylet"
                    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
                    xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
                    mc:Ignorable="d"
                    FadeContentIfInactive="False"
                    Icon="/Resources/Images/Logo/bow.ico"
                    Title="{Binding DisplayName}"
                    TitleBarIcon="{svgc:SvgImage Source=/Resources/Images/Logo/bow-white.svg}"
                    Foreground="{DynamicResource MaterialDesignBody}"
                    Background="{DynamicResource MaterialDesignPaper}"
                    FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto"
                    UseLayoutRounding="True"
                    Height="800" Width="1200"
                    d:DataContext="{d:DesignInstance {x:Type local:ScriptsDialogViewModel}}">
    <mde:MaterialWindow.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Sidebar/ArtemisSidebar.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
        </ResourceDictionary>
    </mde:MaterialWindow.Resources>
    <materialDesign:DialogHost IsTabStop="False" Focusable="False" Identifier="ScriptsDialog" DialogTheme="Inherit">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="240" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <!-- Sidebar -->
            <Border Grid.Column="0" ClipToBounds="True" Background="{DynamicResource MaterialDesignToolBarBackground}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <ListBox Grid.Row="0"
                             Margin="0 10 0 0"
                             ItemContainerStyle="{StaticResource SidebarListBoxItem}"
                             HorizontalContentAlignment="Stretch"
                             ItemsSource="{Binding ScriptConfigurations}"
                             SelectedItem="{Binding SelectedScript}">
                        <ListBox.ItemTemplate>
                            <DataTemplate DataType="{x:Type local:ScriptConfigurationViewModel}">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition />
                                        <RowDefinition />
                                    </Grid.RowDefinitions>
                                    <shared:ArtemisIcon Grid.Row="0"
                                                        Grid.Column="0"
                                                        Grid.RowSpan="2"
                                                        Icon="{Binding ScriptConfiguration.Script.ScriptingProvider.Info.ResolvedIcon, FallbackValue=QuestionMark}"
                                                        Width="18 "
                                                        Height="18"
                                                        Margin="0 0 10 0"
                                                        VerticalAlignment="Center" />
                                    <TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Text="{Binding ScriptConfiguration.Name}"
                                               Visibility="{Binding ScriptConfiguration.HasChanges, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}" />
                                    <TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"
                                               Visibility="{Binding ScriptConfiguration.HasChanges, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
                                        <Run Text="{Binding ScriptConfiguration.Name}" FontWeight="Bold" />
                                        <Run Text="*" />
                                    </TextBlock>
                                    <TextBlock Grid.Row="1"
                                               Grid.Column="1"
                                               Text="{Binding ScriptConfiguration.Script.ScriptingProvider.LanguageName, FallbackValue='Unknown scripting provider'}"
                                               Foreground="{DynamicResource MaterialDesignBodyLight}"
                                               VerticalAlignment="Center" />

                                    <Button Grid.Row="0" 
                                            Grid.RowSpan="2" 
                                            Grid.Column="2" 
                                            ToolTip="View properties" 
                                            Width="20"
                                            Height="20"
                                            Command="{s:Action ViewProperties}"
                                            CommandParameter="{Binding}" 
                                            HorizontalAlignment="Right">
                                        <Button.Style>
                                            <Style TargetType="{x:Type Button}" BasedOn="{StaticResource MaterialDesignIconForegroundButton}">
                                                <Setter Property="Visibility" Value="Collapsed" />
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}, Mode=FindAncestor}}" Value="True">
                                                        <Setter Property="Visibility" Value="Visible" />
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Button.Style>
                                        <materialDesign:PackIcon Kind="Cog" Width="16" Height="16" />
                                    </Button>
                                    <ToggleButton Grid.Row="0" Grid.RowSpan="2" Grid.Column="3" ToolTip="Suspend profile" Width="18" Height="18" Margin="2 0 0 0"
                                                  IsChecked="{Binding ScriptConfiguration.IsSuspended}">
                                        <ToggleButton.Style>
                                            <Style TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource MaterialDesignFlatToggleButton}">
                                                <Setter Property="Visibility" Value="Collapsed" />
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}, Mode=FindAncestor}}" Value="True">
                                                        <Setter Property="Visibility" Value="Visible" />
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </ToggleButton.Style>
                                        <materialDesign:PackIcon Kind="Pause" Height="14" Width="14" />
                                    </ToggleButton>

                                </Grid>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

                    <StackPanel Grid.Row="0"
                                Visibility="{Binding HasScripts, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}"
                                VerticalAlignment="Center"
                                HorizontalAlignment="Center" Margin="0 20 0 10">
                        <TextBlock Style="{StaticResource MaterialDesignBody2TextBlock}" HorizontalAlignment="Center">Your scripts will be listed here</TextBlock>
                    </StackPanel>
                    <Button Grid.Row="1"
                            Style="{StaticResource MaterialDesignOutlinedButton}"
                            Content="ADD NEW SCRIPT"
                            Margin="10 10 10 0"
                            Command="{s:Action AddScriptConfiguration}"
                            VerticalAlignment="Top" />
                </Grid>
            </Border>

            <!-- Script editor -->
            <ContentControl Grid.Column="1" s:View.Model="{Binding ActiveItem}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
            <StackPanel Grid.Column="1"
                        Visibility="{Binding ActiveItem, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted}"
                        VerticalAlignment="Center"
                        HorizontalAlignment="Center">
                <materialDesign:PackIcon Kind="CodeGreaterThanOrEqual" Width="150" Height="150" HorizontalAlignment="Center" />
                <TextBlock Style="{StaticResource MaterialDesignHeadline4TextBlock}" HorizontalAlignment="Center">Get ready to start scripting!</TextBlock>
                <TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}" HorizontalAlignment="Center">Use the sidebar to create new scripts and manage existing scripts.</TextBlock>
            </StackPanel>
        </Grid>
    </materialDesign:DialogHost>
</mde:MaterialWindow>