Celerium.Nova.psm1

#Region './Private/Html/ConvertTo-clNovaHtmlDataUri.ps1' -1

function ConvertTo-clNovaHtmlDataUri {
<#
    .SYNOPSIS
        Converts an image file to a data uri that can be embedded in an HTML page

    .DESCRIPTION
        The ConvertTo-clNovaHtmlDataUri cmdlet reads an image file & returns it as a base64 data uri
        (data:image/png;base64,...) so the image is part of the HTML file & is also shown when the
        computer is offline

        The supported files are png, jpg, jpeg, gif, svg, webp, & ico

        This is an internal helper function that is used by the public functions

    .PARAMETER Path
        The path of the image file

    .EXAMPLE
        ConvertTo-clNovaHtmlDataUri -Path .\logo.png

        Returns data:image/png;base64,iVBORw0KGgo...

    .NOTES
        N\A

    .LINK
        https://celerium.github.io/Celerium.Nova/site/Internal/ConvertTo-clNovaHtmlDataUri.html
#>


    [CmdletBinding()]
    [OutputType([string])]
    param (
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string]$Path
    )

    $FullPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path)

    if (-not (Test-Path -Path $FullPath -PathType Leaf)) { throw "The image [ $Path ] was not found" }

    $Types = @{ '.png' = 'image/png'; '.jpg' = 'image/jpeg'; '.jpeg' = 'image/jpeg'; '.gif' = 'image/gif'; '.svg' = 'image/svg+xml'; '.webp' = 'image/webp'; '.ico' = 'image/x-icon' }
    $Type  = $Types[[System.IO.Path]::GetExtension($FullPath).ToLowerInvariant()]

    if (-not $Type) { throw "The image [ $Path ] must be a png, jpg, gif, svg, webp, or ico file" }

    return ('data:{0};base64,{1}' -f $Type, [Convert]::ToBase64String([System.IO.File]::ReadAllBytes($FullPath)))

}
#EndRegion './Private/Html/ConvertTo-clNovaHtmlDataUri.ps1' 50
#Region './Private/Html/ConvertTo-clNovaHtmlEncoded.ps1' -1

function ConvertTo-clNovaHtmlEncoded {
<#
    .SYNOPSIS
        Encodes text so that it can safely be placed in HTML

    .DESCRIPTION
        The ConvertTo-clNovaHtmlEncoded cmdlet HTML encodes the string value of an object so that
        characters such as < > & " ' are shown as text & can not change the HTML of a report

        A null value returns an empty string

        This is an internal helper function that is used by the public functions

    .PARAMETER InputObject
        The value to encode, the string value of the object is encoded

    .EXAMPLE
        ConvertTo-clNovaHtmlEncoded -InputObject '<b>Server & Client</b>'

        Returns &lt;b&gt;Server &amp; Client&lt;/b&gt;

    .EXAMPLE
        'DC01', 'A&B' | ConvertTo-clNovaHtmlEncoded

        Returns the encoded value of every item sent down the pipeline

    .NOTES
        N\A

    .LINK
        https://celerium.github.io/Celerium.Nova/site/Internal/ConvertTo-clNovaHtmlEncoded.html
#>


    [CmdletBinding()]
    [OutputType([string])]
    param (
        [Parameter(Mandatory = $false, ValueFromPipeline = $true, Position = 0)]
        [AllowNull()]
        [AllowEmptyString()]
        [object]$InputObject
    )

    process {

        if ($null -eq $InputObject) { return '' }

        [System.Net.WebUtility]::HtmlEncode([string]$InputObject)

    }

}
#EndRegion './Private/Html/ConvertTo-clNovaHtmlEncoded.ps1' 52
#Region './Private/Html/Expand-clNovaHtmlTemplate.ps1' -1

function Expand-clNovaHtmlTemplate {
<#
    .SYNOPSIS
        Replaces the {{Name}} tokens of an HTML template with values

    .DESCRIPTION
        The Expand-clNovaHtmlTemplate cmdlet replaces every {{Name}} token of a template with
        the value of the same name in the Token hashtable

        The tokens are replaced in one pass, so a {{Name}} text inside of a value is never
        replaced again. A token without a value is replaced with an empty string

        The values are NOT encoded, encode text values with ConvertTo-clNovaHtmlEncoded before
        adding them to the Token hashtable

        This is an internal helper function that is used by the public functions

    .PARAMETER Template
        The text with the {{Name}} tokens

    .PARAMETER Token
        Hashtable of token names & the values to replace them with

        Example:
            @{ Title = 'Report'; Body = '<p>Text</p>' }

    .EXAMPLE
        Expand-clNovaHtmlTemplate -Template '<h1>{{Title}}</h1>' -Token @{ Title = 'Report' }

        Returns <h1>Report</h1>

    .NOTES
        N\A

    .LINK
        https://celerium.github.io/Celerium.Nova/site/Internal/Expand-clNovaHtmlTemplate.html
#>


    [CmdletBinding()]
    [OutputType([string])]
    param (
        [Parameter(Mandatory = $true)]
        [AllowEmptyString()]
        [string]$Template,

        [Parameter(Mandatory = $true)]
        [System.Collections.IDictionary]$Token
    )

    $Values = $Token

    $Evaluator = [System.Text.RegularExpressions.MatchEvaluator]{
        param ($Match)

        $Name = $Match.Groups[1].Value

        if ($Values.Contains($Name) -and $null -ne $Values[$Name]) { return [string]$Values[$Name] }

        return ''
    }

    return [regex]::Replace($Template, '\{\{(\w+)\}\}', $Evaluator)

}
#EndRegion './Private/Html/Expand-clNovaHtmlTemplate.ps1' 65
#Region './Private/Html/Get-clNovaCardLayout.ps1' -1

