import { useModal } from '@material-hu/hooks/useModal';

import useTimeout from 'src/hooks/useTimeout';

import useGetShowAdminInformation from '../hooks/useGetShowAdminInformation';
import useHideAdminInformationMutation from '../hooks/useHideAdminInformationMutation';
import PathsNewFeatureDialog from '../List/components/PathsNewFeatureDialog';

const useNewFeatureModal = () => {
  const { data: showAdminInformation } = useGetShowAdminInformation();
  const { mutate: hideAdminInformation } = useHideAdminInformationMutation();

  useTimeout(() => showAdminInformation && showNewFeatureModal(), 2000);

  const {
    showModal: showNewFeatureModal,
    closeModal: closeNewFeatureModal,
    modal: newFeatureModal,
  } = useModal(
    PathsNewFeatureDialog,
    {
      fullWidth: true,
      sx: {
        '& .MuiPaper-root': { maxWidth: '540px' },
        '& .MuiDialogContent-root': {
          p: 0,
          maxHeight: 'unset',
        },
      },
    },
    {
      onClose: () => {
        closeNewFeatureModal();
        hideAdminInformation();
      },
    },
  );

  return {
    showNewFeatureModal,
    closeNewFeatureModal,
    newFeatureModal,
  };
};

export default useNewFeatureModal;
