<?php
require_once 'conexion.php';
$id = (int) $_GET['id'];
$res = mysqli_query($con, "SELECT * FROM comandas_cocina WHERE id = $id");
$row = mysqli_fetch_assoc($res);
$items = json_decode($row['detalle'], true);
?>
<!DOCTYPE html>
<html lang="es">
<head>
  <meta charset="UTF-8">
  <title>Ticket</title>
  <style>
    body { font-family: monospace; padding: 20px; }
    .ticket { border: 1px dashed #000; padding: 10px; max-width: 300px; }
    .ticket h3 { margin: 0 0 10px; }
  </style>
</head>
<body onload="window.print()">
<div class="ticket">
  <h3>🧾 Comanda</h3>
  Mesa <?= $row['mesa_id'] ?><br>
  <?= date('H:i', strtotime($row['hora'])) ?><br>
  <hr>
  <?php foreach ($items as $item): ?>
    <?= $item['cantidad'] ?>x <?= $item['producto'] ?><br>
  <?php endforeach; ?>
</div>
</body>
</html>