<?php
include "../../root.class.php";
$db = new db_safeguard();

$jobcard_id = $_POST['jobcard_id'];

$res_data = $db->query("notes", "SELECT * FROM notes WHERE jobcard_id = '{$jobcard_id}' ORDER BY record_id DESC");

    echo "
        <table style='width: 100%; border-collapse: collapse; text-align: center; border: 2px solid black; background-color: #ffffffc4;'>
            <tr>
                <th>REASON</th>
                <th>NOTE</th>
                <th>IMAGE</th>
                <th>DATE</th>
            </tr>
    ";

if ($res_data->num_rows > 0) {
    while ($note = $res_data->fetch_assoc()) {
        $image_cell = !empty($note['image'])
            ? "<a href='https://dev.savuki.elegantwork.co.za/app/jobcards/notes/{$note['image']}' target='_blank'>
                <button style='padding: 5px 12px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 4vw;'>VIEW</button>
            </a>"
            : "N/A";

        echo "
            <tr>
                <td>{$note['reason']}</td>
                <td>{$note['note']}</td>
                <td>{$image_cell}</td>
                <td>{$note['date_time']}</td>
            </tr>
        ";
    }
} else {
    echo "<tr><td colspan='4' style='text-align: center; font-size: 4vw;'>No notes found.</td></tr>";
}

echo "</table>";
?>