import { injectable } from '@theia/core/shared/inversify';
import { AbstractViewContribution } from '@theia/core/lib/browser';
import { Command, CommandRegistry, MenuModelRegistry } from '@theia/core/lib/common';
import { CommonMenus } from '@theia/core/lib/browser';
import { DesignPanelWidget } from './design-panel-widget';

export const DesignPanelCommand: Command = {
    id: 'vibn.design.panel.open',
    label: 'Open Design Panel',
    category: 'Design',
};

@injectable()
export class DesignPanelContribution extends AbstractViewContribution<DesignPanelWidget> {

    constructor() {
        super({
            widgetId: DesignPanelWidget.ID,
            widgetName: DesignPanelWidget.LABEL,
            defaultWidgetOptions: {
                area: 'main',
            },
            toggleCommandId: DesignPanelCommand.id,
        });
    }

    override registerCommands(registry: CommandRegistry): void {
        super.registerCommands(registry);
        registry.registerCommand(DesignPanelCommand, {
            execute: () => this.openView({ reveal: true, activate: true }),
        });
    }

    override registerMenus(menus: MenuModelRegistry): void {
        super.registerMenus(menus);
        menus.registerMenuAction(CommonMenus.VIEW_VIEWS, {
            commandId: DesignPanelCommand.id,
            label: 'Design Panel',
            order: 'z',
        });
    }
}
