<?xml version="1.0" encoding="utf-8" ?>
<local:VideoPartsSectionBase
    x:Class="BiliCopilot.UI.Controls.Player.VideoPartsSection"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:base="using:Richasy.WinUIKernel.Share.Base"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:ext="using:BiliCopilot.UI.Extensions"
    xmlns:local="using:BiliCopilot.UI.Controls.Player"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:media="using:Richasy.BiliKernel.Models.Media"
    mc:Ignorable="d">

    <UserControl.Resources>
        <DataTemplate x:Name="DefaultTemplate" x:DataType="media:VideoPart">
            <ItemContainer Style="{StaticResource AppItemContainerStyle}">
                <Grid
                    MinHeight="40"
                    Padding="12,8"
                    Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
                    ColumnSpacing="8">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <base:TrimTextBlock
                        VerticalAlignment="Center"
                        MaxLines="1"
                        Text="{x:Bind Identifier.Title}" />
                    <TextBlock
                        Grid.Column="1"
                        VerticalAlignment="Center"
                        Foreground="{ThemeResource TextFillColorTertiaryBrush}"
                        Style="{StaticResource CaptionTextBlockStyle}"
                        Text="{x:Bind Duration, Converter={StaticResource DurationConverter}}" />
                </Grid>
            </ItemContainer>
        </DataTemplate>
        <DataTemplate x:Name="IndexTemplate" x:DataType="media:VideoPart">
            <ItemContainer Style="{StaticResource AppItemContainerStyle}" ToolTipService.ToolTip="{x:Bind Identifier.Title}">
                <Grid Background="{ThemeResource CardBackgroundFillColorDefaultBrush}">
                    <TextBlock
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"
                        FontSize="14"
                        FontWeight="Bold"
                        Text="{x:Bind Index}" />
                </Grid>
            </ItemContainer>
        </DataTemplate>
        <StackLayout x:Name="DefaultLayout" Spacing="8" />
        <UniformGridLayout
            x:Name="IndexLayout"
            ItemsStretch="Fill"
            MinColumnSpacing="8"
            MinItemHeight="40"
            MinItemWidth="36"
            MinRowSpacing="8" />
    </UserControl.Resources>

    <Grid RowSpacing="8">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <ToggleSwitch
            Margin="12,8,12,0"
            IsOn="{x:Bind ViewModel.OnlyIndex, Mode=TwoWay}"
            OffContent="{ext:Locale Name=OnlyIndex}"
            OnContent="{ext:Locale Name=OnlyIndex}"
            Toggled="OnIndexToggledAsync" />

        <ItemsView
            x:Name="View"
            Grid.Row="1"
            Padding="12,0,12,12"
            ItemTemplate="{StaticResource DefaultTemplate}"
            ItemsSource="{x:Bind ViewModel.Parts, Mode=OneWay}"
            SelectionChanged="OnPartSelectionChanged"
            SelectionMode="Single" />
    </Grid>
</local:VideoPartsSectionBase>
