import { api } from '../../lib/api';
import { log } from '$lib/cot-logger';

// #region load:Function [C:2] [TYPE Function]
// @BRIEF Loads application settings and environment list.
// @POST Returns settings object or default values on error.
/** @type {import('./$types').PageLoad} */
export async function load() {
    try {
        const settings = await api.getSettings();
        return {
            settings
        };
    } catch (error) {
        log("SettingsPage", "EXPLORE", "Failed to load settings in load function", {}, String(error));
        return {
            settings: {
                environments: [],
                settings: {
                    default_environment_id: null,
                    storage: {
                        root_path: '',
                        backup_structure_pattern: '',
                        repo_structure_pattern: '',
                        filename_pattern: ''
                    }
                }
            },
            error: 'Failed to load settings'
        };
    }
}
// #endregion load:Function
