import { __decorate } from "tslib";
import { DesignSystem } from '@ni/fast-foundation';
import { attr } from '@ni/fast-element';
import { template } from './template';
import { styles } from '../base/styles';
import { tableColumnMenuButtonCellViewTag } from './cell-view';
import { ColumnValidator } from '../base/models/column-validator';
import { mixinFractionalWidthColumnAPI } from '../mixins/fractional-width-column';
import { TableColumn } from '../base';
import { cellViewMenuSlotName } from './types';
/**
 * The table column for displaying string fields as the content within a menu button.
 */
export class TableColumnMenuButton extends mixinFractionalWidthColumnAPI((TableColumn)) {
    /** @internal */
    onDelegatedEvent(e) {
        e.stopImmediatePropagation();
        const event = e;
        const originalEvent = event.detail.originalEvent;
        if (originalEvent.type === 'beforetoggle'
            || originalEvent.type === 'toggle') {
            const newEventName = `menu-button-column-${originalEvent.type}`;
            const originalToggleEvent = originalEvent;
            const detail = {
                ...originalToggleEvent.detail,
                recordId: event.detail.recordId
            };
            this.$emit(newEventName, detail);
        }
    }
    getColumnInternalsOptions() {
        return {
            cellRecordFieldNames: ['value'],
            cellViewTag: tableColumnMenuButtonCellViewTag,
            delegatedEvents: ['beforetoggle', 'toggle'],
            slotNames: [cellViewMenuSlotName],
            validator: new ColumnValidator([])
        };
    }
    fieldNameChanged() {
        this.columnInternals.dataRecordFieldNames = [this.fieldName];
        this.columnInternals.operandDataRecordFieldName = this.fieldName;
    }
    menuSlotChanged() {
        this.updateColumnConfig();
    }
    updateColumnConfig() {
        this.columnInternals.columnConfig = {
            menuSlot: this.menuSlot
        };
    }
}
__decorate([
    attr({ attribute: 'field-name' })
], TableColumnMenuButton.prototype, "fieldName", void 0);
__decorate([
    attr({ attribute: 'menu-slot' })
], TableColumnMenuButton.prototype, "menuSlot", void 0);
const nimbleTableColumnMenuButton = TableColumnMenuButton.compose({
    baseName: 'table-column-menu-button',
    template,
    styles
});
DesignSystem.getOrCreate()
    .withPrefix('nimble')
    .register(nimbleTableColumnMenuButton());
export const tableColumnMenuButtonTag = 'nimble-table-column-menu-button';
//# sourceMappingURL=index.js.map