/*
 * Copyright 2026, Jaime Terrats.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { basename, dirname } from 'node:path';
export const lwcParser = {
    type: 'LightningComponentBundle',
    glob: '**/lwc/*/*.js',
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    parse(filePath, _content) {
        // LWC main JS file: lwc/componentName/componentName.js
        const componentDir = dirname(filePath);
        const componentName = basename(componentDir);
        const fileName = basename(filePath, '.js');
        // Only parse the main component file (matches dir name)
        if (fileName !== componentName)
            return null;
        return {
            apiName: componentName,
            type: 'LightningComponentBundle',
            path: filePath,
            category: 'lwc',
            dependencies: [],
        };
    },
    extractDependencies(_entry, content) {
        const deps = new Set();
        // Apex imports: import methodName from '@salesforce/apex/ClassName.methodName'
        const apexPattern = /@salesforce\/apex\/([A-Za-z][A-Za-z0-9_]+)\./g;
        let match = apexPattern.exec(content);
        while (match) {
            deps.add(match[1]);
            match = apexPattern.exec(content);
        }
        // Wire adapters with object references: @salesforce/schema/ObjectName.FieldName
        const schemaPattern = /@salesforce\/schema\/([A-Za-z][A-Za-z0-9_]+)/g;
        match = schemaPattern.exec(content);
        while (match) {
            deps.add(match[1]);
            match = schemaPattern.exec(content);
        }
        // LWC component imports: import X from 'c/componentName'
        const lwcImportPattern = /from\s+['"]c\/([A-Za-z][A-Za-z0-9_]+)['"]/g;
        match = lwcImportPattern.exec(content);
        while (match) {
            deps.add(match[1]);
            match = lwcImportPattern.exec(content);
        }
        // Custom labels: import X from '@salesforce/label/c.LabelName'
        const labelPattern = /@salesforce\/label\/c\.([A-Za-z][A-Za-z0-9_]+)/g;
        match = labelPattern.exec(content);
        while (match) {
            deps.add(match[1]);
            match = labelPattern.exec(content);
        }
        return [...deps];
    },
};
//# sourceMappingURL=lwc-parser.js.map