"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const APEX_REGEX = /^(@salesforce\/apex)(?:\/([A-Za-z0-9_]+\.[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)?))?$/;
function matchesApexScopedModule(id) {
    return id && id.match(APEX_REGEX);
}
exports.default = () => {
    return {
        name: 'rollup-plugin-apex',
        resolveId(id) {
            return matchesApexScopedModule(id) ? id : null;
        },
        load(id) {
            const idParts = matchesApexScopedModule(id);
            if (idParts) {
                const [scope, apexDefinition] = idParts.slice(1, 3);
                if (apexDefinition) {
                    const [method, classname, namespace = '""'] = apexDefinition
                        .split('.')
                        .reverse()
                        .map(content => JSON.stringify(content));
                    return `
import { getApexInvoker, generateGetApexWireAdapter } from 'force/lds';
import { register } from 'wire-service';

const apexInvoker = getApexInvoker(${namespace}, ${classname}, ${method}, false);
register(apexInvoker, generateGetApexWireAdapter(${namespace}, ${classname}, ${method}, false));
export default apexInvoker;
`;
                }
                else if (scope) {
                    return `
export { refresh as refreshApex, getSObjectValue } from 'force/lds';
`;
                }
            }
            return null;
        }
    };
};
//# sourceMappingURL=rollup-plugin-salesforce-apex.js.map