import { getTagGroupsItems, getTagsItems, getTagsWithOperations } from './tags.js';
import { addMarkdownItems } from './markdown.js';
import { flattenByProp, getValueFromMdParsedExtension } from '../../utils/index.js';
import { DEFAULT_WEBHOOKS_TAG_NAME } from '../../constants.js';
export function buildMenuStructure(parser, options) {
    const { definition } = parser;
    const { schemaDefinitionsTagName } = options;
    const items = [
        {
            id: '',
            name: definition?.info?.['x-seo']?.title || definition?.info?.title || 'Overview',
            href: '/',
            depth: 1, // special case for root item,
            level: 1,
            type: 'section',
            infoDefinition: definition.info,
            items: [],
        },
    ];
    const tags = [...(definition.tags || [])];
    if (!tags.some((tag) => tag.name === DEFAULT_WEBHOOKS_TAG_NAME)) {
        tags.push({ name: DEFAULT_WEBHOOKS_TAG_NAME });
    }
    const hasAutogenerated = tags.find((tag) => tag?.name === schemaDefinitionsTagName);
    if (!hasAutogenerated && schemaDefinitionsTagName) {
        tags.push({ name: schemaDefinitionsTagName });
    }
    const tagsMap = getTagsWithOperations(parser, tags);
    const xTagGroups = definition['x-tagGroups'];
    items.push(...addMarkdownItems(getValueFromMdParsedExtension(definition.info, 'description') || '', undefined, 1));
    if (xTagGroups && xTagGroups.length > 0) {
        items.push(...getTagGroupsItems(parser, undefined, xTagGroups, tagsMap, options));
    }
    else {
        items.push(...getTagsItems(parser, tagsMap, undefined, undefined, options));
    }
    return items;
}
export function buildContentItems(parser, options) {
    const contentItems = buildMenuStructure(parser, options);
    const flatItems = flattenByProp(contentItems || [], 'items');
    return {
        contentItems,
        flatItems,
    };
}
//# sourceMappingURL=builder.js.map