import { normalizePath } from '../../utils/index.js';
export function isRootItem(item) {
    return item.type === 'section' && item.id === '';
}
export function getItemsByType(items) {
    const groupItems = [];
    const tagItems = [];
    const operationItems = [];
    let rootItem = undefined;
    for (const item of items) {
        switch (item.type) {
            case 'group':
                groupItems.push(item);
                break;
            case 'tag':
                tagItems.push(item);
                break;
            case 'operation':
                operationItems.push(item);
                break;
            case 'section':
                if (isRootItem(item)) {
                    rootItem = item;
                }
                break;
        }
    }
    return { groupItems, tagItems, operationItems, rootItem };
}
export function getFirstPageLink(items, defaultRootLink) {
    for (const item of items) {
        if (item.type === 'group') {
            return getFirstPageLink(item.items, defaultRootLink);
        }
        else if (item.type === 'tag') {
            if (!item.description) {
                return normalizePath(getFirstPageLink(item.items, defaultRootLink));
            }
            if (item.href) {
                return normalizePath(item.href);
            }
        }
        else if (item.type === 'operation' || item.type === 'schema') {
            return normalizePath(item.href);
        }
    }
    return defaultRootLink;
}
//# sourceMappingURL=helpers.js.map