import style from '../styles/item.module.css' import { Skeleton, SkeletonProps, Tooltip } from '@chakra-ui/react' import { InfoIcon } from 'lucide-react' import Image from 'next/image' import Link from 'next/link' import { PROMO_CATEGORY } from '~/constants/promotion' import formatCurrency from '~/libs/formatCurrency' import { createSlug } from '~/libs/slug' import { CartItem as CartItemProps } from '~/types/cart' import CartItemAction from './ItemAction' import CartItemPromo from './ItemPromo' import CartItemSelect from './ItemSelect' type Props = { item: CartItemProps editable?: boolean pilihSemuaCart?: boolean } const CartItem = ({ item, editable = true,}: Props) => { return (
{item.cart_type === 'promotion' && (
{item.promotion_type?.value && (
Paket {PROMO_CATEGORY[item.promotion_type?.value].alias}
)}
Selamat! Pembelian anda lebih hemat {' '} Rp{formatCurrency((item.package_price || 0) * item.quantity - item.subtotal)}
)}
{editable && ( )}
{item.cart_type === 'promotion' && (
Rp {formatCurrency((item.package_price || 0))} Rp {formatCurrency(item.price.price)}
)} {item.cart_type === 'product' && (
{item.price.discount_percentage > 0 && ( Rp {formatCurrency((item.price.price || 0))} )}
{item.price.price_discount > 0 && `Rp ${formatCurrency(item.price.price_discount)}`} {item.price.price_discount === 0 && '-'}
)}
{item.cart_type === 'product' && item.code}
{Math.round(item.weight * 10) / 10} Kg
{editable && } {!editable &&
{item.quantity}
}
{item.products?.map((product) => )} {item.free_products?.map((product) => )}
) } CartItem.Image = function CartItemImage({ item }: { item: CartItemProps }) { const image = item?.image || item?.parent?.image const imageProgram = item?.image_program ? item.image_program[0] : item?.parent?.image; return ( <> {item.cart_type === 'promotion' && (
{imageProgram && {item.name}} {!imageProgram &&
No Image
}
)} {item.cart_type === 'product' && ( {image && {item.name}} {!image &&
No Image
} )} ) } CartItem.Name = function CartItemName({ item }: { item: CartItemProps }) { return ( <> {item.cart_type === 'promotion' && (
{item.name}
)} {item.cart_type === 'product' && ( {item.name} )} ) } CartItem.Skeleton = function CartItemSkeleton(props: SkeletonProps & { count: number }) { return Array.from({ length: props.count }).map((_, index) => ( )) } export default CartItem