// File: src/core/registry.js

export function createRegistry() {
    const modules = new Map();   // key: name -> moduleInstance
    const plugins = new Map();   // key: name -> pluginDefinition
    const formatters = new Map(); // مثال: برای نمایش عدد/تاریخ

    return {
        // ماژول‌ها (مثلاً dataManager, uiManager, ...)
        registerModule(name, instance) {
            modules.set(name, instance);
        },
        getModule(name) {
            return modules.get(name) || null;
        },
        hasModule(name) {
            return modules.has(name);
        },

        // پلاگین‌ها
        registerPlugin(name, pluginDefinition) {
            if (plugins.has(name)) {
                console.warn(`CPM registry: plugin "${name}" is already registered`);
            }
            plugins.set(name, pluginDefinition);
        },
        getPlugin(name) {
            return plugins.get(name) || null;
        },
        listPlugins() {
            return Array.from(plugins.keys());
        },

        // formatterها (مثلاً number, date, currency)
        registerFormatter(name, fn) {
            formatters.set(name, fn);
        },
        getFormatter(name) {
            return formatters.get(name) || null;
        },
        format(name, value, options = {}) {
            const fn = formatters.get(name);
            return fn ? fn(value, options) : value;
        }
    };
}
