Option Strict On
Option Explicit On

Imports System
Imports Nexamas.UI.Values

Namespace Nexamas.UI.TextInput

    ''' <summary>
    ''' Stores validation presentation state for MASInputBoxSkiaBase.
    ''' </summary>
    ''' <remarks>
    ''' Validation message/state/indicator are visual concerns used by the input renderer
    ''' and higher-level form systems. Keeping them in a small value-owning collaborator
    ''' prevents MASInputBoxSkiaBase from owning validation storage and rendering policy
    ''' directly while preserving the existing public properties.
    ''' </remarks>
    Friend NotInheritable Class MASTextInputValidationVisualState

#Region "Properties"

        Friend Property State As MASTextValidationState = MASTextValidationState.None
        Friend Property Message As String = String.Empty
        Friend Property ShowIndicator As Boolean = True

#End Region

#Region "Operations"

        Friend Function Clear() As Boolean
            Dim changed As Boolean = State <> MASTextValidationState.None OrElse
                                      Not String.IsNullOrEmpty(Message)

            State = MASTextValidationState.None
            Message = String.Empty

            Return changed
        End Function

        Friend Function SetValidation(state As MASTextValidationState,
                                      message As String) As Boolean

            Dim normalized As String = If(message, String.Empty)
            Dim changed As Boolean = State <> state OrElse
                                      Not String.Equals(Message, normalized, StringComparison.Ordinal)

            State = state
            Message = normalized

            Return changed
        End Function

#End Region

    End Class

End Namespace