function Get-clNovaCardLayout {
<#
    .SYNOPSIS
        Calculates how many summary cards are placed in each row

    .DESCRIPTION
        The Get-clNovaCardLayout cmdlet calculates the number of summary cards per row so that
        every row has the same number of cards

            2 rows with 6 cards -> 3 cards on the top row & 3 on the bottom row
            3 rows with 12 cards -> 4 cards on each of the 3 rows

        The number of rows is the minimum number of rows needed with the MaxPerRow limit. The cards
        per row is then the number of cards divided by the rows. When the cards can not be divided
        evenly (7 cards) the last row is shorter

        The layout is calculated for desktops (Xl), tablets (Md), & phones (Sm)

        This is an internal helper function that is used by the public functions

    .PARAMETER Count
        The number of summary cards

    .PARAMETER MaxPerRow
        The most cards that are allowed on one row of a desktop screen

        Default value: 4

    .PARAMETER MaxPerRowTablet
        The most cards that are allowed on one row of a tablet screen

        Default value: 2

    .EXAMPLE
        Get-clNovaCardLayout -Count 6

        Returns a layout of 2 rows with 3 cards per row for desktops

    .EXAMPLE
        Get-clNovaCardLayout -Count 12 -MaxPerRow 4

        Returns a layout of 3 rows with 4 cards per row for desktops

    .NOTES
        N\A

    .LINK
        https://celerium.github.io/Celerium.Nova/site/Internal/Get-clNovaCardLayout.html
#>


    [CmdletBinding()]
    [OutputType([pscustomobject])]
    param (
        [Parameter(Mandatory = $true)]
        [ValidateRange(0, 1000)]
        [int]$Count,

        [Parameter(Mandatory = $false)]
        [ValidateRange(1, 12)]
        [int]$MaxPerRow = 4,

        [Parameter(Mandatory = $false)]
        [ValidateRange(1, 6)]
        [int]$MaxPerRowTablet = 2
    )

    function Get-clNovaEvenColumn {
        param (
            [int]$ItemCount,
            [int]$Limit
        )

        if ($ItemCount -le 0)       { return 1 }
        if ($ItemCount -le $Limit)  { return $ItemCount }

        $MinimumRows = [int][Math]::Ceiling($ItemCount / $Limit)

        # One more row than the minimum is allowed to find a layout where every row is full
        foreach ($Rows in $MinimumRows, ($MinimumRows + 1)) {
            if ($ItemCount % $Rows -eq 0 -and ($ItemCount / $Rows) -le $Limit) { return [int]($ItemCount / $Rows) }
        }

        return [int][Math]::Ceiling($ItemCount / $MinimumRows)
    }

    $Xl = Get-clNovaEvenColumn -ItemCount $Count -Limit $MaxPerRow
    $Md = Get-clNovaEvenColumn -ItemCount $Count -Limit $MaxPerRowTablet

    [PSCustomObject]@{
        Count       = $Count
        Xl          = $Xl
        Md          = $Md
        Sm          = 1
        Rows        = if ($Count -eq 0) { 0 } else { [int][Math]::Ceiling($Count / $Xl) }
    }

}
#EndRegion './Private/Html/Get-clNovaCardLayout.ps1' 98
#Region './Private/Html/Get-clNovaHtmlIcon.ps1' -1

function Get-clNovaHtmlIcon {
<#
    .SYNOPSIS
        Gets an inline SVG icon for an HTML report

    .DESCRIPTION
        The Get-clNovaHtmlIcon cmdlet returns a Bootstrap Icon as inline SVG so that the icon
        works in an offline report & does not need a font or an internet connection

        The icons are the svg files in the icons folder of the report resources
        (build\HtmlReport\icons). The Update-HtmlResources.ps1 build script downloads them

        When the icon does not exist the info-circle icon is returned. An empty string
        is returned when there are no icons at all

        This is an internal helper function that is used by the public functions

    .PARAMETER Name
        The name of the Bootstrap Icon without the .svg extension

        Example:
            server
            check-circle-fill

    .PARAMETER ResourcePath
        The HtmlReport folder to read the icons from

        By default the folder of the module is used

    .EXAMPLE
        Get-clNovaHtmlIcon -Name 'server'

        Returns the SVG of the server icon

    .NOTES
        N\A

    .LINK
        https://celerium.github.io/Celerium.Nova/site/Internal/Get-clNovaHtmlIcon.html
#>


    [CmdletBinding()]
    [OutputType([string])]
    param (
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string]$Name,

        [Parameter(Mandatory = $false)]
        [string]$ResourcePath
    )

    $Svg = $null

    # The icons folder is found once, a missing icon is checked with Test-Path so it does not add an error to $Error
    $IconFolder = $null
    if ($ResourcePath) { $IconFolder = Join-Path -Path $ResourcePath -ChildPath 'icons' }
    else {
        $FallbackPath = Get-clNovaResourcePath -RelativePath 'HtmlReport/icons/info-circle.svg' -ErrorAction Ignore
        if ($FallbackPath) { $IconFolder = Split-Path -Path $FallbackPath -Parent }
    }

    if (-not $IconFolder) { return '' }

    # Only letters, numbers, & dashes are valid in the name of an icon
    foreach ($IconName in $Name, 'info-circle') {

        if ($IconName -notmatch '^[A-Za-z0-9-]+$') { continue }

        $IconPath = Join-Path -Path $IconFolder -ChildPath "$IconName.svg"
        if (Test-Path -LiteralPath $IconPath -PathType Leaf) { $Svg = [System.IO.File]::ReadAllText($IconPath, [System.Text.Encoding]::UTF8) }

        if ($Svg) { break }

    }

    if (-not $Svg) { return '' }

    $Svg = $Svg.Trim()
    $Svg = [regex]::Replace($Svg, 'class="([^"]*)"', 'class="$1 psn-icon" aria-hidden="true" focusable="false"', 1)

    return $Svg

}
#EndRegion './Private/Html/Get-clNovaHtmlIcon.ps1' 85
#Region './Private/Html/Get-clNovaHtmlResource.ps1' -1

function Get-clNovaHtmlResource {
<#
    .SYNOPSIS
        Gets the content of a file used to build an HTML report

    .DESCRIPTION
        The Get-clNovaHtmlResource cmdlet reads a template, css, js, or other text file that
        is used to build an HTML report

        The files are in the HtmlReport folder of the module (build\HtmlReport in the source
        module). A different folder can be used with the ResourcePath parameter

        This is an internal helper function that is used by the public functions

    .PARAMETER Name
        The path of the file relative to the HtmlReport folder

        Example:
            templates/Page.html
            css/Celerium.Nova.css

    .PARAMETER ResourcePath
        The HtmlReport folder to read the file from

        By default the folder of the module is used

    .EXAMPLE
        Get-clNovaHtmlResource -Name 'templates/Page.html'

        Returns the text of the Page.html report template

    .EXAMPLE
        Get-clNovaHtmlResource -Name 'css/Celerium.Nova.css' -ResourcePath 'C:\Branding\HtmlReport'

        Returns the css from a custom HtmlReport folder

    .NOTES
        N\A

    .LINK
        https://celerium.github.io/Celerium.Nova/site/Internal/Get-clNovaHtmlResource.html
#>


    [CmdletBinding()]
    [OutputType([string])]
    param (
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string]$Name,

        [Parameter(Mandatory = $false)]
        [string]$ResourcePath
    )

    if ($ResourcePath) {
        $Path = Join-Path -Path $ResourcePath -ChildPath ($Name.Replace('/', [System.IO.Path]::DirectorySeparatorChar))
    }
    else {
        $Path = Get-clNovaResourcePath -RelativePath "HtmlReport/$Name" -ErrorAction Stop
    }

    if (-not (Test-Path -Path $Path -PathType Leaf)) {
        throw "The report resource [ $Name ] was not found at [ $Path ]"
    }

    return [System.IO.File]::ReadAllText($Path, [System.Text.Encoding]::UTF8)

}
#EndRegion './Private/Html/Get-clNovaHtmlResource.ps1' 69
#Region './Private/Resources/Get-clNovaResourcePath.ps1' -1

