Src/Private/Add-DiaHtmlSignatureTable.ps1

function Add-DiaHtmlSignatureTable {
    <#
    .SYNOPSIS
        Converts a string array to an HTML table for use in a Signature table.
 
    .DESCRIPTION
        The Add-DiaHtmlSignatureTable function generates an HTML table representation from a string array, suitable for use as a Signature table, such as in GraphViz labels. It supports customization of table appearance, cell formatting, font styles, and inclusion of a logo image from a provided hashtable. The function also offers debug mode and various style options.
 
    .PARAMETER Rows
        An array of strings/objects to place in the table rows.
 
    .PARAMETER Align
        Alignment of content inside table cells. Default is 'Center'.
 
    .PARAMETER TableBorder
        The table border thickness. Default is 0.
 
    .PARAMETER CellBorder
        The table cell border thickness. Default is 0.
 
    .PARAMETER CellSpacing
        The table cell spacing. Default is 5.
 
    .PARAMETER CellPadding
        The table cell padding space. Default is 5.
 
    .PARAMETER fontSize
        The text font size used inside the cell. Default is 14.
 
    .PARAMETER fontName
        The text font name used inside the cell. Default is "Segoe Ui".
 
    .PARAMETER fontColor
        The text font color used inside the cell. Default is "#000000".
 
    .PARAMETER ImagesObj
        Hashtable mapping IconName to IconPath. Required for logo image support.
 
    .PARAMETER IconDebug
        Enables table debug mode, highlighting table borders and logo cell.
 
    .PARAMETER TableStyle
        Sets the table style (e.g., "ROUNDED", "RADIAL", "SOLID", "INVISIBLE", "INVIS", "DOTTED", "DASHED"). Styles can be combined.
 
    .PARAMETER NoFontBold
        Disables bold formatting for additional node info text.
 
    .PARAMETER Label
        Sets the SubGraph label.
 
    .PARAMETER Logo
        Icon name used to represent the node type, resolved from ImagesObj.
 
    .PARAMETER TableBorderColor
        Sets the subgraph table border color. Default is "#000000".
 
    .OUTPUTS
        [System.String] - Returns the generated HTML table as a string.
 
    .EXAMPLE
        Add-DiaHtmlSignatureTable -ImagesObj $Images -Rows "Author: Bugs Bunny", "Company: ACME Inc." -TableBorder 2 -CellBorder 0 -Align 'left' -Logo "Logo_Footer" -DraftMode:$DraftMode
 
    .NOTES
        Version: 0.2.30
        Author: Jonathan Colon
        Bluesky: @jcolonfpr.bsky.social
        Github: rebelinux
    #>


    [CmdletBinding()]
    [OutputType([System.String])]
    param(
        [Parameter(
            Mandatory = $true,
            HelpMessage = 'The table array to process'
        )]
        [string[]] $Rows,

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Allow to set the text align'
        )]
        [string] $Align = 'Center',

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Allow to set the width of the html table border'
        )]
        [int] $TableBorder = 0,

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Allow to set the width of the html cell border'
        )]
        [int] $CellBorder = 0,

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Allow to set the spacing of the html cell border'
        )]
        [int] $CellSpacing = 5,

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Allow to set the padding of the html cell border'
        )]
        [int] $CellPadding = 5,

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'The cell text font size'
        )]
        [int] $FontSize = 14,

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'The cell text font name'
        )]
        [string] $FontName = 'Segoe Ui',

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'The cell text font color'
        )]
        [string] $FontColor = '#000000',

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Allow to set the font bold'
        )]
        [switch] $FontBold,

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Allow to set the font italic'
        )]
        [switch] $FontItalic,

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Allow to set the font underline'
        )]
        [switch] $FontUnderline,

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Allow to set the font overline'
        )]
        [switch] $FontOverline,

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Allow to set the font subscript'
        )]
        [switch] $FontSubscript,

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Allow to set the font superscript'
        )]
        [switch] $FontSuperscript,

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Allow to set the font strikethrough'
        )]
        [switch] $FontStrikeThrough,

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Include the full path for the icon images'
        )]
        [System.IO.FileInfo] $IconPath,

        [Parameter(
            Mandatory = $true,
            HelpMessage = 'Please provide the Image Hashtable Object'
        )]
        [Hashtable] $ImagesObj = @{},

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Enable the icon debug mode'
        )]
        [Alias('DraftMode')]
        [bool] $IconDebug,

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Set the image size in percent (100% is default)'
        )]
        [ValidateRange(1, 100)]
        [int] $ImageSizePercent = 100,

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Allow to set a table style (ROUNDED, RADIAL, SOLID, INVISIBLE, INVIS, DOTTED, and DASHED)'
        )]
        [string] $TableStyle = 'rounded,dashed',

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Disable the aditional text bold configuration'
        )]
        [Switch] $NoFontBold,


        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Allow to set the subgraph table label'
        )]
        [string]$Label,
        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Allow to set the logo icon'
        )]
        [string]$Logo,

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Allow to set a table border color'
        )]
        [string]$TableBorderColor = '#000000',

        [Parameter(
            Mandatory = $false,
            HelpMessage = 'Used inside Graphviz to modify the head or tail of an edge, so that the end attaches directly to the object'
        )]
        [string] $Port = 'EdgeDot'
    )

    if ($ImagesObj[$Logo]) {
        $ICON = $ImagesObj[$Logo]
    } else { $ICON = $false }

    if ($ImageSizePercent -lt 100) {
        if (-not $IconPath) {
            throw 'IconPath is required when ImageSizePercent is less than 100.'
        }
        $ImageSize = Get-DiaImagePercent -ImageInput (Join-Path -Path $IconPath -Child $ICON) -Percent $ImageSizePercent
    }

    $TR = ''
    foreach ($Row in $Rows) {
        $FormattedRow = Format-HtmlFontProperty -Text $Row -FontSize $FontSize -FontColor $FontColor -FontBold:$FontBold -FontItalic:$FontItalic -FontUnderline:$FontUnderline -FontName $FontName -FontSubscript:$FontSubscript -FontSuperscript:$FontSuperscript -FontStrikeThrough:$FontStrikeThrough -FontOverline:$FontOverline

        if ($NoFontBold) {
            $TR += '<TR><TD valign="top" align="{0}" colspan="2">{1}</TD></TR>' -f $Align, $FormattedRow
        } else {
            $TR += '<TR><TD valign="top" align="{0}" colspan="2">{1}</TD></TR>' -f $Align, $FormattedRow
        }
    }

    if ($ICON) {
        if ($IconDebug) {
            $TRContent = '<TR><TD bgcolor="#FFCCCC" ALIGN="{0}" colspan="1" rowspan="4">{1}</TD></TR>{2}' -f $Align, $ICON, $TR

            Format-HtmlTable -Port $Port -TableStyle $TableStyle -TableBorder $TableBorder -CellSpacing $CellSpacing -CellPadding $CellPadding -TableRowContent $TRContent -CellBorder $CellBorder
        } else {
            if ($ImageSize) {
                $TRContent = '<TR><TD ALIGN="{0}" fixedsize="true" width="{1}" height="{2}" colspan="1" rowspan="4"><img src="{3}"/></TD></TR>{4}' -f $Align, $ImageSize.Width, $ImageSize.Height, $ICON, $TR

                Format-HtmlTable -TableStyle $TableBorderStyle -TableBorder $TableBorder -TableBorderColor $TableBorderColor -CellBorder 0 -TableRowContent $TRContent

            } else {
                $TRContent = '<TR><TD fixedsize="true" width="80" height="80" ALIGN="{0}" colspan="1" rowspan="4"><img src="{1}"/></TD></TR>{2}' -f $Align, $ICON, $TR

                Format-HtmlTable -Port $Port -TableStyle $TableStyle -TableBorderColor $TableBorderColor -TableBorder $TableBorder -CellSpacing $CellSpacing -CellPadding $CellPadding -TableRowContent $TRContent -CellBorder $CellBorder
            }
        }
    } else {
        if ($IconDebug) {
            $TRContent = $TR

            Format-HtmlTable -Port $Port -TableStyle $TableStyle -TableBorderColor $TableBorderColor -TableBorder $TableBorder -CellSpacing $CellSpacing -CellPadding $CellPadding -TableRowContent $TRContent -CellBorder $CellBorder
        } else {
            $TRContent = $TR

            Format-HtmlTable -Port $Port -TableStyle $TableStyle -TableBorderColor $TableBorderColor -TableBorder $TableBorder -CellSpacing $CellSpacing -CellPadding $CellPadding -TableRowContent $TRContent -CellBorder $CellBorder
        }
    }
}