<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>Maintenance Report PDF</title>
    <style type="text/css">
        * {
            color: #040404;
        }

        .title {
            text-align: center;
            margin-bottom: 20px;
        }

        .title h2 {
            font-size: 16px;
            text-transform: uppercase;
           
        }

        .report-container {
            font-size: 10px;
            width: 700px; /* Fixed width for Dompdf */
            padding: 0;
            margin: 0 auto;
        }

        .header {
            margin-bottom: 20px;
            overflow: hidden;
            height: 100px;
        }

        .header .logo {
            float: left;
            width: 100px;
        }

        .header .info {
            float: right;
            font-size: 12px;
            line-height: 20px;
            padding-bottom: 10px;
            width: calc(100% - 200px);
            text-align: right;
        }

        .info span {
            margin-left: 15px;
            font-weight: bold;
        }

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

        th, td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
            vertical-align: top;
        }

        th {
            background-color: #f2f2f2;
            font-weight: bold;
            font-size: 11px;
            color: #333;
        }
        
        .maintenance_title {
            padding: 8px;
            text-align: left;
            vertical-align: top;
        }

        .section-title {
            font-weight: bold;
            font-size: 12px;
            margin-bottom: 10px;
            color: #336EE5;
            border-bottom: 1px solid #eee;
            padding-bottom: 5px;
            margin-top: 20px;
        }

        .checkbox-container {
            display: inline-block;
            width: 12px;
            height: 12px;
            border: 1px solid #000;
            vertical-align: middle;
            margin-right: 5px;
        }

        .checkbox-checked {
            background-color: #336EE5; /* Or a checkmark image/unicode character */
            border: 1px solid #336EE5;
            color: white;
            text-align: center;
            line-height: 12px; /* Center the checkmark */
            font-size: 8px;
        }
    </style>
</head>
<body>
    <?php
    // Variables for the maintenance report
    $rootcause = $data['root_causes'] ?? [];
    $corrective = $data['corrective_actions'] ?? [];
    $effective = $data['effective_actions'] ?? [];
    $prevention = $data['preventions'] ?? [];
    $suggestion = $data['suggestions'] ?? [];
    $report_media = $data['report_media'] ?? [];
    $generator_serial_number = $data['generator_serial_number'] ?? 'N/A';
    ?>

    <div class="header">
        <div class="logo"><img src="https://testing.rehlkocustomercare.com/test/public/logo/logowtext.png" width="100" alt="Company Logo"></div>
        <div class="info">
            <span>Address :  3A International Business Park,<br>
