<UserControl x:Class="Artemis.UI.Screens.Plugins.PluginPrerequisitesInstallDialogView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:Artemis.UI.Screens.Plugins"
             xmlns:s="https://github.com/canton7/Stylet"
             xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:converters="clr-namespace:Artemis.UI.Converters"
             mc:Ignorable="d"
             d:DesignHeight="450" d:DesignWidth="800"
             d:DataContext="{d:DesignInstance local:PluginPrerequisitesInstallDialogViewModel}">
    <UserControl.Resources>
        <converters:InverseBooleanConverter x:Key="InverseBooleanConverter"/>
        <converters:NullToBooleanConverter x:Key="NullToBooleanConverter" />
        <shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
    </UserControl.Resources>
    <Grid Margin="16">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition MinHeight="150" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300" />
            <ColumnDefinition Width="500" />
        </Grid.ColumnDefinitions>
        <TextBlock Grid.Row="0" Style="{StaticResource MaterialDesignHeadline6TextBlock}" TextWrapping="Wrap" Margin="0 0 0 20">
            Plugin/feature prerequisites
        </TextBlock>

        <ListBox Grid.Row="1"
                 Grid.Column="0"
                 ItemsSource="{Binding Prerequisites}"
                 SelectedItem="{Binding ActivePrerequisite, Mode=OneWay}"
                 HorizontalContentAlignment="Stretch">
            <ListBox.ItemTemplate>
                <DataTemplate DataType="{x:Type local:PluginPrerequisiteViewModel}">
                    <Border Padding="8" BorderThickness="0 0 0 1" BorderBrush="{DynamicResource MaterialDesignDivider}" VerticalAlignment="Stretch">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <ToggleButton VerticalAlignment="Center"
                                          Style="{StaticResource MaterialDesignActionToggleButton}"
                                          Focusable="False"
                                          IsHitTestVisible="False"
                                          IsChecked="{Binding IsMet}">
                                <ToggleButton.Content>
                                    <Border Background="#E74C4C" Width="32" Height="32">
                                        <materialDesign:PackIcon Kind="Close" VerticalAlignment="Center" HorizontalAlignment="Center" />
                                    </Border>
                                </ToggleButton.Content>
                                <materialDesign:ToggleButtonAssist.OnContent>
                                    <materialDesign:PackIcon Kind="Check" />
                                </materialDesign:ToggleButtonAssist.OnContent>
                            </ToggleButton>

                            <StackPanel Margin="8 0 0 0" Grid.Column="1" VerticalAlignment="Stretch">
                                <TextBlock FontWeight="Bold" Text="{Binding PluginPrerequisite.Name}" TextWrapping="Wrap" />
                                <TextBlock Text="{Binding PluginPrerequisite.Description}" TextWrapping="Wrap" />
                            </StackPanel>
                        </Grid>
                    </Border>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <ContentControl Grid.Row="0"
                        Grid.RowSpan="2"
                        Grid.Column="1"
                        s:View.Model="{Binding ActivePrerequisite}"
                        VerticalContentAlignment="Stretch"
                        HorizontalContentAlignment="Stretch"
                        Margin="10 0"
                        IsTabStop="False"
                        Visibility="{Binding ShowProgress, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />

        <TextBlock Grid.Row="1"
                   Grid.Column="1"
                   Style="{StaticResource MaterialDesignBody1TextBlock}"
                   TextWrapping="Wrap"
                   Margin="10 0"
                   Visibility="{Binding ShowIntro, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
            In order for this plugin/feature to function certain prerequisites must be met. <LineBreak /><LineBreak />
            On the left side you can see all prerequisites and whether they are currently met or not.
            Clicking install prerequisites will automatically set everything up for you.
        </TextBlock>

        <TextBlock Grid.Row="1"
                   Grid.Column="1"
                   Style="{StaticResource MaterialDesignBody1TextBlock}"
                   TextWrapping="Wrap"
                   Margin="10 0"
                   Visibility="{Binding ShowFailed, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
            Installing <Run Text="{Binding ActivePrerequisite.PluginPrerequisite.Name, Mode=OneWay}" FontWeight="SemiBold" /> failed. <LineBreak /><LineBreak />
            You may try again to see if that helps, otherwise install the prerequisite manually or contact the plugin developer.
        </TextBlock>

        <StackPanel Grid.Row="2"
                    Grid.Column="0"
                    Grid.ColumnSpan="2"
                    Orientation="Horizontal"
                    HorizontalAlignment="Right"
                    Margin="0 8 0 0"
                    Visibility="{Binding ShowInstall, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}">
            <Button Style="{StaticResource MaterialDesignFlatButton}"
                    Focusable="False"
                    IsCancel="True"
                    Command="{s:Action Cancel}"
                    Content="CANCEL" />
            <Button x:Name="ConfirmButton"
                    Style="{StaticResource MaterialDesignFlatButton}"
                    IsDefault="True"
                    Focusable="True"
                    IsEnabled="{Binding ShowProgress, Converter={StaticResource InverseBooleanConverter}, Mode=OneWay}"
                    Command="{s:Action Install}"
                    Content="INSTALL PREREQUISITES" />
        </StackPanel>

        <StackPanel Grid.Row="2"
                    Grid.Column="0"
                    Grid.ColumnSpan="2"
                    Orientation="Horizontal"
                    HorizontalAlignment="Right"
                    Margin="0 8 0 0"
                    Visibility="{Binding ShowInstall, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay}">
            <Button Style="{StaticResource MaterialDesignFlatButton}"
                    Focusable="False"
                    IsCancel="True"
                    Command="{s:Action Accept}"
                    Content="FINISH" />
        </StackPanel>

    </Grid>
</UserControl>