/* eslint-disable @cspell/spellchecker */
import { useEffect, useMemo } from 'react';
import { NiceAxiosFallbackProps } from '@/shared/@types/error';
import { Dialog, DialogProps } from '@/shared/ui/dialogs/dialog';

export const KickOutError = ({ 
  error, 
  resetErrorBoundary 
}: NiceAxiosFallbackProps) => {
  useEffect(() => {
    console.error('[ErrorBoundary] Kickout Error', JSON.stringify(error.response?.data));
    // clearAuthData();
  }, [error]);

  const msg = useMemo(() => {
    let message: Partial<DialogProps> = {
      title: '일시적인 오류가 발생하였습니다.',
      message: '잠시 후 다시 시도해주세요.',
    };
    if(error?.response?.data?.message){
      message = { 
        message: error.response.data.message 
      };
    }
    return message;
  }, [error]);

  const handleCancel = () => {
    resetErrorBoundary?.();
  };
 
  const handleConfirm = () => {
    resetErrorBoundary?.();
    // kickOut();
  };

  return (
    <Dialog
      afterLeave={ () => null }
      open={ true }
      onClose={ () => null }
      onConfirmClick={ handleConfirm }
      onCancelClick={ handleCancel }
      message={ msg.message }
      buttonLabel={ ['취소', '재시도'] }
    />
  );
};
