import React, { forwardRef, useCallback, useImperativeHandle, useRef } from 'react';
import { Field, Form } from '../../../../utilities/form';
import { AmbientAutoComplete } from '../../../../UI/inputs/textField';
import { useTranslation } from 'react-i18next';
const UdpTransactionUiActionForm = (props, ref) => {
    const { onSubmit, initialData, transactionUiActionTypeOptions, actionApiOptions, pageOptions } = props;
    const { t } = useTranslation();
    const handleSubmitRef = useRef();
    useImperativeHandle(ref, () => ({
        submit: () => {
            // eslint-disable-next-line no-unused-expressions
            handleSubmitRef === null || handleSubmitRef === void 0 ? void 0 : handleSubmitRef.current();
        }
    }));
    const handleSubmit = useCallback(formData => {
        onSubmit(formData, initialData);
    }, [initialData, onSubmit]);
    return (React.createElement(Form, { onSubmit: handleSubmit, render: ({ handleSubmit }) => {
            handleSubmitRef.current = handleSubmit;
            return (React.createElement(React.Fragment, null, React.createElement(Field, { component: AmbientAutoComplete, label: t("Transaction UI Action Type"), id: "transactionUiActionType", name: "transactionUiActionType", variant: "outlined", isMultiple: false, disableCloseOnSelect: false, options: transactionUiActionTypeOptions || [], getOptionLabelFunction: option => option.name, initialValue: (transactionUiActionTypeOptions === null || transactionUiActionTypeOptions === void 0 ? void 0 : transactionUiActionTypeOptions.find(transactionUiActionType => (transactionUiActionType === null || transactionUiActionType === void 0 ? void 0 : transactionUiActionType.transactionUiActionTypeId) === (initialData === null || initialData === void 0 ? void 0 : initialData.transactionUiActionTypeId))) || null, required: true }), React.createElement(Field, { component: AmbientAutoComplete, label: t("Action Api"), id: "actionApi", name: "actionApi", variant: "outlined", isMultiple: false, disableCloseOnSelect: false, options: actionApiOptions || [], getOptionLabelFunction: option => option.name, initialValue: (actionApiOptions === null || actionApiOptions === void 0 ? void 0 : actionApiOptions.find(actionApi => {
                    var _a;
                    return (actionApi === null || actionApi === void 0 ? void 0 : actionApi.actionApiId) === ((_a = initialData === null || initialData === void 0 ? void 0 : initialData.parameters) === null || _a === void 0 ? void 0 : _a.actionApiId);
                })) || null }), React.createElement(Field, { component: AmbientAutoComplete, label: t("Page"), id: "page", name: "page", variant: "outlined", isMultiple: false, disableCloseOnSelect: false, options: pageOptions || [], getOptionLabelFunction: option => option.name, initialValue: (pageOptions === null || pageOptions === void 0 ? void 0 : pageOptions.find(page => {
                    var _a;
                    return (page === null || page === void 0 ? void 0 : page.pageId) === ((_a = initialData === null || initialData === void 0 ? void 0 : initialData.parameters) === null || _a === void 0 ? void 0 : _a.pageId);
                })) || null })));
        } }));
};
export default forwardRef(UdpTransactionUiActionForm);
//# sourceMappingURL=UdpTransactionUiActionForm.js.map