"use client";

import { FiCheckCircle } 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 } from "next/navigation";

export default function ActivateUserModal({ userId }: { userId?: string }) {
  const { closeModal } = useModal();
  const { handleUserStatusUpdate, loading } = useUserStatusUpdate(
    "User Activated Successfully",
  );
  let { id } = useParams<{ id: string }>();

  const handleActivate = async () => {
    if (userId) {
      id = userId;
    }

    if (!id) return;

    try {
      await handleUserStatusUpdate(id);
      closeModal();
    } catch (error) {}
  };

  return (
    <div className="text-center">
      <div className="mx-auto flex h-29 w-29 items-center justify-center rounded-full bg-green-100">
        <div className="flex h-20 w-20 items-center justify-center rounded-full bg-green-500">
          <FiCheckCircle size={34} className="text-white" />
        </div>
      </div>

      <h2 className="mt-7 text-2xl font-semibold leading-8 text-heading">
        Are you sure you want to activate this user?
      </h2>

      <p className="mx-auto mt-5 max-w-98 text-lg leading-6 text-text">
        Activating this user will restore their account access immediately, and
        they will be able to sign in and use the platform again.
      </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={handleActivate}
          loading={loading}
          buttonClassName="shadow-none! p-0!"
          BtnInnerclassName="border border-green-500 text-green-600! px-8! py-3.5!"
        >
          Yes, Activate
        </Button>
      </div>
    </div>
  );
}
