import { cartProducts, type CartProduct } from "@/data/cart";
import { shopProducts, type ShopProduct } from "@/data/shop";

const CART_THUMB = 120;

export function shopProductToCartProduct(p: ShopProduct): CartProduct {
  return {
    id: p.id,
    title: p.title,
    titleHeading: "h3",
    href: p.href,
    imageSrc: p.imageSrc,
    imageAlt: p.imageAlt,
    imageWidth: CART_THUMB,
    imageHeight: CART_THUMB,
    unitPrice: p.unitPrice,
    rating: p.rating,
    reviewCountLabel: "(0)",
  };
}

export function getCartProduct(id: string): CartProduct | undefined {
  const fromCart = cartProducts.find((p) => p.id === id);
  if (fromCart) return fromCart;
  const fromShop = shopProducts.find((p) => p.id === id);
  if (fromShop) return shopProductToCartProduct(fromShop);
  return undefined;
}
