'use strict';

/* ────────────────────────────────────────────────────────────────
   EPIC E5 — Advanced Editor
   
   Collaborative editing, Git integration, plugin system,
   custom node creation, marketplace integration, AI assistant
──────────────────────────────────────────────────────────────── */
function mergeVersionVectors(a, b) {
    var _a;
    const result = { ...a };
    for (const [key, val] of Object.entries(b)) {
        result[key] = Math.max((_a = result[key]) !== null && _a !== void 0 ? _a : 0, val);
    }
    return result;
}
function happensBefore(a, b) {
    var _a, _b;
    let atLeastOneLess = false;
    for (const key of Object.keys({ ...a, ...b })) {
        const av = (_a = a[key]) !== null && _a !== void 0 ? _a : 0;
        const bv = (_b = b[key]) !== null && _b !== void 0 ? _b : 0;
        if (av > bv)
            return false;
        if (av < bv)
            atLeastOneLess = true;
    }
    return atLeastOneLess;
}
const DEFAULT_GIT_CONFIG = {
    enabled: true,
    autoCommit: false,
    autoCommitInterval: 0,
    commitPrefix: '[nice2dev] ',
    branch: 'main',
    remote: 'origin',
    lfs: true,
    lfsPatterns: ['*.png', '*.jpg', '*.wav', '*.mp3', '*.ogg', '*.glb', '*.gltf', '*.fbx'],
    ignorePatterns: ['node_modules/', 'dist/', '.cache/', '*.log'],
};
class PluginRegistry {
    constructor() {
        this.plugins = new Map();
    }
    register(manifest) {
        this.plugins.set(manifest.id, {
            manifest,
            state: 'installed',
            api: {},
        });
    }
    activate(pluginId) {
        const plugin = this.plugins.get(pluginId);
        if (!plugin || plugin.state === 'active')
            return false;
        plugin.state = 'active';
        plugin.activatedAt = Date.now();
        return true;
    }
    deactivate(pluginId) {
        const plugin = this.plugins.get(pluginId);
        if (!plugin || plugin.state !== 'active')
            return false;
        plugin.state = 'disabled';
        return true;
    }
    getPlugin(pluginId) {
        return this.plugins.get(pluginId);
    }
    getActivePlugins() {
        const result = [];
        this.plugins.forEach(p => { if (p.state === 'active')
            result.push(p); });
        return result;
    }
    getContributions(key) {
        const result = [];
        for (const p of this.getActivePlugins()) {
            const contrib = p.manifest.contributes[key];
            if (Array.isArray(contrib))
                result.push(...contrib);
        }
        return result;
    }
    getAllPlugins() {
        const result = [];
        this.plugins.forEach(p => result.push(p));
        return result;
    }
}
function createCustomNode(name, category) {
    return {
        id: `custom_${name.toLowerCase().replace(/\s+/g, '_')}_${Date.now()}`,
        name,
        category,
        description: '',
        color: '#667788',
        inputs: [{ name: 'Exec', type: 'exec' }],
        outputs: [{ name: 'Exec', type: 'exec' }],
        properties: [],
        isSubgraph: false,
    };
}
const DEFAULT_KEYBINDINGS = [
    { id: 'save', commandId: 'project.save', key: 'Ctrl+S', description: 'Save project' },
    { id: 'undo', commandId: 'edit.undo', key: 'Ctrl+Z', description: 'Undo' },
    { id: 'redo', commandId: 'edit.redo', key: 'Ctrl+Y', description: 'Redo' },
    { id: 'copy', commandId: 'edit.copy', key: 'Ctrl+C', description: 'Copy' },
    { id: 'paste', commandId: 'edit.paste', key: 'Ctrl+V', description: 'Paste' },
    { id: 'cut', commandId: 'edit.cut', key: 'Ctrl+X', description: 'Cut' },
    { id: 'delete', commandId: 'edit.delete', key: 'Delete', description: 'Delete selection' },
    { id: 'selectAll', commandId: 'edit.selectAll', key: 'Ctrl+A', description: 'Select all' },
    { id: 'play', commandId: 'game.play', key: 'F5', description: 'Play game' },
    { id: 'stop', commandId: 'game.stop', key: 'Shift+F5', description: 'Stop game' },
    { id: 'pause', commandId: 'game.pause', key: 'F6', description: 'Pause game' },
    { id: 'duplicate', commandId: 'edit.duplicate', key: 'Ctrl+D', description: 'Duplicate selection' },
    { id: 'group', commandId: 'edit.group', key: 'Ctrl+G', description: 'Group selection' },
    { id: 'zoomIn', commandId: 'view.zoomIn', key: 'Ctrl+=', description: 'Zoom in' },
    { id: 'zoomOut', commandId: 'view.zoomOut', key: 'Ctrl+-', description: 'Zoom out' },
    { id: 'zoomReset', commandId: 'view.zoomReset', key: 'Ctrl+0', description: 'Reset zoom' },
    { id: 'toggleGrid', commandId: 'view.toggleGrid', key: 'Ctrl+G', when: 'shift', description: 'Toggle grid' },
    { id: 'search', commandId: 'edit.search', key: 'Ctrl+F', description: 'Search' },
    { id: 'commandPalette', commandId: 'editor.commandPalette', key: 'Ctrl+Shift+P', description: 'Command palette' },
];
const DEFAULT_EDITOR_LAYOUT = {
    id: 'default',
    name: 'Default',
    panels: [
        { panelId: 'scene-tree', visible: true, docked: true, position: 'left', width: 250, height: 0, order: 0 },
        { panelId: 'inspector', visible: true, docked: true, position: 'right', width: 300, height: 0, order: 0 },
        { panelId: 'assets', visible: true, docked: true, position: 'bottom', width: 0, height: 200, order: 0 },
        { panelId: 'console', visible: true, docked: true, position: 'bottom', width: 0, height: 200, order: 1 },
        { panelId: 'node-graph', visible: false, docked: true, position: 'bottom', width: 0, height: 300, order: 2 },
    ],
    toolbars: [
        { id: 'main', visible: true, position: 'top', items: ['save', 'undo', 'redo', 'play', 'pause', 'stop'] },
        { id: 'tools', visible: true, position: 'left', items: ['select', 'move', 'rotate', 'scale', 'rect', 'tile-paint'] },
    ],
    activeScene: '',
};

exports.DEFAULT_EDITOR_LAYOUT = DEFAULT_EDITOR_LAYOUT;
exports.DEFAULT_GIT_CONFIG = DEFAULT_GIT_CONFIG;
exports.DEFAULT_KEYBINDINGS = DEFAULT_KEYBINDINGS;
exports.PluginRegistry = PluginRegistry;
exports.createCustomNode = createCustomNode;
exports.happensBefore = happensBefore;
exports.mergeVersionVectors = mergeVersionVectors;
//# sourceMappingURL=AdvancedEditor.js.map
