<?php
include '../db/db.php';
include '../includes/session_control.php';

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

if (!isset($_SESSION['user'])) {
    header('Content-Type: application/json');
    echo json_encode(['error' => 'User not authenticated']);
    exit;
}

$id = $conn->real_escape_string($_POST['id'] ?? '');

if (!$id) {
    header('Content-Type: application/json');
    echo json_encode(['error' => 'Missing id']);
    exit;
}

$sql = "DELETE FROM tb_cotizacion_detalle WHERE id = '$id'";

if ($conn->query($sql) === TRUE) {
    header('Content-Type: application/json');
    echo json_encode(['success' => 'Producto eliminado']);
} else {
    header('Content-Type: application/json');
    echo json_encode(['error' => $conn->error]);
}
exit;
?>
