"use client";

import { FiTrash2 } from "react-icons/fi";
import Button from "../../../../components/ui/Button";
import { useModal } from "../../../../lib/modal-system/ModalContext";
import useUserStatusUpdate from "../../../../hooks/features/admin/users/useUserStatusUpdate";
import { useParams, useRouter } from "next/navigation";

export default function DeleteUserModal() {
  const { closeModal } = useModal();
  const { handleUserStatusUpdate, loading } = useUserStatusUpdate(
    "User deleted Successfully",
  );
  const { id } = useParams<{ id: string }>();
  const router = useRouter();

  const handleDelete = async () => {
    if (!id) return;
    try {
      await handleUserStatusUpdate(id);
      router.replace("/admin/users");
      closeModal();
    } catch (error) {}
  };

  return (
    <div className="text-center">
      <div className="mx-auto flex h-29 w-29 items-center justify-center rounded-full bg-danger-light">
        <div className="flex h-20 w-20 items-center justify-center rounded-full bg-red-400">
          <FiTrash2 size={34} className="text-white" />
        </div>
      </div>

      <h2 className="mt-7 mx-auto max-w-2xs text-2xl font-semibold leading-8 text-heading">
        Are you sure you want to delete this user?
      </h2>

      <p className="mx-auto mt-5 max-w-98 text-lg leading-6 text-text">
        This user will be permanently removed and cannot be recovered. Any
        active sessions will be terminated immediately.
      </p>

      <div className="mt-7.5 flex flex-col justify-center gap-4 sm:flex-row">
        <Button
          variant="white"
          onClick={closeModal}
          buttonClassName="shadow-none!"
          BtnInnerclassName="px-8! py-3.5!"
        >
          Cancel
        </Button>

        <Button
          variant="white"
          onClick={handleDelete}
          loading={loading}
          buttonClassName="shadow-none! p-0!"
          BtnInnerclassName="border border-danger-400 text-danger! px-8! py-3.5!"
        >
          Yes, Delete
        </Button>
      </div>
    </div>
  );
}
