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 { ShadowlessElement, WithDisposable } from '@blockeditor/lit';
import { css, html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
let BlockRenderer = class BlockRenderer extends WithDisposable(ShadowlessElement) {
    get model() {
        return this.root?.page.getBlockById(this.rowId);
    }
    connectedCallback() {
        super.connectedCallback();
        this.root = this.closest('editor-host') ?? undefined;
        this._disposables.addFromEvent(this, 'keydown', e => {
            if (e.key === 'Enter' && !e.shiftKey && !e.isComposing) {
                e.stopPropagation();
                e.preventDefault();
                return;
            }
            if (e.key === 'Backspace' &&
                !e.shiftKey &&
                !e.metaKey &&
                this.model?.text?.length === 0) {
                e.stopPropagation();
                e.preventDefault();
                return;
            }
        }, true);
    }
    renderIcon() {
        const iconColumn = this.view.header.iconColumn;
        if (!iconColumn) {
            return;
        }
        return html ` <div class="database-block-detail-header-icon">
      ${this.view.cellGetValue(this.rowId, iconColumn)}
    </div>`;
    }
    render() {
        const model = this.model;
        if (!model) {
            return;
        }
        return html ` ${this.root?.renderModel(model)} ${this.renderIcon()} `;
    }
};
BlockRenderer.styles = css `
    database-datasource-block-renderer {
      padding-bottom: 20px;
      display: flex;
      flex-direction: column;
      gap: 12px;
      margin-bottom: 4px;
      border-bottom: 1px solid var(--affine-border-color);
      font-size: var(--affine-font-base);
      line-height: var(--affine-line-height);
    }

    database-datasource-block-renderer .tips-placeholder {
      display: none;
    }

    .database-block-detail-header-icon {
      width: 20px;
      height: 20px;
      padding: 2px;
      border-radius: 4px;
      background-color: var(--affine-background-secondary-color);
    }

    .database-block-detail-header-icon svg {
      width: 16px;
      height: 16px;
    }
  `;
__decorate([
    property({ attribute: false })
], BlockRenderer.prototype, "view", void 0);
__decorate([
    property({ attribute: false })
], BlockRenderer.prototype, "rowId", void 0);
BlockRenderer = __decorate([
    customElement('database-datasource-block-renderer')
], BlockRenderer);
export { BlockRenderer };
//# sourceMappingURL=block-renderer.js.map