/**
 * Component Discovery
 *
 * Discovers and catalogs components in a Zenith project
 * Similar to layout discovery but for reusable components
 */
let native;
try {
    try {
        native = require('../../native/compiler-native');
    }
    catch {
        native = require('../../native/compiler-native/index.js');
    }
}
catch (e) {
    // Bridge load handled elsewhere
}
/**
 * Discover all components in a directory
 * @param baseDir - Base directory to search (e.g., src/components)
 * @returns Map of component name to metadata
 */
export function discoverComponents(baseDir) {
    if (native && native.discoverComponentsNative) {
        try {
            const raw = native.discoverComponentsNative(baseDir);
            // The native function returns a Map-like object or Record
            const components = new Map();
            for (const [name, metadata] of Object.entries(raw)) {
                components.set(name, metadata);
            }
            return components;
        }
        catch (error) {
            console.warn(`[Zenith Native] Discovery failed for ${baseDir}: ${error.message}`);
        }
    }
    // Fallback or empty if native fails (bridge is required for performance)
    return new Map();
}
/**
 * Use native bridge for tag name checks
 */
export function isComponentTag(tagName) {
    if (native && native.isComponentTagNative) {
        return native.isComponentTagNative(tagName);
    }
    return tagName.length > 0 && tagName[0] === tagName[0]?.toUpperCase();
}
/**
 * Get component metadata by name
 */
export function getComponent(components, name) {
    return components.get(name);
}
