"use client";

import { FiTrash2 } from "react-icons/fi";
import Button from "../../../../components/ui/Button";
import { Package } from "../../../../hooks/features/packages/usePackagesFetch";
import usePackageDelete from "../../../../hooks/features/admin/packages/usePackageDelete";
import { useModal } from "../../../../lib/modal-system/ModalContext";

export default function DeletePackageModal({ item }: { item: Package }) {
  const { closeModal } = useModal();
  const { handlePackageDelete, loading: deleteLoading } = usePackageDelete();

  const handleDelete = async () => {
    try {
      await handlePackageDelete(item.uuid);

      closeModal();
    } catch (error) {
      console.log(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 package?
      </h2>

      <p className="mx-auto mt-5 max-w-98 text-lg leading-6 text-text">
        This package will be permanently removed and cannot be recovered.
      </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"
          loading={deleteLoading}
          onClick={handleDelete}
          buttonClassName="shadow-none! p-0!"
          BtnInnerclassName="border border-danger-400 text-danger! px-8! py-3.5!"
        >
          Yes, Delete
        </Button>
      </div>
    </div>
  );
}
