import { attr, nullableNumberConverter } from '@ni/fast-element';
import { TableColumnSortDirection } from '../../table/types';
// As the returned class is internal to the function, we can't write a signature that uses is directly, so rely on inference
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
export function mixinSortableColumnAPI(base) {
    /**
     * The Mixin that provides a concrete column with the API to allow sorting
     * by the values in that column.
     */
    class SortableColumn extends base {
        constructor() {
            super(...arguments);
            this.sortingDisabled = false;
            this.sortDirection = TableColumnSortDirection.none;
        }
        /** @internal */
        sortingDisabledChanged() {
            this.columnInternals.sortingDisabled = this.sortingDisabled;
            if (this.sortingDisabled) {
                this.columnInternals.currentSortDirection = TableColumnSortDirection.none;
                this.columnInternals.currentSortIndex = undefined;
            }
            else {
                this.columnInternals.currentSortDirection = this.sortDirection;
                this.columnInternals.currentSortIndex = this.sortIndex ?? undefined;
            }
        }
        /** @internal */
        sortDirectionChanged() {
            if (!this.sortingDisabled) {
                this.columnInternals.currentSortDirection = this.sortDirection;
            }
        }
        /** @internal */
        sortIndexChanged() {
            if (!this.sortingDisabled) {
                this.columnInternals.currentSortIndex = this.sortIndex ?? undefined;
            }
        }
    }
    attr({ attribute: 'sorting-disabled', mode: 'boolean' })(SortableColumn.prototype, 'sortingDisabled');
    attr({ attribute: 'sort-index', converter: nullableNumberConverter })(SortableColumn.prototype, 'sortIndex');
    attr({ attribute: 'sort-direction' })(SortableColumn.prototype, 'sortDirection');
    return SortableColumn;
}
//# sourceMappingURL=sortable-column.js.map