<UserControl
    x:Class="AmbientSounds.Controls.SoundGridControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:animations="using:Microsoft.Toolkit.Uwp.UI.Animations"
    xmlns:converters="using:AmbientSounds.Converters"
    xmlns:core="using:Microsoft.Xaml.Interactions.Core"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
    xmlns:local="using:AmbientSounds.Controls"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
    d:DesignHeight="300"
    d:DesignWidth="400"
    mc:Ignorable="d">
    <interactivity:Interaction.Behaviors>
        <core:EventTriggerBehavior EventName="Loaded">
            <core:InvokeCommandAction Command="{x:Bind ViewModel.LoadCommand}" />
        </core:EventTriggerBehavior>
    </interactivity:Interaction.Behaviors>

    <Grid>
        <ScrollViewer CanContentRenderOutsideBounds="False">
            <Grid HorizontalAlignment="Center">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                </Grid.RowDefinitions>
                <GridView
                    x:Uid="SoundsGridView"
                    MaxWidth="{x:Bind ItemGridMaxWidth, Mode=OneWay}"
                    Padding="20,0"
                    animations:ItemsReorderAnimation.Duration="0:0:0.3"
                    IsItemClickEnabled="True"
                    ItemClick="{x:Bind GridView_ItemClick}"
                    ItemContainerStyle="{StaticResource GridViewItemExpanded}"
                    ItemTemplate="{x:Bind ItemTemplate, Mode=OneWay}"
                    ItemsSource="{x:Bind ViewModel.Sounds}"
                    ScrollViewer.HorizontalScrollMode="Disabled"
                    ScrollViewer.VerticalScrollMode="Disabled"
                    SelectionMode="None">
                    <interactivity:Interaction.Behaviors>
                        <core:ItemClickBehavior Command="{x:Bind ViewModel.PlaySoundCommand}" />
                    </interactivity:Interaction.Behaviors>
                    <GridView.ItemContainerTransitions>
                        <TransitionCollection>
                            <EntranceThemeTransition IsStaggeringEnabled="True" />
                        </TransitionCollection>
                    </GridView.ItemContainerTransitions>
                </GridView>

                <local:ViewCatalogueButton
                    x:Name="CatalogueButton"
                    Grid.Row="1"
                    Margin="0,12,24,20"
                    HorizontalAlignment="Right"
                    x:Load="{x:Bind ShowCatalogueButton, Mode=OneWay}"
                    Visibility="{x:Bind converters:VisibilityConverter.InvertBool(ViewModel.LoadCommand.IsRunning), Mode=OneWay}" />
            </Grid>
        </ScrollViewer>

        <muxc:ProgressRing
            x:Uid="SoundsLoadingRing"
            Width="40"
            Height="40"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Foreground="{ThemeResource DefaultTextForegroundThemeBrush}"
            IsActive="{x:Bind ViewModel.LoadCommand.IsRunning, Mode=OneWay}"
            Visibility="{x:Bind ViewModel.LoadCommand.IsRunning, Mode=OneWay}" />
    </Grid>
</UserControl>
