import { jsx as _jsx } from "react/jsx-runtime";
import { AlertTriangle } from "lucide-react";
import { NewPageDialog, OpenPageDialog } from "../../../splash-screen/DialogWrappers";
const dialogMap = {
    newPage: NewPageDialog,
    openPage: OpenPageDialog,
};
function stopEvent(context) {
    context.event?.preventDefault?.();
    context.event?.stopPropagation?.();
}
export const openDialogCommandHandler = {
    type: "openDialog",
    disabled: (command) => {
        const settings = command.settings;
        return !settings.dialogId || !dialogMap[settings.dialogId];
    },
    execute: async (command, context) => {
        stopEvent(context);
        const settings = command.settings;
        const dialogId = settings.dialogId;
        if (!dialogId)
            return;
        const dialog = dialogMap[dialogId];
        if (!dialog)
            return;
        await context.editContext.openDialog(dialog, {});
    },
};
export const switchWorkspaceCommandHandler = {
    type: "switchWorkspace",
    disabled: (command) => {
        const settings = command.settings;
        return !settings.workspaceId;
    },
    execute: async (command, context) => {
        stopEvent(context);
        const settings = command.settings;
        if (!settings.workspaceId)
            return;
        context.editContext.switchWorkspace(settings.workspaceId);
    },
};
export const openUrlCommandHandler = {
    type: "openUrl",
    disabled: (command) => {
        const settings = command.settings;
        return !settings.url;
    },
    execute: async (command, context) => {
        stopEvent(context);
        const settings = command.settings;
        if (!settings.url)
            return;
        window.open(settings.url, settings.newTab ? "_blank" : "_self");
    },
};
export const startTourCommandHandler = {
    type: "startTour",
    disabled: (_command, context) => !context.editContext.startTour,
    execute: async (_command, context) => {
        stopEvent(context);
        context.editContext.startTour();
    },
};
export const openStatusPanelCommandHandler = {
    type: "openStatusPanel",
    disabled: (_command, context) => !context.editContext.updateUrl,
    execute: async (command, context) => {
        stopEvent(context);
        const settings = command.settings;
        const targetWorkspace = settings.workspaceId || "settings";
        const targetPanel = settings.panelId || "status";
        context.editContext.switchWorkspace(targetWorkspace, {
            skipConfirmation: false,
            urlParams: {
                ccpanel: targetPanel,
            },
        });
    },
    renderIcon: () => _jsx(AlertTriangle, { size: 16, strokeWidth: 1 }),
};
//# sourceMappingURL=uiActionHandlers.js.map