import { Dialog, DialogContent, DialogDescription } from '@/components/ui/dialog';
import { DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Ban } from 'lucide-react';
import { useAuth } from 'hooks/useAuth';
import type { ErrorDialogsProps } from './index';

export const UnauthorizedDialog = ({ setApiError }: ErrorDialogsProps) => {
  const { signout } = useAuth();
  const onOpenChange = (value: boolean) => {
    if (!value) {
      setApiError(null);
      signout();
      window.location.reload();
    }
  };
  return (
    <Dialog open={true} onOpenChange={onOpenChange}>
      <DialogContent className="sm:max-w-[425px]">
        <DialogHeader>
          <DialogTitle className="flex items-center gap-10">
            <Ban className="h-12 w-12 text-red-500" />
            Invalid Credentials
          </DialogTitle>
          <DialogDescription className="flex flex-col gap-4 py-5">Your access token has expired</DialogDescription>
        </DialogHeader>
        <p>Please Signin again</p>
        <DialogFooter>
          <Button type="submit" onClick={() => onOpenChange(false)}>
            Ok
          </Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  );
};
