import { Arr, Optional, Strings } from '@ephox/katamari';
const markAsBehaviourApi = (f, apiName, apiFunction) => {
    const delegate = apiFunction.toString();
    const endIndex = delegate.indexOf(')') + 1;
    const openBracketIndex = delegate.indexOf('(');
    const parameters = delegate.substring(openBracketIndex + 1, endIndex - 1).split(/,\s*/);
    f.toFunctionAnnotation = () => ({
        name: apiName,
        parameters: cleanParameters(parameters.slice(0, 1).concat(parameters.slice(3)))
    });
    return f;
};
// Remove any comment (/*) at end of parameter names
const cleanParameters = (parameters) => Arr.map(parameters, (p) => Strings.endsWith(p, '/*') ? p.substring(0, p.length - '/*'.length) : p);
const markAsExtraApi = (f, extraName) => {
    const delegate = f.toString();
    const endIndex = delegate.indexOf(')') + 1;
    const openBracketIndex = delegate.indexOf('(');
    const parameters = delegate.substring(openBracketIndex + 1, endIndex - 1).split(/,\s*/);
    f.toFunctionAnnotation = () => ({
        name: extraName,
        parameters: cleanParameters(parameters)
    });
    return f;
};
const markAsSketchApi = (f, apiFunction) => {
    const delegate = apiFunction.toString();
    const endIndex = delegate.indexOf(')') + 1;
    const openBracketIndex = delegate.indexOf('(');
    const parameters = delegate.substring(openBracketIndex + 1, endIndex - 1).split(/,\s*/);
    f.toFunctionAnnotation = () => ({
        name: 'OVERRIDE',
        parameters: cleanParameters(parameters.slice(1))
    });
    return f;
};
const getAnnotation = (f) => { var _a; return Optional.from((_a = f.toFunctionAnnotation) === null || _a === void 0 ? void 0 : _a.call(f)); };
export { markAsBehaviourApi, markAsExtraApi, markAsSketchApi, getAnnotation };
//# sourceMappingURL=FunctionAnnotator.js.map