"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ActionRowApiImpl = void 0;
const PopupRedux_1 = require("../../Redux/ActionsReducers/PopupRedux");
const ApiBase_1 = require("./ApiBase");
const ActionRowInternalApi_1 = require("../Internal/ActionRowInternalApi");
class ActionRowApiImpl extends ApiBase_1.ApiBase {
    constructor(_adaptable) {
        super(_adaptable);
        this.internalApi = new ActionRowInternalApi_1.ActionRowInternalApi(_adaptable);
    }
    getActionRowButtons() {
        var actionRowButtons = this.getActionRowOptions().actionRowButtons;
        if (typeof actionRowButtons === 'function') {
            const context = this.getAdaptableInternalApi().buildBaseContext();
            actionRowButtons = actionRowButtons(context);
        }
        return actionRowButtons !== null && actionRowButtons !== void 0 ? actionRowButtons : [];
    }
    displayEditActionRow(primaryKey) {
        const rowNode = this.getGridApi().getRowNodeForPrimaryKey(primaryKey);
        if (!rowNode) {
            this.logWarn(`Can NOT 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,
            },
        }));
    }
    displayCreateActionRow() {
        const createForm = this.internalApi.buildRowCreateForm();
        this.dispatchAction((0, PopupRedux_1.PopupShowForm)({
            Id: 'create_row_form',
            Form: createForm,
        }));
    }
    displayCloneActionRow(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,
            },
        }));
    }
}
exports.ActionRowApiImpl = ActionRowApiImpl;
