Option Strict On
Option Explicit On

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

Namespace Nexamas.UI.Controls

    Partial Public NotInheritable Class MASNotificationPanel

#Region "Input"

        Protected Overrides Sub OnMouseMove(ctx As MASThemeContext,
                                            ptPx As SKPoint)
            Dim hit As NotificationRowHit = HitTestRow(ptPx)
            Dim index As Integer = If(hit Is Nothing, -1, hit.Index)
            If index = _hoverIndex Then Return
            _hoverIndex = index
            InvalidateVisual()
        End Sub

        Protected Overrides Function OnMouseDown(ctx As MASThemeContext,
                                                 ptPx As SKPoint,
                                                 button As Integer) As Boolean
            If button <> CInt(MouseButtons.Left) Then Return False
            Dim hit As NotificationRowHit = HitTestRow(ptPx)
            If hit Is Nothing Then Return False
            _pressedIndex = hit.Index
            InvalidateVisual()
            Return True
        End Function

        Protected Overrides Function OnMouseUp(ctx As MASThemeContext,
                                               ptPx As SKPoint,
                                               button As Integer) As Boolean
            If button <> CInt(MouseButtons.Left) Then Return False
            Dim pressed As Integer = _pressedIndex
            _pressedIndex = -1
            Dim hit As NotificationRowHit = HitTestRow(ptPx)
            If hit IsNot Nothing AndAlso hit.Index = pressed Then
                If hit.Index >= 0 AndAlso hit.Index < _items.Count AndAlso _items(hit.Index).IsUnread Then
                    _items(hit.Index).IsUnread = False
                    RaiseNotificationsChangedSafe()
                End If
                InvalidateVisual()
                Return True
            End If
            InvalidateVisual()
            Return False
        End Function

        Protected Overrides Sub OnMouseLeave(ctx As MASThemeContext)
            If _hoverIndex < 0 AndAlso _pressedIndex < 0 Then Return
            _hoverIndex = -1
            _pressedIndex = -1
            InvalidateVisual()
        End Sub

        Protected Overrides Sub OnMouseCancel(ctx As MASThemeContext)
            If _pressedIndex < 0 Then Return
            _pressedIndex = -1
            InvalidateVisual()
        End Sub

        Protected Overrides Sub OnHostLostFocus(ctx As MASThemeContext)
            If _pressedIndex < 0 Then Return
            _pressedIndex = -1
            InvalidateVisual()
        End Sub

#End Region
    End Class

End Namespace
