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/tags/multi-tag-select.js';
import '../../../../_common/components/tags/multi-tag-view.js';
import { customElement } from 'lit/decorators.js';
import { html } from 'lit/static-html.js';
import { createIcon } from '../../../../_common/components/icon/uni-icon.js';
import { popTagSelect } from '../../../../_common/components/tags/multi-tag-select.js';
import { BaseCellRenderer } from '../base-cell.js';
import { columnRenderer, createFromBaseCellRenderer } from '../renderer.js';
import { selectPureColumnConfig } from './define.js';
let SelectCell = class SelectCell extends BaseCellRenderer {
    render() {
        const value = this.value ? [this.value] : [];
        return html `
      <affine-multi-tag-view
        .value="${value}"
        .options="${this.column.data.options}"
      ></affine-multi-tag-view>
    `;
    }
};
SelectCell = __decorate([
    customElement('affine-database-select-cell')
], SelectCell);
export { SelectCell };
let SelectCellEditing = class SelectCellEditing extends BaseCellRenderer {
    constructor() {
        super(...arguments);
        this._onChange = ([id]) => {
            this.onChange(id);
        };
        this._editComplete = () => {
            this.selectCurrentCell(false);
        };
        this._onOptionsChange = (options) => {
            this.column.updateData(data => {
                return {
                    ...data,
                    options,
                };
            });
        };
        this.popTagSelect = () => {
            this._disposables.add({
                dispose: popTagSelect(this.querySelector('affine-multi-tag-view') ?? this, {
                    mode: 'single',
                    options: this._options,
                    onOptionsChange: this._onOptionsChange,
                    value: this._value,
                    onChange: this._onChange,
                    onComplete: this._editComplete,
                    minWidth: 400,
                }),
            });
        };
    }
    get _options() {
        return this.column.data.options;
    }
    get _value() {
        const value = this.value;
        return value ? [value] : [];
    }
    firstUpdated() {
        this.popTagSelect();
    }
    render() {
        return html `
      <affine-multi-tag-view
        .value="${this._value}"
        .options="${this._options}"
      ></affine-multi-tag-view>
    `;
    }
};
SelectCellEditing = __decorate([
    customElement('affine-database-select-cell-editing')
], SelectCellEditing);
export { SelectCellEditing };
columnRenderer.register({
    type: selectPureColumnConfig.type,
    icon: createIcon('DatabaseSelect'),
    cellRenderer: {
        view: createFromBaseCellRenderer(SelectCell),
        edit: createFromBaseCellRenderer(SelectCellEditing),
    },
});
export const selectColumnConfig = selectPureColumnConfig;
//# sourceMappingURL=cell-renderer.js.map