<?php
require_once('../../backend/bd/Conexion.php');

if(isset($_POST['id']) && isset($_POST['state'])) {
    $id = $_POST['id'];
    $state = $_POST['state'];
    
    try {
        $query = "UPDATE patients SET state = :state WHERE idpa = :id";
        $statement = $connect->prepare($query);
        
        $data = [
            ':id' => $id,
            ':state' => $state
        ];
        
        $result = $statement->execute($data);
        
        if($result) {
            echo json_encode(['status' => 'success']);
        } else {
            echo json_encode(['status' => 'error', 'message' => 'Error al actualizar el estado']);
        }
    } catch(PDOException $e) {
        echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
    }
} else {
    echo json_encode(['status' => 'error', 'message' => 'Datos incompletos']);
}
exit();
?>