"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderInitSuccessSummary = renderInitSuccessSummary;
exports.renderInitServiceEnableFailure = renderInitServiceEnableFailure;
const branding_1 = require("../../core/branding");
const paths_1 = require("../../core/paths");
const catalog_1 = require("../../i18n/catalog");
const registry_1 = require("../../platform/ticket-tracker/registry");
function renderInitSuccessSummary(locale, config, options = {}) {
    const trackerProvider = (0, registry_1.requireTicketTrackerProvider)(config.ticketTracker.kind);
    const workflowLabels = config.ticketTracker.workflowLabels;
    const trackerGuidance = trackerProvider.renderInitCompletionInstructions?.(config.ticketTracker, locale, options) ?? getGenericTrackerInitGuidance(locale, workflowLabels.aiReady);
    return [
        (0, catalog_1.translate)(locale, "init.command.success.ready"),
        "",
        (0, catalog_1.translate)(locale, "init.command.success.savedSetup", {
            file: paths_1.CONFIG_FILENAME,
        }),
        (0, catalog_1.translate)(locale, "init.command.success.outputLanguage", {
            language: config.i18n.defaultLanguage,
        }),
        (0, catalog_1.translate)(locale, "init.command.success.displayTimeZone", {
            timeZone: config.i18n.displayTimeZone,
        }),
        ...(options.registeredCwd !== undefined
            ? [
                (0, catalog_1.translate)(locale, "init.command.success.registeredCwd", {
                    cwd: options.registeredCwd,
                }),
            ]
            : []),
        (0, catalog_1.translate)(locale, "init.command.success.repositoryRemote", {
            remoteName: config.repositoryHost.remoteName,
            baseBranch: config.repositoryHost.baseBranch,
        }),
        (0, catalog_1.translate)(locale, "init.command.success.watchReadyLabel", {
            label: workflowLabels.aiReady,
        }),
        (0, catalog_1.translate)(locale, "doctor.repo.issueCompletion", {
            target: config.issueCompletion.target,
            reviewPolicy: config.issueCompletion.pullRequest.reviewPolicy,
            mergePolicy: config.issueCompletion.pullRequest.mergePolicy,
        }),
        "",
        (0, catalog_1.translate)(locale, "init.command.success.howToUse"),
        ...trackerGuidance.map((line) => `- ${line}`),
        `- ${(0, catalog_1.translate)(locale, "init.command.success.changeLabelsLater")}`,
        `- ${(0, catalog_1.translate)(locale, "init.command.success.syncWorkflowLabelsLater")}`,
        `- ${(0, catalog_1.translate)(locale, "init.command.success.noLabelMigration")}`,
        ...renderWorkflowMaintenanceInitGuidance(locale),
        `- ${(0, catalog_1.translate)(locale, "init.command.success.pauseProcessing")}`,
    ].join("\n");
}
function renderInitServiceEnableFailure(locale, error) {
    return [
        (0, catalog_1.translate)(locale, "init.command.serviceEnableFailed.heading"),
        (0, catalog_1.translate)(locale, "init.command.serviceEnableFailed.kept"),
        (0, catalog_1.translate)(locale, "init.command.serviceEnableFailed.reason", {
            message: formatErrorMessage(error),
        }),
        (0, catalog_1.translate)(locale, "init.command.serviceEnableFailed.next"),
        (0, catalog_1.translate)(locale, "init.command.serviceEnableFailed.detail"),
    ].join("\n");
}
function renderWorkflowMaintenanceInitGuidance(locale) {
    return [
        `- ${(0, catalog_1.translate)(locale, "init.command.success.workflowMaintenanceCommand", {
            command: buildWorkflowMaintenanceIssueCreateCommand(),
        })}`,
    ];
}
function buildWorkflowMaintenanceIssueCreateCommand() {
    return [
        branding_1.CLI_COMMAND_NAME,
        "issue",
        "create",
        "--prompt",
        '"<describe this repository\'s purpose and desired workflow behavior>"',
        "--workflow",
        "__system/workflow-maintenance.md",
        "--pr-workflow",
        "no_template",
        "--unplanned-workflow",
        "no_template",
        "--followup-proposal",
        "off",
    ].join(" ");
}
function getGenericTrackerInitGuidance(locale, readyLabel) {
    return [
        (0, catalog_1.translate)(locale, "init.command.success.addReadyLabel", {
            label: readyLabel,
        }),
    ];
}
function formatErrorMessage(error) {
    return error instanceof Error ? error.message : String(error);
}
