import {ErrorBoundary, Loading, Modal} from '@components';
import {FC, Suspense} from 'react';
import Info from './Info';
import {useSubmit, useTransfer} from './hooks';

type Props = {
  id: string;
  onClose: () => void;
  onFetch: () => void;
  visible: boolean;
};

const PdaMenuModal: FC<Props> = function ({id, onClose, onFetch, visible}) {
  const [selected, onChange] = useTransfer(id);
  const [isLoading, onSubmit] = useSubmit({selected, id, onFetch, onClose});

  return (
    <Modal
      title='PDA菜单权限'
      visible={visible}
      testId='role_pda_menu_modal'
      onSubmit={onSubmit}
      onClose={onClose}
      isLoading={isLoading}
    >
      <ErrorBoundary>
        <Suspense fallback={<Loading tip='正在获取菜单' height='200px' />}>
          <Info selected={selected} onChange={onChange} />
        </Suspense>
      </ErrorBoundary>
    </Modal>
  );
};

export default PdaMenuModal;
