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