import React, { forwardRef, useImperativeHandle, useMemo, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { SideSheet } from '../../../../UI';
import { SearchMethodUdpGrid } from '../../../../UI/templates/newGrid';
import UdpTransactionAttachmentTypeCreateAndEditSidesheet from './UdpTransactionAttachmentTypeCreateAndEditSidesheet';
import { ConfigService } from '../../../../configService';
const UdpTransactionAttachmentTypeSidesheet = (props, ref) => {
    const { transactionType, transactionAttachmentType, isSideSheetOpen, isTransactionAttachmentTypeCreateOrEditSidesheetOpen, handleTransactionAttachmentTypeSidesheet, handleCreateOrEditTransactionAttachmentTypeSidesheet, handleCreateTransactionAttachmentType, handleUpdateTransactionAttachmentType, handleDeleteTransactionAttachmentType } = props;
    const transactionAttachmentTypeGridApiRef = useRef(null);
    const { t } = useTranslation();
    useImperativeHandle(ref, () => ({
        refreshServerSide: () => {
            var _a;
            // eslint-disable-next-line no-unused-expressions
            (_a = transactionAttachmentTypeGridApiRef === null || transactionAttachmentTypeGridApiRef === void 0 ? void 0 : transactionAttachmentTypeGridApiRef.current) === null || _a === void 0 ? void 0 : _a.refreshServerSide();
        }
    }));
    const columnDefs = useMemo(() => {
        return [
            {
                headerName: t('Attachment Type Id'),
                field: 'transactionAttachmentTypeId',
                resizable: true,
                sortable: false,
                hide: true,
            },
            {
                headerName: t('Name'),
                field: 'name',
                resizable: true,
                sortable: false,
            },
            {
                headerName: t('Actions'),
                field: 'actions',
                cellRenderer: 'actionsRenderer',
                cellRendererParams: {
                    actionList: [
                        {
                            id: 0,
                            title: t('Edit'),
                            iconName: 'edit',
                            handleOnClick: (e, transactionAttachmentType) => {
                                handleCreateOrEditTransactionAttachmentTypeSidesheet(true, transactionAttachmentType === null || transactionAttachmentType === void 0 ? void 0 : transactionAttachmentType.data);
                            }
                        },
                        {
                            id: 1,
                            title: t('Delete'),
                            iconName: 'trashCan',
                            handleOnClick: (e, transactionAttachmentType) => {
                                handleDeleteTransactionAttachmentType(transactionAttachmentType === null || transactionAttachmentType === void 0 ? void 0 : transactionAttachmentType.data);
                            }
                        },
                    ],
                },
                suppressMenu: true,
                sortable: false,
                filter: false,
                valueGetter: params => params.data,
            },
        ];
    }, [t, handleCreateOrEditTransactionAttachmentTypeSidesheet, handleDeleteTransactionAttachmentType]);
    const headerConfig = {
        title: t('Attachment Types'),
        primaryActionButton: {
            label: t('Add'),
            iconName: 'add',
            onClick: () => handleCreateOrEditTransactionAttachmentTypeSidesheet(true),
        },
    };
    const gridFunctions = [
        { name: 'agGridExport' },
        { name: 'agGridSizeColumnsToFit' },
        { name: 'agGridAutoSizeColumns' },
        { name: 'agGridResetColumns' },
        { name: 'agGridHideShowColumns' },
    ];
    const gridOptions = useMemo(() => {
        return {
            pagination: true,
        };
    }, []);
    const handleGridApiCallback = api => {
        transactionAttachmentTypeGridApiRef.current = api;
    };
    const searchMethodConfig = useMemo(() => {
        let filterElements = [];
        if (transactionType === null || transactionType === void 0 ? void 0 : transactionType.transactionTypeId) {
            filterElements = [
                {
                    searchField: 'TransactionTypeId',
                    searchOperator: '=',
                    searchValue: transactionType === null || transactionType === void 0 ? void 0 : transactionType.transactionTypeId,
                    groupId: 1,
                },
            ];
            return {
                requestUrl: `${ConfigService.productV1ApiUrl}/UdpTransactionAttachmentType/search`,
                customSearchObject: {
                    filterElements: filterElements,
                },
            };
        }
        return {};
    }, [transactionType]);
    return (React.createElement(SideSheet, { open: isSideSheetOpen, width: 800, title: t('Manage Attachment Types'), onClose: () => handleTransactionAttachmentTypeSidesheet(false) }, React.createElement(SearchMethodUdpGrid, { searchMethodConfig: searchMethodConfig, columnDefs: columnDefs, gridHeaderConfig: headerConfig, gridOptions: gridOptions, gridApiCallback: handleGridApiCallback, gridFunctions: gridFunctions }), React.createElement(UdpTransactionAttachmentTypeCreateAndEditSidesheet, { initialTransactionAttachmentType: transactionAttachmentType, isSideSheetOpen: isTransactionAttachmentTypeCreateOrEditSidesheetOpen, handleCreateTransactionAttachmentType: handleCreateTransactionAttachmentType, handleUpdateTransactionAttachmentType: handleUpdateTransactionAttachmentType, handleSideSheet: handleCreateOrEditTransactionAttachmentTypeSidesheet })));
};
export default forwardRef(UdpTransactionAttachmentTypeSidesheet);
//# sourceMappingURL=UdpTransactionAttachmentTypeSidesheet.js.map