import React, { forwardRef, useCallback, useImperativeHandle, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { Field, Form } from '../../../../utilities/form';
import { AmbientAutoComplete } from '../../../../UI/inputs/textField';
const UdpTransactionTypeConfigurationTransactionActionForm = (props, ref) => {
    const { onSubmit, initialData, transactionTypeTransactionActionOptions, isEditing } = 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, isEditing &&
                React.createElement(Field, { component: AmbientAutoComplete, label: t("TransactionTypeTransactionActions"), id: "transactionTypeTransactionAction", name: "transactionTypeTransactionAction", variant: "outlined", isMultiple: false, disableCloseOnSelect: false, options: transactionTypeTransactionActionOptions || [], getOptionLabelFunction: option => option.name, initialValue: (transactionTypeTransactionActionOptions === null || transactionTypeTransactionActionOptions === void 0 ? void 0 : transactionTypeTransactionActionOptions.find(ttta => (ttta === null || ttta === void 0 ? void 0 : ttta.transactionTypeTransactionActionId) === (initialData === null || initialData === void 0 ? void 0 : initialData.transactionTypeTransactionActionId))) || null, required: true }), !!!isEditing &&
                React.createElement(Field, { component: AmbientAutoComplete, label: t("Actions to Link"), id: "transactionTypeTransactionActions", name: "transactionTypeTransactionActions", variant: "outlined", isMultiple: true, disableCloseOnSelect: true, options: transactionTypeTransactionActionOptions || [], getOptionLabelFunction: option => option.name, required: true })));
        } }));
};
export default forwardRef(UdpTransactionTypeConfigurationTransactionActionForm);
//# sourceMappingURL=UdpTransactionTypeConfigurationTransactionActionForm.js.map