summaryrefslogtreecommitdiff
path: root/src/lib/product/components/ProductCard.jsx
blob: a8964310c180dd30d5def458c1fb5fd32e2d3c04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import Image from '@/core/components/elements/Image/Image'
import Link from '@/core/components/elements/Link/Link'
import currencyFormat from '@/core/utils/currencyFormat'
import { createSlug } from '@/core/utils/slug'
import whatsappUrl from '@/core/utils/whatsappUrl'

const ProductCard = ({ product, simpleTitle, variant = 'vertical' }) => {
  const callForPriceWhatsapp = whatsappUrl('product', {
    name: product.name,
    url: createSlug('/shop/product/', product.name, product.id, true)
  })

  if (variant == 'vertical') {
    return (
      <div className='rounded shadow-sm border border-gray_r-4 bg-white h-[350px]'>
        <Link
          href={createSlug('/shop/product/', product?.name, product?.id)}
          className='border-b border-gray_r-4 relative'
        >
          <Image
            src={product?.image}
            alt={product?.name}
            className='w-full object-contain object-center h-36 sm:h-48'
          />
          {product.variantTotal > 1 && (
            <div className='absolute badge-gray bottom-1.5 left-1.5'>
              {product.variantTotal} Varian
            </div>
          )}
        </Link>
        <div className='p-2 sm:p-3 pb-3 text-caption-2 sm:text-body-2 leading-5'>
          {product?.manufacture?.name ? (
            <Link
              href={createSlug(
                '/shop/brands/',
                product?.manufacture?.name,
                product?.manufacture.id
              )}
              className='mb-1'
            >
              {product.manufacture.name}
            </Link>
          ) : (
            <div>-</div>
          )}
          <Link
            href={createSlug('/shop/product/', product?.name, product?.id)}
            className={`mb-2 !text-gray_r-12 leading-6 block ${
              simpleTitle ? 'line-clamp-2 h-12' : 'line-clamp-3 h-[64px]'
            }`}
            title={product?.name}
          >
            {product?.name}
          </Link>
          {product?.lowestPrice.discountPercentage > 0 && (
            <div className='flex gap-x-1 mb-1 items-center'>
              <div className='text-gray_r-11 line-through text-[11px] sm:text-caption-2'>
                {currencyFormat(product.lowestPrice.price)}
              </div>
              <div className='badge-solid-red'>{product?.lowestPrice.discountPercentage}%</div>
            </div>
          )}

          <div className='text-danger-500 font-semibold mb-2'>
            {product?.lowestPrice.priceDiscount > 0 ? (
              currencyFormat(product?.lowestPrice.priceDiscount)
            ) : (
              <a href={callForPriceWhatsapp}>Call for price</a>
            )}
          </div>

          {product?.stockTotal > 0 && (
            <div className='flex gap-x-1'>
              <div className='badge-solid-red'>Ready Stock</div>
              <div className='badge-gray'>{product?.stockTotal > 5 ? '> 5' : '< 5'}</div>
            </div>
          )}
        </div>
      </div>
    )
  }

  if (variant == 'horizontal') {
    return (
      <div className='flex bg-white'>
        <div className='w-4/12'>
          <Link
            href={createSlug('/shop/product/', product?.name, product?.id)}
            className='relative'
          >
            <Image
              src={product?.image}
              alt={product?.name}
              className='w-full object-contain object-center h-36'
            />
            {product.variantTotal > 1 && (
              <div className='absolute badge-gray bottom-1.5 left-1.5'>
                {product.variantTotal} Varian
              </div>
            )}
          </Link>
        </div>
        <div className='w-8/12 p-2'>
          {product?.manufacture?.name ? (
            <Link
              href={createSlug(
                '/shop/brands/',
                product?.manufacture?.name,
                product?.manufacture.id
              )}
              className='mb-1'
            >
              {product.manufacture.name}
            </Link>
          ) : (
            <div>-</div>
          )}
          <Link
            href={createSlug('/shop/product/', product?.name, product?.id)}
            className={`mb-2 !text-gray_r-12 leading-6 ${
              simpleTitle ? 'line-clamp-2' : 'line-clamp-3'
            }`}
          >
            {product?.name}
          </Link>

          {product?.lowestPrice?.discountPercentage > 0 && (
            <div className='flex gap-x-1 mb-1 items-center'>
              <div className='badge-solid-red'>{product?.lowestPrice?.discountPercentage}%</div>
              <div className='text-gray_r-11 line-through text-caption-2'>
                {currencyFormat(product?.lowestPrice?.price)}
              </div>
            </div>
          )}

          <div className='text-danger-500 font-semibold mb-2'>
            {product?.lowestPrice?.priceDiscount > 0 ? (
              currencyFormat(product?.lowestPrice?.priceDiscount)
            ) : (
              <a href={callForPriceWhatsapp}>Call for price</a>
            )}
          </div>

          {product?.stockTotal > 0 && (
            <div className='flex gap-x-1'>
              <div className='badge-solid-red'>Ready Stock</div>
              <div className='badge-gray'>{product?.stockTotal > 5 ? '> 5' : '< 5'}</div>
            </div>
          )}
        </div>
      </div>
    )
  }
}

export default ProductCard