<?php
// cms/confirmation-read.php
header('Content-Type: application/json');

require_once('db_connection.php');

try {
    $data = [
        'general' => [],
        'steps' => []
    ];

    // Obtener datos generales de la sección
    $stmt = $pdo->query("SELECT * FROM cms_confirmation ORDER BY updated_at DESC LIMIT 1");
    $generalData = $stmt->fetch(PDO::FETCH_ASSOC);

    if ($generalData) {
        $data['general'] = $generalData;
        $confirmationId = $generalData['id'];

        // Obtener la lista de pasos
        $stmtSteps = $pdo->prepare("SELECT step_icon, step_title, step_description FROM cms_confirmation_steps WHERE confirmation_id = ? ORDER BY id ASC");
        $stmtSteps->execute([$confirmationId]);
        $data['steps'] = $stmtSteps->fetchAll(PDO::FETCH_ASSOC);
    } 

    echo json_encode(['success' => true, 'data' => $data]);
} catch (PDOException $e) {
    // Si hay un error de conexión o de tabla, se devuelve el error 500 al cliente.
    http_response_code(500);
    echo json_encode(['success' => false, 'message' => 'Error Al Cargar Los Datos' . $e->getMessage()]);
}
?>