Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Windows.Forms
Imports Nexamas.UI.Architecture
Imports Nexamas.UI.Components.ListPopup
Imports Nexamas.UI.Components.ListRendering
Imports Nexamas.UI.Composition
Imports Nexamas.UI.Controls
Imports Nexamas.UI.FloatRuntime
Imports Nexamas.UI.General
Imports Nexamas.UI.Layout
Imports Nexamas.UI.Rendering
Imports Nexamas.UI.Theming
Imports Nexamas.UI.TextRendering
Imports Nexamas.UI.Values
Imports SkiaSharp

Namespace Nexamas.UI.Components

    Partial Public NotInheritable Class MASComboBox

#Region "Properties"

        ''' <summary>
        ''' Read-only view of the current item text. Consumers must mutate the collection
        ''' through SetItems, AddItems, or ClearItems so layout, selection, and dropdown
        ''' ownership remain synchronized.
        ''' </summary>
        Public ReadOnly Property Items As IReadOnlyList(Of String)
            Get
                Return _itemsView
            End Get
        End Property

        ''' <summary>
        ''' Number of items currently owned by the combo-box item store.
        ''' </summary>
        Public ReadOnly Property ItemCount As Integer
            Get
                Return _items.Count
            End Get
        End Property

        ''' <summary>
        ''' Gets or sets the selected item index. Invalid indexes normalize to -1.
        ''' </summary>
        Public Property SelectedIndex As Integer
            Get
                Return _selectedIndex
            End Get
            Set(value As Integer)
                Dim nextIndex As Integer = NormalizeSelectionIndex(value)
                If _selectedIndex = nextIndex Then Return

                _selectedIndex = nextIndex
                SyncOpenDropdownSelection()
                InvalidateVisual()
                RaiseSelectionChangedSafe()
            End Set
        End Property

        Public ReadOnly Property SelectedText As String
            Get
                If _selectedIndex >= 0 AndAlso _selectedIndex < _items.Count Then
                    Return If(_items(_selectedIndex), String.Empty)
                End If

                Return String.Empty
            End Get
        End Property

#End Region

    End Class

End Namespace
