import { api } from '../../lib/api';

// [DEF:load:Function]
/* @PURPOSE: Loads application settings and environment list.
   @PRE: API must be reachable.
   @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) {
        console.error('Failed to load settings:', 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'
        };
    }
}
// [/DEF:load:Function]
