"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComponentRegistry = void 0;
const path = __importStar(require("path"));
const fs = __importStar(require("fs-extra"));
/**
 * ComponentRegistry - Track all components in the project
 *
 * Maintains .mycontext/components_registry.json with metadata about:
 * - Installed shadCN components
 * - Custom generated components
 * - Component dependencies and usage
 *
 * Enables:
 * - LEGO assembly (component reuse)
 * - Token usage tracking
 * - Avoiding duplicate installations
 */
class ComponentRegistry {
    /**
     * Initialize component registry for a new project
     */
    async initialize(projectPath, asl, shadcnComponents) {
        const registry = {
            version: '1.0',
            shadcnComponents: shadcnComponents.map(name => ({
                name,
                version: 'latest',
                installedAt: new Date().toISOString()
            })),
            customComponents: [],
            stats: {
                totalShadCN: shadcnComponents.length,
                totalCustom: 0
            }
        };
        const registryPath = path.join(projectPath, '.mycontext', 'components_registry.json');
        await fs.ensureDir(path.dirname(registryPath));
        await fs.writeJSON(registryPath, registry, { spaces: 2 });
    }
    /**
     * Register a custom component
     */
    async registerComponent(projectPath, component) {
        const registryPath = path.join(projectPath, '.mycontext', 'components_registry.json');
        // Load existing registry
        const registry = await fs.readJSON(registryPath);
        // Add component
        registry.customComponents.push(component);
        registry.stats.totalCustom = registry.customComponents.length;
        // Save
        await fs.writeJSON(registryPath, registry, { spaces: 2 });
    }
    /**
     * Check if a shadCN component is installed
     */
    async has(projectPath, componentName) {
        try {
            const registryPath = path.join(projectPath, '.mycontext', 'components_registry.json');
            const registry = await fs.readJSON(registryPath);
            return registry.shadcnComponents.some(c => c.name === componentName);
        }
        catch {
            return false;
        }
    }
    /**
     * Get all custom components of a specific type
     */
    async findByType(projectPath, type) {
        try {
            const registryPath = path.join(projectPath, '.mycontext', 'components_registry.json');
            const registry = await fs.readJSON(registryPath);
            return registry.customComponents.filter(c => c.type === type);
        }
        catch {
            return [];
        }
    }
    /**
     * Get registry stats
     */
    async getStats(projectPath) {
        try {
            const registryPath = path.join(projectPath, '.mycontext', 'components_registry.json');
            const registry = await fs.readJSON(registryPath);
            return registry.stats;
        }
        catch {
            return null;
        }
    }
}
exports.ComponentRegistry = ComponentRegistry;
//# sourceMappingURL=ComponentRegistry.js.map