<Window
    x:Class="PowerRenameUI.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:animatedVisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals"
    xmlns:controls="using:Microsoft.UI.Xaml.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="using:PowerRenameUI"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Window.SystemBackdrop>
        <MicaBackdrop />
    </Window.SystemBackdrop>
    <Grid Padding="12">
        <Grid.RowDefinitions>
            <RowDefinition Height="0" />
            <!--  48 if we need to draw the title bar ourself  -->
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <Grid
            Grid.Row="1"
            Grid.Column="1"
            HorizontalAlignment="Stretch"
            VerticalAlignment="Stretch"
            Background="{ThemeResource LayerFillColorDefaultBrush}"
            BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
            BorderThickness="1"
            CornerRadius="8">
            <Grid.RowDefinitions>
                <RowDefinition Height="40" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <StackPanel Orientation="Horizontal">
                <CheckBox
                    x:Name="checkBox_selectAll"
                    x:Uid="SelectAllCheckBox"
                    MinWidth="0"
                    Margin="10,0,0,0"
                    Checked="SelectAll"
                    Content=""
                    IsChecked="True"
                    Style="{StaticResource CheckBoxDefaultStyleOverride}"
                    Unchecked="SelectAll" />
                <Image
                    Width="16"
                    Margin="4,0,0,0"
                    HorizontalAlignment="Left"
                    Source="ms-appx:///Assets/PowerRename/file.png" />

                <StackPanel
                    Grid.Column="2"
                    Margin="6,-2,0,0"
                    VerticalAlignment="Center"
                    Orientation="Horizontal">
                    <TextBlock x:Uid="TxtBlock_Original" FontWeight="Medium" />
                    <TextBlock Margin="4,0,0,0" FontWeight="Medium">
                        <Run Text="(" /><Run Text="{x:Bind OriginalCount, Mode=OneWay}" /><Run Text=")" />
                    </TextBlock>
                </StackPanel>
            </StackPanel>
            <AppBarSeparator Margin="-6,4,0,4" HorizontalAlignment="Right" />

            <StackPanel
                Grid.Column="2"
                Margin="4,-2,0,0"
                VerticalAlignment="Center"
                Orientation="Horizontal">
                <TextBlock x:Uid="TxtBlock_Renamed" FontWeight="Medium" />
                <TextBlock Margin="4,0,0,0" FontWeight="Medium">
                    <Run Text="(" /><Run Text="{x:Bind RenamedCount, Mode=OneWay}" /><Run Text=")" />
                </TextBlock>
            </StackPanel>

            <Button
                x:Uid="FilterButton"
                Grid.Column="1"
                Height="32"
                Margin="0,0,8,0"
                HorizontalAlignment="Right"
                Background="Transparent"
                BorderThickness="0"
                Content="&#xE71C;"
                FontFamily="{ThemeResource SymbolThemeFontFamily}">
                <Button.Flyout>
                    <MenuBarItemFlyout Placement="Bottom">
                        <controls:RadioMenuFlyoutItem
                            x:Name="button_showAll"
                            x:Uid="ShowAll"
                            Click="ShowAll"
                            GroupName="Filter"
                            IsChecked="True" />
                        <controls:RadioMenuFlyoutItem
                            x:Name="button_showRenamed"
                            x:Uid="ShowOnly"
                            Click="ShowRenamed"
                            GroupName="Filter" />
                    </MenuBarItemFlyout>
                </Button.Flyout>
            </Button>

            <Rectangle
                Grid.ColumnSpan="5"
                Height="1"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Bottom"
                Fill="{ThemeResource DividerStrokeColorDefaultBrush}" />
            <!--  Changing VirtualizationMode to Recycling introduces the issue with popping indent/icons, but makes scrolling slightly faster  -->
            <ListView
                x:Name="listView_ExplorerItems"
                Grid.Row="1"
                Grid.ColumnSpan="6"
                IsItemClickEnabled="False"
                IsTabStop="false"
                ItemsSource="{x:Bind ExplorerItems, Mode=OneWay}"
                SelectionMode="None"
                VirtualizingStackPanel.VirtualizationMode="Standard"
                XYFocusKeyboardNavigation="Enabled">
                <ListView.ItemTemplate>
                    <DataTemplate x:DataType="local:ExplorerItemViewModel">
                        <local:ExplorerItem
                            Checked="{x:Bind CheckedVM, Mode=TwoWay, FallbackValue=True}"
                            Id="{x:Bind IdVM, Mode=OneWay}"
                            IdStr="{x:Bind IdStrVM}"
                            ImagePath="{x:Bind ImagePathVM}"
                            Indentation="{x:Bind IndentationVM}"
                            Original="{x:Bind OriginalVM}"
                            Renamed="{x:Bind RenamedVM}"
                            State="{x:Bind StateVM}"
                            Type="{x:Bind TypeVM}" />
                    </DataTemplate>
                </ListView.ItemTemplate>
                <ListView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel />
                    </ItemsPanelTemplate>
                </ListView.ItemsPanel>

                <ListView.ItemContainerStyle>
                    <Style TargetType="ListViewItem">
                        <Setter Property="IsTabStop" Value="False" />
                        <Setter Property="Padding" Value="0" />
                        <Setter Property="Margin" Value="0" />
                        <Setter Property="MinHeight" Value="0" />
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ListViewItem">
                                    <StackPanel Orientation="Vertical">
                                        <ContentPresenter />
                                        <Rectangle
                                            Grid.ColumnSpan="5"
                                            Height="1"
                                            Margin="0,0,0,0"
                                            HorizontalAlignment="Stretch"
                                            VerticalAlignment="Bottom"
                                            Fill="{ThemeResource DividerStrokeColorDefaultBrush}"
                                            Opacity="1" />
                                    </StackPanel>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListView.ItemContainerStyle>
            </ListView>
        </Grid>

        <Grid
            Grid.Row="1"
            Grid.Column="0"
            MaxWidth="359"
            HorizontalAlignment="Stretch"
            VerticalAlignment="Stretch">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="48" />
            </Grid.RowDefinitions>

            <StackPanel
                Margin="0,0,12,0"
                Padding="0,0,0,16"
                Orientation="Vertical">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <AutoSuggestBox
                        x:Name="textBox_search"
                        x:Uid="SearchBox"
                        Height="40"
                        VerticalContentAlignment="Center"
                        ItemsSource="{x:Bind SearchMRU}" />

                    <Button
                        x:Uid="RegExButton"
                        Grid.Column="1"
                        Width="28"
                        Height="40"
                        Margin="0,0,-4,0"
                        Padding="0"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Center"
                        Background="Transparent"
                        BorderBrush="Transparent"
                        Content="&#xE946;"
                        FontFamily="{ThemeResource SymbolThemeFontFamily}"
                        Visibility="{Binding ElementName=checkBox_regex, Path=IsChecked}">
                        <Button.Flyout>
                            <Flyout x:Name="RegExFlyout" ShouldConstrainToRootBounds="False">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="28" />
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="48" />
                                    </Grid.RowDefinitions>
                                    <TextBlock x:Uid="RegExCheatSheet_Title" FontWeight="SemiBold" />
                                    <ListView
                                        Grid.Row="1"
                                        Margin="-4,12,0,0"
                                        IsItemClickEnabled="True"
                                        ItemClick="RegExItemClick"
                                        ItemsSource="{x:Bind SearchRegExShortcuts}"
                                        SelectionMode="None">
                                        <ListView.ItemTemplate>
                                            <DataTemplate x:DataType="local:PatternSnippet">
                                                <Grid Margin="-10,0,0,0" ColumnSpacing="8">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="48" />
                                                        <ColumnDefinition Width="*" />
                                                    </Grid.ColumnDefinitions>
                                                    <Border
                                                        Padding="8"
                                                        HorizontalAlignment="Left"
                                                        Background="{ThemeResource ButtonBackground}"
                                                        BorderBrush="{ThemeResource ButtonBorderBrush}"
                                                        BorderThickness="1"
                                                        CornerRadius="4">
                                                        <TextBlock
                                                            FontFamily="Consolas"
                                                            Foreground="{ThemeResource ButtonForeground}"
                                                            Text="{x:Bind Code}" />
                                                    </Border>

                                                    <TextBlock
                                                        Grid.Column="1"
                                                        VerticalAlignment="Center"
                                                        FontSize="12"
                                                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                                        Text="{x:Bind Description}" />
                                                </Grid>
                                            </DataTemplate>
                                        </ListView.ItemTemplate>
                                    </ListView>
                                    <HyperlinkButton
                                        Grid.Row="2"
                                        VerticalAlignment="Bottom"
                                        NavigateUri="https://aka.ms/powertoysRegExHelp">
                                        <TextBlock x:Uid="RegExCheatSheet_LearnMore" />
                                    </HyperlinkButton>
                                </Grid>
                            </Flyout>
                        </Button.Flyout>
                    </Button>
                </Grid>


                <CheckBox
                    x:Name="checkBox_regex"
                    x:Uid="CheckBox_RegEx"
                    Margin="2,6,0,0" />
                <CheckBox
                    x:Name="checkBox_matchAll"
                    x:Uid="CheckBox_MatchAll"
                    Margin="2,0,0,0" />
                <CheckBox
                    x:Name="checkBox_case"
                    x:Uid="CheckBox_Case"
                    Margin="2,0,0,0" />

                <Rectangle
                    Height="1"
                    Margin="0,16,0,20"
                    HorizontalAlignment="Stretch"
                    Fill="{ThemeResource CardStrokeColorDefaultBrush}" />
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <AutoSuggestBox
                        x:Name="textBox_replace"
                        x:Uid="ReplaceBox"
                        Height="40"
                        Padding="12,12,0,0"
                        VerticalContentAlignment="Center"
                        ItemsSource="{x:Bind ReplaceMRU}" />

                    <Button
                        x:Uid="FileCreationButton"
                        Grid.Column="1"
                        Width="28"
                        Height="40"
                        Margin="0,0,-4,0"
                        Padding="0"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Center"
                        Background="Transparent"
                        BorderBrush="Transparent"
                        Content="&#xE946;"
                        FontFamily="{ThemeResource SymbolThemeFontFamily}">
                        <Button.Flyout>
                            <Flyout x:Name="DateTimeFlyout" ShouldConstrainToRootBounds="False">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="28" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="28" />
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>
                                    <TextBlock x:Uid="DateTimeCheatSheet_Title" FontWeight="SemiBold" />
                                    <ListView
                                        Grid.Row="1"
                                        Margin="-4,12,0,0"
                                        IsItemClickEnabled="True"
                                        ItemClick="DateTimeItemClick"
                                        ItemsSource="{x:Bind DateTimeShortcuts}"
                                        SelectionMode="None">
                                        <ListView.ItemTemplate>
                                            <DataTemplate x:DataType="local:PatternSnippet">
                                                <Grid Margin="-10,0,0,0" ColumnSpacing="8">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="56" />
                                                        <ColumnDefinition Width="*" />
                                                    </Grid.ColumnDefinitions>
                                                    <Border
                                                        Padding="8"
                                                        HorizontalAlignment="Left"
                                                        Background="{ThemeResource ButtonBackground}"
                                                        BorderBrush="{ThemeResource ButtonBorderBrush}"
                                                        BorderThickness="1"
                                                        CornerRadius="4">
                                                        <TextBlock
                                                            FontFamily="Consolas"
                                                            Foreground="{ThemeResource ButtonForeground}"
                                                            Text="{x:Bind Code}" />
                                                    </Border>

                                                    <TextBlock
                                                        Grid.Column="1"
                                                        VerticalAlignment="Center"
                                                        FontSize="12"
                                                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                                        Text="{x:Bind Description}" />
                                                </Grid>
                                            </DataTemplate>
                                        </ListView.ItemTemplate>
                                    </ListView>
                                    <TextBlock
                                        x:Uid="CounterCheatSheet_Title"
                                        Grid.Row="2"
                                        Margin="0,10,0,0"
                                        FontWeight="SemiBold" />
                                    <ListView
                                        Grid.Row="3"
                                        Margin="-4,12,0,0"
                                        IsItemClickEnabled="True"
                                        ItemClick="DateTimeItemClick"
                                        ItemsSource="{x:Bind CounterShortcuts}"
                                        SelectionMode="None">
                                        <ListView.ItemTemplate>
                                            <DataTemplate x:DataType="local:PatternSnippet">
                                                <Grid Margin="-10,0,0,0" ColumnSpacing="8">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="Auto" />
                                                        <ColumnDefinition Width="*" />
                                                    </Grid.ColumnDefinitions>
                                                    <Border
                                                        Padding="8"
                                                        HorizontalAlignment="Left"
                                                        Background="{ThemeResource ButtonBackground}"
                                                        BorderBrush="{ThemeResource ButtonBorderBrush}"
                                                        BorderThickness="1"
                                                        CornerRadius="4">
                                                        <TextBlock
                                                            FontFamily="Consolas"
                                                            Foreground="{ThemeResource ButtonForeground}"
                                                            Text="{x:Bind Code}" />
                                                    </Border>
                                                    <TextBlock
                                                        Grid.Column="1"
                                                        VerticalAlignment="Center"
                                                        FontSize="12"
                                                        Foreground="{ThemeResource TextFillColorSecondaryBrush}"
                                                        Text="{x:Bind Description}" />
                                                </Grid>
                                            </DataTemplate>
                                        </ListView.ItemTemplate>
                                    </ListView>
                                </Grid>
                            </Flyout>
                        </Button.Flyout>
                    </Button>
                </Grid>

                <TextBlock
                    x:Name="ApplyToLabel"
                    x:Uid="TextBox_ApplyTo"
                    Margin="0,16,0,8"
                    FontSize="12"
                    Foreground="{ThemeResource TextFillColorSecondaryBrush}" />

                <StackPanel
                    Grid.Row="1"
                    Grid.Column="1"
                    Orientation="Horizontal"
                    Spacing="4">
                    <ComboBox
                        x:Name="comboBox_renameParts"
                        Grid.Row="1"
                        Grid.Column="0"
                        Width="200"
                        HorizontalAlignment="Stretch"
                        AutomationProperties.LabeledBy="{Binding ElementName=ApplyToLabel}"
                        SelectedIndex="0">
                        <ComboBoxItem x:Uid="RenameParts_FilenameAndExtension" />
                        <ComboBoxItem x:Uid="RenameParts_FilenameOnly" />
                        <ComboBoxItem x:Uid="RenameParts_ExtensionOnly" />
                    </ComboBox>
                    <AppBarSeparator Margin="5,0,5,0" />
                    <ToggleButton
                        x:Name="toggleButton_includeFiles"
                        x:Uid="ToggleButton_IncludeFiles"
                        Height="32"
                        MinHeight="0"
                        Content="&#xE7C3;"
                        FontFamily="{ThemeResource SymbolThemeFontFamily}"
                        IsChecked="True" />
                    <ToggleButton
                        x:Name="toggleButton_includeFolders"
                        x:Uid="ToggleButton_IncludeFolders"
                        Height="32"
                        MinHeight="0"
                        Content="&#xE8B7;"
                        FontFamily="{ThemeResource SymbolThemeFontFamily}"
                        IsChecked="True" />
                    <ToggleButton
                        x:Name="toggleButton_includeSubfolders"
                        x:Uid="ToggleButton_IncludeSubFolders"
                        Height="32"
                        MinHeight="0"
                        Content="&#xED41;"
                        FontFamily="{ThemeResource SymbolThemeFontFamily}"
                        IsChecked="True" />
                </StackPanel>

                <TextBlock
                    x:Uid="TextBlock_TextFormatting"
                    Margin="0,16,0,8"
                    FontSize="12"
                    Foreground="{ThemeResource TextFillColorSecondaryBrush}" />


                <StackPanel Orientation="Horizontal" Spacing="4">
                    <ToggleButton
                        x:Name="toggleButton_lowerCase"
                        x:Uid="ToggleButton_Lowercase"
                        Height="32"
                        MinHeight="0"
                        Content="aa"
                        FontWeight="Medium" />
                    <ToggleButton
                        x:Name="toggleButton_upperCase"
                        x:Uid="ToggleButton_Uppercase"
                        Height="32"
                        MinHeight="0"
                        Content="AA"
                        FontWeight="Medium" />
                    <ToggleButton
                        x:Name="toggleButton_titleCase"
                        x:Uid="ToggleButton_TitleCase"
                        Height="32"
                        MinHeight="0"
                        Content="Aa"
                        FontWeight="Medium" />
                    <ToggleButton
                        x:Name="toggleButton_capitalize"
                        x:Uid="ToggleButton_Capitalize"
                        Height="32"
                        MinHeight="0"
                        Content="Aa Aa"
                        FontWeight="Medium" />
                    <AppBarSeparator Margin="5,0,5,0" />

                    <ToggleButton
                        x:Name="toggleButton_enumItems"
                        x:Uid="ToggleButton_EnumItems"
                        Height="32"
                        Content="&#xEA40;"
                        FontFamily="{ThemeResource SymbolThemeFontFamily}" />
                </StackPanel>
            </StackPanel>

            <Rectangle
                Grid.Row="1"
                Height="1"
                Margin="0,0,12,0"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Top"
                Fill="{ThemeResource CardStrokeColorDefaultBrush}" />
        </Grid>

        <StackPanel
            Grid.Row="2"
            Grid.Column="0"
            Margin="0"
            HorizontalAlignment="Left"
            VerticalAlignment="Bottom"
            Orientation="Horizontal"
            Spacing="8">

            <Button
                x:Name="button_settings"
                x:Uid="TxtBlock_ButtonSettings"
                Grid.Row="5"
                Grid.Column="1"
                Height="32"
                Padding="6"
                Background="Transparent"
                BorderBrush="Transparent"
                FontFamily="{ThemeResource SymbolThemeFontFamily}">
                <Button.Content>
                    <controls:AnimatedIcon x:Name="SearchAnimatedIcon">
                        <controls:AnimatedIcon.Source>
                            <animatedVisuals:AnimatedSettingsVisualSource />
                        </controls:AnimatedIcon.Source>
                        <controls:AnimatedIcon.FallbackIconSource>
                            <controls:SymbolIconSource Symbol="Setting" />
                        </controls:AnimatedIcon.FallbackIconSource>
                    </controls:AnimatedIcon>

                </Button.Content>
            </Button>

            <Button
                x:Name="button_docs"
                x:Uid="DocsButton"
                Grid.Row="1"
                Height="32"
                HorizontalAlignment="Left"
                VerticalAlignment="Bottom"
                Background="Transparent"
                BorderBrush="Transparent"
                Click="OpenDocs"
                Content="&#xE897;"
                FontFamily="{ThemeResource SymbolThemeFontFamily}" />

            <!--<Button Content="&#xE728;"
                        FontFamily="{ThemeResource SymbolThemeFontFamily}"
                        ToolTipService.ToolTip="Presets"
                        Background="Transparent"
                        BorderBrush="Transparent"
                        Grid.Row="1"
                        Height="36"
                        VerticalAlignment="Bottom"
                        HorizontalAlignment="Left">
                    <Button.Flyout>
                        <MenuFlyout>
                            <MenuFlyoutItem Text="Photo rule 1" />
                            <MenuFlyoutItem Text="Date time rule" />
                            <MenuFlyoutItem Text="And another rule" />
                        </MenuFlyout>
                    </Button.Flyout>
                </Button>-->
        </StackPanel>

        <SplitButton
            x:Name="button_rename"
            x:Uid="ButtonApply"
            Grid.Row="2"
            Grid.Column="0"
            Margin="0,0,12,1"
            HorizontalAlignment="Right"
            VerticalAlignment="Bottom"
            Click="button_rename_Click"
            Style="{StaticResource AccentSplitButtonStyle}">
            <SplitButton.KeyboardAccelerators>
                <KeyboardAccelerator Key="Enter" />
                <KeyboardAccelerator Key="Enter" Modifiers="Control" />
            </SplitButton.KeyboardAccelerators>
            <SplitButton.Content>
                <StackPanel Orientation="Horizontal">
                    <FontIcon
                        Margin="0,2,10,0"
                        VerticalAlignment="Center"
                        FontSize="14"
                        Glyph="&#xE8AC;" />
                    <TextBlock x:Uid="TxtBlock_ButtonApply" />
                </StackPanel>
            </SplitButton.Content>
            <SplitButton.Flyout>
                <MenuFlyout>
                    <MenuFlyoutItem x:Uid="TxtBlock_ButtonApplyAndClose" Click="MenuFlyoutItem_Click" />
                </MenuFlyout>
            </SplitButton.Flyout>
        </SplitButton>
    </Grid>
</Window>