function Get-clNovaResourcePath {
<#
    .SYNOPSIS
        Finds a resource file (template, css, js, icon, or data file) of the module

    .DESCRIPTION
        The Get-clNovaResourcePath cmdlet finds the full path of a resource file that is
        shipped with the module

        The module is used from two places & the resources are in a different place in each
            - Source module : build\HtmlReport (next to the module folder)
            - Built module : <module folder>\HtmlReport

        The folders above the file that calls the function are searched for the relative path,
        first as <folder>\<RelativePath> & then as <folder>\build\<RelativePath>

        This is an internal helper function that is used by the public functions

    .PARAMETER RelativePath
        The path of the resource relative to the root of the resources

        Example:
            HtmlReport/templates/Page.html
            HtmlReport/css/Celerium.Nova.css

    .PARAMETER SearchPath
        The folder the search starts from & works up from

        By default the folder of this file is used

    .EXAMPLE
        Get-clNovaResourcePath -RelativePath 'HtmlReport/templates/Page.html'

        Returns the full path of the Page.html report template

    .EXAMPLE
        Get-clNovaResourcePath -RelativePath 'HtmlReport/missing.json' -ErrorAction SilentlyContinue

        Returns nothing when the resource does not exist

    .NOTES
        N\A

    .LINK
        https://celerium.github.io/Celerium.Nova/site/Internal/Get-clNovaResourcePath.html
#>


    [CmdletBinding()]
    [OutputType([string])]
    param (
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string]$RelativePath,

        [Parameter(Mandatory = $false)]
        [ValidateNotNullOrEmpty()]
        [string]$SearchPath = $PSScriptRoot
    )

    $Relative   = $RelativePath.Replace('/', [System.IO.Path]::DirectorySeparatorChar).Replace('\', [System.IO.Path]::DirectorySeparatorChar)
    $Directory  = $SearchPath

    while ($Directory) {

        foreach ($Candidate in (Join-Path -Path $Directory -ChildPath $Relative), (Join-Path -Path (Join-Path -Path $Directory -ChildPath 'build') -ChildPath $Relative)) {
            if (Test-Path -Path $Candidate -PathType Leaf) { return $Candidate }
        }

        $Directory = Split-Path -Path $Directory -Parent

    }

    Write-Error "The resource [ $RelativePath ] was not found"

}
#EndRegion './Private/Resources/Get-clNovaResourcePath.ps1' 76
#Region './Public/HtmlReport/New-clNovaHtmlReport.ps1' -1

