import { __decorate } from "tslib";
import { observable } from '@ni/fast-element';
import { FoundationElement } from '@ni/fast-foundation';
/**
 * Base class for table cell views, which are used within the nimble-table-cell.
 * Each TableColumn type has a corresponding TableCellView type (linked via TableColumn.cellViewTag).
 */
export class TableCellView extends FoundationElement {
    constructor() {
        super(...arguments);
        this.delegatedEvents = [];
        this.delegatedEventHandler = () => { };
    }
    /**
     * Gets the child elements in this cell view that should be able to be reached via Tab/ Shift-Tab,
     * if any.
     */
    get tabbableChildren() {
        return [];
    }
    columnChanged() {
        for (const eventName of this.delegatedEvents) {
            this.removeEventListener(eventName, this.delegatedEventHandler);
        }
        this.delegatedEvents = [];
        this.delegatedEventHandler = () => { };
        if (!this.column) {
            return;
        }
        this.delegatedEvents = this.column.columnInternals.delegatedEvents;
        this.delegatedEventHandler = (event) => {
            if (this.recordId) {
                this.column?.dispatchEvent(new CustomEvent('delegated-event', {
                    detail: {
                        originalEvent: event,
                        recordId: this.recordId
                    }
                }));
            }
        };
        for (const delegatedEvent of this.delegatedEvents) {
            this.addEventListener(delegatedEvent, this.delegatedEventHandler);
        }
    }
}
__decorate([
    observable
], TableCellView.prototype, "cellRecord", void 0);
__decorate([
    observable
], TableCellView.prototype, "columnConfig", void 0);
__decorate([
    observable
], TableCellView.prototype, "column", void 0);
__decorate([
    observable
], TableCellView.prototype, "recordId", void 0);
//# sourceMappingURL=index.js.map