<?php
include "../../root.class.php";

$html = new html();
$html->add_styles_page();
$db = new db_safeguard();

$assets_res = $db->query(
    "assets",
    "SELECT * FROM assets WHERE status = 'ACTIVE' ORDER BY record_id DESC"
);
?>

<style>
    :root {
        --blue: #1e3a8a;
        --light-blue: #eaf0ff;
        --orange: #f97316;
        --orange-soft: #fde7d6;
        --white: #ffffff;
        --border: #d1d5db;
        --text: #0f172a;
    }

    body {
        margin: 0;
        background: #f8fafc;
        color: var(--text);
        font-family: "Segoe UI", Roboto, Arial, sans-serif;
    }

    .form_down {
        width: 95%;
        margin: auto;
        padding-bottom: 3vw;
    }

    h1 {
        color: var(--blue);
        margin: 2.5vw 0 1.5vw;
        font-size: 3vw;
        /* border-left: 6px solid var(--orange); */
        padding-left: 1vw;
    }

    table {
        width: 100%;
        border-collapse: collapse;
        background: var(--white);
        border-radius: 12px;
        overflow: hidden;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    }

    thead th {
        background: var(--blue);
        color: var(--white);
        text-align: left;
        padding: 1vw;
        font-size: 1.5vw;
        letter-spacing: 0.05em;
    }

    tbody td {
        padding: 1vw;
        font-size: 1.3vw;
        border-bottom: 1px solid var(--border);
    }

    tbody tr:nth-child(even) {
        background-color: var(--light-blue);
    }

    tbody tr:hover {
        background-color: var(--orange-soft);
        transition: background 0.2s ease;
    }

    tbody tr {
        cursor: pointer;
    }

    tbody tr:last-child td {
        border-bottom: none;
    }

    .status {
        font-weight: 600;
        color: var(--blue);
    }
</style>

<body>

    <div class="form_down">
        <h1>Current Assets</h1>

        <table>
            <thead>
                <tr>
                    <th>Team Name</th>
                    <th>Asset Type</th>
                    <th>Current Level</th>
                    <th>Odo Type</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody>
                <?php
                while ($assets = $assets_res->fetch_assoc()) {

                    $asset_type_res = $db->query(
                        "asset_type",
                        "SELECT * FROM asset_type WHERE record_id = '" . $assets["asset_type_id"] . "'"
                    );
                    $asset_type = $asset_type_res->fetch_assoc();

                    ?>
                    <tr
                        onclick="window.location.href='../teams/edit_teams.php?record_id=<?php echo $assets['record_id']; ?>'">
                        <td><?php echo htmlspecialchars($assets["name"]); ?></td>
                        <td><?php echo htmlspecialchars($asset_type["name"]); ?></td>
                        <td><?php echo htmlspecialchars($assets["current_level"]); ?></td>
                        <td><?php echo htmlspecialchars($assets["odo"]); ?></td>
                        <td>
                            <span class="status">
                                <?php echo htmlspecialchars($assets["status"]); ?>
                            </span>
                        </td>
                    </tr>
                    <?php
                }
                ?>
            </tbody>
        </table>
    </div>

</body>