function New-clNovaHtmlReport {
<#
    .SYNOPSIS
        Creates a modern, mobile friendly HTML report from PowerShell objects

    .DESCRIPTION
        The New-clNovaHtmlReport cmdlet turns any PowerShell objects into a single HTML file with
        a dark sidebar & header, an off white body, summary cards, & a sortable, searchable table

        The design is based on SB Admin 2 (ported to Bootstrap 5.3) & works on desktops
        (Windows, Linux, & macOS) as well as on Android & iOS phones & tablets

        By default everything needed (Bootstrap, the theme, the icons, & the scripts) is embedded in the
        file so the report works offline. Use -ResourceMode Cdn to link the Bootstrap 5.3 CDN files instead
        which makes the file smaller

        The pieces of the report are also available as separate functions which can be used to build
        other reports
            - New-clNovaHtmlSummaryCardSet & New-clNovaHtmlSummaryCard
            - New-clNovaHtmlTable

    .PARAMETER InputObject
        The objects shown in the table of the report

    .PARAMETER Path
        The file to save the report to. The folder is created when it does not exist

        When it is not used the HTML text is returned instead

    .PARAMETER Title
        The title of the report, shown in the header, the page title, & as the heading

    .PARAMETER Subtitle
        A line of text shown next to the heading such as where the data came from

    .PARAMETER Property
        The properties shown as table columns

        By default the first 8 properties of the first object are used

    .PARAMETER ColumnName
        Hashtable of a property name & the column title to show for it

    .PARAMETER StatusMap
        Colors the values of a column as a status badge, see New-clNovaHtmlTable

        Example:
            @{ Support = @{ Yes = 'Success'; 'Ending Soon' = 'Warning'; No = 'Danger' } }

    .PARAMETER SummaryCard
        The summary cards shown above the table. Hashtables or objects with the properties of
        New-clNovaHtmlSummaryCard (Title, Value, Note, Percent, Color, Icon, Tooltip, & Url)

        The cards are laid out in rows that all have the same number of cards

    .PARAMETER MaxCardsPerRow
        The most summary cards on one row of a desktop screen

        Default value: 4

    .PARAMETER TableTitle
        The title shown in the header of the table

    .PARAMETER TableNote
        Notes shown in a list below the table

    .PARAMETER PageSize
        The number of table rows shown per page, 0 shows all rows

        Default value: 10

    .PARAMETER NavigationItem
        The links of the sidebar. Hashtables or objects with the properties Text, Url, Icon, & Heading

        Items with the same Heading are grouped under it. By default links to the summary & the table are shown

        Example:
            @{ Heading = 'Help'; Text = 'Documentation'; Url = 'https://celerium.org'; Icon = 'info-circle' }

    .PARAMETER BrandText
        The name shown at the top of the sidebar

        Default value: Celerium.Nova

    .PARAMETER BrandIcon
        The name of the Bootstrap Icon shown next to the name at the top of the sidebar

        Default value: speedometer2

    .PARAMETER BrandLogoPath
        The path of a logo image (png, jpg, gif, svg, or webp) that replaces the icon & the name at the top of the sidebar

        The logo is embedded in the report, so it is also shown when the computer is offline. The icon & the name
        are used as the alternative text. When the sidebar is collapsed only the left part (the symbol) of the logo is shown
        unless BrandLogoCollapsedPath is used

    .PARAMETER BrandLogoCollapsedPath
        The path of the logo image that is shown at the top of the sidebar when the sidebar is collapsed

        Only used with BrandLogoPath. BrandLogoPath is shown when the sidebar is expanded. A square image works best

    .PARAMETER FaviconPath
        The path of the icon (ico, png, or svg) that is shown on the browser tab

        The icon is embedded in the report. By default an icon of BrandIcon is used
    .PARAMETER BrandUrl
        The link of the name at the top of the sidebar

        Default value: #

    .PARAMETER Description
        The description meta tag of the page

    .PARAMETER Author
        The author meta tag of the page

    .PARAMETER Footer
        Text shown at the bottom of the page

        By default no footer is shown

    .PARAMETER ResourceMode
        How Bootstrap is added to the report

        Acceptable values:
            'Embedded','Cdn'

        Embedded places the files in the report so it works offline (default). Cdn links the Bootstrap 5.3
        files of the jsDelivr CDN, an internet connection is needed to view the report

    .PARAMETER ResourcePath
        The HtmlReport folder to read the templates, css, js, & icons from

        By default the folder of the module is used. Use this to change the look of the report

    .EXAMPLE
        Get-Service | New-clNovaHtmlReport -Title 'Services' -Property Name, Status, StartType -Path .\Services.html

        Creates an HTML report of the services & saves it to Services.html

    .EXAMPLE
        $Cards = @(
            @{ Title = 'Running'; Value = 120; Color = 'Success'; Icon = 'check-circle-fill' }
            @{ Title = 'Stopped'; Value = 80; Color = 'Danger'; Icon = 'x-circle-fill' }
        )
        $Services | New-clNovaHtmlReport -Title 'Services' -SummaryCard $Cards -StatusMap @{ Status = @{ Running = 'Success'; Stopped = 'Danger' } } -Path .\Services.html

        Creates a report with 2 summary cards & colors the Status column

    .EXAMPLE
        $Html = Get-Process | New-clNovaHtmlReport -Title 'Processes' -ResourceMode Cdn

        Returns the HTML text of a report that links to the Bootstrap CDN files

    .NOTES
        N\A

    .LINK
        https://celerium.github.io/Celerium.Nova/site/HtmlReport/New-clNovaHtmlReport.html
#>


    [CmdletBinding(SupportsShouldProcess = $true)]
    [OutputType([string], [System.IO.FileInfo])]
    param (
        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
        [AllowNull()]
        [object[]]$InputObject,

        [Parameter(Mandatory = $false)]
        [ValidateNotNullOrEmpty()]
        [string]$Path,

        [Parameter(Mandatory = $false)]
        [ValidateNotNullOrEmpty()]
        [string]$Title = 'Celerium.Nova Report',

        [Parameter(Mandatory = $false)]
        [string]$Subtitle,

        [Parameter(Mandatory = $false)]
        [ValidateNotNullOrEmpty()]
        [string[]]$Property,

        [Parameter(Mandatory = $false)]
        [System.Collections.IDictionary]$ColumnName,

        [Parameter(Mandatory = $false)]
        [System.Collections.IDictionary]$StatusMap,

        [Parameter(Mandatory = $false)]
        [object[]]$SummaryCard,

        [Parameter(Mandatory = $false)]
        [ValidateRange(1, 12)]
        [int]$MaxCardsPerRow = 4,

        [Parameter(Mandatory = $false)]
        [string]$TableTitle,

        [Parameter(Mandatory = $false)]
        [string[]]$TableNote,

        [Parameter(Mandatory = $false)]
        [ValidateRange(0, 100000)]
        [int]$PageSize = 10,

        [Parameter(Mandatory = $false)]
        [object[]]$NavigationItem,

        [Parameter(Mandatory = $false)]
        [ValidateNotNullOrEmpty()]
        [string]$BrandText = 'Celerium.Nova',

        [Parameter(Mandatory = $false)]
        [ValidateNotNullOrEmpty()]
        [string]$BrandIcon = 'speedometer2',

        [Parameter(Mandatory = $false)]
        [string]$BrandLogoPath,

        [Parameter(Mandatory = $false)]
        [string]$BrandLogoCollapsedPath,

        [Parameter(Mandatory = $false)]
        [string]$FaviconPath,

        [Parameter(Mandatory = $false)]
        [ValidatePattern('^(https?://|mailto:|#|\./|/)')]
        [string]$BrandUrl = '#',

        [Parameter(Mandatory = $false)]
        [string]$Description,

        [Parameter(Mandatory = $false)]
        [string]$Author = 'Celerium.Nova',

        [Parameter(Mandatory = $false)]
        [string]$Footer,

        [Parameter(Mandatory = $false)]
        [ValidateSet('Embedded', 'Cdn')]
        [string]$ResourceMode = 'Embedded',

        [Parameter(Mandatory = $false)]
        [string]$ResourcePath
    )

    begin {
        $Rows = [System.Collections.Generic.List[object]]::new()
    }

    process {
        foreach ($Item in $InputObject) { if ($null -ne $Item) { $Rows.Add($Item) } }
    }

    end {

        $Culture        = [System.Globalization.CultureInfo]::InvariantCulture
        $GeneratedAt    = [datetime]::Now.ToString('yyyy-MM-dd h:mmtt', $Culture).ToLowerInvariant()
        $ModuleVersion  = $null
        $LoadedModule   = @(Get-Module -Name Celerium.Nova)[0]
        if ($LoadedModule) { $ModuleVersion = $LoadedModule.Version.ToString() }
        $Generator      = if ($ModuleVersion) { "Celerium.Nova $ModuleVersion" } else { 'Celerium.Nova' }

        $Resources      = Get-clNovaHtmlResource -Name 'resources.json' -ResourcePath $ResourcePath | ConvertFrom-Json

        #Region [ Resources ]

        $RemoveSourceMap = { param ([string]$Text) [regex]::Replace($Text, '(?m)^\s*(/\*#|//#) sourceMappingURL=.*$', '') }

        if ($ResourceMode -eq 'Cdn') {
            $BootstrapCss   = ' <link rel="stylesheet" href="{0}" integrity="{1}" crossorigin="anonymous">' -f $Resources.Bootstrap.Css.Cdn, $Resources.Bootstrap.Css.Integrity
            $BootstrapJs    = ' <script src="{0}" integrity="{1}" crossorigin="anonymous"></script>' -f $Resources.Bootstrap.Js.Cdn, $Resources.Bootstrap.Js.Integrity
        }
        else {
            $BootstrapCss   = " <style>`n{0}`n </style>" -f (& $RemoveSourceMap (Get-clNovaHtmlResource -Name $Resources.Bootstrap.Css.File -ResourcePath $ResourcePath)).Trim()
            $BootstrapJs    = " <script>`n{0}`n </script>" -f (& $RemoveSourceMap (Get-clNovaHtmlResource -Name $Resources.Bootstrap.Js.File -ResourcePath $ResourcePath)).Trim()
        }

        $Css = (Get-clNovaHtmlResource -Name 'css/Celerium.Nova.css' -ResourcePath $ResourcePath).Trim()
        $Js  = (Get-clNovaHtmlResource -Name 'js/Celerium.Nova.js' -ResourcePath $ResourcePath).Trim()

        # The favicon is embedded as well, an svg favicon of the brand icon is used when there is no FaviconPath
        $FaviconHtml = ''
        $BrandSvg    = Get-clNovaHtmlIcon -Name $BrandIcon -ResourcePath $ResourcePath
        if ($FaviconPath) {
            $FaviconUri  = ConvertTo-clNovaHtmlDataUri -Path $FaviconPath
            $FaviconHtml = ' <link rel="icon" href="{0}">' -f $FaviconUri
        }
        elseif ($BrandSvg) {
            $FaviconSvg  = [regex]::Replace($BrandSvg, 'fill="currentColor"', 'fill="#212529"')
            $FaviconHtml = ' <link rel="icon" type="image/svg+xml" href="data:image/svg+xml;base64,{0}">' -f [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($FaviconSvg))
        }

        #EndRegion [ Resources ]

        #Region [ Summary cards & table ]

        $CardsHtml = ''
        if ($SummaryCard) {
            $CardsHtml = New-clNovaHtmlSummaryCardSet -Card $SummaryCard -MaxPerRow $MaxCardsPerRow -ResourcePath $ResourcePath
        }

        $TableParameters = @{
            Title       = $TableTitle
            Id          = 'psn-table'
            PageSize    = $PageSize
            Note        = $TableNote
        }
        if ($ResourcePath)  { $TableParameters['ResourcePath'] = $ResourcePath }
        if ($Property)      { $TableParameters['Property'] = $Property }
        if ($ColumnName)    { $TableParameters['ColumnName'] = $ColumnName }
        if ($StatusMap)     { $TableParameters['StatusMap'] = $StatusMap }

        $TableHtml = New-clNovaHtmlTable -InputObject $Rows.ToArray() @TableParameters

        #EndRegion [ Summary cards & table ]

        #Region [ Sidebar ]

        if (-not $NavigationItem) {

            $NavigationItem = @()
            if ($CardsHtml) { $NavigationItem += @{ Heading = 'Report'; Text = 'Summary'; Url = '#psn-summary'; Icon = 'speedometer2' } }
            $NavigationItem += @{ Heading = 'Report'; Text = 'Data'; Url = '#psn-table-card'; Icon = 'table' }

        }

        $NavigationHtml     = [System.Text.StringBuilder]::new()
        $PreviousHeading    = $null

        foreach ($Item in $NavigationItem) {

            $ItemValues = @{ Text = $null; Url = '#'; Icon = 'info-circle'; Heading = $null }

            foreach ($Name in 'Text', 'Url', 'Icon', 'Heading') {

                $ItemValue = $null
                if ($Item -is [System.Collections.IDictionary]) { if ($Item.Contains($Name)) { $ItemValue = $Item[$Name] } }
                elseif ($Item.PSObject.Properties[$Name])       { $ItemValue = $Item.PSObject.Properties[$Name].Value }

                if ($ItemValue) { $ItemValues[$Name] = [string]$ItemValue }

            }

            $ItemText       = $ItemValues['Text']
            $ItemUrl        = $ItemValues['Url']
            $ItemIcon       = $ItemValues['Icon']
            $ItemHeading    = $ItemValues['Heading']

            if (-not $ItemText) { continue }
            if ($ItemUrl -notmatch '^(https?://|mailto:|#|\./|/)') { $ItemUrl = '#' }

            if ($ItemHeading -and $ItemHeading -ne $PreviousHeading) {
                [void]$NavigationHtml.AppendLine((' <div class="psn-sidebar-heading">{0}</div>' -f (ConvertTo-clNovaHtmlEncoded -InputObject $ItemHeading)))
                $PreviousHeading = $ItemHeading
            }

            $External   = if ($ItemUrl -match '^https?://') { ' target="_blank" rel="noopener noreferrer"' } else { '' }
            $EncodedText = ConvertTo-clNovaHtmlEncoded -InputObject $ItemText

            [void]$NavigationHtml.AppendLine((' <a class="nav-link" href="{0}"{1} title="{2}">{3}<span class="psn-sidebar-text">{2}</span></a>' -f (ConvertTo-clNovaHtmlEncoded -InputObject $ItemUrl), $External, $EncodedText, (Get-clNovaHtmlIcon -Name $ItemIcon -ResourcePath $ResourcePath)))

        }

        $SidebarTemplate = Get-clNovaHtmlResource -Name 'templates/Sidebar.html' -ResourcePath $ResourcePath

        $BrandContent = '{0}{1} <span class="psn-sidebar-text">{2}</span>' -f $BrandSvg, "`n", (ConvertTo-clNovaHtmlEncoded -InputObject $BrandText)

        if ($BrandLogoPath) {

            # The logos are embedded in the page so they are also shown when the computer is offline
            $LogoAlt  = ConvertTo-clNovaHtmlEncoded -InputObject $BrandText
            $LogoData = ConvertTo-clNovaHtmlDataUri -Path $BrandLogoPath

            if ($BrandLogoCollapsedPath) {
                $CollapsedData = ConvertTo-clNovaHtmlDataUri -Path $BrandLogoCollapsedPath
                $BrandContent  = '<img class="psn-brand-logo psn-brand-logo-expanded" src="{0}" alt="{2}">{3} <img class="psn-brand-logo-collapsed" src="{1}" alt="{2}">' -f $LogoData, $CollapsedData, $LogoAlt, "`n"
            }
            else {
                $BrandContent  = '<img class="psn-brand-logo" src="{0}" alt="{1}">' -f $LogoData, $LogoAlt
            }

        }

        $SidebarHtml = Expand-clNovaHtmlTemplate -Template $SidebarTemplate -Token @{
            BrandUrl            = ConvertTo-clNovaHtmlEncoded -InputObject $BrandUrl
            BrandText           = ConvertTo-clNovaHtmlEncoded -InputObject $BrandText
            BrandContent        = $BrandContent
            NavigationItems     = $NavigationHtml.ToString().TrimEnd()
            FooterLabel         = 'Generated At:'
            FooterValue         = ConvertTo-clNovaHtmlEncoded -InputObject $GeneratedAt
        }

        #EndRegion [ Sidebar ]

        $TopbarTemplate = Get-clNovaHtmlResource -Name 'templates/Topbar.html' -ResourcePath $ResourcePath

        $TopbarHtml = Expand-clNovaHtmlTemplate -Template $TopbarTemplate -Token @{
            ToggleIcon  = Get-clNovaHtmlIcon -Name 'list' -ResourcePath $ResourcePath
        }

        $FooterHtml = ''
        if ($Footer) { $FooterHtml = ' <footer class="psn-footer">{0}</footer>' -f (ConvertTo-clNovaHtmlEncoded -InputObject $Footer) }

        $PageTemplate = Get-clNovaHtmlResource -Name 'templates/Page.html' -ResourcePath $ResourcePath

        $Html = Expand-clNovaHtmlTemplate -Template $PageTemplate -Token @{
            Description     = ConvertTo-clNovaHtmlEncoded -InputObject $(if ($Description) { $Description } else { $Title })
            Author          = ConvertTo-clNovaHtmlEncoded -InputObject $Author
            Generator       = ConvertTo-clNovaHtmlEncoded -InputObject $Generator
            Title           = ConvertTo-clNovaHtmlEncoded -InputObject $Title
            Heading         = ConvertTo-clNovaHtmlEncoded -InputObject $Title
            Subtitle        = ConvertTo-clNovaHtmlEncoded -InputObject $Subtitle
            Favicon         = $FaviconHtml
            BootstrapCss    = $BootstrapCss
            BootstrapJs     = $BootstrapJs
            Css             = $Css
            Js              = $Js
            Sidebar         = $SidebarHtml
            Topbar          = $TopbarHtml
            SummaryCards    = $CardsHtml
            Body            = $TableHtml
            Footer          = $FooterHtml
        }

        if (-not $Path) { return $Html }

        $FullPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path)

        if ($PSCmdlet.ShouldProcess($FullPath, 'Create the HTML report')) {

            $Folder = Split-Path -Path $FullPath -Parent
            if ($Folder -and -not (Test-Path -Path $Folder -PathType Container)) { New-Item -Path $Folder -ItemType Directory -Force > $null }

            [System.IO.File]::WriteAllText($FullPath, $Html, [System.Text.UTF8Encoding]::new($false))

            return (Get-Item -Path $FullPath)

        }

    }

}
#EndRegion './Public/HtmlReport/New-clNovaHtmlReport.ps1' 445
#Region './Public/HtmlReport/New-clNovaHtmlSummaryCard.ps1' -1