#12-10, ICON@IBP, Tower B,<br>
Singapore 609935</span><br>
            <span>Mail : admin@rehlkocustomercare.com</span><br>
            <span>Phone : 096489079</span>
        </div>
        <div class="title">
            <h4>Field Report ID -  <?= htmlspecialchars($data['report_index']); ?></h4>
        </div>
    </div>

    <div class="report-container">
        <div class="section-title">
            General Information
        </div>
       <table>
           <tr>
                <th>Report Index</th>
                <td><?= htmlspecialchars($data['report_index']); ?></td>
            </tr>
            <tr>
                <th>Problem Issue</th>
                <td><?= htmlspecialchars($data['problem_issue']); ?></td>
            </tr>
            <tr>
                <th>Created Time </th>
                <td><?= $data['created_datetime']; ?></td>
            </tr>
            <tr>
                <th>Solved Time </th>
                <td><?= $data['modified_datetime']; ?></td>
            </tr>
       </table>
        <div class="section-title">
            Customer Information
        </div>
        <table>
            <tr>
                <th>Name</th>
                <th>Phone Number</th>
                <th>Email</th>
                <th>Country</th>
                
            </tr>
            <tr>
                <td><?= htmlspecialchars($data['customer_name']); ?></td>
                <td><?= htmlspecialchars($data['customer_phone']); ?></td>
                <td><?= htmlspecialchars($data['customer_email']); ?></td>
                <td><?= htmlspecialchars($data['customer_country_name']); ?></td>
            </tr>
        </table>
        <div class="section-title">
            Generator Information
        </div>
        <table>
            <tr>
                <th>Generator Serial Number</th>
                <th>Level</th>
                <th>Gantry</th>
                
            </tr>
            <tr>
                <td><?= htmlspecialchars($data['generator_serial_number']); ?></td>
                <td><?= htmlspecialchars($data['level']); ?></td>
                <td><?= htmlspecialchars($data['gantry']); ?></td>
            </tr>
        </table>
        <div class="section-title">
            Engineer Team Information
        </div>
        <table>
            <tr>
                <th></th>
                <th> Name </th>
                <th> Phone Number </th>
                <th> Email </th>
            </tr>
            <tr>
                <th>Prepared By </th>
                <td><?= htmlspecialchars($data['engineer_name']); ?></td>
                <td><?= htmlspecialchars($data['engineer_phone']); ?></td>
                <td><?= htmlspecialchars($data['engineer_email']); ?></td>
            </tr>
            <tr>
                <th>Confirmed By </th>
                <td><?= htmlspecialchars($data['supervisor_name']); ?></td>
                <td><?= htmlspecialchars($data['supervisor_phone']); ?></td>
                <td><?= htmlspecialchars($data['supervisor_email']); ?></td>
            </tr>
        </table>
        <div class="section-title">
            Report Details
        </div>
        <table>
            <tr>
                <th>Report Index</th>
                <td><?= htmlspecialchars($data['report_index']); ?></td>
            </tr>
            <tr>
                <th>Problem issue</th>
                <td><?= htmlspecialchars($data['problem_issue']); ?></td>
            </tr>
            <tr>
                <th>Report Type</th>
                <td><?= htmlspecialchars($data['report_type']); ?></td>
            </tr>
            <tr>
                <th>Remarks</th>
                <td><?= htmlspecialchars($data['remarks']); ?></td>
            </tr>
        <?php if (!empty($report_media)): ?>
            <tr>
                    <th>Report Images</th>
            <?php foreach ($report_media as $media): ?>
                
                
                <?php if (!empty($media['media_path'])): ?>
                   
                        <td style="text-align: center;">
                            <img src="<?= htmlspecialchars('https://testing.rehlkocustomercare.com/test/' . $media['media_path']); ?>" alt="<?= htmlspecialchars($media['media_name']); ?>" width="200" style="margin-top: 10px;">
                        </td>
                <?php endif; ?>
                    
                
            <?php endforeach; ?>
            </tr>
        
        <?php endif; ?>
        </table>
        <?php if (!empty($rootcause)): ?>
        <div class="section-title">
            Root Causes
        </div>
        <table>
                <tr>
                    <th>Description</th>
                    <th>Created By</th>
                    <th>Date/Time</th>
                </tr>
            <?php foreach ($rootcause as $cause): ?>
                <tr>
                    <td><?= htmlspecialchars($cause['root_cause_title']); ?></td>
                    <td><?= htmlspecialchars($cause['created_user_name']); ?></td>
                    <td><?= htmlspecialchars($cause['modified_datetime']); ?></td>
                </tr>
                <?php if (!empty($cause['root_cause_media_path'])): ?>
                    <tr>
                        <td colspan="3" style="text-align: center;">
                            <img src="<?= htmlspecialchars('https://testing.rehlkocustomercare.com/test/' . $cause['root_cause_media_path']); ?>" alt="<?= htmlspecialchars($cause['root_cause_media_name'] ?? 'Root Cause Image'); ?>" width="200" style="margin-top: 10px;">
                        </td>
                    </tr>
                <?php endif; ?>
            <?php endforeach; ?>
        </table>
        <?php endif; ?>
        
        <?php if (!empty($corrective)): ?>
        <div class="section-title">
            Corrective Actions
        </div>
        <table>
                <tr>
                    <th>Description</th>
                    <th>Created By</th>
                    <th>Date/Time</th>
                </tr>
            <?php foreach ($corrective as $correct): ?>
                <tr>
                    <td><?= htmlspecialchars($correct['corrective_action_title']); ?></td>
                    <td><?= htmlspecialchars($correct['created_user_name']); ?></td>
                    <td><?= htmlspecialchars($correct['modified_datetime']); ?></td>
                </tr>
                <?php if (!empty($correct['corrective_action_media_path'])): ?>
                    <tr>
                        <td colspan="3" style="text-align: center;">
                            <img src="<?= htmlspecialchars('https://testing.rehlkocustomercare.com/test/public/' . $correct['corrective_action_media_path']); ?>" alt="<?= htmlspecialchars($correct['corrective_action_media_name'] ?? 'Corrective Action Image'); ?>" width="200" style="margin-top: 10px;">
                        </td>
                    </tr>
                <?php endif; ?>
            <?php endforeach; ?>
        </table>
        <?php endif; ?>
        
        <?php if (!empty($effective)): ?>
        <div class="section-title">
            Effective Actions
        </div>
        <table>
                <tr>
                    <th>Description</th>
                    <th>Created By</th>
                    <th>Date/Time</th>
                </tr>
            <?php foreach ($effective as $effect): ?>
                <tr>
                    <td><?= htmlspecialchars($effect['effective_action_title']); ?></td>
                    <td><?= htmlspecialchars($effect['created_user_name']); ?></td>
                    <td><?= htmlspecialchars($effect['modified_datetime']); ?></td>
                </tr>
            <?php endforeach; ?>
        </table>
        <?php endif; ?>
        
        <?php if (!empty($prevention)): ?>
        <div class="section-title">
            Preventions
        </div>
        <table>
                <tr>
                    <th>Description</th>
                    <th>Created By</th>
                    <th>Date/Time</th>
                </tr>
            <?php foreach ($prevention as $prevent): ?>
                <tr>
                    <td><?= htmlspecialchars($prevent['prevention_title']); ?></td>
                    <td><?= htmlspecialchars($prevent['created_user_name']); ?></td>
                    <td><?= htmlspecialchars($prevent['modified_datetime']); ?></td>
                </tr>
            <?php endforeach; ?>
        </table>
        <?php endif; ?>
        
        <?php if (!empty($suggestion)): ?>
        <div class="section-title">
            Suggestions
        </div>
        <table>
                <tr>
                    <th>Description</th>
                    <th>Created By</th>
                    <th>Date/Time</th>
                </tr>
            <?php foreach ($suggestion as $suggest): ?>
                <tr>
                    <td><?= htmlspecialchars($suggest['suggestion_title']); ?></td>
                    <td><?= htmlspecialchars($suggest['created_user_name']); ?></td>
                    <td><?= htmlspecialchars($suggest['modified_datetime']); ?></td>
                </tr>
            <?php endforeach; ?>
        </table>
        <?php endif; ?>

        
    </div>
</body>
</html>