Option Strict On
Option Explicit On

Imports System
Imports Nexamas.UI.General
Imports Nexamas.UI.Values
Imports SkiaSharp

Namespace Nexamas.UI.Rendering

    Partial Friend NotInheritable Class MASShadowPainter

        ''' <summary>
        ''' Draws a direct blurred rounded-rect shadow for chrome/effect layers that do not need cached geometry.
        ''' This keeps blur ownership in ShadowSystem instead of component chrome or material painters.
        ''' </summary>
        Friend Shared Sub DrawImmediateBlurredRoundRectShadow(canvas As SKCanvas,
                                                             rectPx As SKRect,
                                                             radiusPx As Single,
                                                             sigmaPx As Single,
                                                             color As SKColor)

            If canvas Is Nothing Then Return
            If rectPx.Width <= 1.0F OrElse rectPx.Height <= 1.0F Then Return
            If color.Alpha = 0 Then Return

            radiusPx = PixelSnap.SafeRadius(radiusPx)
            sigmaPx = Math.Max(0.01F, sigmaPx)

            Using blur As SKImageFilter = SKImageFilter.CreateBlur(sigmaPx, sigmaPx)
                Using p As New SKPaint With {
                    .IsAntialias = True,
                    .IsDither = True,
                    .Style = SKPaintStyle.Fill,
                    .Color = color,
                    .ImageFilter = blur
                }
                    canvas.DrawRoundRect(rectPx, radiusPx, radiusPx, p)
                End Using
            End Using

        End Sub

        ''' <summary>
        ''' Draws a non-blurred rounded-rect shadow while preserving the caller-provided
        ''' geometry and color exactly. Use for tiny component affordance shadows that are
        ''' visually authored as flat translucent offsets but must still be owned by ShadowSystem.
        ''' </summary>
        Friend Shared Sub DrawFlatRoundRectShadow(canvas As SKCanvas,
                                                  rectPx As SKRect,
                                                  radiusPx As Single,
                                                  color As SKColor)

            If canvas Is Nothing Then Return
            If rectPx.Width <= 1.0F OrElse rectPx.Height <= 1.0F Then Return
            If color.Alpha = 0 Then Return

            radiusPx = PixelSnap.SafeRadius(radiusPx)

            Using p As New SKPaint With {
                .IsAntialias = True,
                .Style = SKPaintStyle.Fill,
                .Color = color
            }
                canvas.DrawRoundRect(rectPx, radiusPx, radiusPx, p)
            End Using

        End Sub


        ''' <summary>
        ''' Draws a non-blurred rectangular shadow strip while preserving exact geometry.
        ''' Intended for separators such as pinned-column depth hints that are visually flat
        ''' but still belong to ShadowSystem instead of data renderers.
        ''' </summary>
        Friend Shared Sub DrawFlatRectShadow(canvas As SKCanvas,
                                             rectPx As SKRect,
                                             color As SKColor)

            If canvas Is Nothing Then Return
            If rectPx.Width <= 0.0F OrElse rectPx.Height <= 0.0F Then Return
            If color.Alpha = 0 Then Return

            Using p As New SKPaint With {
                .IsAntialias = False,
                .Style = SKPaintStyle.Fill,
                .Color = color
            }
                canvas.DrawRect(rectPx, p)
            End Using

        End Sub

        ''' <summary>
        ''' Draws a non-blurred oval shadow for compact icon badges while preserving the
        ''' exact caller-supplied bounds and color.
        ''' </summary>
        Friend Shared Sub DrawFlatOvalShadow(canvas As SKCanvas,
                                             rectPx As SKRect,
                                             color As SKColor)

            If canvas Is Nothing Then Return
            If rectPx.Width <= 1.0F OrElse rectPx.Height <= 1.0F Then Return
            If color.Alpha = 0 Then Return

            Using p As New SKPaint With {
                .IsAntialias = True,
                .Style = SKPaintStyle.Fill,
                .Color = color
            }
                canvas.DrawOval(rectPx, p)
            End Using

        End Sub

    End Class

End Namespace
