<Page x:Class="DesktopMagic.Pages.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:DesktopMagic.Pages"
      xmlns:dataContext="clr-namespace:DesktopMagic.DataContexts"
      mc:Ignorable="d"
      d:DataContext="{d:DesignInstance Type=dataContext:MainWindowDataContext}"
      d:DesignHeight="450" d:DesignWidth="800"
      ScrollViewer.CanContentScroll="False"
      Title="MainPage">

    <Grid Margin="{StaticResource DefaultMargin}">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>

        <ui:Card Padding="5" Margin="0 0 0 5">
            <ui:ToggleSwitch x:Name="editCheckBox" Height="30" VerticalAlignment="Center" Margin="5 0 0 0" Content="{DynamicResource editLayout}" Click="EditCheckBox_Click" />
        </ui:Card>

        <ScrollViewer Background="#FFBBBBBB" PreviewMouseWheel="ScrollViewer_PreviewMouseWheel" Grid.Row="1" VerticalAlignment="Stretch" VerticalContentAlignment="Top">
            <ItemsControl ItemsSource="{Binding Settings.CurrentLayout.Plugins}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <ui:CardExpander Tag="{Binding}" Margin="0 0 0 5" Expanded="OptionsCardExpander_Expanded">
                            <ui:CardExpander.Header>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <ui:TextBlock Grid.Row="0" Grid.Column="0" FontTypography="Body" Text="{Binding Value.Metadata.Name}" />
                                    <Label Grid.Row="1" Grid.Column="0" Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}" FontSize="12" ContentStringFormat="{DynamicResource authorFormat}">
                                        <Label.Style>
                                            <Style TargetType="Label" BasedOn="{StaticResource {x:Type Label}}">
                                                <Setter Property="Content" Value="{Binding Value.Metadata.Author, Converter={StaticResource UnderscoreEscapingConverter}}" />
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding Value.Metadata.Author}" Value="{x:Null}">
                                                        <Setter Property="Content" Value="{DynamicResource unknown}" />
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Label.Style>
                                    </Label>
                                    <ui:ToggleSwitch Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" Click="PluginCheckBox_Click" IsChecked="{Binding Value.Enabled}" Tag="{Binding Key}" Margin="0,0,16,0" VerticalAlignment="Center" />
                                </Grid>
                            </ui:CardExpander.Header>
                        </ui:CardExpander>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>

        <ui:Card Grid.Row="2" Grid.ColumnSpan="2" Margin="0 5 0 0" Padding="5">
            <Grid  >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="1*" />
                    <ColumnDefinition Width="5" />
                    <ColumnDefinition Width="0.5*" />
                    <ColumnDefinition Width="5" />
                    <ColumnDefinition Width="0.5*" />
                </Grid.ColumnDefinitions>

                <ComboBox x:Name="layoutsComboBox" ItemsSource="{Binding Settings.Layouts}" DisplayMemberPath="Name" SelectedValue="{Binding Settings.CurrentLayoutName}" SelectedValuePath="Name" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="4" SelectionChanged="LayoutsComboBox_SelectionChanged" />
                <Button x:Name="newLayoutButton" Grid.Column="2" HorizontalAlignment="Stretch" Click="NewLayoutButton_Click" FontWeight="Regular">
                    <StackPanel Orientation="Horizontal">
                        <ui:SymbolIcon Symbol="Add24" Margin="0 0 10 0" />
                        <TextBlock Text="{DynamicResource newLayout}" />
                    </StackPanel>
                </Button>
                <Button x:Name="removeLayoutButton" Grid.Column="4" HorizontalAlignment="Stretch" Click="RemoveLayoutButton_Click" FontWeight="Regular">
                    <StackPanel Orientation="Horizontal">
                        <ui:SymbolIcon Symbol="Delete24" Margin="0 0 10 0" />
                        <TextBlock Text="{DynamicResource deleteLayout}" />
                    </StackPanel>
                </Button>
            </Grid>
        </ui:Card>
    </Grid>
</Page>
