<?php
// escalasproducto.php
include '../includes/session_control.php';
require_once '../cotizaciones/api/_node.php';

$idProducto = isset($_GET['id']) ? intval($_GET['id']) : 0;
if (!$idProducto) {
    echo "ID de producto inválido.";
    exit;
}

$token = cpn_node_token_or_fail();
$base = cpn_node_api_base();

$r = cpn_node_request('GET', $base . '/api/productos/' . urlencode((string)$idProducto) . '/escalas-variaciones', $token, null);
$rows = (!empty($r['ok']) && isset($r['data']['rows']) && is_array($r['data']['rows'])) ? $r['data']['rows'] : [];
?>

<table class="table table-bordered">
    <thead>
        <tr>
            <th>Referencia</th>
            <th>Colores</th>
            <th>Escala</th>
            <th class="text-right">Cant</th>
            <th class="text-right">Precio antes de IVA</th>
            <th class="text-right">Precio Iva Incluido</th>

        </tr>
    </thead>
    <tbody>
        <?php foreach ($rows as $r):
            // si isVisible=1 verde claro, si =0 azul claro
            $rowClass = $r['isVisible']
                ? 'table-success'   // Bootstrap light-green
                : 'table-primary';  // Bootstrap light-blue
        ?>
            <tr class="<?= $rowClass ?>">
                <td><?= htmlspecialchars($r['referenciaCPN']) ?></td>
                <td><?= htmlspecialchars($r['txtColors']) ?></td>
                <td><?= htmlspecialchars($r['nombre']) ?></td>
                <td class="text-right">
                    <?= number_format($r['cantidadRequerida'], 0, ',', '.') ?>
                </td>
                <td class="text-right">
                    $ <?= number_format($r['PVPantesImpuestos'], 0, ',', '.') ?>
                </td>
                <td class="text-right">
                    $ <?= number_format($r['PVP'], 0, ',', '.') ?>
                </td>


            </tr>
        <?php endforeach; ?>
    </tbody>
</table>