
import { EventHelper } from '../../../base/browser/dom.js';
import { mainWindow } from '../../../base/browser/window.js';
import { fromNow } from '../../../base/common/date.js';
import { localize } from '../../../nls.js';
import { ResultKind } from '../../keybinding/common/keybindingResolver.js';
import { defaultDialogStyles, defaultInputBoxStyles, defaultCheckboxStyles, defaultButtonStyles } from '../../theme/browser/defaultStyles.js';

const defaultDialogAllowableCommands = [
    "workbench.action.quit",
    "workbench.action.reloadWindow",
    "copy",
    "cut",
    "editor.action.selectAll",
    "editor.action.clipboardCopyAction",
    "editor.action.clipboardCutAction",
    "editor.action.clipboardPasteAction"
];
function createWorkbenchDialogOptions(
    options,
    keybindingService,
    layoutService,
    allowableCommands = defaultDialogAllowableCommands
) {
    return {
        keyEventProcessor: event => {
            const resolved = keybindingService.softDispatch(event, layoutService.activeContainer);
            if (resolved.kind === ResultKind.KbFound && resolved.commandId) {
                if (!allowableCommands.includes(resolved.commandId)) {
                    EventHelper.stop(event, true);
                }
            }
        },
        buttonStyles: defaultButtonStyles,
        checkboxStyles: defaultCheckboxStyles,
        inputBoxStyles: defaultInputBoxStyles,
        dialogStyles: defaultDialogStyles,
        ...options
    };
}
function createBrowserAboutDialogDetails(productService) {
    const detailString = useAgo => {
        return localize(
            1801,
            "Version: {0}\nCommit: {1}\nDate: {2}\nBrowser: {3}",
            productService.version || "Unknown",
            productService.commit || "Unknown",
            productService.date ? `${productService.date}${useAgo ? " (" + fromNow(( new Date(productService.date)), true) + ")" : ""}` : "Unknown",
            mainWindow.navigator.userAgent
        );
    };
    const details = detailString(true);
    const detailsToCopy = detailString(false);
    return {
        title: productService.nameLong,
        details: details,
        detailsToCopy: detailsToCopy
    };
}

export { createBrowserAboutDialogDetails, createWorkbenchDialogOptions };
