var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { WidgetElement } from '@blockeditor/lit';
import { limitShift, offset, shift } from '@floating-ui/dom';
import { customElement } from 'lit/decorators.js';
import { HoverController } from '../../../_common/components/hover/controller.js';
import { PAGE_HEADER_HEIGHT } from '../../../_common/consts.js';
import { ImageOptionsTemplate } from './image-options.js';
export const AFFINE_IMAGE_TOOLBAR_WIDGET = 'affine-image-toolbar-widget';
let AffineImageToolbarWidget = class AffineImageToolbarWidget extends WidgetElement {
    constructor() {
        super(...arguments);
        this._hoverController = new HoverController(this, ({ abortController }) => {
            const imageBlock = this.blockElement;
            const imageContainer = imageBlock.resizeImg;
            if (!imageContainer)
                return null;
            return {
                template: ImageOptionsTemplate({
                    editorHost: this.host,
                    model: imageBlock.model,
                    blob: imageBlock.blob,
                    abortController,
                    host: this.blockElement.host,
                }),
                computePosition: {
                    referenceElement: imageContainer,
                    placement: 'right-start',
                    middleware: [
                        offset({
                            mainAxis: 12,
                            crossAxis: 10,
                        }),
                        shift({
                            crossAxis: true,
                            padding: {
                                top: PAGE_HEADER_HEIGHT + 12,
                                bottom: 12,
                                right: 12,
                            },
                            limiter: limitShift(),
                        }),
                    ],
                    autoUpdate: true,
                },
            };
        });
    }
    connectedCallback() {
        super.connectedCallback();
        const imageBlock = this.blockElement;
        this._hoverController.setReference(imageBlock);
    }
};
AffineImageToolbarWidget = __decorate([
    customElement(AFFINE_IMAGE_TOOLBAR_WIDGET)
], AffineImageToolbarWidget);
export { AffineImageToolbarWidget };
//# sourceMappingURL=image-toolbar.js.map