<?php require __DIR__.'/../../inc/bootstrap.php'; $id=(int)($_GET['id']??0);
$stmt=$pdo->prepare("SELECT id, nombre, lote, vencimiento, precio_compra_g, precio_venta_g, estado FROM componentes WHERE id=?"); $stmt->execute([$id]); $r=$stmt->fetch();
if(!$r){ http_response_code(404); echo 'No encontrado'; exit; } ?>
<!doctype html><html lang='es'><head>
<meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'>
<link rel='stylesheet' href='../../assets/styles.css'>
<link rel='stylesheet' href='../../assets/theme.css'>
<title>Editar componente</title></head><body>
<div class='container'><div class='card theme-comp'>
<a class='btn' href='index.php'>&larr; Volver</a>
<h2>Editar componente</h2>
<form method='post' action='update.php?id=<?= (int)$r['id'] ?>'>
<div class='grid' style='grid-template-columns: repeat(2,1fr); gap:12px'>
<div><div class='label'>Nombre</div><input class='input' type='text' name='nombre' value='<?=h($r["nombre"])?>'></div><div><div class='label'>Lote</div><input class='input' type='text' name='lote' value='<?=h($r["lote"])?>'></div><div><div class='label'>Vencimiento</div><input class='input' type='date' name='vencimiento' value='<?=h($r["vencimiento"])?>'></div><div><div class='label'>Precio compra g</div><input class='input' type='number' name='precio_compra_g' value='<?=h($r["precio_compra_g"])?>'></div><div><div class='label'>Precio venta g</div><input class='input' type='number' name='precio_venta_g' value='<?=h($r["precio_venta_g"])?>'></div><div><div class='label'>Estado</div>
<select class='input' name='estado'>
  <option value="en_uso" <?= $r['estado']=='en_uso'?'selected':'' ?>>en_uso</option>
  <option value="no_uso" <?= $r['estado']=='no_uso'?'selected':'' ?>>no_uso</option>
</select></div>
</div>
<div style='margin-top:12px'><button class='btn' type='submit'>Guardar cambios</button></div>
</form>
</div></div></body></html>
