import { REDOCLY_TEAMS_RBAC } from '@redocly/config';
import { joinWithSeparator } from '../services/index.js';
import { getValueFromMdParsedExtension, safeSlugify } from '../utils/index.js';
import { getHref } from '../services/menu/operation.js';
import { saveTextBeforeHeading } from '../utils/saveTextBeforeHeading.js';
export function getTagOrGroup(type, tagOrGroup, parent) {
    let id;
    if (parent?.id && type === 'schema') {
        // handle schemas ids similar to how it is done for operations
        id = joinWithSeparator(parent.id, safeSlugify(tagOrGroup.name));
    }
    else {
        id = tagOrGroup.id || safeSlugify(tagOrGroup.name);
    }
    const name = tagOrGroup['x-displayName'] || tagOrGroup.name;
    const level = tagOrGroup.level || 1;
    const isSchema = tagOrGroup.isSchema;
    const ast = tagOrGroup.ast || undefined;
    const description = saveTextBeforeHeading(getValueFromMdParsedExtension(tagOrGroup, 'description') || '');
    const items = tagOrGroup.items || [];
    const externalDocs = tagOrGroup.externalDocs;
    return {
        id: id.toLowerCase(),
        type,
        parent,
        name,
        level,
        depth: 0,
        isSchema,
        description,
        items,
        ast,
        externalDocs,
        href: getHref({ id }),
        [REDOCLY_TEAMS_RBAC]: tagOrGroup[REDOCLY_TEAMS_RBAC] || parent?.[REDOCLY_TEAMS_RBAC],
    };
}
//# sourceMappingURL=group.js.map