<?php
// templates/blank_report_template.php
// HTML/PHP template for Electrical Installation Condition Report
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <style>
    body {
        font-family: Arial, sans-serif;
        font-size: 12px;
        margin: 0;
        padding: 0;
    }

    .page {
        page-break-after: always;
        padding: 20mm;
    }

    .landscape {
        writing-mode: lr-tb;
    }

    .header,
    .footer {
        text-align: center;
        font-size: 10px;
    }

    .section {
        margin-bottom: 10px;
    }

    .section-title {
        font-weight: bold;
        background: #eee;
        padding: 4px;
    }

    table {
        width: 100%;
        border-collapse: collapse;
        margin-bottom: 8px;
    }

    th,
    td {
        border: 1px solid #000;
        padding: 4px;
    }

    .checkbox {
        display: inline-block;
        width: 12px;
        height: 12px;
        border: 1px solid #000;
        margin-right: 4px;
        vertical-align: middle;
    }
    </style>
</head>

<body>

    <div class="page portrait">
        <div class="header">ELECTRICAL INSTALLATION CONDITION REPORT</div>
        <div class="section">
            <div class="section-title">SECTION A. DETAILS OF THE CLIENT</div>
            <table>
                <tr>
                    <td>Client:</td>
                    <td><?= htmlspecialchars($common['client_name']) ?></td>
                </tr>
                <tr>
                    <td>Address:</td>
                    <td><?= htmlspecialchars($common['client_address']) ?></td>
                </tr>
            </table>
        </div>

        <div class="section">
            <div class="section-title">SECTION B. REASON FOR PRODUCING THIS REPORT</div>
            <table>
                <tr>
                    <td>Reason:</td>
                    <td><?= htmlspecialchars($common['report_reason']) ?></td>
                </tr>
                <tr>
                    <td>Date(s) on which inspection and testing was carried out:</td>
                    <td><?= htmlspecialchars($common['inspection_dates']) ?></td>
                </tr>
            </table>
        </div>

        <div class="section">
            <div class="section-title">SECTION C. DETAILS OF THE INSTALLATION</div>
            <table>
                <tr>
                    <td>Occupier:</td>
                    <td><?= htmlspecialchars($common['occupier_name']) ?></td>
                </tr>
                <tr>
                    <td>Address:</td>
                    <td><?= htmlspecialchars($common['occupier_address']) ?></td>
                </tr>
                <tr>
                    <td>Description of Premises:</td>
                    <td>
                        Residential <span class="checkbox"><?= $common['type']=='residential'? 'X':'' ?></span>
                        Commercial <span class="checkbox"><?= $common['type']=='commercial'? 'X':'' ?></span>
                        Industrial <span class="checkbox"><?= $common['type']=='industrial'? 'X':'' ?></span>
                        Other: <?= htmlspecialchars($common['other_type']) ?>
                    </td>
                </tr>
                <tr>
                    <td>Evidence of Alterations or Additions:</td>
                    <td><?= htmlspecialchars($common['evidence_alterations']) ?></td>
                </tr>
                <tr>
                    <td>If ‘Yes’, estimate age (years):</td>
                    <td><?= htmlspecialchars($common['alteration_age']) ?></td>
                </tr>
                <tr>
                    <td>Date of previous inspection:</td>
                    <td><?= htmlspecialchars($common['previous_inspection_date']) ?></td>
                </tr>
                <tr>
                    <td>Installation records available:</td>
                    <td><?= htmlspecialchars($common['records_available']) ?></td>
                </tr>
                <tr>
                    <td>Estimated age of the wiring system:</td>
                    <td><?= htmlspecialchars($common['wiring_age']) ?></td>
                </tr>
                <tr>
                    <td>District Network Operator (DNO):</td>
                    <td><?= htmlspecialchars($common['dno']) ?></td>
                </tr>
                <tr>
                    <td>Sub-Station Number:</td>
                    <td><?= htmlspecialchars($common['substation_number']) ?></td>
                </tr>
            </table>
        </div>

        <div class="section">
            <div class="section-title">SECTION D. EXTENT OF THE INSTALLATION AND LIMITATIONS</div>
            <p><?= nl2br(htmlspecialchars($common['extent_limitations'])) ?></p>
        </div>

        <div class="section">
            <div class="section-title">SECTION E. SUMMARY OF THE CONDITION OF THE INSTALLATION</div>
            <p>General condition: <?= htmlspecialchars($common['general_condition']) ?></p>
            <p>Overall assessment: <?= htmlspecialchars($common['overall_assessment']) ?></p>
        </div>

        <div class="section">
            <div class="section-title">SECTION F. RECOMMENDATIONS</div>
            <p><?= nl2br(htmlspecialchars($common['recommendations'])) ?></p>
            <p>Date of Next Inspection: <?= htmlspecialchars($common['next_inspection_date']) ?></p>
        </div>

        <div class="section">
            <div class="section-title">SECTION G. DECLARATION</div>
            <p>Inspected and tested by: <?= htmlspecialchars($common['inspector_name']) ?></p>
            <p>Report authorised by: <?= htmlspecialchars($common['authoriser_name']) ?></p>
        </div>
    </div>

    <div class="page landscape">
        <div class="section">
            <div class="section-title">SECTION H. SCHEDULE(S) OF TEST RESULTS</div>
            <?php foreach ($boardResults as $index => $board): ?>
            <h4>Board <?= $index + 1 ?></h4>
            <table>
                <?php foreach ($board as $field => $value): ?>
                <tr>
                    <td><?= htmlspecialchars($field) ?></td>
                    <td><?= htmlspecialchars($value) ?></td>
                </tr>
                <?php endforeach; ?>
            </table>
            <?php endforeach; ?>
        </div>
    </div>

</body>

</html>