import { ApiBase } from './ApiBase';
import { RowFormInternalApi } from '../Internal/RowFormInternalApi';
import { PopupShowForm } from '../../Redux/ActionsReducers/PopupRedux';
export class RowFormApiImpl extends ApiBase {
    constructor(_adaptable) {
        super(_adaptable);
        this.internalApi = new RowFormInternalApi(_adaptable);
    }
    displayEditRowForm(primaryKey) {
        const rowNode = this.getGridApi().getRowNodeForPrimaryKey(primaryKey);
        if (!rowNode) {
            this.logWarn(`Cannot edit row: rowNode not found for primaryKey ${primaryKey}`);
        }
        const editForm = this.internalApi.buildRowEditForm(rowNode);
        this.dispatchAction(PopupShowForm({
            Id: 'edit_row_form',
            Form: editForm,
            // formProps are added to the formContext
            FormProps: {
                rowNode,
            },
        }));
    }
    displayCreateRowForm() {
        const createForm = this.internalApi.buildRowCreateForm();
        this.dispatchAction(PopupShowForm({
            Id: 'create_row_form',
            Form: createForm,
        }));
    }
    displayCloneRowForm(primaryKey) {
        const rowNode = this.getGridApi().getRowNodeForPrimaryKey(primaryKey);
        if (!rowNode) {
            this.logWarn(`Can NOT clone row: rowNode not found for primaryKey ${primaryKey}`);
        }
        const createForm = this.internalApi.buildRowCreateForm(rowNode);
        this.dispatchAction(PopupShowForm({
            Id: 'create_row_form',
            Form: createForm,
            // formProps are added to the formContext
            FormProps: {
                clonedRowNode: rowNode,
            },
        }));
    }
}
