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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
|
import style from '../styles/product-detail.module.css';
import Link from 'next/link';
import { useRouter } from 'next/router';
import { useEffect, useRef, useState, UIEvent, useMemo } from 'react';
// Import komponen Chakra UI
import {
Button,
Tabs,
TabList,
TabPanels,
Tab,
TabPanel,
Table,
Tbody,
Tr,
Td,
Th,
Thead,
Box,
Spinner,
Center,
Text,
Stack,
} from '@chakra-ui/react';
// Import Icons
import {
AlertTriangle,
MessageCircleIcon,
Share2Icon,
ExternalLink,
} from 'lucide-react';
import { LazyLoadComponent } from 'react-lazy-load-image-component';
import useDevice from '@/core/hooks/useDevice';
import { getAuth } from '~/libs/auth';
import { whatsappUrl } from '~/libs/whatsappUrl';
import ProductPromoSection from '~/modules/product-promo/components/Section';
import { IProductDetail } from '~/types/product';
import { useProductDetail } from '../stores/useProductDetail';
import AddToWishlist from './AddToWishlist';
import Breadcrumb from './Breadcrumb';
import ProductImage from './Image';
import Information from './Information';
import PriceAction from './PriceAction';
import SimilarBottom from './SimilarBottom';
import SimilarSide from './SimilarSide';
import dynamic from 'next/dynamic';
// 1. IMPORT MODAL (Baru)
import ProductComparisonModal from './ProductComparisonModal';
import { gtagProductDetail } from '@/core/utils/googleTag';
import Skeleton from 'react-loading-skeleton';
type Props = {
product: IProductDetail;
};
const RWebShare = dynamic(
() => import('react-web-share').then((m) => m.RWebShare),
{ ssr: false },
);
// 1. STYLE DESKTOP (Tebal, Jelas, dengan Border/Padding)
const cssScrollbarDesktop = {
'&::-webkit-scrollbar': {
width: '10px',
height: '10px',
},
'&::-webkit-scrollbar-track': {
background: '#f1f1f1',
borderRadius: '4px',
},
'&::-webkit-scrollbar-thumb': {
backgroundColor: '#9ca3af', // Gray-400
borderRadius: '6px',
border: '2px solid #f1f1f1', // Efek padding
},
'&::-webkit-scrollbar-thumb:hover': {
backgroundColor: '#6b7280',
},
};
// 2. STYLE MOBILE (Tipis, Minimalis, Tanpa Border)
const cssScrollbarMobile = {
'&::-webkit-scrollbar': {
width: '3px', // Sangat tipis vertikal
height: '3px', // Sangat tipis horizontal
},
'&::-webkit-scrollbar-track': {
background: 'transparent',
},
'&::-webkit-scrollbar-thumb': {
backgroundColor: '#cbd5e1', // Gray-300
borderRadius: '3px',
},
};
const SELF_HOST = process.env.NEXT_PUBLIC_SELF_HOST;
const ProductDetail = ({ product }: Props) => {
const { isDesktop, isMobile } = useDevice();
const router = useRouter();
const [auth, setAuth] = useState<any>(null);
// console.log('Render ProductDetail for product ID:', product);
// State Data dari Magento
const [specsMatrix, setSpecsMatrix] = useState<any[]>([]);
const [upsellIds, setUpsellIds] = useState<number[]>([]);
const [relatedIds, setRelatedIds] = useState<number[]>([]);
const [descriptionMap, setDescriptionMap] = useState<Record<string, string>>(
{},
);
const [loadingSpecs, setLoadingSpecs] = useState(false);
// 2. STATE MODAL COMPARE (Baru)
const [isCompareOpen, setCompareOpen] = useState(false);
useEffect(() => {
try {
setAuth(getAuth() ?? null);
} catch {}
}, []);
const canShare =
typeof navigator !== 'undefined' &&
typeof (navigator as any).share === 'function';
const {
setAskAdminUrl,
askAdminUrl,
activeVariantId,
setIsApproval,
isApproval,
selectedVariant,
setSelectedVariant,
} = useProductDetail();
useEffect(() => {
gtagProductDetail(product);
}, [product]);
useEffect(() => {
const createdAskUrl = whatsappUrl({
template: 'product',
payload: {
manufacture: product.manufacture.name,
productName: product.name,
url: process.env.NEXT_PUBLIC_SELF_HOST + router.asPath,
},
fallbackUrl: router.asPath,
});
setAskAdminUrl(createdAskUrl);
}, [router.asPath, product.manufacture.name, product.name, setAskAdminUrl]);
// useEffect(() => {
// if (!product?.variants?.length) return;
// setIsApproval(auth?.feature?.soApproval);
// setSelectedVariant((prev: any) => {
// if (prev) return prev;
// return product.variants[0];
// });
// }, [product?.id]);
// 1. LOGIC INISIALISASI VARIANT
useEffect(() => {
if (typeof auth === 'object') {
setIsApproval(auth?.feature?.soApproval);
}
const variantInit =
product?.variants?.find((variant) => variant.is_in_bu) ||
product?.variants?.[0];
setSelectedVariant(variantInit);
setSpecsMatrix([]);
setUpsellIds([]);
setRelatedIds([]);
}, [product, auth]);
// 2. LOGIC FETCH DATA
useEffect(() => {
const fetchMagentoData = async () => {
const allVariantIds = product.variants.map((v) => v.id);
if (allVariantIds.length === 0) return;
const mainId = allVariantIds[0];
setLoadingSpecs(true);
try {
const params = new URLSearchParams({
skus: allVariantIds.join(','),
main_sku: String(mainId),
});
const endpoint = `/api/magento-product?${params.toString()}`;
const response = await fetch(endpoint, {
method: 'GET',
headers: { 'Content-Type': 'application/json' },
});
if (!response.ok) {
setSpecsMatrix([]);
setUpsellIds([]);
setRelatedIds([]);
return;
}
const data = await response.json();
// 1. Specs Matrix (Processed Grouping)
if (data.specsMatrix && Array.isArray(data.specsMatrix)) {
// const filteredMatrix = data.specsMatrix.filter((item: any) => {
// const code = item.code || '';
// return !code.includes('z_brand');
// });
const processed = processMatrixData(data.specsMatrix);
setSpecsMatrix(processed);
// const processed = processMatrixData(filteredMatrix);
// setSpecsMatrix(processed);
} else {
setSpecsMatrix([]);
}
if (data.descriptions) {
setDescriptionMap(data.descriptions);
}
// 2. Upsell & Related
if (data.upsell_ids && Array.isArray(data.upsell_ids))
setUpsellIds(data.upsell_ids);
else setUpsellIds([]);
if (data.related_ids && Array.isArray(data.related_ids))
setRelatedIds(data.related_ids);
else setRelatedIds([]);
} catch (error) {
console.error('Gagal mengambil data Magento:', error);
setSpecsMatrix([]);
} finally {
setLoadingSpecs(false);
}
};
fetchMagentoData();
}, [product.id]);
// HELPER 1: GROUPING DATA BY LABEL
const processMatrixData = (rawMatrix: any[]) => {
const groups: any = {};
const result: any[] = [];
rawMatrix.forEach((item) => {
if (item.label && item.label.includes(' : ')) {
const parts = item.label.split(' : ');
const groupName = parts[0].trim();
const childLabel = parts.slice(1).join(' : ').trim();
if (!groups[groupName]) {
groups[groupName] = {
type: 'group',
label: groupName,
children: [],
};
result.push(groups[groupName]);
}
groups[groupName].children.push({
...item,
label: childLabel,
});
} else {
result.push({ ...item, type: 'single' });
}
});
return result;
};
// HELPER 2: RENDER SPEC VALUE
const renderSpecValue = (val: any) => {
if (!val) return '-';
const strVal = String(val).trim();
const isUrl =
!strVal.includes(' ') &&
(strVal.startsWith('http') || strVal.startsWith('www.'));
if (isUrl) {
const href = strVal.startsWith('http') ? strVal : `https://${strVal}`;
return (
<a
href={href}
target='_blank'
rel='noopener noreferrer'
className='text-red-600 hover:underline inline-flex items-center gap-1'
>
<ExternalLink size={14} /> Link
</a>
);
}
if (strVal.includes('<') && strVal.includes('>')) {
return (
<Box
className='prose prose-sm text-gray-700'
sx={{
'& ul, & ol': {
paddingLeft: '1.2rem',
margin: 0,
textAlign: 'left',
},
'& li': {
fontWeight: 'normal',
marginBottom: '4px',
textAlign: 'left',
},
'& strong': {
display: 'block',
marginBottom: '2px',
fontWeight: 'bold',
},
'& p': {
margin: 0,
textAlign: 'left',
},
}}
dangerouslySetInnerHTML={{ __html: strVal }}
/>
);
}
return strVal;
};
const allImages = (() => {
const arr: string[] = [];
if (product?.image) arr.push(product.image);
if (
Array.isArray(product?.image_carousel) &&
product.image_carousel.length
) {
const set = new Set(arr);
for (const img of product.image_carousel) {
if (!set.has(img)) {
arr.push(img);
set.add(img);
}
}
}
return arr;
})();
const [mainImage, setMainImage] = useState(allImages[0] || '');
const hasPrice = Number(product?.lowest_price?.price) > 0;
useEffect(() => {
if (!allImages.includes(mainImage)) {
setMainImage(allImages[0] || '');
}
}, [allImages]);
const sliderRef = useRef<HTMLDivElement | null>(null);
const [currentIdx, setCurrentIdx] = useState(0);
const handleMobileScroll = (e: UIEvent<HTMLDivElement>) => {
const el = e.currentTarget;
if (!el) return;
const idx = Math.round(el.scrollLeft / el.clientWidth);
if (idx !== currentIdx) {
setCurrentIdx(idx);
setMainImage(allImages[idx] || '');
}
};
const scrollToIndex = (i: number) => {
const el = sliderRef.current;
if (!el) return;
el.scrollTo({ left: i * el.clientWidth, behavior: 'smooth' });
setCurrentIdx(i);
setMainImage(allImages[i] || '');
};
const sortedVariants = useMemo(() => {
if (!product?.variants) return [];
return [...product.variants].sort((a, b) => {
const labelA =
a.attributes && a.attributes.length > 0
? a.attributes.join(' - ')
: a.code || '';
const labelB =
b.attributes && b.attributes.length > 0
? b.attributes.join(' - ')
: b.code || '';
const getNumber = (str: string) => {
const match = String(str).match(/(\d+(\.\d+)?)/);
return match ? parseFloat(match[0]) : null;
};
const numA = getNumber(labelA);
const numB = getNumber(labelB);
if (numA !== null && numB !== null && numA !== numB) {
return numA - numB;
}
return String(labelA).localeCompare(String(labelB), undefined, {
numeric: true,
sensitivity: 'base',
});
});
}, [product.variants]);
const activeMagentoDesc = selectedVariant?.id
? descriptionMap[String(selectedVariant.id)]
: '';
const finalDescription =
activeMagentoDesc ||
product.description ||
'Deskripsi produk tidak tersedia.';
const cleanDescription =
finalDescription === '<p><br></p>'
? 'Deskripsi produk tidak tersedia.'
: finalDescription;
return (
<>
{/* 3. MODAL POPUP DIRENDER DISINI */}
{/* Render di luar layout utama agar tidak tertutup elemen lain */}
<ProductComparisonModal
isOpen={isCompareOpen}
onClose={() => setCompareOpen(false)}
mainProduct={product}
selectedVariant={selectedVariant}
/>
<div className='relative'>
{isDesktop && !hasPrice && (
<div className='absolute inset-0 z-[20] flex items-center justify-center pointer-events-none select-none'>
<img
src='/images/produk_tidak_tersedia.svg'
alt='Produk tidak tersedia'
className='w-[47%] opacity-50 -translate-x-[3%] -translate-y-[-70%]'
/>
</div>
)}
</div>
<div className='relative'>
{isMobile && !hasPrice && (
<div className='absolute inset-0 z-[50] flex items-center justify-center pointer-events-none select-none'>
<img
src='/images/produk_tidak_tersedia.svg'
alt='Produk tidak tersedia'
className='w-[100%] opacity-[1000%] -translate-x-[0%] -translate-y-[-197%]'
/>
</div>
)}
</div>
<div className='md:flex md:flex-wrap'>
<div className='w-full mb-4 md:mb-0 px-4 md:px-0'>
<Breadcrumb id={product.id} name={product.name} />
</div>
<div className='md:w-9/12 md:flex md:flex-col md:pr-4 md:pt-6'>
<div className='md:flex md:flex-wrap'>
{/* ===== Kolom kiri: gambar ===== */}
<div className='md:w-4/12'>
{/* ... Image Slider ... */}
{isMobile ? (
<div className='relative'>
<div
ref={sliderRef}
onScroll={handleMobileScroll}
className='flex overflow-x-auto snap-x snap-mandatory scroll-smooth no-scrollbar'
style={{
scrollBehavior: 'smooth',
msOverflowStyle: 'none',
scrollbarWidth: 'none',
}}
>
{allImages.length > 0 ? (
allImages.map((img, i) => (
<div
key={i}
className='w-full flex-shrink-0 snap-center flex justify-center items-center'
>
<img
src={img}
alt={`Gambar ${i + 1}`}
className='w-[85%] aspect-square object-contain'
onError={(e) => {
(e.target as HTMLImageElement).src =
'/images/noimage.jpeg';
}}
/>
</div>
))
) : (
<div className='w-full flex-shrink-0 snap-center flex justify-center items-center'>
<img
src={mainImage || '/images/noimage.jpeg'}
alt='Gambar produk'
className='w-[85%] aspect-square object-contain'
/>
</div>
)}
</div>
{allImages.length > 1 && (
<div className='absolute bottom-2 left-0 right-0 flex justify-center gap-2'>
{allImages.map((_, i) => (
<button
key={i}
aria-label={`Ke slide ${i + 1}`}
className={`w-2 h-2 rounded-full ${currentIdx === i ? 'bg-gray-800' : 'bg-gray-300'}`}
onClick={() => scrollToIndex(i)}
/>
))}
</div>
)}
</div>
) : (
<>
<ProductImage product={{ ...product, image: mainImage }} />
{allImages.length > 0 && (
<div className='mt-4 overflow-x-auto'>
<div className='flex space-x-3 pb-3'>
{allImages.map((img, index) => (
<div
key={index}
className={`flex-shrink-0 w-16 h-16 cursor-pointer border-2 rounded-md transition-colors ${mainImage === img ? 'border-red-500 ring-2 ring-red-200' : 'border-gray-200 hover:border-gray-300'}`}
onClick={() => setMainImage(img)}
>
<img
src={img}
alt={`Thumbnail ${index + 1}`}
className='w-full h-full object-cover rounded-sm'
loading='lazy'
onError={(e) => {
(e.target as HTMLImageElement).src =
'/images/noimage.jpeg';
}}
/>
</div>
))}
</div>
</div>
)}
</>
)}
</div>
{/* ===== Kolom kanan: info ===== */}
{isDesktop && (
<div className='md:w-8/12 px-4 md:pl-6'>
{!hasPrice && (
<div className='bg-red-50 p-2 py-1.5 rounded-lg border border-red-500 flex gap-1 items-center '>
<AlertTriangle
size={18}
className='text-red-600 shrink-0 mx-2'
/>
<h1 className='text-red-600 font-normal text-h-sm'>
Maaf untuk saat ini Produk yang anda cari tidak tersedia
</h1>
</div>
)}
<div className='h-6 md:h-0' />
<h1 className={style['title']}>{product.name}</h1>
<div className='h-3 md:h-0' />
<Information product={product} />
<div className='h-6' />
</div>
)}
{isMobile && (
<div className='md:w-8/12 px-4 md:pl-6 relative'>
{!hasPrice && (
<div className='bg-red-50 p-2 py-1.5 border-b border-red-500 flex gap-1 items-center w-screen relative left-1/2 right-1/2 -translate-x-1/2'>
<AlertTriangle
size={18}
className='text-red-600 shrink-0 mx-2'
/>
<h1 className='text-red-600 font-normal text-h-sm'>
Maaf untuk saat ini Produk yang anda cari tidak tersedia
</h1>
</div>
)}
<h1 className={style['title']}>{product.name}</h1>
<div className='h-3 md:h-0' />
<Information product={product} />
<div className='h-2' />
</div>
)}
</div>
<div className='h-full'>
{isMobile && (
<div className='px-4 pt-2'>
<PriceAction product={product} />
</div>
)}
<div className='h-2 md:h-10' />
{!!activeVariantId && !isApproval && (
<ProductPromoSection
product={product}
productId={activeVariantId}
/>
)}
<div className='h-0 md:h-6' />
{/* === SECTION TABS: DESKRIPSI & SPESIFIKASI === */}
<div className={style['section-card']}>
<Tabs variant='unstyled'>
<TabList borderBottom='1px solid' borderColor='gray.200'>
<Tab
_selected={{
color: 'red.600',
borderColor: 'red.600',
borderBottomWidth: '3px',
fontWeight: 'bold',
marginBottom: '-1.5px',
}}
color='gray.500'
fontWeight='medium'
fontSize='sm'
px={4}
py={3}
>
Deskripsi
</Tab>
<Tab
_selected={{
color: 'red.600',
borderColor: 'red.600',
borderBottomWidth: '3px',
fontWeight: 'bold',
marginBottom: '-1.5px',
}}
color='gray.500'
fontWeight='medium'
fontSize='sm'
px={4}
py={3}
>
Spesifikasi
</Tab>
{/* <Tab
_selected={{ color: 'red.600', borderColor: 'red.600', borderBottomWidth: '3px', fontWeight: 'bold', marginBottom: '-1.5px' }}
color="gray.500" fontWeight="medium" fontSize="sm" px={4} py={3}
>
Detail Lainnya
</Tab> */}
</TabList>
<TabPanels>
{/* DESKRIPSI */}
<TabPanel px={0} py={6}>
<div className='overflow-x-auto text-sm text-gray-700'>
{loadingSpecs ? (
<Stack spacing={4}>
<Skeleton height='20px' width='100%' />
<Skeleton height='20px' width='90%' />
<Skeleton height='20px' width='95%' />
<Skeleton height='20px' width='70%' />
</Stack>
) : (
<Box
className={style['description']}
sx={{
'ul, ol': {
marginTop: '0.5em !important',
marginBottom: '1em !important',
marginLeft: '0 !important',
listStylePosition: 'outside !important',
paddingLeft: '1.5em !important',
},
ul: { listStyleType: 'disc !important' },
ol: { listStyleType: 'decimal !important' },
li: {
marginBottom: '0.4em !important',
paddingLeft: '0.3em !important',
lineHeight: '1.6 !important',
},
}}
dangerouslySetInnerHTML={{ __html: cleanDescription }}
/>
)}
</div>
</TabPanel>
{/* SPESIFIKASI */}
<TabPanel px={0} py={2}>
<Box
border='1px solid'
borderColor='gray.200'
borderRadius='sm'
overflowX='auto'
overflowY='auto'
maxHeight='500px'
css={isMobile ? cssScrollbarMobile : cssScrollbarDesktop}
>
{loadingSpecs ? (
<Center py={6}>
<Spinner color='red.500' />
</Center>
) : specsMatrix.length > 0 ? (
(() => {
const variantCount = sortedVariants.length;
const isSingleVariant = variantCount === 1;
// === LOGIC 1: SINGLE VARIANT (VERTICAL TABLE) ===
if (isSingleVariant) {
const singleVariantId = sortedVariants[0].id;
// Flatten data untuk list vertical
const rows: any[] = [];
specsMatrix.forEach((row) => {
if (row.type === 'group') {
row.children.forEach((child: any) =>
rows.push(child),
);
} else {
rows.push(row);
}
});
return (
<Table
variant='simple'
size={isMobile ? 'sm' : 'md'}
>
<Tbody>
{rows.map((row, idx) => (
<Tr
key={idx}
bg={idx % 2 === 0 ? 'white' : 'gray.50'}
>
{/* Kolom Label (Kiri) */}
<Td
width='40%'
fontWeight='bold'
color='gray.600'
borderColor='gray.200'
verticalAlign='top'
py={3}
>
{row.label}
</Td>
{/* Kolom Value (Kanan) */}
<Td
color='gray.800'
borderColor='gray.200'
verticalAlign='top'
py={3}
>
{renderSpecValue(
row.values[singleVariantId],
)}
</Td>
</Tr>
))}
</Tbody>
</Table>
);
}
// === LOGIC 2: MULTIPLE VARIANTS (MATRIX TABLE HORIZONTAL) ===
const topHeaders: any[] = [];
const subHeaders: any[] = [];
const flatSpecs: any[] = [];
specsMatrix.forEach((row) => {
if (row.type === 'group') {
topHeaders.push({
label: row.label,
type: 'group',
colSpan: row.children.length,
rowSpan: 1,
});
row.children.forEach((child: any) => {
subHeaders.push(child);
flatSpecs.push(child);
});
} else {
topHeaders.push({
label: row.label,
type: 'single',
colSpan: 1,
rowSpan: 2,
});
flatSpecs.push(row);
}
});
return (
<Table
variant='simple'
size={isMobile ? 'sm' : 'md'}
>
<Thead
bg='red.600'
position='sticky'
top={0}
zIndex={3}
>
<Tr>
{topHeaders.map((th, idx) => (
<Th
key={`top-${idx}`}
position={idx === 0 ? 'sticky' : 'static'}
left={idx === 0 ? 0 : undefined}
zIndex={idx === 0 ? 4 : 3}
boxShadow={
idx === 0
? '2px 0 5px -2px rgba(0,0,0,0.2)'
: 'none'
}
bg='red.600'
colSpan={th.colSpan}
rowSpan={th.rowSpan}
color='white'
textAlign='center'
fontSize={isMobile ? 'xs' : 'sm'}
textTransform='none'
fontWeight='800'
letterSpacing='wide'
verticalAlign='middle'
borderBottom='none'
px={isMobile ? 2 : 4}
>
{th.label}
</Th>
))}
</Tr>
<Tr>
{subHeaders.map((sub, idx) => {
const isFirstHeaderGroup =
topHeaders[0]?.type === 'group';
const shouldSticky =
idx === 0 && isFirstHeaderGroup;
return (
<Th
key={`sub-${idx}`}
position={
shouldSticky ? 'sticky' : 'static'
}
left={shouldSticky ? 0 : undefined}
zIndex={shouldSticky ? 4 : 1}
boxShadow={
shouldSticky
? '2px 0 5px -2px rgba(0,0,0,0.2)'
: 'none'
}
color='white'
textAlign='center'
fontSize='xs'
textTransform='none'
verticalAlign='middle'
whiteSpace='nowrap'
bg='red.600'
pt={1}
pb={1}
px={isMobile ? 2 : 4}
>
{sub.label}
</Th>
);
})}
</Tr>
</Thead>
<Tbody>
{sortedVariants.map((v, vIdx) => (
<Tr
key={v.id}
bg={vIdx % 2 === 0 ? 'white' : 'gray.50'}
>
{flatSpecs.map((spec, sIdx) => {
const rawValue = spec.values[v.id] || '-';
const isFirstCol = sIdx === 0;
return (
<Td
key={sIdx}
position={
isFirstCol ? 'sticky' : 'static'
}
left={isFirstCol ? 0 : undefined}
zIndex={isFirstCol ? 2 : 1}
bg={
vIdx % 2 === 0 ? 'white' : 'gray.50'
}
boxShadow={
isFirstCol
? '2px 0 5px -2px rgba(0,0,0,0.1)'
: 'none'
}
borderColor='gray.200'
textAlign='center'
fontSize={isMobile ? 'xs' : 'sm'}
verticalAlign='middle'
px={isMobile ? 1 : 2}
py={3}
minW={isMobile ? '100px' : '120px'}
maxW='200px'
whiteSpace='normal'
overflowWrap='break-word'
fontWeight={
isFirstCol ? 'bold' : 'normal'
}
>
{renderSpecValue(rawValue)}
</Td>
);
})}
</Tr>
))}
</Tbody>
</Table>
);
})()
) : (
<Box p={4} color='gray.500' fontSize='sm'>
<Text>Spesifikasi teknis belum tersedia.</Text>
</Box>
)}
</Box>
</TabPanel>
</TabPanels>
</Tabs>
</div>
</div>
</div>
{isDesktop && (
<div className='md:w-3/12'>
{/* 4. INTEGRASI: PASSING HANDLER MODAL KE PRICE ACTION */}
<PriceAction
product={product}
onCompare={() => setCompareOpen(true)}
/>
<div className='flex gap-x-5 items-center justify-center py-4'>
<Button
as={Link}
href={askAdminUrl}
variant='link'
target='_blank'
colorScheme='gray'
leftIcon={<MessageCircleIcon size={18} />}
isDisabled={!hasPrice}
>
Ask Admin
</Button>
<span>|</span>
<div className={hasPrice ? '' : 'opacity-40 pointer-events-none'}>
<AddToWishlist productId={product.id} />
</div>
<span>|</span>
{canShare && (
<RWebShare
data={{
text: 'Check out this product',
title: `${product.name} - Indoteknik.com`,
url:
(process.env.NEXT_PUBLIC_SELF_HOST || '') +
(router?.asPath || '/'),
}}
>
<Button
variant='link'
colorScheme='gray'
leftIcon={<Share2Icon size={18} />}
isDisabled={!hasPrice}
>
Share
</Button>
</RWebShare>
)}
</div>
<div className='h-6' />
<div className={style['heading']}>Produk Serupa</div>
<div className='h-4' />
<SimilarSide product={product} relatedIds={relatedIds} />
</div>
)}
<div className='md:w-full pt-4 md:py-10 px-4 md:px-0'>
<div className={style['heading']}>Kamu Mungkin Juga Suka</div>
<div className='h-6' />
<LazyLoadComponent>
<SimilarBottom product={product} upsellIds={upsellIds} />
</LazyLoadComponent>
</div>
<div className='h-6 md:h-0' />
</div>
</>
);
};
export default ProductDetail;
|