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 '../_common/components/embed-card/embed-card-caption.js';
import { assertExists } from '@blockeditor/global/utils';
import { ShadowlessElement, WithDisposable } from '@blockeditor/lit';
import { html, nothing } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
import { EMBED_CARD_HEIGHT, EMBED_CARD_WIDTH } from '../_common/consts.js';
import { getEdgelessPageByElement } from '../_common/utils/query.js';
import { Bound } from '../surface-block/utils/bound.js';
let EdgelessBookmarkBlockComponent = class EdgelessBookmarkBlockComponent extends WithDisposable(ShadowlessElement) {
    get model() {
        return this.block.model;
    }
    get edgeless() {
        const edgeless = getEdgelessPageByElement(this);
        assertExists(edgeless);
        return edgeless;
    }
    connectedCallback() {
        super.connectedCallback();
        this.disposables.add(this.edgeless.slots.elementUpdated.on(({ id }) => {
            if (id === this.model.id) {
                this.requestUpdate();
            }
        }));
    }
    render() {
        const style = this.model.style;
        const width = EMBED_CARD_WIDTH[style];
        const height = EMBED_CARD_HEIGHT[style];
        const bound = Bound.deserialize((this.edgeless.surface.pickById(this.model.id) ??
            this.model).xywh);
        const scaleX = bound.w / width;
        const scaleY = bound.h / height;
        return html `<div
      style=${styleMap({
            width: `${width}px`,
            height: `${height}px`,
            transform: `scale(${scaleX}, ${scaleY})`,
            transformOrigin: '0 0',
        })}
    >
      <bookmark-card .bookmark=${this.block}></bookmark-card>
      <embed-card-caption
        .block=${this.block}
        .display=${this.block.showCaption}
        @blur=${() => {
            if (!this.model.caption)
                this.block.showCaption = false;
        }}
      ></embed-card-caption>
      ${this.block.selected?.is('block')
            ? html `<affine-block-selection></affine-block-selection>`
            : nothing}
    </div>`;
    }
};
__decorate([
    property({ attribute: false })
], EdgelessBookmarkBlockComponent.prototype, "block", void 0);
EdgelessBookmarkBlockComponent = __decorate([
    customElement('affine-edgeless-bookmark')
], EdgelessBookmarkBlockComponent);
export { EdgelessBookmarkBlockComponent };
//# sourceMappingURL=edgeless-bookmark-block.js.map