Option Strict On
Option Explicit On

Imports System
Imports Nexamas.UI.Architecture
Imports Nexamas.UI.Composition
Imports Nexamas.UI.Controls
Imports Nexamas.UI.General
Imports Nexamas.UI.Layout
Imports Nexamas.UI.Rendering
Imports Nexamas.UI.TextRendering
Imports Nexamas.UI.Theming
Imports Nexamas.UI.Values
Imports SkiaSharp

Namespace Nexamas.UI.Components

    ''' <summary>
    ''' Official Nexamas UI premium responsive app-layout visual surface. It owns
    ''' app chrome slot presentation, responsive breakpoint geometry, RTL-aware layout,
    ''' and readiness evidence. Routing, PageHost ownership, child-content hosting,
    ''' persistence, native shell composition, wrappers, adapters, bridges, and
    ''' mouse-click outer focus rings remain outside this control.
    ''' </summary>
    Partial Public NotInheritable Class MASAppLayout
        Inherits MASControlBase
        Implements IMASLayoutParticipant
        Implements IMASIntrinsicSizeContract

#Region "Fields"
        Private ReadOnly _primitives As New MASVisualPrimitivesPainter()
        Private _title As String = AppLayoutTokens.DefaultTitle
        Private _navigationTitle As String = AppLayoutTokens.DefaultNavigationTitle
        Private _navigationText As String = AppLayoutTokens.DefaultNavigationText
        Private _contentTitle As String = AppLayoutTokens.DefaultContentTitle
        Private _contentText As String = AppLayoutTokens.DefaultContentText
        Private _detailTitle As String = AppLayoutTokens.DefaultDetailTitle
        Private _detailText As String = AppLayoutTokens.DefaultDetailText
        Private _statusText As String = AppLayoutTokens.DefaultStatusText
        Private _showNavigation As Boolean = True
        Private _showDetails As Boolean = True
        Private _showStatusBar As Boolean = True
        Private _lastMode As String = "Wide"

#End Region

#Region "Constructor / Factory"

        Public Sub New()
            MyBase.New()
        End Sub

        Public Shared Function Create(Optional title As String = Nothing) As MASAppLayout
            Dim control As New MASAppLayout()
            control._title = MASAppLayoutPolicy.NormalizeTitle(title)
            Return control
        End Function

#End Region

#Region "Public API"

        Public Property Title As String
            Get
                Return _title
            End Get
            Set(value As String)
                Dim normalized As String = MASAppLayoutPolicy.NormalizeTitle(value)
                If String.Equals(_title, normalized, StringComparison.Ordinal) Then Return
                _title = normalized
                RequestSizeLayoutRefreshForSizeAffectingChange("MASAppLayout.Title")
                InvalidateVisual()
            End Set
        End Property

        Public Property NavigationTitle As String
            Get
                Return _navigationTitle
            End Get
            Set(value As String)
                Dim normalized As String = MASAppLayoutPolicy.NormalizeSectionTitle(value, AppLayoutTokens.DefaultNavigationTitle)
                If String.Equals(_navigationTitle, normalized, StringComparison.Ordinal) Then Return
                _navigationTitle = normalized
                InvalidateVisual()
            End Set
        End Property

        Public Property NavigationText As String
            Get
                Return _navigationText
            End Get
            Set(value As String)
                Dim normalized As String = MASAppLayoutPolicy.NormalizeSectionText(value, AppLayoutTokens.DefaultNavigationText)
                If String.Equals(_navigationText, normalized, StringComparison.Ordinal) Then Return
                _navigationText = normalized
                InvalidateVisual()
            End Set
        End Property

        Public Property ContentTitle As String
            Get
                Return _contentTitle
            End Get
            Set(value As String)
                Dim normalized As String = MASAppLayoutPolicy.NormalizeSectionTitle(value, AppLayoutTokens.DefaultContentTitle)
                If String.Equals(_contentTitle, normalized, StringComparison.Ordinal) Then Return
                _contentTitle = normalized
                InvalidateVisual()
            End Set
        End Property

        Public Property ContentText As String
            Get
                Return _contentText
            End Get
            Set(value As String)
                Dim normalized As String = MASAppLayoutPolicy.NormalizeSectionText(value, AppLayoutTokens.DefaultContentText)
                If String.Equals(_contentText, normalized, StringComparison.Ordinal) Then Return
                _contentText = normalized
                InvalidateVisual()
            End Set
        End Property

        Public Property DetailTitle As String
            Get
                Return _detailTitle
            End Get
            Set(value As String)
                Dim normalized As String = MASAppLayoutPolicy.NormalizeSectionTitle(value, AppLayoutTokens.DefaultDetailTitle)
                If String.Equals(_detailTitle, normalized, StringComparison.Ordinal) Then Return
                _detailTitle = normalized
                InvalidateVisual()
            End Set
        End Property

        Public Property DetailText As String
            Get
                Return _detailText
            End Get
            Set(value As String)
                Dim normalized As String = MASAppLayoutPolicy.NormalizeSectionText(value, AppLayoutTokens.DefaultDetailText)
                If String.Equals(_detailText, normalized, StringComparison.Ordinal) Then Return
                _detailText = normalized
                InvalidateVisual()
            End Set
        End Property

        Public Property StatusText As String
            Get
                Return _statusText
            End Get
            Set(value As String)
                Dim normalized As String = MASAppLayoutPolicy.NormalizeStatusText(value)
                If String.Equals(_statusText, normalized, StringComparison.Ordinal) Then Return
                _statusText = normalized
                InvalidateVisual()
            End Set
        End Property

        Public Property ShowNavigation As Boolean
            Get
                Return _showNavigation
            End Get
            Set(value As Boolean)
                If _showNavigation = value Then Return
                _showNavigation = value
                RequestSizeLayoutRefreshForSizeAffectingChange("MASAppLayout.ShowNavigation")
                InvalidateVisual()
            End Set
        End Property

        Public Property ShowDetails As Boolean
            Get
                Return _showDetails
            End Get
            Set(value As Boolean)
                If _showDetails = value Then Return
                _showDetails = value
                RequestSizeLayoutRefreshForSizeAffectingChange("MASAppLayout.ShowDetails")
                InvalidateVisual()
            End Set
        End Property

        Public Property ShowStatusBar As Boolean
            Get
                Return _showStatusBar
            End Get
            Set(value As Boolean)
                If _showStatusBar = value Then Return
                _showStatusBar = value
                RequestSizeLayoutRefreshForSizeAffectingChange("MASAppLayout.ShowStatusBar")
                InvalidateVisual()
            End Set
        End Property

        Public ReadOnly Property LayoutModeText As String
            Get
                Return _lastMode
            End Get
        End Property

        Public ReadOnly Property SummaryText As String
            Get
                Return MASAppLayoutPolicy.BuildSummary(AppLayoutTokens.PreferredWidthDip, _showNavigation, _showDetails, _showStatusBar)
            End Get
        End Property

        Public Function SetNavigation(title As String, text As String) As MASAppLayout
            NavigationTitle = title
            NavigationText = text
            Return Me
        End Function

        Public Function SetContent(title As String, text As String) As MASAppLayout
            ContentTitle = title
            ContentText = text
            Return Me
        End Function

        Public Function SetDetails(title As String, text As String) As MASAppLayout
            DetailTitle = title
            DetailText = text
            Return Me
        End Function

        Public Function WithTitle(value As String) As MASAppLayout
            Title = value
            Return Me
        End Function

        Public Shadows Function WithSize(sizeIntent As MASSize) As MASAppLayout
            MyBase.SetSize(sizeIntent)
            Return Me
        End Function

#End Region

#Region "Layout"

        Friend Function GetPreferredLayoutSize(context As MASLayoutMeasureContext) As SKSize Implements IMASLayoutParticipant.GetPreferredLayoutSize
            Return MeasureIntrinsicSize(CreateSizeContext(context), SizeIntent).DesiredSize
        End Function

        Friend Function GetMinLayoutSize(context As MASLayoutMeasureContext) As SKSize Implements IMASLayoutParticipant.GetMinLayoutSize
            Return MeasureIntrinsicSize(CreateSizeContext(context), SizeIntent).MinSize
        End Function

        Private Shared Function CreateSizeContext(context As MASLayoutMeasureContext) As MASSizeContext
            If context Is Nothing Then Return MASIntrinsicControlSizeMetrics.EnsureContext(Nothing)
            Return context.ToSizeContext()
        End Function

        Friend Function MeasureIntrinsicSize(context As MASSizeContext, intent As MASSize) As MASSizeResult Implements IMASIntrinsicSizeContract.MeasureIntrinsicSize
            Dim safeContext As MASSizeContext = MASIntrinsicControlSizeMetrics.EnsureContext(context)
            Return MASSizeResolver.FromMeasured(
                desiredSize:=New SKSize(AppLayoutTokens.PreferredWidthDip, AppLayoutTokens.PreferredHeightDip),
                minSize:=New SKSize(AppLayoutTokens.MinWidthDip, AppLayoutTokens.MinHeightDip),
                maxSize:=New SKSize(AppLayoutTokens.MaxWidthDip, Single.PositiveInfinity),
                intent:=intent,
                context:=safeContext,
                canGrowWidth:=True,
                canGrowHeight:=True,
                contentInset:=New MASLayoutInset(AppLayoutTokens.PaddingDip, AppLayoutTokens.PaddingDip, AppLayoutTokens.PaddingDip, AppLayoutTokens.PaddingDip),
                visualOverflowInset:=MASLayoutInset.Empty,
                hitOverflowInset:=MASLayoutInset.Empty,
                isFallback:=False)
        End Function

#End Region

#Region "Rendering"

        Protected Overrides Sub Render(canvas As SKCanvas, ctx As MASThemeContext, pixelBounds As SKRect)
            If canvas Is Nothing OrElse ctx Is Nothing Then Return
            If pixelBounds.Width <= 1.0F OrElse pixelBounds.Height <= 1.0F Then Return
            Dim pixelDpi As Single = PixelSnap.SafeDpi(ctx.Dpi)
            Dim bounds As SKRect = PixelSnap.SnapRect(pixelBounds, pixelDpi)
            Dim plan As MASAppLayoutLayoutPlan = MASAppLayoutLayoutPlan.Create(ctx, bounds, SizeIntent, _showNavigation, _showDetails, _showStatusBar)
            Dim dpi As Single = plan.MetricDpi
            _primitives.DrawCardSurface(canvas, ctx, bounds, pixelDpi, Me.ArchitectureContract, MASCardVisualStyle.Secondary)
            Dim content As SKRect = PixelSnap.SnapRect(Inset(bounds, plan.PaddingPx), pixelDpi)
            If content.Width <= 1.0F OrElse content.Height <= 1.0F Then Return
            Dim isRtl As Boolean = MASAppLayoutPolicy.ResolveRightToLeft()
            Dim accent As SKColor = MASAppLayoutPolicy.ResolveAccentColor(ctx)
            _lastMode = plan.ModeText
            DrawHeader(canvas, ctx, content, dpi, accent, isRtl)
            DrawBody(canvas, ctx, content, dpi, accent, isRtl, _lastMode, plan)
        End Sub

        Private Sub DrawHeader(canvas As SKCanvas, ctx As MASThemeContext, content As SKRect, dpi As Single, accent As SKColor, isRtl As Boolean)
            Dim headerRect As New SKRect(content.Left, content.Top, content.Right, content.Top + AppLayoutTokens.HeaderHeightDip * dpi)
            Using fill As New SKPaint With {.IsAntialias = True, .Style = SKPaintStyle.Fill, .Color = accent.WithAlpha(AppLayoutTokens.HeaderFillAlpha)}
                canvas.DrawRoundRect(headerRect, AppLayoutTokens.SectionRadiusDip * dpi, AppLayoutTokens.SectionRadiusDip * dpi, fill)
            End Using
            Using stroke As New SKPaint With {.IsAntialias = True, .Style = SKPaintStyle.Stroke, .StrokeWidth = Math.Max(1.0F, dpi), .Color = accent.WithAlpha(AppLayoutTokens.SectionStrokeAlpha)}
                canvas.DrawRoundRect(headerRect, AppLayoutTokens.SectionRadiusDip * dpi, AppLayoutTokens.SectionRadiusDip * dpi, stroke)
            End Using

            Dim chipWidth As Single = Math.Min(AppLayoutTokens.ModeChipWidthDip * dpi, headerRect.Width * 0.32F)
            Dim chipHeight As Single = 24.0F * dpi
            Dim chip As SKRect = If(isRtl,
                                    New SKRect(headerRect.Left + 12.0F * dpi, headerRect.MidY - chipHeight / 2.0F, headerRect.Left + 12.0F * dpi + chipWidth, headerRect.MidY + chipHeight / 2.0F),
                                    New SKRect(headerRect.Right - 12.0F * dpi - chipWidth, headerRect.MidY - chipHeight / 2.0F, headerRect.Right - 12.0F * dpi, headerRect.MidY + chipHeight / 2.0F))
            Using chipFill As New SKPaint With {.IsAntialias = True, .Style = SKPaintStyle.Fill, .Color = accent.WithAlpha(AppLayoutTokens.StatusFillAlpha)}
                canvas.DrawRoundRect(chip, 999.0F, 999.0F, chipFill)
            End Using
            TypographyTextPrimitives.DrawSingleLineText(canvas, ctx, _lastMode, chip, dpi, MASTypography.MASTextStyle.Micro, MASAppLayoutPolicy.ResolveMutedTextColor(ctx), TypographyTextPrimitives.TextAlign.Center, False)

            Dim titleRect As SKRect = If(isRtl,
                                         New SKRect(chip.Right + 12.0F * dpi, headerRect.Top, headerRect.Right - 16.0F * dpi, headerRect.Bottom),
                                         New SKRect(headerRect.Left + 16.0F * dpi, headerRect.Top, chip.Left - 12.0F * dpi, headerRect.Bottom))
            TypographyTextPrimitives.DrawSingleLineText(canvas, ctx, _title, titleRect, dpi, MASTypography.MASTextStyle.Title, MASAppLayoutPolicy.ResolvePrimaryTextColor(ctx), If(isRtl, TypographyTextPrimitives.TextAlign.Right, TypographyTextPrimitives.TextAlign.Left), False)
            PlaceAppLayoutHostedContent("header", Inset(headerRect, AppLayoutTokens.SectionPaddingDip * dpi), dpi, True)
        End Sub

        Private Sub DrawBody(canvas As SKCanvas, ctx As MASThemeContext, content As SKRect, dpi As Single, accent As SKColor, isRtl As Boolean, mode As String, plan As MASAppLayoutLayoutPlan)
            Dim gap As Single = AppLayoutTokens.GapDip * dpi
            Dim top As Single = content.Top + AppLayoutTokens.HeaderHeightDip * dpi + gap
            Dim bottom As Single = content.Bottom
            If plan.ShowStatusBar Then bottom -= AppLayoutTokens.StatusHeightDip * dpi
            Dim body As New SKRect(content.Left, top, content.Right, bottom - If(plan.ShowStatusBar, gap, 0.0F))
            If mode = "Compact" Then
                DrawCompact(canvas, ctx, body, dpi, accent, isRtl, plan)
            ElseIf mode = "Balanced" Then
                DrawBalanced(canvas, ctx, body, dpi, accent, isRtl, plan)
            Else
                DrawWide(canvas, ctx, body, dpi, accent, isRtl, plan)
            End If
            If plan.ShowStatusBar Then
                DrawStatusBar(canvas, ctx, New SKRect(content.Left, content.Bottom - AppLayoutTokens.StatusHeightDip * dpi, content.Right, content.Bottom), dpi, accent, isRtl)
            End If
        End Sub

        Private Sub DrawCompact(canvas As SKCanvas, ctx As MASThemeContext, body As SKRect, dpi As Single, accent As SKColor, isRtl As Boolean, plan As MASAppLayoutLayoutPlan)
            Dim top As Single = body.Top
            If plan.ShowNavigation Then
                Dim navRect As New SKRect(body.Left, top, body.Right, top + AppLayoutTokens.CompactRailHeightDip * dpi)
                DrawSection(canvas, ctx, navRect, _navigationTitle, _navigationText, dpi, accent, isRtl, False, "navigation", MASHostedContentSlotKind.AppLayoutNavigation)
                top = navRect.Bottom + AppLayoutTokens.GapDip * dpi
            End If
            DrawSection(canvas, ctx, New SKRect(body.Left, top, body.Right, body.Bottom), _contentTitle, _contentText, dpi, accent, isRtl, False, "content", MASHostedContentSlotKind.AppLayoutContent)
        End Sub

        Private Sub DrawBalanced(canvas As SKCanvas, ctx As MASThemeContext, body As SKRect, dpi As Single, accent As SKColor, isRtl As Boolean, plan As MASAppLayoutLayoutPlan)
            If Not plan.ShowNavigation Then
                DrawSection(canvas, ctx, body, _contentTitle, _contentText, dpi, accent, isRtl, False, "content", MASHostedContentSlotKind.AppLayoutContent)
                Return
            End If
            Dim gap As Single = AppLayoutTokens.GapDip * dpi
            Dim railWidth As Single = Math.Min(AppLayoutTokens.RailWidthDip * dpi, body.Width * 0.36F)
            Dim navRect As SKRect = If(isRtl, New SKRect(body.Right - railWidth, body.Top, body.Right, body.Bottom), New SKRect(body.Left, body.Top, body.Left + railWidth, body.Bottom))
            Dim contentRect As SKRect = If(isRtl, New SKRect(body.Left, body.Top, navRect.Left - gap, body.Bottom), New SKRect(navRect.Right + gap, body.Top, body.Right, body.Bottom))
            DrawSection(canvas, ctx, navRect, _navigationTitle, _navigationText, dpi, accent, isRtl, False, "navigation", MASHostedContentSlotKind.AppLayoutNavigation)
            DrawSection(canvas, ctx, contentRect, _contentTitle, _contentText, dpi, accent, isRtl, False, "content", MASHostedContentSlotKind.AppLayoutContent)
        End Sub

        Private Sub DrawWide(canvas As SKCanvas, ctx As MASThemeContext, body As SKRect, dpi As Single, accent As SKColor, isRtl As Boolean, plan As MASAppLayoutLayoutPlan)
            Dim gap As Single = AppLayoutTokens.GapDip * dpi
            Dim navWidth As Single = If(plan.ShowNavigation, Math.Min(AppLayoutTokens.RailWidthDip * dpi, body.Width * 0.24F), 0.0F)
            Dim detailWidth As Single = If(plan.ShowDetails, Math.Min(AppLayoutTokens.DetailWidthDip * dpi, body.Width * 0.30F), 0.0F)
            Dim contentLeft As Single = body.Left
            Dim contentRight As Single = body.Right
            Dim navRect As SKRect = SKRect.Empty
            Dim detailRect As SKRect = SKRect.Empty
            If plan.ShowNavigation Then
                navRect = If(isRtl, New SKRect(body.Right - navWidth, body.Top, body.Right, body.Bottom), New SKRect(body.Left, body.Top, body.Left + navWidth, body.Bottom))
                If isRtl Then contentRight = navRect.Left - gap Else contentLeft = navRect.Right + gap
            End If
            If plan.ShowDetails Then
                detailRect = If(isRtl, New SKRect(body.Left, body.Top, body.Left + detailWidth, body.Bottom), New SKRect(body.Right - detailWidth, body.Top, body.Right, body.Bottom))
                If isRtl Then contentLeft = detailRect.Right + gap Else contentRight = detailRect.Left - gap
            End If
            If plan.ShowNavigation Then DrawSection(canvas, ctx, navRect, _navigationTitle, _navigationText, dpi, accent, isRtl, False, "navigation", MASHostedContentSlotKind.AppLayoutNavigation)
            DrawSection(canvas, ctx, New SKRect(contentLeft, body.Top, contentRight, body.Bottom), _contentTitle, _contentText, dpi, accent, isRtl, False, "content", MASHostedContentSlotKind.AppLayoutContent)
            If plan.ShowDetails Then DrawSection(canvas, ctx, detailRect, _detailTitle, _detailText, dpi, accent, isRtl, False, "details", MASHostedContentSlotKind.AppLayoutDetails)
        End Sub

        Private Sub DrawSection(canvas As SKCanvas, ctx As MASThemeContext, rect As SKRect, title As String, text As String, dpi As Single, accent As SKColor, isRtl As Boolean, isStatus As Boolean, slotKey As String, slotKind As MASHostedContentSlotKind)
            If rect.Width <= 1.0F OrElse rect.Height <= 1.0F Then Return
            Dim snapped As SKRect = PixelSnap.SnapRect(rect, dpi)
            Using fill As New SKPaint With {.IsAntialias = True, .Style = SKPaintStyle.Fill, .Color = accent.WithAlpha(If(isStatus, AppLayoutTokens.StatusFillAlpha, AppLayoutTokens.SectionFillAlpha))}
                canvas.DrawRoundRect(snapped, AppLayoutTokens.SectionRadiusDip * dpi, AppLayoutTokens.SectionRadiusDip * dpi, fill)
            End Using
            Using stroke As New SKPaint With {.IsAntialias = True, .Style = SKPaintStyle.Stroke, .StrokeWidth = Math.Max(1.0F, dpi), .Color = accent.WithAlpha(AppLayoutTokens.SectionStrokeAlpha)}
                canvas.DrawRoundRect(snapped, AppLayoutTokens.SectionRadiusDip * dpi, AppLayoutTokens.SectionRadiusDip * dpi, stroke)
            End Using
            Dim inner As SKRect = Inset(snapped, AppLayoutTokens.SectionPaddingDip * dpi)
            TypographyTextPrimitives.DrawSingleLineText(canvas, ctx, title, New SKRect(inner.Left, inner.Top, inner.Right, inner.Top + 26.0F * dpi), dpi, If(isStatus, MASTypography.MASTextStyle.Micro, MASTypography.MASTextStyle.Body), MASAppLayoutPolicy.ResolvePrimaryTextColor(ctx), If(isRtl, TypographyTextPrimitives.TextAlign.Right, TypographyTextPrimitives.TextAlign.Left), False)
            TypographyTextPrimitives.DrawSingleLineText(canvas, ctx, text, New SKRect(inner.Left, inner.Top + 30.0F * dpi, inner.Right, inner.Bottom), dpi, MASTypography.MASTextStyle.Micro, MASAppLayoutPolicy.ResolveMutedTextColor(ctx).WithAlpha(If(isStatus, AppLayoutTokens.BoundaryTextAlpha, AppLayoutTokens.MutedTextAlpha)), If(isRtl, TypographyTextPrimitives.TextAlign.Right, TypographyTextPrimitives.TextAlign.Left), False)
            If Not isStatus Then DrawSlotHints(canvas, snapped, dpi, accent)
            PlaceAppLayoutHostedContent(slotKey, Inset(snapped, AppLayoutTokens.SectionPaddingDip * dpi), dpi, True)
        End Sub

        Private Sub DrawStatusBar(canvas As SKCanvas, ctx As MASThemeContext, rect As SKRect, dpi As Single, accent As SKColor, isRtl As Boolean)
            If rect.Width <= 1.0F OrElse rect.Height <= 1.0F Then Return
            Dim snapped As SKRect = PixelSnap.SnapRect(rect, dpi)
            Using fill As New SKPaint With {.IsAntialias = True, .Style = SKPaintStyle.Fill, .Color = accent.WithAlpha(AppLayoutTokens.StatusFillAlpha)}
                canvas.DrawRoundRect(snapped, AppLayoutTokens.StatusRadiusDip * dpi, AppLayoutTokens.StatusRadiusDip * dpi, fill)
            End Using
            Using stroke As New SKPaint With {.IsAntialias = True, .Style = SKPaintStyle.Stroke, .StrokeWidth = Math.Max(1.0F, dpi), .Color = accent.WithAlpha(AppLayoutTokens.StatusStrokeAlpha)}
                canvas.DrawRoundRect(snapped, AppLayoutTokens.StatusRadiusDip * dpi, AppLayoutTokens.StatusRadiusDip * dpi, stroke)
            End Using
            Dim inner As SKRect = InsetHorizontal(snapped, 12.0F * dpi)
            Dim primaryWidth As Single = Math.Min(inner.Width * 0.42F, 300.0F * dpi)
            Dim statusRect As SKRect = If(isRtl,
                                          New SKRect(inner.Right - primaryWidth, inner.Top, inner.Right, inner.Bottom),
                                          New SKRect(inner.Left, inner.Top, inner.Left + primaryWidth, inner.Bottom))
            Dim boundaryRect As SKRect = If(isRtl,
                                            New SKRect(inner.Left, inner.Top, statusRect.Left - 12.0F * dpi, inner.Bottom),
                                            New SKRect(statusRect.Right + 12.0F * dpi, inner.Top, inner.Right, inner.Bottom))
            TypographyTextPrimitives.DrawSingleLineText(canvas, ctx, _statusText, statusRect, dpi, MASTypography.MASTextStyle.Micro, MASAppLayoutPolicy.ResolvePrimaryTextColor(ctx), If(isRtl, TypographyTextPrimitives.TextAlign.Right, TypographyTextPrimitives.TextAlign.Left), False)
            TypographyTextPrimitives.DrawSingleLineText(canvas, ctx, AppLayoutTokens.BoundaryText, boundaryRect, dpi, MASTypography.MASTextStyle.Micro, MASAppLayoutPolicy.ResolveMutedTextColor(ctx).WithAlpha(AppLayoutTokens.BoundaryTextAlpha), If(isRtl, TypographyTextPrimitives.TextAlign.Left, TypographyTextPrimitives.TextAlign.Right), False)
            PlaceAppLayoutHostedContent("status", inner, dpi, True)
        End Sub

        Private Sub DrawSlotHints(canvas As SKCanvas, rect As SKRect, dpi As Single, accent As SKColor)
            If rect.Width < 120.0F * dpi OrElse rect.Height < 96.0F * dpi Then Return
            Dim left As Single = rect.Left + AppLayoutTokens.SectionPaddingDip * dpi
            Dim right As Single = rect.Right - AppLayoutTokens.SectionPaddingDip * dpi
            Dim y As Single = rect.Bottom - 42.0F * dpi
            If y <= rect.Top + 64.0F * dpi Then Return
            Dim first As New SKRect(left, y, left + Math.Min((right - left) * 0.54F, 190.0F * dpi), y + AppLayoutTokens.SlotHintHeightDip * dpi)
            Dim second As New SKRect(left, first.Bottom + 8.0F * dpi, left + Math.Min((right - left) * 0.38F, 140.0F * dpi), first.Bottom + 8.0F * dpi + AppLayoutTokens.SlotHintHeightDip * dpi)
            Using fill As New SKPaint With {.IsAntialias = True, .Style = SKPaintStyle.Fill, .Color = accent.WithAlpha(AppLayoutTokens.SlotHintStrongAlpha)}
                canvas.DrawRoundRect(first, 999.0F, 999.0F, fill)
            End Using
            Using fill As New SKPaint With {.IsAntialias = True, .Style = SKPaintStyle.Fill, .Color = accent.WithAlpha(AppLayoutTokens.SlotHintAlpha)}
                canvas.DrawRoundRect(second, 999.0F, 999.0F, fill)
            End Using
        End Sub

#End Region

#Region "Helpers"

        Private Shared Function Inset(rect As SKRect, amount As Single) As SKRect
            Return New SKRect(rect.Left + amount, rect.Top + amount, rect.Right - amount, rect.Bottom - amount)
        End Function

        Private Shared Function InsetHorizontal(rect As SKRect, amount As Single) As SKRect
            Return New SKRect(rect.Left + amount, rect.Top, rect.Right - amount, rect.Bottom)
        End Function

        Protected Overrides Function WantsPointerFocus() As Boolean
            Return False
        End Function

        Friend Function CreateAppLayoutReadinessManifest() As MASAppLayoutReadinessManifest
            Return MASAppLayoutReadinessManifest.CreateDefault()
        End Function

#End Region

    End Class

End Namespace
