<windowing:AppWindow xmlns="https://github.com/avaloniaui"
                      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:core="clr-namespace:Artemis.Core;assembly=Artemis.Core"
                      xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared"
                      xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
                      xmlns:local="clr-namespace:Artemis.UI.Screens.Sidebar"
                      xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
                      xmlns:windowing="clr-namespace:FluentAvalonia.UI.Windowing;assembly=FluentAvalonia"
                      xmlns:materialIconPicker="clr-namespace:Artemis.UI.Shared.MaterialIconPicker;assembly=Artemis.UI.Shared"
                      mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="850"
                      x:Class="Artemis.UI.Screens.Sidebar.ProfileConfigurationEditView"
                      x:DataType="local:ProfileConfigurationEditViewModel"
                      Icon="/Assets/Images/Logo/application.ico"
                      Title="{CompiledBinding DisplayName}"
                      Width="800"
                      MinWidth="420"
                      Height="975">
    <Window.Resources>
        <converters:EnumToBooleanConverter x:Key="EnumBoolConverter" />
    </Window.Resources>
    <Grid Margin="16" RowDefinitions="*,Auto">
        <ScrollViewer>
            <StackPanel>
                <StackPanel.Styles>
                    <Style Selector="TextBlock.label">
                        <Setter Property="Margin" Value="0 10 0 5" />
                    </Style>
                    <Style Selector="TextBlock.section-header">
                        <Setter Property="Margin" Value="0 0 5 0" />
                    </Style>
                    <Style Selector="TextBlock.section-subtitle">
                        <Setter Property="VerticalAlignment" Value="Bottom" />
                        <Setter Property="Margin" Value="0 0 0 1" />
                        <Setter Property="TextWrapping" Value="Wrap" />
                    </Style>
                </StackPanel.Styles>

                <Grid>
                    <TextBlock Classes="h4" IsVisible="{CompiledBinding IsNew}">Add a new profile</TextBlock>
                    <TextBlock Classes="h4" IsVisible="{CompiledBinding !IsNew}" Text="{CompiledBinding ProfileConfiguration.Name}" />
                </Grid>

                <Border Classes="card" Margin="0 0 0 15">
                    <StackPanel>
                        <TextBlock Classes="label">Profile name</TextBlock>
                        <TextBox Watermark="Name" Text="{CompiledBinding ProfileName}" />
                        <TextBlock Classes="label">Module</TextBlock>
                        <ComboBox SelectedItem="{CompiledBinding SelectedModule}" IsEnabled="{CompiledBinding Modules.Count}" ItemsSource="{CompiledBinding Modules}" HorizontalAlignment="Stretch">
                            <ComboBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <VirtualizingStackPanel />
                                </ItemsPanelTemplate>
                            </ComboBox.ItemsPanel>
                            <ComboBox.ItemTemplate>
                                <DataTemplate x:DataType="local:ProfileModuleViewModel">
                                    <StackPanel Orientation="Horizontal">
                                        <shared:ArtemisIcon Icon="{CompiledBinding Icon, FallbackValue='Close'}" Width="16" Height="16" Margin="0 0 5 0" />
                                        <TextBlock Text="{CompiledBinding Name, FallbackValue='None'}" />
                                    </StackPanel>
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>
                        <Grid>
                            <TextBlock Classes="subtitle" IsVisible="{CompiledBinding Modules.Count}">Optional and binds the profile to the selected module, making module data available</TextBlock>
                            <TextBlock Classes="subtitle" IsVisible="{CompiledBinding !Modules.Count}">No available modules were found</TextBlock>
                        </Grid>

                        <TextBlock Classes="label">Icon</TextBlock>
                        <WrapPanel Orientation="Horizontal">
                            <RadioButton Content="Material Icon"
                                         IsChecked="{CompiledBinding IconType, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationIconType.MaterialIcon}}" />
                            <RadioButton Content="Bitmap image"
                                         IsChecked="{CompiledBinding IconType, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationIconType.BitmapImage}}" />
                        </WrapPanel>

                        <StackPanel Orientation="Horizontal"
                                    IsVisible="{CompiledBinding IconType, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationIconType.BitmapImage}}">

                            <Border IsVisible="{CompiledBinding ProfileConfiguration.Icon.Fill}" Background="{DynamicResource CheckerboardBrush}" CornerRadius="{DynamicResource CardCornerRadius}"
                                    Width="78" Height="78">
                                <Border Name="FillPreview"
                                        Background="{DynamicResource TextFillColorPrimary}" 
                                        VerticalAlignment="Stretch" 
                                        HorizontalAlignment="Stretch" Margin="10"
                                        RenderOptions.BitmapInterpolationMode="HighQuality" >
                                    <Border.OpacityMask>
                                        <ImageBrush Source="{CompiledBinding SelectedBitmapSource}" />
                                    </Border.OpacityMask>
                                </Border>
                            </Border>
                            <Border IsVisible="{CompiledBinding !ProfileConfiguration.Icon.Fill}" Background="{DynamicResource CheckerboardBrush}" CornerRadius="{DynamicResource CardCornerRadius}"
                                    Width="78" Height="78">
                                <Image Source="{CompiledBinding SelectedBitmapSource}" Margin="10" />
                            </Border>

                            <Button Command="{CompiledBinding BrowseBitmapFile}"
                                    VerticalAlignment="Bottom"
                                    Margin="10 0"
                                    IsVisible="{CompiledBinding IconType, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationIconType.BitmapImage}}">
                                Browse bitmap file
                            </Button>
                            <CheckBox VerticalAlignment="Bottom" IsChecked="{CompiledBinding ProfileConfiguration.Icon.Fill}">Fill</CheckBox>
                        </StackPanel>

                        <StackPanel Orientation="Horizontal"
                                    IsVisible="{CompiledBinding IconType, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationIconType.MaterialIcon}}">
                            <Border Background="{DynamicResource CheckerboardBrush}" CornerRadius="{DynamicResource CardCornerRadius}" Width="78" Height="78">
                                <avalonia:MaterialIcon Kind="{CompiledBinding SelectedMaterialIcon.Icon}" Width="45" Height="45" />
                            </Border>
                            <materialIconPicker:MaterialIconPickerButton 
                                Value="{CompiledBinding SelectedMaterialIcon.Icon}"
                                Margin="10 0"
                                Width="250"
                                VerticalAlignment="Bottom" 
                                IsVisible="{CompiledBinding IconType, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationIconType.MaterialIcon}}"/>
                        </StackPanel>

                        <CheckBox VerticalAlignment="Bottom" IsChecked="{CompiledBinding FadeInAndOut}" ToolTip.Tip="Smoothly animates in and out when the profile activation conditions change.">
                            Fade when enabling and disabling
                        </CheckBox>
                    </StackPanel>
                </Border>

                <StackPanel Orientation="Horizontal">
                    <TextBlock Classes="h5 section-header">Keybindings</TextBlock>
                    <TextBlock Classes="subtitle section-subtitle">You may set up hotkeys to activate/deactivate the profile</TextBlock>
                </StackPanel>
                <Border Classes="card" Margin="0 5 0 15">
                    <StackPanel>
                        <TextBlock>Hotkey mode</TextBlock>
                        <WrapPanel Orientation="Horizontal">
                            <RadioButton Content="None"
                                         IsChecked="{CompiledBinding HotkeyMode, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationHotkeyMode.None}}" />
                            <RadioButton Content="Toggle"
                                         IsChecked="{CompiledBinding HotkeyMode, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationHotkeyMode.Toggle}}" />
                            <RadioButton Content="Separate enable/disable"
                                         IsChecked="{CompiledBinding HotkeyMode, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationHotkeyMode.EnableDisable}}" />
                        </WrapPanel>

                        <shared:HotkeyBox Watermark="Toggle hotkey"
                                          Hotkey="{CompiledBinding EnableHotkey}"
                                          IsVisible="{CompiledBinding HotkeyMode, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationHotkeyMode.Toggle}}"
                                          HorizontalAlignment="Left"
                                          Width="200"
                                          Margin="0 5 0 0" />
                        <StackPanel Orientation="Horizontal"
                                    IsVisible="{CompiledBinding HotkeyMode, Converter={StaticResource EnumBoolConverter}, ConverterParameter={x:Static core:ProfileConfigurationHotkeyMode.EnableDisable}}"
                                    HorizontalAlignment="Left"
                                    Margin="0 5 0 0">
                            <shared:HotkeyBox Watermark="Enable hotkey" Hotkey="{CompiledBinding EnableHotkey}" Margin="0 0 4 0" Width="200" />
                            <shared:HotkeyBox Watermark="Disable hotkey" Hotkey="{CompiledBinding DisableHotkey}" Margin="4 0 0 0" Width="200" />
                        </StackPanel>
                    </StackPanel>
                </Border>

                <StackPanel Orientation="Horizontal">
                    <TextBlock Classes="h5 section-header">Activation conditions</TextBlock>
                    <TextBlock Classes="subtitle section-subtitle">Set up certain conditions under which the profile should be active</TextBlock>
                </StackPanel>
                <Border Classes="card" Margin="0 5">
                    <Grid>
                        <Border CornerRadius="5" ClipToBounds="True">
                            <ContentControl Content="{CompiledBinding VisualEditorViewModel}" Height="150" />
                        </Border>
                        <Border Background="Black" Opacity="0.5" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" CornerRadius="5" />

                        <Button DockPanel.Dock="Bottom"
                                ToolTip.Tip="Open editor"
                                HorizontalAlignment="Center"
                                VerticalAlignment="Center"
                                Command="{CompiledBinding OpenConditionEditor}">
                            Edit condition script
                        </Button>
                    </Grid>
                </Border>

                <ContentControl Content="{CompiledBinding ModuleActivationRequirementsViewModel}" />
            </StackPanel>
        </ScrollViewer>

        <StackPanel Grid.Row="1" Spacing="5" HorizontalAlignment="Right" Orientation="Horizontal">
            <Button Command="{CompiledBinding Confirm}" Classes="accent">Confirm</Button>
            <Button Command="{CompiledBinding Delete}" IsVisible="{CompiledBinding !IsNew}">Delete</Button>
            <Button Command="{CompiledBinding Cancel}">Cancel</Button>
        </StackPanel>
    </Grid>

</windowing:AppWindow>