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;
};
/// <reference types="vite/client" />
import { BlockElement } from '@blockeditor/lit';
import { html } from 'lit';
import { customElement, state } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
import { isCssVariable } from '../_common/theme/css-variables.js';
import { Bound } from '../surface-block/index.js';
let FrameBlockComponent = class FrameBlockComponent extends BlockElement {
    constructor() {
        super(...arguments);
        this._isNavigator = false;
    }
    get titleElement() {
        return (this.closest('affine-edgeless-page')?.querySelector?.(`[data-frame-title-id="${this.model.id}"]`) ?? null);
    }
    get isInner() {
        const title = this.titleElement;
        if (!title)
            return false;
        return title.isInner;
    }
    get surface() {
        return this.closest('affine-edgeless-page').surface;
    }
    connectedCallback() {
        super.connectedCallback();
        let lastZoom = 0;
        this._disposables.add(this.surface.viewport.slots.viewportUpdated.on(({ zoom }) => {
            if (zoom !== lastZoom) {
                this.requestUpdate();
                lastZoom = zoom;
            }
        }));
        this._disposables.add(this.surface.edgeless.slots.elementUpdated.on(({ id }) => {
            if (id === this.model.id) {
                this.requestUpdate();
            }
        }));
    }
    createRenderRoot() {
        return this;
    }
    firstUpdated() {
        this.surface.edgeless.slots.edgelessToolUpdated.on(tool => {
            this._isNavigator = tool.type === 'frameNavigator' ? true : false;
        });
    }
    render() {
        const { model, _isNavigator } = this;
        const bound = Bound.deserialize(model.xywh);
        return html `
      <div
        class="affine-frame-container"
        style=${styleMap({
            width: bound.w + 'px',
            height: bound.h + 'px',
            backgroundColor: isCssVariable(model.background)
                ? `var(${model.background})`
                : '',
            borderRadius: '8px',
            border: _isNavigator ? 'none' : `2px solid var(--affine-black-30)`,
        })}
      ></div>
    `;
    }
};
__decorate([
    state()
], FrameBlockComponent.prototype, "_isNavigator", void 0);
FrameBlockComponent = __decorate([
    customElement('affine-frame')
], FrameBlockComponent);
export { FrameBlockComponent };
//# sourceMappingURL=frame-block.js.map