<!--  Copyright (c) Microsoft Corporation. All rights reserved.  -->
<!--  Licensed under the MIT License. See LICENSE in the project root for license information.  -->

<UserControl
    x:Class="Peek.FilePreviewer.Controls.AudioControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="using:Peek.FilePreviewer.Controls"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:tkconverters="using:CommunityToolkit.WinUI.Converters"
    mc:Ignorable="d">
    <UserControl.Resources>
        <tkconverters:StringVisibilityConverter x:Key="StringVisibilityConverter" />
    </UserControl.Resources>

    <Grid
        Margin="24"
        VerticalAlignment="Center"
        ColumnSpacing="24"
        RowSpacing="24">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <Border
            Grid.Row="0"
            Grid.Column="0"
            HorizontalAlignment="Right"
            BorderBrush="{ThemeResource SurfaceStrokeColorDefaultBrush}"
            BorderThickness="1"
            ToolTipService.ToolTip="{x:Bind ToolTipText, Mode=OneWay}">
            <Image Width="180" Source="{x:Bind Source.Thumbnail, Mode=OneWay}" />
        </Border>

        <StackPanel
            Grid.Row="0"
            Grid.Column="1"
            HorizontalAlignment="Left"
            VerticalAlignment="Center"
            Spacing="4">
            <TextBlock
                MaxLines="3"
                Style="{StaticResource TitleTextBlockStyle}"
                Text="{x:Bind Source.Title, Mode=OneWay}"
                TextTrimming="CharacterEllipsis"
                TextWrapping="Wrap">
                <ToolTipService.ToolTip>
                    <ToolTip Content="{x:Bind Source.Title, Mode=OneWay}" />
                </ToolTipService.ToolTip>
            </TextBlock>
            <TextBlock
                Text="{x:Bind Source.Artist, Mode=OneWay}"
                TextTrimming="CharacterEllipsis"
                Visibility="{x:Bind Source.Artist, Mode=OneWay, Converter={StaticResource StringVisibilityConverter}}">
                <ToolTipService.ToolTip>
                    <ToolTip Content="{x:Bind Source.Artist, Mode=OneWay}" />
                </ToolTipService.ToolTip>
            </TextBlock>
            <TextBlock
                Text="{x:Bind Source.Album, Mode=OneWay}"
                TextTrimming="CharacterEllipsis"
                Visibility="{x:Bind Source.Album, Mode=OneWay, Converter={StaticResource StringVisibilityConverter}}">
                <ToolTipService.ToolTip>
                    <ToolTip Content="{x:Bind Source.Album, Mode=OneWay}" />
                </ToolTipService.ToolTip>
            </TextBlock>
            <TextBlock Text="{x:Bind Source.Length, Mode=OneWay}" TextTrimming="CharacterEllipsis">
                <ToolTipService.ToolTip>
                    <ToolTip Content="{x:Bind Source.Length, Mode=OneWay}" />
                </ToolTipService.ToolTip>
            </TextBlock>
        </StackPanel>

        <MediaPlayerElement
            x:Name="PlayerElement"
            Grid.Row="1"
            Grid.ColumnSpan="2"
            AreTransportControlsEnabled="True"
            AutoPlay="True"
            Source="{x:Bind Source.MediaSource, Mode=OneWay}">
            <MediaPlayerElement.KeyboardAccelerators>
                <KeyboardAccelerator Key="Space" Invoked="KeyboardAccelerator_Space_Invoked" />
            </MediaPlayerElement.KeyboardAccelerators>
            <MediaPlayerElement.TransportControls>
                <MediaTransportControls
                    MaxWidth="800"
                    IsCompact="True"
                    IsZoomButtonVisible="False" />
            </MediaPlayerElement.TransportControls>
        </MediaPlayerElement>
    </Grid>
</UserControl>
