import { formatBytes, formatPayloadJson } from '../utils.js';
const CATEGORY_ORDER = [
    'code',
    'office',
    'prose',
    'data',
    'config',
    'image',
    'binary',
    'other',
];
function formatCategoryList(result) {
    return CATEGORY_ORDER.map(category => {
        const entry = result.composition.byCategory[category];
        return entry.files > 0 ? `${entry.pct}% ${category}` : '';
    })
        .filter(Boolean)
        .join(', ');
}
function formatSignals(result) {
    const markers = [
        ...result.signals.manifests.map(marker => marker.path),
        ...result.signals.markers.map(marker => marker.path),
    ];
    const frameworks = result.signals.frameworks.length > 0 ? ` (${result.signals.frameworks.join(', ')})` : '';
    const packageManager = result.signals.packageManager ? ` package-manager:${result.signals.packageManager}` : '';
    return markers.length > 0
        ? `${markers.slice(0, 8).join(', ')}${frameworks}${packageManager}`
        : `none${frameworks}${packageManager}`;
}
function formatFull(result) {
    const lines = [
        result.classification.summary,
        `Root: ${result.rootDir}`,
        `Kind: ${result.classification.primaryType} (${result.classification.confidence})`,
        `Files: ${result.composition.totals.files}, ${formatBytes(result.composition.totals.bytes)}`,
        `Composition: ${formatCategoryList(result) || 'empty'}`,
        `Signals: ${formatSignals(result)}`,
    ];
    if (result.projects.length > 0) {
        lines.push('Projects:');
        for (const project of result.projects) {
            const suffix = [
                project.kinds.join(', '),
                project.frameworks.length > 0 ? project.frameworks.join(', ') : '',
                project.packageManager ? `pm:${project.packageManager}` : '',
            ]
                .filter(Boolean)
                .join(' - ');
            lines.push(`  ${project.path}: ${suffix}`);
        }
        if (result.projectSummary.truncated) {
            lines.push(`  ... ${result.projectSummary.total - result.projectSummary.shown} more`);
        }
    }
    if (result.recommendedCommands.length > 0) {
        lines.push(`Recommended: ${result.recommendedCommands.join('; ')}`);
    }
    return lines.join('\n');
}
function formatCompact(result) {
    const files = `${result.composition.totals.files} files`;
    const bytes = formatBytes(result.composition.totals.bytes);
    const lines = [
        `${result.classification.summary} - ${files} - ${bytes}`,
        `  composition: ${formatCategoryList(result) || 'empty'}`,
        `  signals: ${formatSignals(result)}`,
    ];
    if (result.projectSummary.total > 0) {
        const suffix = result.projectSummary.truncated
            ? `, ${result.projectSummary.total - result.projectSummary.shown} hidden`
            : '';
        lines.push(`  projects: ${result.projectSummary.shown}/${result.projectSummary.total}${suffix}`);
    }
    return lines.join('\n');
}
export function formatWorkspaceDescription(result, options = {}) {
    if (options.format === 'json')
        return formatPayloadJson(result, options.pretty);
    if (options.quiet)
        return result.classification.summary;
    if (options.full)
        return formatFull(result);
    return formatCompact(result);
}
//# sourceMappingURL=describe-output.js.map