Option Strict On
Option Explicit On

Imports System
Imports SkiaSharp

Namespace Nexamas.UI.Controls

    Friend NotInheritable Class MASTooltipState

        Friend IsOpen As Boolean
        Friend Opacity As Single = 0.0F
        Friend TargetOpacity As Single = 0.0F

        Friend WantsVisible As Boolean

        Friend AnchorClientPx As SKPoint
        Friend SmoothAnchorClientPx As SKPoint
        Friend HasAnchor As Boolean

        Friend LastPointerClientPx As SKPoint

        Friend HoverRectClientPx As SKRect = SKRect.Empty
        Friend HasHoverRect As Boolean

        Friend LastPanelRectPx As SKRect = SKRect.Empty
        Friend LastPlacement As MASTooltip.TooltipPlacement = MASTooltip.TooltipPlacement.Top
        Friend LastTextMaxWidthPx As Single = 0.0F

        Friend PendingShow As Boolean
        Friend PendingShowText As String = String.Empty
        Friend PendingShowStartedUtc As DateTime = DateTime.MinValue

        Friend PendingHide As Boolean
        Friend PendingHideStartedUtc As DateTime = DateTime.MinValue

        Friend VisibleText As String = String.Empty

        Friend ViewportBoundsPx As SKRect = SKRect.Empty
        Friend HasViewportBoundsPx As Boolean

        Friend Sub CompleteHiddenState()
            IsOpen = False
            TargetOpacity = 0.0F
            Opacity = 0.0F
            VisibleText = String.Empty
            PendingShowText = String.Empty
            LastPanelRectPx = SKRect.Empty
            LastTextMaxWidthPx = 0.0F
            AnchorClientPx = SKPoint.Empty
            SmoothAnchorClientPx = SKPoint.Empty
            LastPointerClientPx = SKPoint.Empty
            HasAnchor = False
        End Sub

        Friend Sub ClearHoverRect()
            HasHoverRect = False
            HoverRectClientPx = SKRect.Empty
        End Sub

        Friend Sub SetViewportBoundsPx(boundsPx As SKRect)
            If boundsPx.IsEmpty OrElse boundsPx.Width <= 1.0F OrElse boundsPx.Height <= 1.0F Then
                HasViewportBoundsPx = False
                ViewportBoundsPx = SKRect.Empty
                Return
            End If

            HasViewportBoundsPx = True
            ViewportBoundsPx = boundsPx
        End Sub

        Friend Sub ClearViewportBoundsPx()
            HasViewportBoundsPx = False
            ViewportBoundsPx = SKRect.Empty
        End Sub

        Friend Function GetRenderedTooltipText() As String
            If Not String.IsNullOrWhiteSpace(VisibleText) Then
                Return VisibleText
            End If

            If PendingShow Then
                Return PendingShowText
            End If

            Return String.Empty
        End Function

    End Class

End Namespace
