import { __decorate } from "tslib";
import { DesignSystem } from '@ni/fast-foundation';
import { ViewTemplate, observable } from '@ni/fast-element';
import { TableCellView } from '../../base/cell-view';
import { styles } from './styles';
import { template } from './template';
import { MappingIconConfig } from '../../enum-base/models/mapping-icon-config';
import { IconSeverity } from '../../../icon-base/types';
import { MappingSpinnerConfig } from '../../enum-base/models/mapping-spinner-config';
import { MappingTextConfig } from '../../enum-base/models/mapping-text-config';
import { MappingEmptyConfig } from '../../enum-base/models/mapping-empty-config';
/**
 * The cell view for the mapping column
 */
export class TableColumnMappingCellView extends TableCellView {
    constructor() {
        super(...arguments);
        this.textHidden = false;
        /** @internal */
        this.hasOverflow = false;
    }
    columnConfigChanged() {
        this.updateState();
    }
    cellRecordChanged() {
        this.updateState();
    }
    updateState() {
        this.resetState();
        if (!this.columnConfig || !this.cellRecord) {
            return;
        }
        const value = this.cellRecord.value;
        if (value === undefined || value === null) {
            return;
        }
        const mappingConfig = this.columnConfig.mappingConfigs.get(value);
        if (mappingConfig instanceof MappingIconConfig) {
            this.severity = mappingConfig.severity;
            this.text = mappingConfig.text;
            this.visualizationTemplate = mappingConfig.iconTemplate;
            this.textHidden = mappingConfig.textHidden;
        }
        else if (mappingConfig instanceof MappingSpinnerConfig) {
            this.text = mappingConfig.text;
            this.visualizationTemplate = mappingConfig.spinnerTemplate;
            this.textHidden = mappingConfig.textHidden;
        }
        else if (mappingConfig instanceof MappingTextConfig) {
            this.text = mappingConfig.text;
            this.textHidden = false;
        }
        else if (mappingConfig instanceof MappingEmptyConfig) {
            this.text = mappingConfig.text;
            this.textHidden = true;
        }
    }
    resetState() {
        this.text = undefined;
        this.textHidden = false;
        this.visualizationTemplate = undefined;
        this.severity = IconSeverity.default;
    }
}
__decorate([
    observable
], TableColumnMappingCellView.prototype, "severity", void 0);
__decorate([
    observable
], TableColumnMappingCellView.prototype, "text", void 0);
__decorate([
    observable
], TableColumnMappingCellView.prototype, "visualizationTemplate", void 0);
__decorate([
    observable
], TableColumnMappingCellView.prototype, "textHidden", void 0);
__decorate([
    observable
], TableColumnMappingCellView.prototype, "hasOverflow", void 0);
const mappingCellView = TableColumnMappingCellView.compose({
    baseName: 'table-column-mapping-cell-view',
    template,
    styles
});
DesignSystem.getOrCreate().withPrefix('nimble').register(mappingCellView());
export const tableColumnMappingCellViewTag = 'nimble-table-column-mapping-cell-view';
//# sourceMappingURL=index.js.map