"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RowFormApiImpl = void 0;
const ApiBase_1 = require("./ApiBase");
const RowFormInternalApi_1 = require("../Internal/RowFormInternalApi");
const PopupRedux_1 = require("../../Redux/ActionsReducers/PopupRedux");
class RowFormApiImpl extends ApiBase_1.ApiBase {
    internalApi;
    constructor(_adaptable) {
        super(_adaptable);
        this.internalApi = new RowFormInternalApi_1.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((0, PopupRedux_1.PopupShowForm)({
            Id: 'edit_row_form',
            Form: editForm,
            // formProps are added to the formContext
            FormProps: {
                rowNode,
            },
        }));
    }
    displayCreateRowForm() {
        const createForm = this.internalApi.buildRowCreateForm();
        this.dispatchAction((0, PopupRedux_1.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((0, PopupRedux_1.PopupShowForm)({
            Id: 'create_row_form',
            Form: createForm,
            // formProps are added to the formContext
            FormProps: {
                clonedRowNode: rowNode,
            },
        }));
    }
    displayDeleteRowForm(primaryKey) {
        const rowNode = this.getGridApi().getRowNodeForPrimaryKey(primaryKey);
        if (!rowNode) {
            this.logWarn(`Can NOT delete row: rowNode not found for primaryKey ${primaryKey}`);
        }
        const eventInfo = {
            type: 'rowDeleted',
            rowNode: rowNode,
            ...this.getAdaptableInternalApi().buildBaseContext(),
        };
        this.getEventApi().internalApi.fireRowFormSubmittedEvent(eventInfo);
        this.getRowFormOptions().onRowFormSubmit?.(eventInfo);
    }
}
exports.RowFormApiImpl = RowFormApiImpl;
