<UserControl x:Class="Artemis.UI.Screens.Settings.Tabs.Plugins.PluginFeatureView"
             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.Settings.Tabs.Plugins"
             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             xmlns:s="https://github.com/canton7/Stylet"
             xmlns:converters="clr-namespace:Artemis.UI.Converters"
             xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
             mc:Ignorable="d"
             d:DesignHeight="450" d:DesignWidth="800"
             d:DataContext="{d:DesignInstance local:PluginFeatureViewModel}">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary
                    Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.PopupBox.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <shared:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid Margin="-3 -8">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="30" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>

        <!-- Icon column -->
        <shared:ArtemisIcon Grid.Column="0"
                            Icon="{Binding FeatureInfo.ResolvedIcon}"
                            Width="20"
                            Height="20"
                            VerticalAlignment="Center"
                            HorizontalAlignment="Center"
                            Visibility="{Binding LoadException, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=Inverted, FallbackValue=Collapsed}" />

        <Button Grid.Column="0"
                Margin="-8"
                VerticalAlignment="Center"
                HorizontalAlignment="Center"
                Visibility="{Binding LoadException, Converter={StaticResource NullToVisibilityConverter}, FallbackValue=Collapsed}"
                Style="{StaticResource MaterialDesignIconButton}"
                Foreground="#E74C4C"
                ToolTip="An exception occurred while enabling this feature, click to view"
                Command="{s:Action ViewLoadException}">
            <materialDesign:PackIcon Kind="AlertCircle" />
        </Button>

        <!-- Display name column -->
        <TextBlock Grid.Column="1"
                   Text="{Binding FeatureInfo.Name}"
                   Style="{StaticResource MaterialDesignTextBlock}"
                   VerticalAlignment="Center"
                   TextWrapping="Wrap"
                   ToolTip="{Binding FeatureInfo.Description}" />

        <!-- Enable toggle column -->
        <StackPanel Grid.Column="2"
                    HorizontalAlignment="Right"
                    Margin="8"
                    Visibility="{Binding Enabling, Converter={x:Static s:BoolToVisibilityConverter.InverseInstance}, Mode=OneWay, FallbackValue=Collapsed}"
                    Orientation="Horizontal"
                    VerticalAlignment="Top"
                    ToolTip="This feature cannot be disabled without disabling the whole plugin"
                    ToolTipService.IsEnabled="{Binding FeatureInfo.AlwaysEnabled}">
            <materialDesign:PackIcon Kind="ShieldHalfFull"
                                     ToolTip="Plugin requires admin rights"
                                     VerticalAlignment="Center"
                                     Margin="0 0 5 0"
                                     Visibility="{Binding ShowShield, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay}" />
            <CheckBox Style="{StaticResource MaterialDesignCheckBox}"
                      IsChecked="{Binding IsEnabled}"
                      IsEnabled="{Binding CanToggleEnabled}">
                Feature enabled
            </CheckBox>

            <materialDesign:PopupBox Style="{StaticResource MaterialDesignToolPopupBox}"
                                     Margin="0 -4 -10 -4"
                                     Foreground="{StaticResource MaterialDesignBody}"
                                     IsEnabled="{Binding IsPopupEnabled}">
                <StackPanel>
                    <Button Command="{s:Action InstallPrerequisites}">
                        <StackPanel Orientation="Horizontal">
                            <materialDesign:PackIcon Kind="CheckAll" Margin="0 0 10 0 " VerticalAlignment="Center" />
                            <TextBlock VerticalAlignment="Center">Install prerequisites</TextBlock>
                        </StackPanel>
                    </Button>
                    <Button Command="{s:Action RemovePrerequisites}">
                        <StackPanel Orientation="Horizontal">
                            <materialDesign:PackIcon Kind="Delete" Margin="0 0 10 0 " VerticalAlignment="Center" />
                            <TextBlock VerticalAlignment="Center">Remove prerequisites</TextBlock>
                        </StackPanel>
                    </Button>
                </StackPanel>
            </materialDesign:PopupBox>
        </StackPanel>
        <StackPanel Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="7"
                    Visibility="{Binding Enabling, Converter={x:Static s:BoolToVisibilityConverter.Instance}, Mode=OneWay, FallbackValue=Collapsed}">
            <ProgressBar Style="{StaticResource MaterialDesignCircularProgressBar}" Value="0" IsIndeterminate="True" />
        </StackPanel>

    </Grid>
</UserControl>