Option Strict On
Option Explicit On

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

Namespace Nexamas.UI.Components

    Friend Enum MASTabNavButtonKind
        None = 0
        LeftButton = 1
        RightButton = 2
    End Enum

    Partial Friend NotInheritable Class MASTabRenderer
        Implements IDisposable

        Private ReadOnly _p As MASVisualPrimitivesPainter
        Private ReadOnly _shadow As New MASShadowPainter()
        Private ReadOnly _state As MASTabItemStateRenderer
        Private ReadOnly _measurePaint As New SKPaint With {
            .IsAntialias = True,
            .IsDither = True,
            .LcdRenderText = True,
            .SubpixelText = True
        }
        Private ReadOnly _navPocketPath As New SKPath()
        Private ReadOnly _navPocketGlossPath As New SKPath()
        Private ReadOnly _navPocketInnerPath As New SKPath()
        Private ReadOnly _navGlyphPath As New SKPath()
        Private ReadOnly _navFillPaint As New SKPaint With {
            .IsAntialias = True,
            .IsDither = True
        }
        Private ReadOnly _navFxPaint As New SKPaint With {
            .IsAntialias = True,
            .IsDither = True
        }
        Private ReadOnly _navStrokePaint As New SKPaint With {
            .IsAntialias = True,
            .IsDither = True,
            .Style = SKPaintStyle.Stroke
        }
        Private ReadOnly _edgeFadePaint As New SKPaint With {
            .IsAntialias = True,
            .IsDither = True,
            .Style = SKPaintStyle.Fill
        }
        Private ReadOnly _seamPaint As New SKPaint With {
            .IsAntialias = True,
            .IsDither = True,
            .Style = SKPaintStyle.Stroke
        }

        Private _fallbackTheme As IMASTabTheme
        Private _fallbackThemeId As String = String.Empty

        Private _disposed As Boolean

        Friend Sub New(primitives As MASVisualPrimitivesPainter)
            If primitives Is Nothing Then Throw New ArgumentNullException(NameOf(primitives))

            _p = primitives
            _state = New MASTabItemStateRenderer(_p, _shadow)
        End Sub

        Public Sub Dispose() Implements IDisposable.Dispose
            If _disposed Then Return
            _disposed = True

            Try
                _measurePaint.Dispose()
            Catch masCaughtException1 As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDisposeCleanup(masCaughtException1)
            End Try
            Try
                _shadow.Dispose()
            Catch masCaughtException2 As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDisposeCleanup(masCaughtException2)
            End Try
            Try
                _navPocketPath.Dispose()
            Catch masCaughtException3 As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDisposeCleanup(masCaughtException3)
            End Try
            Try
                _navPocketGlossPath.Dispose()
            Catch masCaughtException4 As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDisposeCleanup(masCaughtException4)
            End Try
            Try
                _navPocketInnerPath.Dispose()
            Catch masCaughtException5 As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDisposeCleanup(masCaughtException5)
            End Try
            Try
                _navGlyphPath.Dispose()
            Catch masCaughtException6 As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDisposeCleanup(masCaughtException6)
            End Try
            Try
                _navFillPaint.Dispose()
            Catch masCaughtException7 As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDisposeCleanup(masCaughtException7)
            End Try
            Try
                _navFxPaint.Dispose()
            Catch masCaughtException8 As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDisposeCleanup(masCaughtException8)
            End Try
            Try
                _navStrokePaint.Dispose()
            Catch masCaughtException9 As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDisposeCleanup(masCaughtException9)
            End Try
            Try
                _edgeFadePaint.Dispose()
            Catch masCaughtException10 As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDisposeCleanup(masCaughtException10)
            End Try
            Try
                _seamPaint.Dispose()
            Catch masCaughtException11 As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDisposeCleanup(masCaughtException11)
            End Try
        End Sub


    End Class

End Namespace
