import { BlockService } from '@blockeditor/block-std';
import { Slot } from '@blockeditor/store';
import { FileDropManager, } from '../_common/components/file-drop-manager.js';
import { matchFlavours } from '../_common/utils/model.js';
import { addSiblingAttachmentBlock } from './utils.js';
export class AttachmentService extends BlockService {
    constructor() {
        super(...arguments);
        this.maxFileSize = 10 * 1000 * 1000; // 10MB (default)
        this.slots = {
            onFilesDropped: new Slot(),
        };
        this._fileDropOptions = {
            flavour: this.flavour,
            onDrop: async ({ files, targetModel, place }) => {
                if (!files.length || !targetModel)
                    return false;
                if (matchFlavours(targetModel, ['affine:surface']))
                    return false;
                // generic attachment block for all files except images
                const attachmentFiles = files.filter(file => !file.type.startsWith('image/'));
                attachmentFiles.forEach(file => {
                    addSiblingAttachmentBlock(this.std.host, file, this.maxFileSize, targetModel, place).catch(console.error);
                });
                this.slots.onFilesDropped.emit(attachmentFiles);
                return true;
            },
        };
    }
    mounted() {
        super.mounted();
        this.fileDropManager = new FileDropManager(this, this._fileDropOptions);
    }
}
//# sourceMappingURL=attachment-service.js.map