"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.imports = void 0;
const transpile_1 = require("../../../transpile");
exports.imports = [
    { name: 'WmFormAction', from: '@wavemaker/app-rn-runtime/components/data/form/form-action/form-action.component' }
];
const getFormActionExpr = (action) => {
    return `($event) => {
        ${action}
    }`;
};
exports.default = {
    pre: (element, context) => {
        element.setAttribute('displayName', element.attrs['display-name']);
        element.removeAttribute('display-name');
        element.removeAttribute('key');
        const formName = element.getAttribute('formKey') || element.attrs['key'] || element.attrs['name'];
        const actionType = element.getAttribute('type');
        let action = element.getAttribute('action');
        let btnClass = 'btn-default';
        if (actionType === 'submit') {
            btnClass = 'btn-primary';
            action = `Widgets.${formName}.submit();` + (action || '');
        }
        if (actionType === 'reset') {
            action = `Widgets.${formName}.formreset();` + (action || '');
        }
        if (action) {
            action = action.endsWith(';') ? action.substring(0, action.length - 1) : action;
            action = action.split(';').map(s => 'fragment.' + s).join(';');
            element.setAttribute('action', `()=> ${action}`);
        }
        element.setAttribute('btnClass', btnClass);
        element.removeAttribute('type');
        if (!element.getAttribute('name')) {
            element.setAttribute('name', formName + '_' + actionType + '_formAction');
        }
        return `<WmFormAction ${(0, transpile_1.transformAttrs)(element, context)}
            ${action && actionType ? `formAction={${getFormActionExpr(action)}}` : ''} >`;
    },
    post: (element, context) => '</WmFormAction>',
    imports: (element, context) => exports.imports
};
//# sourceMappingURL=form-action.transformer.js.map