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

require_once('db_connection.php');

try {
    $data = [
        'differentiators_page_enabled' => 1, 'process_page_enabled' => 1, 'coverage_page_enabled' => 1,
        'services_page_enabled' => 1, 'results_page_enabled' => 1, 'reviews_page_enabled' => 1,
        'cta_page_enabled' => 1, 'hours_page_enabled' => 1, 'exit_intent_enabled' => 0
    ];
    
    $stmtBusiness = $pdo->query("SELECT id FROM business_info ORDER BY updated_at DESC LIMIT 1");
    $businessData = $stmtBusiness->fetch(PDO::FETCH_ASSOC);

    if ($businessData) {
        $stmt = $pdo->prepare("SELECT * FROM sections_enabled WHERE business_info_id = ?");
        $stmt->execute([$businessData['id']]);
        $sectionsData = $stmt->fetch(PDO::FETCH_ASSOC);
        if ($sectionsData) {
            $data = $sectionsData;
        }
    }
    
    echo json_encode(['success' => true, 'data' => $data]);

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