import camelCase from 'lodash/camelCase';
import upperFirst from 'lodash/upperFirst';
import { getAllScopeMap } from './scopes';
export const parseScope = (scope) => {
    const [action, predicate] = scope.split(':');
    const [subjectPart, modifier] = predicate.split('@');
    const subject = upperFirst(camelCase(subjectPart));
    return [
        action,
        subject,
        modifier,
    ];
};
export const normalizeScopeName = (scope) => {
    const [action, subject, modifier] = parseScope(scope);
    return `${action}:${subject}${modifier ? `@${modifier}` : ''}`;
};
export const parseScopes = ({ scopes, isEnterprise, }) => {
    const scopeMap = getAllScopeMap({ isEnterprise });
    const filtered = scopes.map(normalizeScopeName).filter((scope) => {
        const foundScope = scopeMap[scope];
        if (!foundScope) {
            // eslint-disable-next-line no-console
            console.warn(`Invalid scope: ${scope}. Please check the scope name and try again.`);
            return false;
        }
        return true;
    });
    return new Set(filtered);
};
//# sourceMappingURL=parseScopes.js.map