<UserControl x:Class="SharepointToolbox.Views.Tabs.TemplatesView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:loc="clr-namespace:SharepointToolbox.Localization"
             xmlns:common="clr-namespace:SharepointToolbox.Views.Common">
    <DockPanel Margin="10">
        <!-- Left panel: Capture and Apply -->
        <ScrollViewer DockPanel.Dock="Left" Width="320" Margin="0,0,10,0"
                      VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
        <StackPanel>
            <!-- Capture Section -->
            <GroupBox Margin="0,0,0,10">
                <GroupBox.Header>
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                        <TextBlock Text="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[templates.capture]}" VerticalAlignment="Center" />
                        <common:InfoButton Margin="6,0,0,0"
                                           Title="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[help.templates.capture.title]}"
                                           Body="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[help.templates.capture.body]}" />
                    </StackPanel>
                </GroupBox.Header>
                <StackPanel Margin="5">
                    <TextBlock Text="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[templates.name]}"
                               Margin="0,0,0,3" />
                    <TextBox Text="{Binding TemplateName, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,0,10" />

                    <!-- Capture options checkboxes -->
                    <TextBlock Text="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[templates.options]}"
                               FontWeight="SemiBold" Margin="0,0,0,5" />
                    <CheckBox Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[templates.opt.libraries]}"
                              IsChecked="{Binding CaptureLibraries}" Margin="0,0,0,3" />
                    <CheckBox Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[templates.opt.folders]}"
                              IsChecked="{Binding CaptureFolders}" Margin="0,0,0,3" />
                    <CheckBox Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[templates.opt.permissions]}"
                              IsChecked="{Binding CapturePermissions}" Margin="0,0,0,3" />
                    <CheckBox Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[templates.opt.logo]}"
                              IsChecked="{Binding CaptureLogo}" Margin="0,0,0,3" />
                    <CheckBox Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[templates.opt.settings]}"
                              IsChecked="{Binding CaptureSettings}" Margin="0,0,0,10" />

                    <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[templates.capture]}"
                            Command="{Binding CaptureCommand}" />
                </StackPanel>
            </GroupBox>

            <!-- Apply Section -->
            <GroupBox Margin="0,0,0,10">
                <GroupBox.Header>
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                        <TextBlock Text="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[templates.apply]}" VerticalAlignment="Center" />
                        <common:InfoButton Margin="6,0,0,0"
                                           Title="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[help.templates.apply.title]}"
                                           Body="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[help.templates.apply.body]}" />
                    </StackPanel>
                </GroupBox.Header>
                <StackPanel Margin="5">
                    <TextBlock Text="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[templates.newtitle]}"
                               Margin="0,0,0,3" />
                    <TextBox Text="{Binding NewSiteTitle, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,0,5" />

                    <TextBlock Text="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[templates.newalias]}"
                               Margin="0,0,0,3" />
                    <TextBox Text="{Binding NewSiteAlias, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,0,10" />

                    <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[templates.apply]}"
                            Command="{Binding ApplyCommand}" />
                </StackPanel>
            </GroupBox>

            <!-- Progress -->
            <TextBlock Text="{Binding StatusMessage}" TextWrapping="Wrap" Margin="0,5,0,0" />
        </StackPanel>
        </ScrollViewer>

        <!-- Right panel: Template list -->
        <DockPanel>
            <StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Margin="0,0,0,5">
                <TextBlock Text="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[templates.list]}"
                           FontWeight="Bold" FontSize="14" VerticalAlignment="Center" Margin="0,0,10,0" />
                <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[templates.rename]}"
                        Command="{Binding RenameCommand}" Margin="0,0,5,0" Padding="10,3" />
                <Button Content="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[templates.delete]}"
                        Command="{Binding DeleteCommand}" Padding="10,3" />
            </StackPanel>

            <DataGrid ItemsSource="{Binding Templates}" SelectedItem="{Binding SelectedTemplate}"
                      AutoGenerateColumns="False" IsReadOnly="True"
                      SelectionMode="Single" CanUserSortColumns="True">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[report.col.name]}"
                                        Binding="{Binding Name}" Width="*" />
                    <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[bulksites.type]}"
                                        Binding="{Binding SiteType}" Width="100" />
                    <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[templates.col.source]}"
                                        Binding="{Binding SourceUrl}" Width="*" />
                    <DataGridTextColumn Header="{Binding Source={x:Static loc:TranslationSource.Instance}, Path=[templates.col.captured]}"
                                        Binding="{Binding CapturedAt, StringFormat=yyyy-MM-dd HH:mm}" Width="140" />
                </DataGrid.Columns>
            </DataGrid>
        </DockPanel>
    </DockPanel>
</UserControl>
