"use strict";
/*
  Simplified BSD License (see LICENSES/BSD-2-Clause.txt or https://opensource.org/licenses/BSD-2-Clause)
  SPDX-FileCopyrightText: Ansible Project
  SPDX-License-Identifier: BSD-2-Clause
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.toAnsibleDocText = void 0;
const opts_1 = require("./opts");
const format_1 = require("./format");
function formatOptionLike(part) {
    let text = part.value === undefined ? `\`${part.name}'` : `\`${part.name}=${part.value}'`;
    if (part.plugin) {
        const plugin_suffix = ['role', 'module', 'playbook'].includes(part.plugin.type) ? '' : ' plugin';
        let plugin = `${part.plugin.type}${plugin_suffix} ${part.plugin.fqcn}`;
        if (part.plugin.type === 'role' && part.entrypoint !== undefined) {
            plugin = `${plugin}, ${part.entrypoint} entrypoint`;
        }
        text = `${text} (of ${plugin})`;
    }
    return text;
}
const DEFAULT_FORMATTER = {
    formatError: (part) => `[[ERROR while parsing: ${part.message}]]`,
    formatBold: (part) => `*${part.text}*`,
    formatCode: (part) => `\`${part.text}'`,
    formatHorizontalLine: () => '\n-------------\n',
    formatItalic: (part) => `\`${part.text}'`,
    formatLink: (part) => `${part.text} <${part.url}>`,
    formatModule: (part) => `[${part.fqcn}]`,
    formatRSTRef: (part) => part.text,
    formatURL: (part) => part.url,
    formatText: (part) => part.text,
    formatEnvVariable: (part) => `\`${part.name}'`,
    formatOptionName: (part) => formatOptionLike(part),
    formatOptionValue: (part) => `\`${part.value}'`,
    formatPlugin: (part) => `[${part.plugin.fqcn}]`,
    formatReturnValue: (part) => formatOptionLike(part),
};
function toAnsibleDocText(paragraphs, opts) {
    const mergedOpts = (0, opts_1.mergeOpts)(Object.assign({}, opts), DEFAULT_FORMATTER);
    const result = [];
    for (const paragraph of paragraphs) {
        const line = [];
        (0, format_1.addToDestination)(line, paragraph, mergedOpts);
        result.push(line.join(''));
    }
    return result.join('\n\n');
}
exports.toAnsibleDocText = toAnsibleDocText;
//# sourceMappingURL=ansible-doc-text.js.map