<?php
// cms/process-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_process ORDER BY updated_at DESC LIMIT 1");
    $generalData = $stmt->fetch(PDO::FETCH_ASSOC);

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

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

    echo json_encode(['success' => true, 'data' => $data]);
} catch (PDOException $e) {
    http_response_code(500);
    echo json_encode(['success' => false, 'error' => 'Error Al Cargar Los Datos: ' . $e->getMessage()]);
}
?>