import { BlockService } from '@blockeditor/block-std';
import { assertExists } from '@blockeditor/global/utils';
import { InlineManager } from '../_common/inline/inline-manager.js';
import { getAffineInlineSpecsWithReference, } from '../_common/inline/presets/affine-inline-specs.js';
import { affineInlineMarkdownMatches } from '../_common/inline/presets/markdown.js';
import { ReferenceNodeConfig } from '../_common/inline/presets/nodes/reference-node/reference-config.js';
import { DatabaseSelection } from './common/selection.js';
export class DatabaseService extends BlockService {
    constructor() {
        super(...arguments);
        this.inlineManager = new InlineManager();
        this.referenceNodeConfig = new ReferenceNodeConfig();
    }
    mounted() {
        super.mounted();
        this.selectionManager.register(DatabaseSelection);
        this.handleEvent('selectionChange', () => true);
        this.referenceNodeConfig.setPage(this.page);
        const inlineSpecs = getAffineInlineSpecsWithReference(this.referenceNodeConfig);
        this.inlineManager.registerSpecs(inlineSpecs);
        this.inlineManager.registerMarkdownMatches(affineInlineMarkdownMatches);
    }
    initDatabaseBlock(page, model, databaseId, viewType, isAppendNewRow = true) {
        const blockModel = page.getBlockById(databaseId);
        assertExists(blockModel);
        blockModel.initTemplate(viewType);
        if (isAppendNewRow) {
            // Add a paragraph after database
            const parent = page.getParent(model);
            assertExists(parent);
            page.addBlock('affine:paragraph', {}, parent.id);
        }
        blockModel.applyColumnUpdate();
    }
}
//# sourceMappingURL=database-service.js.map