import { cartClass } from "../lib/config";

/**
 * Add to cart link for a product column. Variable and external products
 * link to their page or shop; in-place adding comes with the table tools.
 */
export function AddToCart({ cart }) {
  if (!cart || !cart.url) {
    return null;
  }

  const external = cart.type === "external";

  return (
    <a
      className={cartClass()}
      href={cart.url}
      rel={external ? "nofollow noopener" : "nofollow"}
      target={external ? "_blank" : undefined}
    >
      {cart.label}
    </a>
  );
}