function New-clNovaHtmlSummaryCard {
<#
    .SYNOPSIS
        Creates the HTML of one summary card

    .DESCRIPTION
        The New-clNovaHtmlSummaryCard cmdlet creates the HTML of a single summary card for an HTML
        report. A summary card shows one quick fact about the data in the report such as a
        total, a percentage, or a link

        A card can show a progress bar (Percent), a small note, an icon, & a tooltip. A card
        with a Url is a link

        The cards are placed on the page with New-clNovaHtmlSummaryCardSet which creates evenly
        filled rows of cards. The HTML needs the Celerium.Nova report css to look right, use
        New-clNovaHtmlReport to create a complete page

    .PARAMETER Title
        The title of the card

    .PARAMETER Value
        The main value of the card such as a total or text like [ 14 | 61% ]

    .PARAMETER Note
        A small line of text shown below the value

    .PARAMETER Percent
        Shows a progress bar that is filled with this percentage (0 - 100)

    .PARAMETER Color
        The color of the card border, title, & progress bar

        Acceptable values:
            'Primary','Success','Info','Warning','Danger','Secondary','Dark'

        Default value: Primary

    .PARAMETER Icon
        The name of a Bootstrap Icon to show on the card

        Default value: clipboard-data

        Icons that can be used are listed in build\HtmlReport\resources.json

    .PARAMETER Tooltip
        The text that is shown when the mouse is over the card

    .PARAMETER Url
        Makes the card a link. Only http, https, mailto, & page (#) links are allowed

    .PARAMETER ResourcePath
        The HtmlReport folder to read the templates & icons from

        By default the folder of the module is used

    .EXAMPLE
        New-clNovaHtmlSummaryCard -Title 'Total Computers' -Value 23 -Icon 'laptop' -Color Primary

        Returns the HTML of a card that shows the total number of computers

    .EXAMPLE
        New-clNovaHtmlSummaryCard -Title 'Supported' -Value '14 | 61%' -Percent 61 -Color Success -Icon 'check-circle-fill' -Tooltip 'Systems Microsoft supports'

        Returns the HTML of a card with a progress bar that is 61% full

    .EXAMPLE
        New-clNovaHtmlSummaryCard -Title 'Microsoft Lifecycles' -Value 'learn.microsoft.com' -Url 'https://learn.microsoft.com/en-us/lifecycle/products/' -Color Info

        Returns the HTML of a card that opens the Microsoft lifecycle pages

    .NOTES
        N\A

    .LINK
        https://celerium.github.io/Celerium.Nova/site/HtmlReport/New-clNovaHtmlSummaryCard.html
#>


    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Only returns HTML text, nothing is changed')]
    [CmdletBinding()]
    [OutputType([string])]
    param (
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string]$Title,

        [Parameter(Mandatory = $true)]
        [AllowEmptyString()]
        [object]$Value,

        [Parameter(Mandatory = $false)]
        [string]$Note,

        [Parameter(Mandatory = $false)]
        [ValidateRange(0, 100)]
        [double]$Percent,

        [Parameter(Mandatory = $false)]
        [ValidateSet('Primary', 'Success', 'Info', 'Warning', 'Danger', 'Secondary', 'Dark')]
        [string]$Color = 'Primary',

        [Parameter(Mandatory = $false)]
        [ValidateNotNullOrEmpty()]
        [string]$Icon = 'clipboard-data',

        [Parameter(Mandatory = $false)]
        [string]$Tooltip,

        [Parameter(Mandatory = $false)]
        [ValidatePattern('^(https?://|mailto:|#|\./|/)')]
        [string]$Url,

        [Parameter(Mandatory = $false)]
        [string]$ResourcePath
    )

    $Template = Get-clNovaHtmlResource -Name 'templates/SummaryCard.html' -ResourcePath $ResourcePath

    $TitleHtml = ConvertTo-clNovaHtmlEncoded -InputObject $Title
    if ($Url) {
        $TitleHtml = '<a class="stretched-link" href="{0}" target="_blank" rel="noopener noreferrer">{1}</a>' -f (ConvertTo-clNovaHtmlEncoded -InputObject $Url), $TitleHtml
    }

    $ProgressHtml = ''
    if ($PSBoundParameters.ContainsKey('Percent')) {
        $Width        = [Math]::Round($Percent, 1).ToString([System.Globalization.CultureInfo]::InvariantCulture)
        $ProgressHtml = ' <div class="progress mt-2" role="progressbar" aria-label="{0}" aria-valuenow="{1}" aria-valuemin="0" aria-valuemax="100"><div class="progress-bar" style="width: {1}%"></div></div>{2}' -f (ConvertTo-clNovaHtmlEncoded -InputObject $Title), $Width, "`n"
    }

    $NoteHtml = ''
    if ($Note) {
        $NoteHtml = ' <div class="psn-card-note mt-1">{0}</div>{1}' -f (ConvertTo-clNovaHtmlEncoded -InputObject $Note), "`n"
    }

    $TooltipAttribute = ''
    if ($Tooltip) { $TooltipAttribute = ' title="{0}"' -f (ConvertTo-clNovaHtmlEncoded -InputObject $Tooltip) }

    $Tokens = @{
        ColorClass          = 'psn-c-' + $Color.ToLowerInvariant()
        TooltipAttribute    = $TooltipAttribute
        Title               = $TitleHtml
        Value               = ConvertTo-clNovaHtmlEncoded -InputObject $Value
        Progress            = $ProgressHtml
        Note                = $NoteHtml
        Icon                = Get-clNovaHtmlIcon -Name $Icon -ResourcePath $ResourcePath
    }

    return (Expand-clNovaHtmlTemplate -Template $Template -Token $Tokens)

}
#EndRegion './Public/HtmlReport/New-clNovaHtmlSummaryCard.ps1' 150
#Region './Public/HtmlReport/New-clNovaHtmlSummaryCardSet.ps1' -1

