<?xml version="1.0" encoding="utf-8" ?>
<UserControl
    x:Class="BetterLyrics.WinUI3.Controls.MediaSettingsControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="using:CommunityToolkit.WinUI.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
    xmlns:local="using:BetterLyrics.WinUI3.Controls"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ui="using:CommunityToolkit.WinUI"
    mc:Ignorable="d">

    <Grid>
        <ScrollViewer Style="{StaticResource SettingsScrollViewerStyle}">
            <Grid Style="{StaticResource SettingsGridStyle}">
                <StackPanel>

                    <TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" />

                    <controls:SettingsCard x:Uid="SettingsPageMusicLib" HeaderIcon="{ui:FontIcon FontFamily={StaticResource IconFontFamily}, Glyph=&#xE8B7;}" />

                    <InfoBar
                        x:Uid="SettingsPageRemoveInfo"
                        BorderThickness="0"
                        CornerRadius="0"
                        IsClosable="False"
                        IsOpen="True"
                        Severity="Success">
                        <interactivity:Interaction.Behaviors>
                            <interactivity:DataTriggerBehavior
                                Binding="{x:Bind ViewModel.AppSettings.LocalMediaFolders.Count, Mode=OneWay}"
                                ComparisonCondition="Equal"
                                Value="0">
                                <interactivity:ChangePropertyAction PropertyName="Visibility" Value="Collapsed" />
                            </interactivity:DataTriggerBehavior>
                            <interactivity:DataTriggerBehavior
                                Binding="{x:Bind ViewModel.AppSettings.LocalMediaFolders.Count, Mode=OneWay}"
                                ComparisonCondition="NotEqual"
                                Value="0">
                                <interactivity:ChangePropertyAction PropertyName="Visibility" Value="Visible" />
                            </interactivity:DataTriggerBehavior>
                        </interactivity:Interaction.Behaviors>
                    </InfoBar>

                    <ListView
                        ItemContainerStyle="{StaticResource ListViewStretchedItemContainerStyle}"
                        ItemsSource="{x:Bind ViewModel.AppSettings.LocalMediaFolders, Mode=OneWay}"
                        SelectionMode="None">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <controls:SettingsExpander>
                                    <controls:SettingsExpander.Header>
                                        <HyperlinkButton
                                            Click="LocalFolderHyperlinkButton_Click"
                                            Content="{Binding Path, Mode=OneWay}"
                                            Tag="{Binding Path, Mode=OneWay}" />
                                    </controls:SettingsExpander.Header>
                                    <ToggleSwitch IsOn="{Binding IsEnabled, Mode=TwoWay}" />
                                    <controls:SettingsExpander.Items>
                                        <controls:SettingsCard>
                                            <controls:SettingsCard.Header>
                                                <HyperlinkButton
                                                    x:Uid="SettingsPageRemovePath"
                                                    Click="SettingsPageRemovePathButton_Click"
                                                    Tag="{Binding}" />
                                            </controls:SettingsCard.Header>
                                        </controls:SettingsCard>
                                        <controls:SettingsCard x:Uid="SettingsPageMusicLibRealTimeWatch">
                                            <ToggleSwitch IsOn="{Binding IsRealTimeWatchEnabled, Mode=TwoWay}" />
                                        </controls:SettingsCard>
                                    </controls:SettingsExpander.Items>
                                </controls:SettingsExpander>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>

                    <controls:SettingsCard x:Uid="SettingsPageAddFolder" Style="{StaticResource DefaultSettingsExpanderItemStyle}">
                        <Button
                            x:Uid="SettingsPageAddFolderButton"
                            Command="{x:Bind ViewModel.SelectAndAddFolderCommand}"
                            CommandParameter="{Binding ElementName=RootGrid}" />
                    </controls:SettingsCard>

                </StackPanel>
            </Grid>
        </ScrollViewer>
    </Grid>
</UserControl>
