export  const getPurchaseActions = ({
  item,
  isActive,
  canDelete,
  canAddChallan,
  setViewPurchase,
  setManagePurchase,
  setDeletingId,
  setIsDeleteModalOpen,
  setChallan,
  setAddPayment,
}) => {
  const actions = [];

  // VIEW
  actions.push({
    key: "view",
    label: "View",
    icon: "bx bx-show",
    show: true,
    onClick: () =>
      setViewPurchase({
        isOpen: true,
        purchaseId: item.id,
      }),
  });

  if (!isActive) {
    // EDIT
    actions.push({
      key: "edit",
      label: "Edit",
      icon: "bx bx-edit",
      show: true,
      onClick: () =>
        setManagePurchase({
          isOpen: true,
          purchaseId: item.id,
        }),
    });

    // DELETE
    actions.push({
      key: "delete",
      label: "Delete",
      icon: "bx bx-trash",
      show: canDelete,
      onClick: () => {
        setDeletingId(item.id);
        setIsDeleteModalOpen(true);
      },
    });

    // ADD CHALLAN
    actions.push({
      key: "challan",
      label: "Add Delivery Challan",
      icon: "bx bx-file bx-plus",
      show: canAddChallan,
      onClick: () =>
        setChallan({
          isOpen: true,
          purchaseId: item.id,
        }),
    });

    // ADD PAYMENT
    actions.push({
      key: "payment",
      label: "Add Payment",
      icon: "bx bx-wallet",
      show: true,
      onClick: () =>
        setAddPayment({
          isOpen: true,
          purchaseId: item.id,
        }),
    });
  } else {
    // RESTORE
    actions.push({
      key: "restore",
      label: "Restore",
      icon: "bx bx-undo",
      show: true,
      onClick: () => {
        setDeletingId(item.id);
        setIsDeleteModalOpen(true);
      },
    });
  }

  return actions.filter((a) => a.show);
};

export const DropdownItem = ({ icon, label, onClick }) => (
  <li>
    <a className="dropdown-item cursor-pointer" onClick={onClick}>
      <i className={`${icon} me-2`}></i> {label}
    </a>
  </li>
);
