import { BindingEventService } from '@slickgrid-universal/binding';
import { SlickEventData } from '../core/index.js';
/*
 * An example of a 'detached' editor.
 * KeyDown events are also handled to provide handling for Tab, Shift-Tab, Esc and Ctrl-Enter.
 */
export class BaseEditorClass {
    constructor(args) {
        this.args = args;
        /** is the Editor disabled? */
        this.disabled = false;
        this.grid = args.grid;
        this.gridOptions = (this.grid.getOptions() || {});
        this._bindEventService = new BindingEventService();
    }
    /** Get Column Definition object */
    get columnDef() {
        return this.args.column;
    }
    /** Get Column Editor object */
    get columnEditor() {
        return this.columnDef?.editor || {};
    }
    /** Getter for the item data context object */
    get dataContext() {
        return this.args.item;
    }
    get hasAutoCommitEdit() {
        return this.gridOptions.autoCommitEdit ?? false;
    }
    /** Get the Validator function, can be passed in Editor property or Column Definition */
    get validator() {
        return this.columnEditor?.validator ?? this.columnDef?.validator;
    }
    // --
    // protected functions
    // ------------------
    /** when it's a Composite Editor, we'll check if the Editor is editable (by checking onBeforeEditCell) and if not Editable we'll disable the Editor */
    checkInputUsabilityState() {
        const activeCell = this.grid.getActiveCell();
        const isCellEditable = this.grid.onBeforeEditCell
            .notify({
            ...activeCell,
            item: this.dataContext,
            column: this.args.column,
            grid: this.grid,
            target: 'composite',
            compositeEditorOptions: this.args.compositeEditorOptions,
        })
            .getReturnValue();
        return isCellEditable;
    }
    handleChangeOnCompositeEditor(event, compositeEditorOptions, triggeredBy = 'user', isCalledByClearValue = false) {
        const activeCell = this.grid.getActiveCell();
        const column = this.args.column;
        const columnId = this.columnDef?.id ?? '';
        const item = this.dataContext;
        const grid = this.grid;
        const isExcludeDisabledFieldFormValues = this.gridOptions?.compositeEditorOptions?.excludeDisabledFieldFormValues ?? false;
        if (isCalledByClearValue ||
            (this.disabled && isExcludeDisabledFieldFormValues && compositeEditorOptions.formValues.hasOwnProperty(columnId))) {
            delete compositeEditorOptions.formValues[columnId]; // when the input is disabled we won't include it in the form result object
        }
        grid.onCompositeEditorChange.notify({
            ...activeCell,
            item,
            grid,
            column,
            formValues: compositeEditorOptions.formValues,
            editors: compositeEditorOptions.editors,
            triggeredBy,
        }, new SlickEventData(event));
    }
}
//# sourceMappingURL=baseEditorClass.js.map