Imports System.IO.Path
Imports System.Xml.Serialization

<Serializable>
Public Class SideNavItem
    Inherits UserControl

#Region "Defined types"

    Enum ItemStatus
        Complete
        Current
        Disabled
        Header
        Subitem
    End Enum

#End Region

#Region "Properties"

    Property title As String = ""
    Property status As ItemStatus = ItemStatus.Disabled
    Property selected As Boolean = False
    Property forceLink As Boolean = False

#End Region

#Region "Event handlers"

    Protected Overrides Sub Render(writer As HtmlTextWriter)

        Dim safeTitle = New Regex("[""']").Replace(title, "")

        ' <li class='status'>
        writer.AddAttribute("class", _GetStatus())
        writer.RenderBeginTag("li")

        ' unclickable menu option
        If (status = ItemStatus.Disabled) Or (status = ItemStatus.Header) Or (selected And Not forceLink) Then
            writer.RenderBeginTag("span")
            writer.Write(safeTitle)
            writer.RenderEndTag()

            ' clickable menu option
        Else
            writer.AddAttribute("value", safeTitle)
            writer.AddAttribute("name", Me.ClientID)
            writer.AddAttribute("type", "submit")
            writer.RenderBeginTag("input")
            writer.RenderEndTag()
        End If

        ' </li>
        writer.RenderEndTag()

    End Sub

#End Region

#Region "Construction"

    Sub New()
        ' nop
    End Sub

    Sub New(title As String, status As ItemStatus)
        Me.title = title
        Me.status = status
    End Sub

#End Region

#Region "Internals"

    Private Function _GetStatus() As String
        Dim ret = If(selected, "selected ", "")
        Select Case status
            Case ItemStatus.Complete
                Return ret & "complete"
            Case ItemStatus.Current
                Return ret & "current"
            Case ItemStatus.Disabled
                Return ret & "disabled"
            Case ItemStatus.Header
                Return ret & "header"
            Case ItemStatus.Subitem
                Return ret & "subitem hidden"
        End Select
        Return ret
    End Function

#End Region

End Class