import { FC } from 'react';

import Stack from '@material-hu/mui/Stack';
import Typography from '@material-hu/mui/Typography';

import Dialog from '@material-hu/components/design-system/Dialog';
import { GroupPrivacyPolicies } from 'src/types/groups';
import { useLokaliseTranslation as useTranslation } from 'src/utils/i18n';

type LeaveGroupModalProps = {
  onClose: () => void;
  onConfirm: () => void;
  privacyPolicy: GroupPrivacyPolicies;
  isLoading?: boolean;
};

const LeaveGroupModal: FC<LeaveGroupModalProps> = ({
  onClose,
  onConfirm,
  privacyPolicy,
  isLoading = false,
}) => {
  const { t } = useTranslation(['group']);

  const getDescriptionKey = () => {
    switch (privacyPolicy) {
      case GroupPrivacyPolicies.OPEN:
        return 'leave_group_confirm_description_open';
      case GroupPrivacyPolicies.CLOSE:
        return 'leave_group_confirm_description_close';
      case GroupPrivacyPolicies.SECRET:
        return 'leave_group_confirm_description_secret';
      default:
        return 'leave_group_confirm_description_open';
    }
  };

  return (
    <Dialog
      onClose={onClose}
      title={t('leave_group_confirm_title')}
      body={
        <Stack sx={{ gap: 2 }}>
          <Typography variant="globalS">{t(getDescriptionKey())}</Typography>
        </Stack>
      }
      primaryButtonProps={{
        children: t('leave_group_confirm_action'),
        onClick: onConfirm,
        loading: isLoading,
        color: 'error',
      }}
      secondaryButtonProps={{
        children: t('cancel'),
        onClick: onClose,
        disabled: isLoading,
      }}
    />
  );
};

export default LeaveGroupModal;
