import { fileExists, hasAnyFile } from '../detection-utils.js';
const DESKTOP_FW_SET = new Set(['electron', 'tauri', 'dotnet', 'qt']);
/**
 * Returns true if the framework string matches a known desktop framework.
 */
export function isDesktopFramework(framework) {
    return framework !== null && DESKTOP_FW_SET.has(framework);
}
/**
 * Returns the desktop framework name if the project is a desktop app.
 * Uses filesystem signals as fallback when framework detection misses.
 */
export async function detectDesktopFramework(projectPath, framework) {
    if (isDesktopFramework(framework)) {
        return framework;
    }
    // Fallback: file-based detection
    if (await fileExists(projectPath, 'tauri.conf.json')) {
        return 'tauri';
    }
    if (await fileExists(projectPath, 'src-tauri/tauri.conf.json')) {
        return 'tauri';
    }
    if (await hasAnyFile(projectPath, ['*.csproj', '*.sln'])) {
        return 'dotnet';
    }
    if (await fileExists(projectPath, 'CMakeLists.txt')) {
        const cmakeContent = await tryReadFile(projectPath, 'CMakeLists.txt');
        if (cmakeContent?.includes('Qt')) {
            return 'qt';
        }
    }
    return null;
}
/**
 * Get the frontend framework embedded in an Electron/Tauri app.
 */
export function getEmbeddedWebFramework(knowledge) {
    const stack = knowledge.stack;
    const webFrameworks = ['react', 'vue', 'angular', 'svelte', 'next.js', 'nuxt'];
    for (const fw of webFrameworks) {
        if (stack.includes(fw)) {
            return fw;
        }
    }
    return null;
}
async function tryReadFile(basePath, relativePath) {
    try {
        const fsModule = await import('node:fs/promises');
        const pathModule = await import('node:path');
        const fullPath = pathModule.join(basePath, relativePath);
        return await fsModule.readFile(fullPath, 'utf-8');
    }
    catch {
        /* v8 ignore next */
        return null;
    }
}
//# sourceMappingURL=desktop.js.map