import { __decorate } from "tslib";
import { observable } from '@ni/fast-element';
import { TableCellView } from '../../base/cell-view';
import { TableColumnAlignment } from '../../../table/types';
/**
 * The cell view base class for displaying fields of any type as text.
 */
export class TableColumnTextCellViewBase extends TableCellView {
    constructor() {
        super(...arguments);
        /** @internal */
        this.hasOverflow = false;
        /**
         * Text to render in the cell.
         */
        this.text = '';
        /**
         * The alignment of the text within the cell.
         */
        this.alignment = TableColumnAlignment.left;
        /**
         * Whether or not the text being displayed in the cell view is a placeholder.
         */
        this.isPlaceholder = false;
    }
    columnConfigChanged() {
        if (!this.applyPlaceholderTextIfNeeded()) {
            this.updateText();
        }
    }
    cellRecordChanged() {
        if (!this.applyPlaceholderTextIfNeeded()) {
            this.updateText();
        }
    }
    /**
     * Sets `this.text` to the appropriate placeholder if `cellValue` warrants it.
     * @returns `true` if `this.text` was set to a placeholder, `false` otherwise.
     */
    applyPlaceholderTextIfNeeded() {
        const cellValue = this.cellRecord?.value;
        const placeholder = this.columnConfig?.placeholder;
        if (typeof placeholder === 'string'
            && (cellValue === null || cellValue === undefined)) {
            this.text = placeholder;
            this.isPlaceholder = true;
        }
        else {
            this.isPlaceholder = false;
        }
        return this.isPlaceholder;
    }
}
__decorate([
    observable
], TableColumnTextCellViewBase.prototype, "hasOverflow", void 0);
__decorate([
    observable
], TableColumnTextCellViewBase.prototype, "text", void 0);
__decorate([
    observable
], TableColumnTextCellViewBase.prototype, "alignment", void 0);
__decorate([
    observable
], TableColumnTextCellViewBase.prototype, "isPlaceholder", void 0);
//# sourceMappingURL=index.js.map