src/Console/Components/New-Alert.psm1

using module ../Context.psm1

<#
.SYNOPSIS
    TODO Renders an alert.
.INPUTS
    The child content.
.OUTPUTS
    The rendered component.
#>

function New-Alert {
    [CmdletBinding()]
    [OutputType([string])]
    param (
        # The child content.
        [Parameter(Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)]
        [object] $Content,

        # The CSS class names to apply to the underlying element.
        [Parameter(ValueFromPipelineByPropertyName)]
        [ValidateNotNull()]
        [string[]] $Class = @(),

        # A contextual modifier.
        [Parameter(ValueFromPipelineByPropertyName)]
        [Context] $Context = [Context]::Info,

        # Value indicating whether this alert can be dismissed.
        [Parameter(ValueFromPipelineByPropertyName)]
        [switch] $Dismissible,

        # Value indicating whether to apply a transition.
        [Parameter(ValueFromPipelineByPropertyName)]
        [switch] $Fade,

        # The icon displayed next to the alert message.
        [Parameter(ValueFromPipelineByPropertyName)]
        [string] $Icon = ""
    )

    process {
        div -class alert, alert-dismissible, $Dismissible ? "alert-dismissible" : "", $Fade ? "fade show" : "", $Class -join " " {
            div -class d-flex, align-items-center {
                i -class icon, flex-shrink-0, me-2 ($Icon ? $Icon : (Get-ContextIcon $Context))
                div $Content
            }

            if ($Dismissible) {
                button -class btn-close -dataset @{ BsDismiss = "alert" } -type button
            }
        }
    }
}