Option Strict On
Option Explicit On

Imports System.Collections.Generic
Imports SkiaSharp

Namespace Nexamas.UI.Theming

    ' ThemeValidator partial implementation extracted for maintainability.
    Partial Friend NotInheritable Class ThemeValidator

#Region "Cross Consistency"

        Private Shared Sub ValidateFoundationCrossConsistency(bundle As IMASThemeFoundation, errors As List(Of String))
            Dim t As IMASTextColorTheme = bundle.TextColors
            Dim b As IMASBrandTheme = bundle.Brand
            Dim n As IMASNeutralTheme = bundle.Neutrals
            Dim i As IMASInteractionTheme = bundle.Interaction
            Dim s As IMASFoundationSurfaceTheme = bundle.Surface

            ValidateContrast(t.PrimaryText, n.Surface0, "PrimaryText on Surface0", MinTextContrast, errors)
            ValidateContrast(t.PrimaryText, n.Surface1, "PrimaryText on Surface1", MinTextContrast, errors)
            ValidateContrast(t.PrimaryText, n.Surface2, "PrimaryText on Surface2", MinTextContrast, errors)

            ValidateContrast(t.SecondaryText, n.Surface0, "SecondaryText on Surface0", MinLargeTextContrast, errors)
            ValidateContrast(t.SecondaryText, n.Surface1, "SecondaryText on Surface1", MinLargeTextContrast, errors)

            ValidateContrast(t.DisabledText, n.Surface0, "DisabledText on Surface0", MinDisabledTextContrast, errors)

            ValidateContrast(t.OnBrandPrimaryText, b.BrandPrimary, "OnBrandPrimaryText on BrandPrimary", MinAccentTextContrast, errors)
            ValidateContrast(t.OnBrandPrimaryStrongText, b.BrandPrimaryStrong, "OnBrandPrimaryStrongText on BrandPrimaryStrong", MinAccentTextContrast, errors)

            ValidateContrast(t.PrimaryText, s.SurfaceTop, "PrimaryText on SurfaceTop", MinTextContrast, errors)
            ValidateContrast(t.PrimaryText, s.SurfaceMid, "PrimaryText on SurfaceMid", MinTextContrast, errors)
            ValidateContrast(t.PrimaryText, s.SurfaceBot, "PrimaryText on SurfaceBot", MinTextContrast, errors)

            ValidateCompositeSeparation(s.BorderOuter, s.SurfaceTop, "BorderOuter over SurfaceTop", MinBorderDistance, MinBorderLuminanceDelta, errors)
            ValidateCompositeSeparation(s.BorderInner, s.SurfaceMid, "BorderInner over SurfaceMid", MinBorderDistance, MinBorderLuminanceDelta, errors)

            ValidateCompositeSeparation(n.BorderSubtle, n.Surface0, "BorderSubtle over Surface0", MinBorderDistance, MinBorderLuminanceDelta, errors)
            ValidateCompositeSeparation(n.BorderDefault, n.Surface1, "BorderDefault over Surface1", MinBorderDistance, MinBorderLuminanceDelta, errors)
            ValidateCompositeSeparation(n.BorderStrong, n.Surface2, "BorderStrong over Surface2", MinBorderDistance, MinBorderLuminanceDelta, errors)

            ValidateCompositeSeparation(s.MaterialWash, s.SurfaceMid, "MaterialWash over SurfaceMid", 5.0, 0.01, errors)

            If i.Hover.Fill.Enabled Then
                ValidateCompositeSeparation(i.Hover.Fill.Color, n.Surface1, "Hover.Fill over Surface1", 6.0, 0.01, errors)
            End If

            If i.Pressed.Fill.Enabled Then
                ValidateCompositeSeparation(i.Pressed.Fill.Color, n.Surface1, "Pressed.Fill over Surface1", 8.0, 0.015, errors)
            End If

            If i.Selected.Fill.Enabled Then
                ValidateCompositeSeparation(i.Selected.Fill.Color, n.Surface1, "Selected.Fill over Surface1", 8.0, 0.015, errors)
            End If

            If i.Focused.Ring.Enabled Then
                ValidateCompositeSeparation(i.Focused.Ring.Color, n.Surface1, "Focused.Ring over Surface1", 10.0, 0.02, errors)
            End If

            If i.Selected.Ring.Enabled Then
                ValidateCompositeSeparation(i.Selected.Ring.Color, n.Surface1, "Selected.Ring over Surface1", 8.0, 0.015, errors)
            End If

            If i.Focused.Ring.Enabled AndAlso i.DisabledFill.Enabled Then
                ValidateDistinctEnough(
                    i.Focused.Ring.Color,
                    i.DisabledFill.Color,
                    "FocusedRing vs DisabledFill",
                    MinDifferentiationDistance,
                    errors)
            End If

            ValidateDistinctEnough(b.BrandPrimary, n.Surface0, "BrandPrimary vs Surface0", MinDifferentiationDistance, errors)
            ValidateDistinctEnough(b.BrandPrimaryStrong, s.ShadowBase, "BrandPrimaryStrong vs ShadowBase", 8.0, errors)

            ValidatePerceptualDifference(t.PrimaryText, n.Surface0, "PrimaryText vs Surface0", MinTextLuminanceDelta, errors)
            ValidatePerceptualDifference(t.PrimaryText, s.SurfaceTop, "PrimaryText vs SurfaceTop", MinTextLuminanceDelta, errors)
        End Sub

#End Region

    End Class

End Namespace
