
<?php
/*
|--------------------------------------------------------------------------
| PACK 582 — NON-DESTRUCTIVE CMS HELPERS
|--------------------------------------------------------------------------
*/

if (!function_exists('ecms_get_section_config')) {

    function ecms_get_section_config(string $sectionKey): array
    {
        $defaults = [
            'enabled' => true,
            'title' => ucfirst($sectionKey),
            'theme' => 'enterprise-gradient',
            'custom_class' => '',
            'sort_order' => 0
        ];

        try {

            global $db, $conference;

            if (!isset($db) || empty($conference['id'])) {
                return $defaults;
            }

            $stmt = $db->prepare("
                SELECT *
                FROM conference_home_sections
                WHERE conference_id = ?
                AND section_key = ?
                LIMIT 1
            ");

            $stmt->execute([
                (int)$conference['id'],
                $sectionKey
            ]);

            $row = $stmt->fetch(PDO::FETCH_ASSOC);

            if (!$row) {
                return $defaults;
            }

            return array_merge($defaults, [
                'enabled' => (bool)($row['enabled'] ?? 1),
                'theme' => $row['theme_name'] ?? 'enterprise-gradient',
                'sort_order' => (int)($row['sort_order'] ?? 0)
            ]);

        } catch (Throwable $e) {

            return $defaults;
        }
    }
}
?>
