import * as core from '@actions/core';
export class GitHubSummaryCapability {
    taskSummaries = new Map();
    async writePlanSummary(planName, result, totalDuration) {
        const status = Object.values(result.tasks).some((t) => t.status === 'failed')
            ? 'failed'
            : 'success';
        const statusIcon = status === 'success' ? '\u2705' : '\u274C';
        let md = `## ${statusIcon} Kitsi: ${planName}\n\n`;
        md += `**Duration:** ${totalDuration.toFixed(1)}s\n\n`;
        md += '| Task | Status | Duration |\n';
        md += '|------|--------|----------|\n';
        for (const [taskName, taskResult] of Object.entries(result.tasks)) {
            const icon = taskResult.status === 'success' ? '\u2713' : '\u2717';
            md += `| ${taskName} | ${icon} | ${taskResult.duration.toFixed(1)}s |\n`;
        }
        md += this.buildTaskSummaries(result);
        md += this.buildBufferedSummaries();
        await core.summary.addRaw(md).write();
    }
    buildTaskSummaries(result) {
        let output = '';
        for (const [taskName, taskResult] of Object.entries(result.tasks)) {
            if (taskResult.summaries && taskResult.summaries.length > 0) {
                output += `\n### ${taskName}\n\n`;
                for (const summary of taskResult.summaries) {
                    output += `${summary.content}\n\n`;
                }
            }
        }
        return output;
    }
    buildBufferedSummaries() {
        let output = '';
        for (const [taskName, summaries] of this.taskSummaries.entries()) {
            if (summaries.length > 0) {
                output += `\n### ${taskName}\n\n`;
                for (const summary of summaries) {
                    output += `${summary}\n\n`;
                }
            }
        }
        return output;
    }
    writeTaskSummary(taskName, content) {
        // Buffer task summaries for inclusion in plan summary
        const existing = this.taskSummaries.get(taskName) ?? [];
        existing.push(content);
        this.taskSummaries.set(taskName, existing);
    }
}
//# sourceMappingURL=summary.js.map