'use server';
import { statSync } from 'node:fs';
import { join } from 'node:path';
import { resolve } from '../../lib/server-container.js';
import { getShepHomeDir } from '../../../../../packages/core/src/infrastructure/services/filesystem/shep-directory.service.js';
function formatFileSize(bytes) {
    if (bytes < 1024)
        return `${bytes} B`;
    if (bytes < 1024 * 1024)
        return `${(bytes / 1024).toFixed(1)} KB`;
    return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
}
export async function loadSettings() {
    try {
        const useCase = resolve('LoadSettingsUseCase');
        const settings = await useCase.execute();
        const shepHome = getShepHomeDir();
        let dbFileSize = 'Unknown';
        try {
            const dbPath = join(shepHome, 'data');
            const stat = statSync(dbPath);
            dbFileSize = formatFileSize(stat.size);
        }
        catch {
            // DB file may not exist yet
        }
        return { settings, shepHome, dbFileSize };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to load settings';
        return { error: message };
    }
}