function New-clNovaHtmlSummaryCardSet {
<#
    .SYNOPSIS
        Creates the HTML of a group of summary cards that are laid out in evenly filled rows

    .DESCRIPTION
        The New-clNovaHtmlSummaryCardSet cmdlet creates the HTML of any number of summary cards &
        scales the layout to fit them. Every row has the same number of cards

            6 cards -> 2 rows of 3 cards
            12 cards -> 3 rows of 4 cards

        At most MaxPerRow cards are placed on one row of a desktop screen, tablets show 2 cards per
        row, & phones show 1 card per row. A row that can not be filled evenly (for example 7 cards)
        is centered

        Every card is defined by a hashtable or an object with the same properties as the
        parameters of New-clNovaHtmlSummaryCard (Title, Value, Note, Percent, Color, Icon, Tooltip, & Url)

    .PARAMETER Card
        One or more cards, hashtables or objects with the properties of New-clNovaHtmlSummaryCard

        Example:
            @{ Title = 'Total'; Value = 23; Icon = 'laptop' }

    .PARAMETER MaxPerRow
        The most cards that are placed on one row of a desktop screen

        Default value: 4

    .PARAMETER Id
        The HTML id of the group, can be used as an anchor (#psn-summary)

        Default value: psn-summary

    .PARAMETER ResourcePath
        The HtmlReport folder to read the templates & icons from

        By default the folder of the module is used

    .EXAMPLE
        $Cards = 1..6 | ForEach-Object { @{ Title = "Card $_"; Value = $_ } }
        New-clNovaHtmlSummaryCardSet -Card $Cards

        Returns the HTML of 6 cards placed on 2 rows with 3 cards on each row

    .EXAMPLE
        $Cards = @(
            @{ Title = 'Supported'; Value = '14 | 61%'; Percent = 61; Color = 'Success'; Icon = 'check-circle-fill' }
            [PSCustomObject]@{ Title = 'Total'; Value = 23; Icon = 'laptop' }
        )
        $Cards | New-clNovaHtmlSummaryCardSet -MaxPerRow 6

        Returns the HTML of 2 cards, cards can be sent down the pipeline

    .NOTES
        N\A

    .LINK
        https://celerium.github.io/Celerium.Nova/site/HtmlReport/New-clNovaHtmlSummaryCardSet.html
#>


    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Only returns HTML text, nothing is changed')]
    [CmdletBinding()]
    [OutputType([string])]
    param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [ValidateNotNull()]
        [object[]]$Card,

        [Parameter(Mandatory = $false)]
        [ValidateRange(1, 12)]
        [int]$MaxPerRow = 4,

        [Parameter(Mandatory = $false)]
        [ValidatePattern('^[A-Za-z][A-Za-z0-9_-]*$')]
        [string]$Id = 'psn-summary',

        [Parameter(Mandatory = $false)]
        [string]$ResourcePath
    )

    begin {
        $AllCards = [System.Collections.Generic.List[object]]::new()
    }

    process {
        foreach ($Item in $Card) { if ($null -ne $Item) { $AllCards.Add($Item) } }
    }

    end {

        if ($AllCards.Count -eq 0) { return '' }

        $CardParameters = 'Title', 'Value', 'Note', 'Percent', 'Color', 'Icon', 'Tooltip', 'Url'

        $CardHtml = foreach ($Item in $AllCards) {

            $Splat = @{}

            foreach ($Name in $CardParameters) {

                $Property = $null

                if ($Item -is [System.Collections.IDictionary]) { if ($Item.Contains($Name)) { $Property = $Item[$Name] } else { continue } }
                elseif ($Item.PSObject.Properties[$Name])       { $Property = $Item.PSObject.Properties[$Name].Value }
                else                                            { continue }

                if ($null -ne $Property -and "$Property" -ne '' -or $Name -eq 'Value') { $Splat[$Name] = $Property }

            }

            if (-not $Splat.ContainsKey('Value')) { $Splat['Value'] = '' }
            if ($ResourcePath) { $Splat['ResourcePath'] = $ResourcePath }

            New-clNovaHtmlSummaryCard @Splat

        }

        $Layout = Get-clNovaCardLayout -Count $AllCards.Count -MaxPerRow $MaxPerRow

        $Style = '--psn-cols-xl: {0}; --psn-cols-md: {1}; --psn-cols-sm: {2};' -f $Layout.Xl, $Layout.Md, $Layout.Sm

        return (' <section class="psn-card-grid" id="{0}" style="{1}" data-psn-cards="{2}" data-psn-rows="{3}" aria-label="Summary">{4}{5}{4} </section>{4}' -f (ConvertTo-clNovaHtmlEncoded -InputObject $Id), $Style, $Layout.Count, $Layout.Rows, "`n", ($CardHtml -join ''))

    }

}
#EndRegion './Public/HtmlReport/New-clNovaHtmlSummaryCardSet.ps1' 129
#Region './Public/HtmlReport/New-clNovaHtmlTable.ps1' -1

