Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic
Imports Nexamas.UI.Architecture
Imports Nexamas.UI.Composition
Imports Nexamas.UI.General
Imports Nexamas.UI.Icons
Imports Nexamas.UI.Layout
Imports Nexamas.UI.Rendering
Imports Nexamas.UI.TextInput
Imports Nexamas.UI.TextRendering
Imports Nexamas.UI.Theming
Imports Nexamas.UI.Values
Imports SkiaSharp

Namespace Nexamas.UI.Controls

    Partial Public NotInheritable Class MASStatusBanner

#Region "Rendering / surface chrome"

        Private Sub DrawSemanticWash(canvas As SKCanvas,
                                     surface As StatusBannerSurfaceGeometry,
                                     toneColor As SKColor)
            If canvas Is Nothing Then Return
            If Not surface.HasValue Then Return
            If surface.Bounds.Width <= 2.0F OrElse surface.Bounds.Height <= 2.0F Then Return

            Dim save As Integer = canvas.Save()
            Try
                Using clip As SKPath = BuildOuterCardPath(surface.Bounds, surface.Radius)
                    canvas.ClipPath(clip, SKClipOperation.Intersect, True)
                End Using

                Using paint As New SKPaint With {
                    .IsAntialias = True,
                    .Style = SKPaintStyle.Fill,
                    .Color = toneColor.WithAlpha(StatusBannerTokens.WashAlpha)
                }
                    canvas.DrawRect(surface.Bounds, paint)
                End Using
            Finally
                canvas.RestoreToCount(save)
            End Try
        End Sub

        Private Sub DrawIntegratedAccentPanel(canvas As SKCanvas,
                                              surface As StatusBannerSurfaceGeometry,
                                              accentRect As SKRect,
                                              toneColor As SKColor,
                                              isRtl As Boolean)
            If canvas Is Nothing Then Return
            If Not surface.HasValue Then Return
            If accentRect.Width <= 0.5F OrElse accentRect.Height <= 0.5F Then Return

            Dim accentWidth As Single = Math.Min(accentRect.Width, surface.Bounds.Width)
            Dim accentFillRect As SKRect
            If isRtl Then
                accentFillRect = New SKRect(
                    Math.Max(surface.Bounds.Left, surface.Bounds.Right - accentWidth),
                    surface.Bounds.Top,
                    surface.Bounds.Right,
                    surface.Bounds.Bottom)
            Else
                accentFillRect = New SKRect(
                    surface.Bounds.Left,
                    surface.Bounds.Top,
                    Math.Min(surface.Bounds.Right, surface.Bounds.Left + accentWidth),
                    surface.Bounds.Bottom)
            End If

            accentFillRect = PixelSnap.SnapRect(accentFillRect, surface.Dpi)
            If accentFillRect.Width <= 0.5F OrElse accentFillRect.Height <= 0.5F Then Return

            Dim save As Integer = canvas.Save()
            Try
                Using clip As SKPath = BuildOuterCardPath(surface.Bounds, surface.Radius)
                    canvas.ClipPath(clip, SKClipOperation.Intersect, True)
                End Using

                Dim startPoint As SKPoint = If(isRtl,
                                               New SKPoint(accentFillRect.Right, accentFillRect.MidY),
                                               New SKPoint(accentFillRect.Left, accentFillRect.MidY))
                Dim endPoint As SKPoint = If(isRtl,
                                             New SKPoint(accentFillRect.Left, accentFillRect.MidY),
                                             New SKPoint(accentFillRect.Right, accentFillRect.MidY))

                Using shader As SKShader = SKShader.CreateLinearGradient(
                    startPoint,
                    endPoint,
                    New SKColor() {
                        ColorMath.Mix(toneColor, SKColors.White, 0.1F).WithAlpha(StatusBannerTokens.AccentPanelFillAlpha),
                        toneColor.WithAlpha(StatusBannerTokens.AccentPanelFillEndAlpha)
                    },
                    Nothing,
                    SKShaderTileMode.Clamp)

                    Using fill As New SKPaint With {
                        .IsAntialias = True,
                        .Style = SKPaintStyle.Fill,
                        .Shader = shader
                    }
                        canvas.DrawRect(accentFillRect, fill)
                    End Using
                End Using
            Finally
                canvas.RestoreToCount(save)
            End Try
        End Sub

#End Region


    End Class

End Namespace
