Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Windows.Forms
Imports Nexamas.UI.Architecture
Imports Nexamas.UI.Composition
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

    Partial Public NotInheritable Class MASPagination

#Region "Rendering Helpers"

        Private Function MeasureTextWidthPx(ctx As MASThemeContext,
                                            text As String) As Single
            If ctx Is Nothing OrElse ctx.Typography Is Nothing Then Return Math.Max(1.0F, If(text, String.Empty).Length * 7.0F)

            Dim paint As SKPaint = ctx.Typography.GetPaint(MASTypography.MASTextStyle.Small, ResolvePrimaryTextColor(ctx))
            If paint Is Nothing Then Return Math.Max(1.0F, If(text, String.Empty).Length * 7.0F)
            Return Math.Max(1.0F, MASShapedText.MeasureWidth(If(text, String.Empty), paint))
        End Function

        Private Shared Function ResolvePrimaryTextColor(ctx As MASThemeContext) As SKColor
            If ctx IsNot Nothing AndAlso ctx.TextColorTheme IsNot Nothing Then Return ctx.TextColorTheme.PrimaryText
            Return Nexamas.UI.Values.Color.Text.Primary
        End Function

        Private Shared Function ResolveMutedTextColor(ctx As MASThemeContext) As SKColor
            If ctx IsNot Nothing AndAlso ctx.TextColorTheme IsNot Nothing Then Return ctx.TextColorTheme.MutedText
            Return SKColors.Gray
        End Function

        Private Shared Function ResolvePanelColor(ctx As MASThemeContext) As SKColor
            If ctx IsNot Nothing AndAlso ctx.SurfaceTheme IsNot Nothing Then Return ctx.SurfaceTheme.SurfaceMid
            Return SKColors.White
        End Function

        Private Shared Function ResolveAccentColor(ctx As MASThemeContext) As SKColor
            If ctx IsNot Nothing AndAlso ctx.BrandTheme IsNot Nothing Then Return ctx.BrandTheme.BrandPrimary
            If ctx IsNot Nothing AndAlso ctx.SemanticTheme IsNot Nothing Then Return ctx.SemanticTheme.Info
            Return SKColors.DodgerBlue
        End Function

        Private Shared Function ResolveNodeTextColor(ctx As MASThemeContext,
                                                     active As Boolean,
                                                     enabled As Boolean) As SKColor
            If ctx Is Nothing Then Return SKColors.Gray
            If Not enabled Then Return ResolveMutedTextColor(ctx).WithAlpha(PaginationTokens.DisabledTextAlpha)
            If active Then Return SKColors.White.WithAlpha(PaginationTokens.NodeSelectedTextAlpha)
            Return ResolvePrimaryTextColor(ctx).WithAlpha(PaginationTokens.TextAlpha)
        End Function

#End Region

    End Class

End Namespace