function New-clNovaHtmlTable {
<#
    .SYNOPSIS
        Creates the HTML of a sortable, searchable table card from PowerShell objects

    .DESCRIPTION
        The New-clNovaHtmlTable cmdlet converts PowerShell objects into the HTML of a table card
        for an HTML report

        The table
            - Can be sorted by clicking any column header (numbers, dates, & text are sorted correctly)
            - Can be searched & shows a configurable number of rows per page
            - Highlights the entire row when the mouse is over it
            - Scrolls sideways on small screens instead of breaking the page

        Only the properties in the Property parameter are shown (in that order). When it is not
        used the first 8 properties of the first object are shown so that the table fits on a typical
        monitor without a lot of horizontal scrolling

        All values are HTML encoded. The sorting, search, & paging are done by the script of the Celerium.Nova
        report (build\HtmlReport\js\Celerium.Nova.js) which New-clNovaHtmlReport adds to the page

    .PARAMETER InputObject
        The objects to show in the table, hashtables are also accepted

    .PARAMETER Property
        The names of the properties to show as columns

        By default the first 8 properties of the first object are used

    .PARAMETER ColumnName
        Hashtable of a property name & the column title to show for it

        Example:
            @{ OSVersion = 'OS Version'; EndOfSupport = 'End Of Support' }

    .PARAMETER StatusMap
        Colors the values of a column as a status badge

        Hashtable of a property name & a hashtable of values & colors

        Acceptable colors:
            'Primary','Success','Info','Warning','Danger','Secondary','Dark'

        Example:
            @{ Support = @{ Yes = 'Success'; 'Ending Soon' = 'Warning'; No = 'Danger' } }

    .PARAMETER Title
        The title shown in the header of the table card

    .PARAMETER Id
        The HTML id of the table

        Default value: psn-table

    .PARAMETER PageSize
        The number of rows shown per page, 0 shows all rows

        Default value: 10

    .PARAMETER Note
        Notes that are shown in a list below the table

    .PARAMETER DateFormat
        The format of date values

        Default value: yyyy-MM-dd HH:mm

    .PARAMETER ResourcePath
        The HtmlReport folder to read the templates from

        By default the folder of the module is used

    .EXAMPLE
        Get-Process | Select-Object -First 50 | New-clNovaHtmlTable -Property Name, Id, CPU -Title 'Processes'

        Returns the HTML of a table card that shows the Name, Id, & CPU of 50 processes

    .EXAMPLE
        $Data | New-clNovaHtmlTable -Property ComputerName, Support -StatusMap @{ Support = @{ Yes = 'Success'; No = 'Danger' } }

        Returns the HTML of a table where the Support column is shown as green & red badges

    .NOTES
        N\A

    .LINK
        https://celerium.github.io/Celerium.Nova/site/HtmlReport/New-clNovaHtmlTable.html
#>


    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Only returns HTML text, nothing is changed')]
    [CmdletBinding()]
    [OutputType([string])]
    param (
        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
        [AllowNull()]
        [object[]]$InputObject,

        [Parameter(Mandatory = $false)]
        [ValidateNotNullOrEmpty()]
        [string[]]$Property,

        [Parameter(Mandatory = $false)]
        [System.Collections.IDictionary]$ColumnName,

        [Parameter(Mandatory = $false)]
        [System.Collections.IDictionary]$StatusMap,

        [Parameter(Mandatory = $false)]
        [string]$Title,

        [Parameter(Mandatory = $false)]
        [ValidatePattern('^[A-Za-z][A-Za-z0-9_-]*$')]
        [string]$Id = 'psn-table',

        [Parameter(Mandatory = $false)]
        [ValidateRange(0, 100000)]
        [int]$PageSize = 10,

        [Parameter(Mandatory = $false)]
        [string[]]$Note,

        [Parameter(Mandatory = $false)]
        [ValidateNotNullOrEmpty()]
        [string]$DateFormat = 'yyyy-MM-dd HH:mm',

        [Parameter(Mandatory = $false)]
        [string]$ResourcePath
    )

    begin {
        $Rows = [System.Collections.Generic.List[object]]::new()
    }

    process {
        foreach ($Item in $InputObject) {
            if ($null -eq $Item) { continue }
            if ($Item -is [System.Collections.IDictionary]) { $Item = [PSCustomObject]$Item }
            $Rows.Add($Item)
        }
    }

    end {

        $Culture        = [System.Globalization.CultureInfo]::InvariantCulture
        $Colors         = 'primary', 'success', 'info', 'warning', 'danger', 'secondary', 'dark'

        $Columns = $Property
        if (-not $Columns) {
            $Columns = if ($Rows.Count -gt 0) { @(@($Rows[0].PSObject.Properties.Name)[0..7] | Where-Object { $_ }) } else { @() }
        }

        # Headers
        $HeaderHtml = foreach ($Name in $Columns) {

            $Text = if ($ColumnName -and $ColumnName.Contains($Name)) { [string]$ColumnName[$Name] } else { $Name }

            '<th scope="col">{0}</th>' -f (ConvertTo-clNovaHtmlEncoded -InputObject $Text)

        }

        # Rows
        $RowHtml = [System.Text.StringBuilder]::new()

        foreach ($Row in $Rows) {

            [void]$RowHtml.Append(' <tr>')

            foreach ($Name in $Columns) {

                $Member     = $Row.PSObject.Properties[$Name]
                $Value      = if ($Member) { $Member.Value } else { $null }
                $SortValue  = $null

                if ($Value -is [datetime]) {
                    $Text       = $Value.ToString($DateFormat, $Culture)
                    $SortValue  = $Value.ToString('yyyy-MM-ddTHH:mm:ss', $Culture)
                }
                elseif ($Value -is [System.Collections.IEnumerable] -and $Value -isnot [string]) {
                    $Text = (@($Value | ForEach-Object { "$_" }) -join '; ')
                }
                elseif ($null -eq $Value) { $Text = '' }
                else {
                    $Text = [string]::Format($Culture, '{0}', $Value)
                }

                $Encoded    = ConvertTo-clNovaHtmlEncoded -InputObject $Text
                $Color      = $null

                if ($StatusMap -and $StatusMap.Contains($Name) -and $StatusMap[$Name] -is [System.Collections.IDictionary] -and $Text -ne '' -and $StatusMap[$Name].Contains($Text)) {
                    $Color = ([string]$StatusMap[$Name][$Text]).ToLowerInvariant()
                    if ($Color -notin $Colors) { $Color = 'secondary' }
                    $Encoded = '<span class="psn-badge psn-c-{0}">{1}</span>' -f $Color, $Encoded
                }

                $SortAttribute = if ($null -ne $SortValue) { ' data-sort="{0}"' -f $SortValue } else { '' }

                [void]$RowHtml.Append('<td').Append($SortAttribute).Append('>').Append($Encoded).Append('</td>')

            }

            [void]$RowHtml.AppendLine('</tr>')

        }

        # Page size choices
        $Sizes = @(10, 25, 50, 0)
        if ($PageSize -notin $Sizes) { $Sizes = @($PageSize) + $Sizes | Sort-Object { if ($_ -eq 0) { [int]::MaxValue } else { $_ } } }

        $SizeOptions = foreach ($Size in $Sizes) {
            $Label = if ($Size -eq 0) { 'All' } else { "$Size" }
            ' <option value="{0}"{1}>{2}</option>' -f $Size, $(if ($Size -eq $PageSize) { ' selected' } else { '' }), $Label
        }

        $HeaderCard = ''
        if ($Title) { $HeaderCard = ' <div class="card-header py-3">{0}</div>{1}' -f (ConvertTo-clNovaHtmlEncoded -InputObject $Title), "`n" }

        $NotesHtml = ''
        if ($Note) {
            $NotesHtml = ' <ul class="psn-table-notes">{0}{1} </ul>{0}' -f "`n", ((@($Note | ForEach-Object { ' <li>{0}</li>{1}' -f (ConvertTo-clNovaHtmlEncoded -InputObject $_), "`n" })) -join '')
        }

        $Template = Get-clNovaHtmlResource -Name 'templates/Table.html' -ResourcePath $ResourcePath

        $Tokens = @{
            Id                  = ConvertTo-clNovaHtmlEncoded -InputObject $Id
            CardHeader          = $HeaderCard
            PageSize            = $PageSize
            PageSizeOptions     = ($SizeOptions -join "`n")
            Headers             = ($HeaderHtml -join '')
            Rows                = $RowHtml.ToString().TrimEnd()
            Notes               = $NotesHtml
        }

        return (Expand-clNovaHtmlTemplate -Template $Template -Token $Tokens)

    }

}
#EndRegion './Public/HtmlReport/New-clNovaHtmlTable.ps1' 240