import { REDOCLY_TEAMS_RBAC } from '@redocly/config';
import { encodeBackSlashes, getOperationId, getOperationName } from '../../utils/index.js';
/**
 * Returns array of Operation items for the tag
 * @param parent parent OperationsGroup
 * @param tag tag info returned from `getTagsWithOperations`
 * @param depth items depth
 */
export function getOperationsItems(parent, tag, depth) {
    if (tag.operations.length === 0) {
        return [];
    }
    const operations = [];
    const webhooks = [];
    for (const operationDefinition of tag.operations) {
        const id = getOperationId(operationDefinition, parent);
        const type = 'operation';
        const item = {
            id,
            type,
            parent,
            operationDefinition,
            depth,
            name: getOperationName(operationDefinition),
            httpVerb: operationDefinition.httpVerb,
            path: operationDefinition.pathName,
            items: [],
            isWebhook: operationDefinition.isWebhook,
            operationId: operationDefinition.operationId,
            badges: operationDefinition['x-badges'] || [],
            href: getHref({ id }),
            deprecated: !!operationDefinition.deprecated,
            [REDOCLY_TEAMS_RBAC]: operationDefinition[REDOCLY_TEAMS_RBAC] || parent?.[REDOCLY_TEAMS_RBAC],
        };
        if (operationDefinition.isWebhook) {
            webhooks.push(item);
        }
        else {
            operations.push(item);
        }
    }
    return [
        ...operations.sort((a, b) => Number(a.deprecated) - Number(b.deprecated)),
        ...webhooks.sort((a, b) => Number(a.deprecated) - Number(b.deprecated)), // webhooks must be in the end for adding separator
    ];
}
export function getHref({ id }) {
    return encodeBackSlashes(`/${id}`.toLowerCase());
}
//# sourceMappingURL=operation.js.map