<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type");
header("Access-Control-Allow-Methods: POST, OPTIONS");
header("Content-Type: application/json");
header("Access-Control-Max-Age: 86400");

require_once(__DIR__ . '/../../config.php');
$input = json_decode(file_get_contents('php://input'), true);
$slug_tienda = trim($input['slug_tienda'] ?? '');
$id = isset($input['id']) ? (int)$input['id'] : 0;

if ($slug_tienda === '' || $id <= 0) { echo json_encode(['success'=>false,'message'=>'Faltan datos']); exit; }

$stmt = $mysqli->prepare("DELETE FROM pos_zonas WHERE id=? AND slug_tienda=?");
$stmt->bind_param("is", $id, $slug_tienda);
$ok = $stmt->execute();
$stmt->close();

echo json_encode(['success'=>$ok, 'message'=>$ok?'Zona eliminada':'Error: '.$mysqli->error]);
$mysqli->close();
