Option Strict On
Option Explicit On

Imports System
Imports System.Windows.Forms
Imports Nexamas.UI.Architecture
Imports Nexamas.UI.Components
Imports Nexamas.UI.Composition
Imports Nexamas.UI.General
Imports Nexamas.UI.Layout
Imports Nexamas.UI.Motion
Imports Nexamas.UI.Rendering
Imports Nexamas.UI.TextRendering
Imports Nexamas.UI.Theming
Imports Nexamas.UI.Values
Imports SkiaSharp

Namespace Nexamas.UI.Controls

    Public Enum MASButtonIconPlacement
        Left = 0
        Right = 1
        Top = 2
        Bottom = 3
    End Enum

    ''' <summary>
    ''' Contract-driven MAS button control.
    ''' Public API lives on the control itself.
    ''' MASUI may create this control, but must not be the only way to configure it.
    ''' </summary>
    Partial Public NotInheritable Class MASButton
        Inherits MASControlBase
        Implements IMASTooltipProvider
        Implements IMASLayoutParticipant
        Implements IMASIntrinsicSizeContract
        Implements IMASLayoutSemanticBoundsProvider

#Region "Fields"

        Private ReadOnly _renderer As MASButtonRenderer
        Private ReadOnly _interactionController As MASButtonInteractionController
        Private ReadOnly _contract As MASResolvedComponentContract

        Private _state As MASButtonState
        Private _pressPulseRunner As MASMotionTimelineRunner
        Private _motionPressActive As Boolean

        Private _text As String
        Private _busyText As String
        Private _tooltip As String

        Private _intent As MASButtonIntent
        Private _personality As MASButtonPersonality

        Private _isDefaultButton As Boolean
        Private _isSelected As Boolean
        Private _isBusy As Boolean
        Private _disableWhileBusy As Boolean

        Private _command As Action(Of MASButton)

        Private _drawIcon As Action(Of SKCanvas, SKRect, Single, SKColor)
        Private _drawIconEmphasis As Action(Of SKCanvas, SKRect, Single, SKColor)
        Private _iconPlacement As MASButtonIconPlacement

        Private _minWidth As Single
        Private _minHeight As Single
        Private _preferredWidth As Single
        Private _preferredHeight As Single

#End Region

#Region "Events"

        Public Event Click As EventHandler
        Public Event IntentChanged As EventHandler
        Public Event PersonalityChanged As EventHandler
        Public Event DefaultButtonChanged As EventHandler
        Public Event SelectedChanged As EventHandler
        Public Event CommandChanged As EventHandler
        Public Event BusyChanged As EventHandler
        Public Event TooltipChanged As EventHandler
        Public Event IconChanged As EventHandler
        Public Event SizeHintsChanged As EventHandler

#End Region

#Region "Ctor"

        Public Sub New()
            _renderer = New MASButtonRenderer()
            _interactionController = New MASButtonInteractionController()
            _contract = MASArchitectureRuntime.ResolveContractOrThrow(GetType(MASButton))

            _state = MASButtonState.CreateDefault(True)
            _pressPulseRunner = Nothing
            _motionPressActive = False

            _text = String.Empty
            _busyText = String.Empty
            _tooltip = String.Empty

            _intent = MASButtonIntent.Default
            _personality = MASButtonPersonality.MAS

            _isDefaultButton = False
            _isSelected = False
            _isBusy = False
            _disableWhileBusy = True

            _command = Nothing

            _drawIcon = Nothing
            _drawIconEmphasis = Nothing
            _iconPlacement = MASButtonIconPlacement.Left

            _minWidth = 0.0F
            _minHeight = 0.0F
            _preferredWidth = 0.0F
            _preferredHeight = 0.0F
        End Sub

        Public Sub New(text As String)
            Me.New()
            Me.Text = text
        End Sub

#End Region

#Region "Factories"

        ''' <summary>
        ''' Creates a new MAS button using the standard SDK entry pattern.
        ''' </summary>
        Public Shared Function Create(Optional text As String = Nothing) As MASButton
            Dim button As New MASButton()

            If text IsNot Nothing Then
                button.Text = text
            End If

            Return button
        End Function

#End Region


    End Class

End Namespace
