import React, { useCallback, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { SideSheet } from '../../../../UI';
import UdpTransactionTypeStatusForm from '../forms/UdpTransactionTypeStatusForm';
const UdpTransactionTypeStatusCreateAndEditSidesheet = (props) => {
    const { initialTransactionTypeStatus, isSideSheetOpen, handleSideSheet, handleCreateTransactionTypeStatus, handleUpdateTransactionTypeStatus } = props;
    const isEditing = !!initialTransactionTypeStatus;
    const formRef = useRef();
    const { t } = useTranslation();
    const onSubmitForm = useCallback(async (values, initialData) => {
        if (initialData) {
            await handleUpdateTransactionTypeStatus(values, initialData);
        }
        else {
            await handleCreateTransactionTypeStatus(values);
        }
    }, [handleCreateTransactionTypeStatus, handleUpdateTransactionTypeStatus]);
    return (React.createElement(SideSheet, { open: isSideSheetOpen, width: 500, title: isEditing ? t('Edit Status') : t('Create Status'), 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(UdpTransactionTypeStatusForm, { ref: formRef, onSubmit: onSubmitForm, initialData: initialTransactionTypeStatus })));
};
export default UdpTransactionTypeStatusCreateAndEditSidesheet;
//# sourceMappingURL=UdpTransactionTypeStatusCreateAndEditSidesheet.js.map