<?php

/**
 * Render a DNS record table extracted from a zonefile.
 *
 * @param string $zone
 * @param array $records  Each record:
 *   [
 *      'name'   => 'www',
 *      'ttl'    => '300',
 *      'class'  => 'IN',
 *      'type'   => 'A',
 *      'value'  => '192.168.1.10'
 *   ]
 *
 * @return string
 */
function render_dns_record_table(string $zone, array $records): string {
    $safeZone = htmlspecialchars($zone);

    $html = "
    <div class='dns-record-table'>
        <h3>DNS Records for {$safeZone}</h3>
        <table class='dns-table'>
            <thead>
                <tr>
                    <th>Name</th>
                    <th>TTL</th>
                    <th>Class</th>
                    <th>Type</th>
                    <th>Value</th>
                </tr>
            </thead>
            <tbody>
    ";

    foreach ($records as $rec) {
        $name  = htmlspecialchars($rec['name']);
        $ttl   = htmlspecialchars($rec['ttl']);
        $class = htmlspecialchars($rec['class']);
        $type  = htmlspecialchars($rec['type']);
        $value = htmlspecialchars($rec['value']);

        $html .= "
            <tr>
                <td>{$name}</td>
                <td>{$ttl}</td>
                <td>{$class}</td>
                <td>{$type}</td>
                <td>{$value}</td>
            </tr>
        ";
    }

    $html .= "
            </tbody>
        </table>
    </div>
    ";

    return $html;
}

