// related component
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 } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
import { createRef } from 'lit/directives/ref.js';
import { html } from 'lit/static-html.js';
import { renderUniLit } from '../../_common/components/uni-component/uni-component.js';
const styles = css `
  affine-data-view-kanban-cell {
    border-radius: 4px;
    display: flex;
    align-items: center;
    padding: 4px;
    min-height: 20px;
    border: 1px solid transparent;
    box-sizing: border-box;
  }

  affine-data-view-kanban-cell:hover {
    background-color: var(--affine-hover-color);
  }

  affine-data-view-kanban-cell .icon {
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: start;
    margin-right: 12px;
    height: var(--data-view-cell-text-line-height);
  }

  affine-data-view-kanban-cell .icon svg {
    width: 16px;
    height: 16px;
    fill: var(--affine-icon-color);
    color: var(--affine-icon-color);
  }

  .kanban-cell {
    flex: 1;
    display: block;
    width: 196px;
  }
`;
let KanbanCell = class KanbanCell extends WithDisposable(ShadowlessElement) {
    constructor() {
        super(...arguments);
        this.contentOnly = false;
        this.isFocus = false;
        this.editing = false;
        this._cell = createRef();
        this.selectCurrentCell = (editing) => {
            const selectionElement = this.closest('affine-data-view-kanban')
                ?.selectionController;
            if (!selectionElement)
                return;
            selectionElement.selection = {
                selectionType: 'cell',
                groupKey: this.groupKey,
                cardId: this.cardId,
                columnId: this.column.id,
                isEditing: editing,
            };
        };
    }
    get cell() {
        return this._cell.value;
    }
    connectedCallback() {
        super.connectedCallback();
        this._disposables.addFromEvent(this, 'click', e => {
            if (e.shiftKey) {
                return;
            }
            e.stopPropagation();
            const selectionElement = this.closest('affine-data-view-kanban')
                ?.selectionController;
            if (!selectionElement)
                return;
            if (e.shiftKey)
                return;
            if (!this.editing) {
                this.selectCurrentCell(!this.column.readonly);
            }
        });
    }
    get selection() {
        return this.closest('affine-data-view-kanban')?.selectionController;
    }
    renderIcon() {
        if (this.contentOnly) {
            return;
        }
        return html ` <uni-lit class="icon" .uni="${this.column.icon}"></uni-lit>`;
    }
    render() {
        const props = {
            view: this.view,
            column: this.column,
            rowId: this.cardId,
            isEditing: this.editing,
            selectCurrentCell: this.selectCurrentCell,
        };
        const { view, edit } = this.column.renderer;
        this.style.border = this.isFocus
            ? '1px solid var(--affine-primary-color)'
            : '';
        this.style.boxShadow = this.editing
            ? '0px 0px 0px 2px rgba(30, 150, 235, 0.30)'
            : '';
        return html ` ${this.renderIcon()}
    ${renderUniLit(this.editing && edit ? edit : view, props, {
            ref: this._cell,
            class: 'kanban-cell',
            style: { display: 'block', flex: '1', overflow: 'hidden' },
        })}`;
    }
};
KanbanCell.styles = styles;
__decorate([
    property({ attribute: false })
], KanbanCell.prototype, "contentOnly", void 0);
__decorate([
    property({ attribute: false })
], KanbanCell.prototype, "view", void 0);
__decorate([
    property({ attribute: false })
], KanbanCell.prototype, "groupKey", void 0);
__decorate([
    property({ attribute: false })
], KanbanCell.prototype, "cardId", void 0);
__decorate([
    property({ attribute: false })
], KanbanCell.prototype, "column", void 0);
__decorate([
    state()
], KanbanCell.prototype, "isFocus", void 0);
__decorate([
    state()
], KanbanCell.prototype, "editing", void 0);
KanbanCell = __decorate([
    customElement('affine-data-view-kanban-cell')
], KanbanCell);
export { KanbanCell };
//# sourceMappingURL=cell.js.map