import React, { useCallback, useRef } from 'react';
import { SideSheet } from '../../../../UI';
import UdpTransactionTypeConfigurationForm from '../forms/UdpTransactionTypeConfigurationForm';
import { useTranslation } from 'react-i18next';
const UdpTransactionTypeConfigurationCreateAndEditSidesheet = (props) => {
    const { initialTransactionTypeConfiguration, isSideSheetOpen, handleSideSheet, handleCreateTransactionTypeConfiguration, handleUpdateTransactionTypeConfiguration, transactionRuleTypes, catalogObjectProperties, ttstatuses, roles, } = props;
    const isEditing = !!initialTransactionTypeConfiguration;
    const formRef = useRef();
    const { t } = useTranslation();
    const onSubmitForm = useCallback(async (values, initialData) => {
        if (initialData) {
            await handleUpdateTransactionTypeConfiguration(values, initialData);
        }
        else {
            await handleCreateTransactionTypeConfiguration(values);
        }
    }, [handleCreateTransactionTypeConfiguration, handleUpdateTransactionTypeConfiguration]);
    return (React.createElement(SideSheet, { open: isSideSheetOpen, width: 800, title: isEditing ? t('Edit Rule') : t('Create Rule'), onClose: () => handleSideSheet(false), buttonLabel: isEditing ? t('Save') : t('Create'), onSubmit: () => {
            var _a;
            // eslint-disable-next-line no-unused-expressions
            (_a = formRef === null || formRef === void 0 ? void 0 : formRef.current) === null || _a === void 0 ? void 0 : _a.submit();
        } }, React.createElement(UdpTransactionTypeConfigurationForm, { ref: formRef, onSubmit: onSubmitForm, initialData: initialTransactionTypeConfiguration, transactionRuleTypes: transactionRuleTypes, catalogObjectProperties: catalogObjectProperties, transactionTypeStatusOptions: ttstatuses, roles: roles })));
};
export default UdpTransactionTypeConfigurationCreateAndEditSidesheet;
//# sourceMappingURL=UdpTransactionTypeConfigurationCreateAndEditSidesheet.js.map