<UserControl x:Class="CalculatorApp.MemoryListItem"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:common="using:CalculatorApp.Common"
             xmlns:controls="using:CalculatorApp.Controls"
             xmlns:converters="using:CalculatorApp.Converters"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="using:CalculatorApp"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:model="using:CalculatorApp.ViewModel"
             xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
             x:Name="MemoryListItem"
             FlowDirection="LeftToRight"
             mc:Ignorable="d">
    <UserControl.Resources>
        <muxc:FontIconSource x:Key="MemClearGlyph"
                             FontFamily="{StaticResource CalculatorFontFamily}"
                             Glyph="&#xf754;"/>
        <muxc:FontIconSource x:Key="MemPlusGlyph"
                             FontFamily="{StaticResource CalculatorFontFamily}"
                             Glyph="&#xf757;"/>
        <muxc:FontIconSource x:Key="MemMinusGlyph"
                             FontFamily="{StaticResource CalculatorFontFamily}"
                             Glyph="&#xf758;"/>

        <muxc:SwipeItems x:Key="MemorySwipeItems" Mode="Reveal">
            <muxc:SwipeItem x:Uid="ClearMemorySwipeItem"
                            Background="{ThemeResource SystemControlBackgroundAccentBrush}"
                            IconSource="{StaticResource MemClearGlyph}"
                            Invoked="OnClearSwipeInvoked"/>
            <muxc:SwipeItem x:Uid="MemPlusSwipeItem"
                            Background="{ThemeResource SystemControlBackgroundAccentBrush}"
                            IconSource="{StaticResource MemPlusGlyph}"
                            Invoked="OnMemoryAddSwipeInvoked"/>
            <muxc:SwipeItem x:Uid="MemMinusSwipeItem"
                            Background="{ThemeResource SystemControlBackgroundAccentBrush}"
                            IconSource="{StaticResource MemMinusGlyph}"
                            Invoked="OnMemorySubtractSwipeInvoked"/>
        </muxc:SwipeItems>
    </UserControl.Resources>

    <muxc:SwipeControl RightItems="{StaticResource MemorySwipeItems}">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="HoverStates">
                <VisualState x:Name="MemoryButtonsVisible">
                    <VisualState.Setters>
                        <Setter Target="MemoryHoverButtons.Opacity" Value="1"/>
                    </VisualState.Setters>
                </VisualState>
                <VisualState x:Name="MemoryButtonsHidden"/>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Grid Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <TextBlock Margin="0,2,14,0"
                       HorizontalAlignment="Right"
                       Style="{ThemeResource TitleTextBlockStyle}"
                       FontWeight="SemiBold"
                       FlowDirection="LeftToRight"
                       IsTextSelectionEnabled="True"
                       Text="{x:Bind Model.Value, Mode=OneWay}"
                       TextAlignment="Right"
                       TextReadingOrder="DetectFromContent"
                       TextWrapping="Wrap"/>
            <Grid x:Name="MemoryHoverButtons"
                  Grid.Row="1"
                  Margin="0,0,10,2"
                  HorizontalAlignment="Right"
                  Opacity="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Button x:Uid="ClearMemoryItemButton"
                        Style="{StaticResource MemoryHoverButtonStyle}"
                        Background="{ThemeResource SystemControlBackgroundAltMediumHighBrush}"
                        AutomationProperties.AutomationId="MClearButton"
                        Click="OnClearButtonClicked"
                        Content="MC"/>
                <Button x:Uid="MemPlusItem"
                        Grid.Column="1"
                        Margin="0"
                        Style="{StaticResource MemoryHoverButtonStyle}"
                        Background="{ThemeResource SystemControlBackgroundAltMediumHighBrush}"
                        AutomationProperties.AutomationId="MAddButton"
                        Click="OnMemoryAddButtonClicked"
                        Content="M+"/>
                <Button x:Uid="MemMinusItem"
                        Grid.Column="2"
                        Style="{StaticResource MemoryHoverButtonStyle}"
                        Background="{ThemeResource SystemControlBackgroundAltMediumHighBrush}"
                        AutomationProperties.AutomationId="MSubButton"
                        Click="OnMemorySubtractButtonClicked"
                        Content="M-"/>
            </Grid>
        </Grid>
    </muxc:SwipeControl>
</UserControl>
