<?php
session_start();
require_once __DIR__ . '/db/config.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $id = $_POST['id'] ?? null;
    $status = $_POST['status'] ?? null;

    if ($id && $status) {
        try {
            $pdo = db();
            $stmt = $pdo->prepare("UPDATE installations SET status = ? WHERE id = ?");
            $stmt->execute([$status, $id]);

            $_SESSION['message'] = 'Status atualizado com sucesso!';
            $_SESSION['message_type'] = 'success';
        } catch (PDOException $e) {
            error_log("Status update error: " . $e->getMessage());
            $_SESSION['message'] = 'Erro ao atualizar o status.';
            $_SESSION['message_type'] = 'danger';
        }
    }
}

header('Location: index.php');
exit;
