import './database-convert-view.js';
import { assertExists } from '@blockeditor/global/utils';
import { html } from 'lit';
import { matchFlavours } from '../../../_common/utils/model.js';
import { createSimplePortal } from '../../components/portal.js';
import { toast } from '../../components/toast.js';
import { CopyIcon, DatabaseTableViewIcon20 } from '../../icons/index.js';
import { getChainWithHost } from '../../utils/command.js';
import { DATABASE_CONVERT_WHITE_LIST } from './database-convert-view.js';
export const quickActionConfig = [
    {
        id: 'copy',
        name: 'Copy',
        disabledToolTip: undefined,
        icon: CopyIcon,
        hotkey: undefined,
        showWhen: () => true,
        enabledWhen: () => true,
        action: host => {
            host.std.command
                .pipe()
                .withHost()
                .getSelectedModels()
                .with({
                onCopy: () => {
                    toast('Copied to clipboard');
                },
            })
                .copySelectedModels()
                .run();
        },
    },
    {
        id: 'convert-to-database',
        name: 'Group as Database',
        disabledToolTip: 'Contains Block types that cannot be converted to Database',
        icon: DatabaseTableViewIcon20,
        hotkey: `Mod-g`,
        showWhen: host => {
            const selectedModels = host.command.getChainCtx(getChainWithHost(host.std).getSelectedModels({
                types: ['block', 'text'],
            })).selectedModels;
            if (!selectedModels || selectedModels.length === 0)
                return false;
            const firstBlock = selectedModels[0];
            assertExists(firstBlock);
            if (matchFlavours(firstBlock, ['affine:database'])) {
                return false;
            }
            return true;
        },
        enabledWhen: host => {
            const selectedModels = host.command.getChainCtx(getChainWithHost(host.std).getSelectedModels({
                types: ['block', 'text'],
            })).selectedModels;
            if (!selectedModels || selectedModels.length === 0)
                return false;
            return selectedModels.every(block => DATABASE_CONVERT_WHITE_LIST.includes(block.flavour));
        },
        action: host => {
            createSimplePortal({
                template: html `<database-convert-view
          .host=${host}
        ></database-convert-view>`,
            });
        },
    },
];
//# sourceMappingURL=config.js.map