summaryrefslogtreecommitdiff
path: root/src/lib/product/components/ProductSearch.jsx
blob: 850d00ccca7fd708a691e67be246c1daecf6cdd2 (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
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
import NextImage from 'next/image';
import { useRouter } from 'next/router';
import { useEffect, useMemo, useState, useRef } from 'react';

import { HStack, Image, Tag, TagCloseButton, TagLabel } from '@chakra-ui/react';
import axios from 'axios';
import _ from 'lodash';
import { toQuery } from 'lodash-contrib';
import { FunnelIcon, AdjustmentsHorizontalIcon } from '@heroicons/react/24/outline';
import odooApi from '@/core/api/odooApi';
import searchSpellApi from '@/core/api/searchSpellApi';
import Link from '@/core/components/elements/Link/Link';
import Pagination from '@/core/components/elements/Pagination/Pagination';
import DesktopView from '@/core/components/views/DesktopView';
import MobileView from '@/core/components/views/MobileView';
import useActive from '@/core/hooks/useActive';
import { formatCurrency } from '@/core/utils/formatValue';
import { createSlug } from '@/core/utils/slug';
import whatsappUrl from '@/core/utils/whatsappUrl';

import useProductSearch from '../hooks/useProductSearch';
import ProductCard from './ProductCard';
import ProductFilter from './ProductFilter';
import ProductFilterDesktop from './ProductFilterDesktop';
import ProductSearchSkeleton from './Skeleton/ProductSearchSkeleton';

import SideBanner from '~/modules/side-banner';
import FooterBanner from '~/modules/footer-banner';
import CategorySection from './CategorySection';
import LobSectionCategory from './LobSectionCategory';
import { getIdFromSlug } from '@/core/utils/slug';
import { data } from 'autoprefixer';

const ProductSearch = ({
  query,
  prefixUrl,
  defaultBrand = null,
  brand = null,
}) => {
  const router = useRouter();
  const { page = 1 } = query;
  const [q, setQ] = useState(query?.q || '*');
  const [search, setSearch] = useState(query?.q || '*');
  const [limit, setLimit] = useState(router.query?.limit || 30);
  const [orderBy, setOrderBy] = useState(router.query?.orderBy);
  const [finalQuery, setFinalQuery] = useState({});
  const [queryFinal, setQueryFinal] = useState({});
  const [dataCategoriesProduct, setDataCategoriesProduct] = useState([]);
  const [dataCategoriesLob, setDataCategoriesLob] = useState([]);
  const categoryId = getIdFromSlug(prefixUrl);
  const [data, setData] = useState([]);
  const [dataLob, setDataLob] = useState([]);
  const appliedDefaultBrandOrder = useRef(false);

  if (defaultBrand) query.brand = defaultBrand.toLowerCase();
  useEffect(() => {
    if (!router.isReady) return;

    const onBrandsPage = router.pathname.includes('brands');
    const hasOrder = typeof router.query?.orderBy === 'string' && router.query.orderBy !== '';

    if (onBrandsPage && !hasOrder && !appliedDefaultBrandOrder.current) {
      let params = {
        ...router.query,
        orderBy: 'popular',
      };
      params = _.pickBy(params, _.identity);
      const qs = toQuery(params);

      // ganti URL tanpa nambah history & tanpa full reload
      router.replace(`${prefixUrl}?${qs}`, undefined, { shallow: true });

      // sinkronkan state lokal
      setOrderBy('popular');

      appliedDefaultBrandOrder.current = true;
    }
  }, [router.isReady, router.pathname, router.query?.orderBy, prefixUrl]);

  const dataIdCategories = [];
  useEffect(() => {
    if (prefixUrl.includes('category')) {
      const loadProduct = async () => {
        const getCategoriesId = await odooApi(
          'GET',
          `/api/v1/category/numFound?parent_id=${categoryId}`
        );
        if (getCategoriesId) {
          setDataCategoriesProduct(getCategoriesId);
        }
      };
      loadProduct();
    } else if (prefixUrl.includes('lob')) {
      const loadProduct = async () => {
        const lobData = await odooApi(
          'GET',
          `/api/v1/lob_homepage/${categoryId}/category_id`
        );

        if (lobData) {
          setDataLob(lobData);
        }
      };
      loadProduct();
    }
  }, [categoryId]);

  useEffect(() => {
    const checkIfPenawaran = async () => {
      if (router.asPath.includes('penawaran')) {
        query = {
          ...query,
          fq: `flashsale_id_i:${router.query.penawaran} AND  flashsale_price_f:[1 TO *]`,
          orderBy: 'flashsale-discount-desc',
        };
        setFinalQuery(query);
        setOrderBy('flashsale-discount-desc');
      }
    };
    checkIfPenawaran();
  }, [router.query]);

  const collectIds = (category) => {
    const ids = [];
    function recurse(cat) {
      if (cat && cat.id) {
        ids.push(cat.id);
      }
      if (Array.isArray(cat.children)) {
        cat.children.forEach(recurse);
      }
    }
    recurse(category);
    return ids;
  };
  useEffect(() => {
    if (prefixUrl.includes('category')) {
      const ids = collectIds(dataCategoriesProduct);
      const newQuery = {
        fq: `category_id_ids:(${ids.join(' OR ')})`,
        page: router.query.page ? router.query.page : 1,
        brand: router.query.brand ? router.query.brand : '',
        category: router.query.category ? router.query.category : '',
        priceFrom: router.query.priceFrom ? router.query.priceFrom : '',
        priceTo: router.query.priceTo ? router.query.priceTo : '',
        limit: router.query.limit ? router.query.limit : '',
        orderBy: router.query.orderBy ? router.query.orderBy : '',
      };
      setFinalQuery(newQuery);
    } else if (prefixUrl.includes('lob')) {
      const fetchCategoryData = async () => {
        if (dataLob[0]?.categoryIds) {
          for (const cate of dataLob[0].categoryIds) {
            dataIdCategories.push(cate.childId);
          }

          const mergedArray = dataIdCategories.flat();

          const newQuery = {
            fq: `category_id_ids:(${mergedArray.join(' OR ')})`,
            category: router.query.category ? router.query.category : '',
            page: router.query.page ? router.query.page : 1,
            brand: router.query.brand ? router.query.brand : '',
            priceFrom: router.query.priceFrom ? router.query.priceFrom : '',
            priceTo: router.query.priceTo ? router.query.priceTo : '',
            limit: router.query.limit ? router.query.limit : '',
            orderBy: router.query.orderBy ? router.query.orderBy : '',
          };

          setFinalQuery(newQuery);
        }
      };
      fetchCategoryData();
    }
  }, [dataCategoriesProduct, dataLob]);

  useEffect(() => {
    if (prefixUrl.includes('category') || prefixUrl.includes('lob') || router.asPath.includes('penawaran')) {
      setQueryFinal({ ...finalQuery, q, limit, orderBy });
    } else {
      setQueryFinal({ ...query, q, limit, orderBy });
    }
  }, [prefixUrl, dataCategoriesProduct, query, finalQuery]);

  const { productSearch } = useProductSearch({
    query: queryFinal,
    operation: 'AND',
  });
  const [products, setProducts] = useState(null);
  const [spellings, setSpellings] = useState(null);
  const [bannerPromotionHeader, setBannerPromotionHeader] = useState(null);
  const [bannerPromotionFooter, setBannerPromotionFooter] = useState(null);
  const [isBrand, setIsBrand] = useState(null);
  const popup = useActive();
  const numRows = [30, 50, 80, 100];
  const [brandValues, setBrand] = useState(
    !router.pathname.includes('brands')
      ? router.query.brand
        ? router.query.brand.split(',')
        : []
      : []
  );
  const [categoryValues, setCategory] = useState(
    router.query?.category?.split(',') || router.query?.category?.split(',')
  );

  const [priceFrom, setPriceFrom] = useState(router.query?.priceFrom || null);
  const [priceTo, setPriceTo] = useState(router.query?.priceTo || null);

  const pageCount = Math.ceil(productSearch.data?.response.numFound / limit);
  const productStart = productSearch.data?.responseHeader.params.start;
  const productRows = limit;
  const productFound = productSearch.data?.response.numFound;
  const [dataCategories, setDataCategories] = useState([]);

  useEffect(() => {
    if (productFound == 0 && query.q && !spellings) {
      searchSpellApi({ query: query.q }).then((response) => {
        const oddIndexSuggestions = response.data.spellcheck.suggestions.filter(
          (_, index) => index % 2 === 1
        );

        const oddIndexCollations = response.data.spellcheck.collations.filter(
          (_, index) => index % 2 === 1
        );

        const dataSpellings = oddIndexSuggestions.reduce((acc, curr) => {
          oddIndexCollations.forEach((collation) => {
            acc.push(collation.collationQuery);
          });
          curr.suggestion.forEach((s) => {
            if (!acc.includes(s.word)) acc.push(s.word);
          });
          return acc;
        }, []);

        if (dataSpellings.length > 0) {
          setQ(dataSpellings[0]);
        }

        setSpellings(dataSpellings);
      });
    }
  }, [productFound, query, spellings]);
  let id = [];
  useEffect(() => {
    const checkIfBrand = async () => {
      const brand = await axios(
        `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/brands?params=search&q=${search}`
      );

      if (brand.data.length > 0) {
        setIsBrand(brand?.data[0]);
      } else {
        setIsBrand(null);
      }
    };
    if (router.pathname.includes('search') && q !== '*') {
      checkIfBrand();
    }
  }, [q]);

  useEffect(() => {
    if (prefixUrl.includes('category')) {
      const loadCategories = async () => {
        const getCategories = await odooApi(
          'GET',
          `/api/v1/category/child?parent_id=${categoryId}`
        );
        if (getCategories) {
          setDataCategories(getCategories);
        }
      };
      loadCategories();
    }
  }, []);

  const brands = [];
  for (
    let i = 0;
    i < productSearch.data?.facetCounts?.facetFields?.manufactureNameS.length;
    i += 2
  ) {
    const brand =
      productSearch.data?.facetCounts?.facetFields?.manufactureNameS[i];
    const qty =
      productSearch.data?.facetCounts?.facetFields?.manufactureNameS[i + 1];
    if (qty > 0) {
      brands.push({ brand, qty });
    }
  }

  const categories = [];
  for (
    let i = 0;
    i < productSearch.data?.facetCounts?.facetFields?.categoryName.length;
    i += 2
  ) {
    const name = productSearch.data?.facetCounts?.facetFields?.categoryName[i];
    const qty =
      productSearch.data?.facetCounts?.facetFields?.categoryName[i + 1];
    if (qty > 0) {
      categories.push({ name, qty });
    }
  }

  const orderOptions = [
    { value: '', label: 'Pilih Filter' },
    { value: 'price-asc', label: 'Harga Terendah' },
    { value: 'price-desc', label: 'Harga Tertinggi' },
    { value: 'popular', label: 'Populer' },
    { value: 'stock', label: 'Ready Stock' },
  ];

  const handleOrderBy = (e) => {
    let params = {
      ...router.query,
      orderBy: e.target.value,
    };
    params = _.pickBy(params, _.identity);
    params = toQuery(params);
    router.push(`${prefixUrl}?${params}`);
  };

  const handleLimit = (e) => {
    let params = {
      ...router.query,
      limit: e.target.value,
    };
    params = _.pickBy(params, _.identity);
    params = toQuery(params);
    router.push(`${prefixUrl}?${params}`);
  };
  const getBanner = async () => {
    if (router.pathname.includes('search')) {
      const getBannerHeader = await odooApi(
        'GET',
        '/api/v1/banner?type=promotion-header'
      );
      const getBannerFooter = await odooApi(
        'GET',
        '/api/v1/banner?type=promotion-footer'
      );
      var randomIndex = Math.floor(Math.random() * getBannerHeader.length);
      var randomIndexFooter = Math.floor(
        Math.random() * getBannerFooter.length
      );
      setBannerPromotionHeader(getBannerHeader[randomIndex]);
      setBannerPromotionFooter(getBannerFooter[randomIndexFooter]);
    }
  };

  useEffect(() => {
    getBanner();
  }, []);

  useEffect(() => {
    setProducts(productSearch.data?.response?.products);
  }, [productSearch]);

  const SpellingComponent = useMemo(() => {
    return (
      <>
        {spellings?.length > 0 ? (
          <>Mungkin yang anda cari </>
        ) : (
          <>Produk yang cari anda tidak ada</>
        )}
        {spellings?.map((spelling, i) => (
          <Link href={`/shop/search?q=${spelling}`} key={i} className='inline'>
            {spelling}
            {i + 1 < spellings.length ? ', ' : ''}
          </Link>
        ))}
      </>
    );
  }, [spellings]);

  const handleDeleteFilter = async (source, value) => {
    let params = {
      penawaran: router.query.penawaran,
      q: router.query.q,
      orderBy: orderBy,
      brand: brandValues.join(','),
      category: categoryValues?.join(','),
      priceFrom,
      priceTo,
    };

    let brands = brandValues;
    let catagories = categoryValues;
    switch (source) {
      case 'brands':
        brands = brandValues.filter((item) => item !== value);
        params.brand = brands.join(',');
        await setBrand(brands);
        break;
      case 'category':
        catagories = categoryValues.filter((item) => item !== value);
        params.category = catagories.join(',');
        await setCategory(catagories);
        break;
      case 'price':
        params.priceFrom = null;
        params.priceTo = null;
        break;
      case 'delete':
        params = {
          penawaran: router.query.penawaran,
          q: router.query.q,
          orderBy: orderBy,
        };
        break;
    }

    handleSubmitFilter(params);
  };
  const handleSubmitFilter = (params) => {
    params = _.pickBy(params, _.identity);
    params = toQuery(params);
    router.push(`${prefixUrl}?${params}`);
  };

  const isNotReadyStockPage = router.asPath !== '/shop/search?orderBy=stock';

  return (
    <>
      <MobileView>
        {productSearch.isLoading && <ProductSearchSkeleton />}
        <div className='p-4 pt-0'>
          {isNotReadyStockPage && isBrand && isBrand.logo && (
            <div className='mb-3'>
              <h1 className='mb-2 font-semibold text-h-sm'>Brand Pencarian {q}</h1>
              <Link
                href={createSlug('/shop/brands/', isBrand.name, isBrand.id)}
                className='inline'
              >
                <Image
                  src={isBrand?.logo}
                  alt=''
                  className='object-cover object-center h-[60px]'
                />
              </Link>
            </div>
          )}

          <h1 className='mb-2 font-semibold text-h-sm'>Produk</h1>

          <FilterChoicesComponent
            brandValues={brandValues}
            categoryValues={categoryValues}
            priceFrom={priceFrom}
            priceTo={priceTo}
            handleDeleteFilter={handleDeleteFilter}
          />

          {/* info jumlah hasil */}
          <div className='mb-2 leading-6 text-gray_r-11'>
            {!spellings ? (
              <>
                Menampilkan&nbsp;
                {pageCount > 1 ? (
                  <>
                    {productStart + 1}-
                    {parseInt(productStart) + parseInt(productRows) > productFound
                      ? productFound
                      : parseInt(productStart) + parseInt(productRows)}
                    &nbsp;dari&nbsp;
                  </>
                ) : (
                  ''
                )}
                {productFound}
                &nbsp;produk{' '}
                {query.q && (
                  <>
                    untuk pencarian <span className='font-semibold'>{query.q}</span>
                  </>
                )}
              </>
            ) : (
              SpellingComponent
            )}
          </div>

          {productFound > 0 && (
            <div className='flex items-center gap-x-2 mt-2 mb-3 justify-end'>
              <div>
                <button
                  aria-label='Filter'
                  title='Filter'
                  onClick={popup.activate}
                  className='btn-light w-fit flex items-center justify-center rounded-md'
                >
                  <AdjustmentsHorizontalIcon className='w-5 h-5' />
                </button>
              </div>
              <div>
                <select
                  name='limit'
                  className='form-input w-20'
                  value={router.query?.limit || ''}
                  onChange={(e) => handleLimit(e)}
                >
                  {numRows.map((option, index) => (
                    <option key={index} value={option}>
                      {option}
                    </option>
                  ))}
                </select>
              </div>
            </div>
          )}
          {!!dataLob?.length && <LobSectionCategory categories={dataLob} />}
          {!!dataCategories?.length && <CategorySection categories={dataCategories} />}
          <div className='grid grid-cols-2 gap-3'>
            {products &&
              products.map((product) => (
                <ProductCard product={product} key={product.id} />
              ))}
          </div>

          <Pagination
            pageCount={pageCount}
            currentPage={parseInt(page)}
            url={`${prefixUrl}?${toQuery(_.omit(query, ['page', 'fq']))}`}
            className='mt-6 mb-2'
          />

          <ProductFilter
            active={popup.active}
            close={popup.deactivate}
            brands={brands || []}
            categories={categories || []}
            prefixUrl={prefixUrl}
            defaultBrand={defaultBrand}
          />
        </div>
      </MobileView>

      <DesktopView>
        <div className='container mx-auto flex mb-3'>
          <div className='w-3/12'>
            {brand && (
              <div className='p-4'>
                <div className='text-caption-1 text-gray_r-11 mb-2'>
                  Produk dari brand:
                </div>
                {brand?.data?.logo && (
                  <Image
                    src={brand?.data?.logo}
                    alt={brand?.data?.name}
                    className='w-32 p-2 border borde-gray_r-6 rounded'
                  />
                )}
                {!brand?.data?.logo && (
                  <div className='bg-danger-500 text-white text-center text-body-1 py-2 px-4 rounded w-fit'>
                    {brand?.data?.name}
                  </div>
                )}
              </div>
            )}

            <ProductFilterDesktop
              brands={brands || []}
              categories={categories || []}
              prefixUrl={prefixUrl}
              defaultBrand={defaultBrand}
            />

            <div className='h-6' />

            <SideBanner query={search} />
          </div>

          <div className='w-9/12 pl-6'>
            <LobSectionCategory categories={dataLob} />
            <CategorySection categories={dataCategories} />
            {bannerPromotionHeader && bannerPromotionHeader?.image && (
              <div className='mb-3'>
                <Image
                  src={bannerPromotionHeader?.image}
                  alt=''
                  className='object-cover object-center h-full mx-auto'
                />
              </div>
            )}

            {isNotReadyStockPage && isBrand && isBrand.logo && (
              <div className='mb-3'>
                <h1 className='text-2xl mb-2 font-semibold'>
                  Brand Pencarian {q}
                </h1>
                <Link
                  href={createSlug('/shop/brands/', isBrand.name, isBrand.id)}
                  className='inline'
                >
                  <Image
                    src={isBrand?.logo}
                    alt=''
                    className='object-cover object-center h-24'
                  />
                </Link>
              </div>
            )}

            <h1 className='text-2xl mb-2 font-semibold'>Hasil Pencarian</h1>
            <FilterChoicesComponent
              brandValues={brandValues}
              categoryValues={categoryValues}
              priceFrom={priceFrom}
              priceTo={priceTo}
              handleDeleteFilter={handleDeleteFilter}
            />
            <div className='flex justify-between items-center mb-5'>
              <div className='leading-6 text-gray_r-11'>
                {spellings?.length < 1 || !spellings ? (
                  <>
                    Menampilkan&nbsp;
                    {pageCount > 1 ? (
                      <>
                        {productStart + 1}-
                        {parseInt(productStart) + parseInt(productRows) >
                          productFound
                          ? productFound
                          : parseInt(productStart) + parseInt(productRows)}
                        &nbsp;dari&nbsp;
                      </>
                    ) : (
                      ''
                    )}
                    {productFound}
                    &nbsp;produk{' '}
                    {query.q && (
                      <>
                        untuk pencarian{' '}
                        <span className='font-semibold'>{query.q}</span>
                      </>
                    )}
                  </>
                ) : (
                  SpellingComponent
                )}
              </div>
              <div className='justify-end flex '>
                <div className='ml-3'>
                  <select
                    name='urutan'
                    className='form-input'
                    value={orderBy}
                    onChange={(e) => handleOrderBy(e)}
                  >
                    {orderOptions.map((option, index) => (
                      <option key={index} value={option.value}>
                        {' '}
                        {option.label}{' '}
                      </option>
                    ))}
                  </select>
                </div>
                <div className='ml-3'>
                  <select
                    name='limit'
                    className='form-input'
                    value={router.query?.limit || ''}
                    onChange={(e) => handleLimit(e)}
                  >
                    {numRows.map((option, index) => (
                      <option key={index} value={option}>
                        {' '}
                        {option}{' '}
                      </option>
                    ))}
                  </select>
                </div>
              </div>
            </div>
            {productSearch.isLoading && <ProductSearchSkeleton />}
            <div className='grid grid-cols-5 gap-x-3 gap-y-6'>
              {products &&
                products.map((product) => (
                  <ProductCard product={product} key={product.id} />
                ))}
            </div>
            <div className='flex justify-between items-center mt-6 mb-2'>
              <div className='pt-2 pb-6 flex items-center gap-x-3'>
                <NextImage
                  src='/images/logo-question.png'
                  alt='Logo Question Indoteknik'
                  width={60}
                  height={60}
                />
                <div className='text-gray_r-12/90'>
                  <span>
                    Barang yang anda cari tidak ada?{' '}
                    <a
                      href={
                        query?.q
                          ? whatsappUrl('productSearch', {
                            name: query.q,
                          })
                          : whatsappUrl()
                      }
                      className='text-danger-500'
                    >
                      Hubungi Kami
                    </a>
                  </span>
                </div>
              </div>

              <Pagination
                pageCount={pageCount}
                currentPage={parseInt(page)}
                url={`${prefixUrl}?${toQuery(_.omit(query, ['page', 'fq']))}`}
                // url={prefixUrl.includes('category') || prefixUrl.includes('lob')? `${prefixUrl}?${toQuery(_.omit(finalQuery, ['page']))}` : `${prefixUrl}?${toQuery(_.omit(query, ['page']))}`}
                className='!justify-end'
              />
            </div>
            {bannerPromotionFooter && bannerPromotionFooter?.image && (
              <div className='mb-3'>
                <Image
                  src={bannerPromotionFooter?.image}
                  alt=''
                  className='object-cover object-center h-full mx-auto'
                />
              </div>
            )}
            <FooterBanner />
          </div>
        </div>
      </DesktopView>
    </>
  );
};

export default ProductSearch;

const FilterChoicesComponent = ({
  brandValues,
  categoryValues,
  priceFrom,
  priceTo,
  handleDeleteFilter,
}) => (
  <div className='flex items-center'>
    <HStack spacing={2} className='flex-wrap'>
      {brandValues?.map((value, index) => (
        <Tag
          size='lg'
          key={index}
          borderRadius='lg'
          variant='outline'
          colorScheme='gray'
        >
          <TagLabel>{value}</TagLabel>
          <TagCloseButton onClick={() => handleDeleteFilter('brands', value)} />
        </Tag>
      ))}

      {categoryValues?.map((value, index) => (
        <Tag
          size='lg'
          key={index}
          borderRadius='lg'
          variant='outline'
          colorScheme='gray'
        >
          <TagLabel>{value}</TagLabel>
          <TagCloseButton
            onClick={() => handleDeleteFilter('category', value)}
          />
        </Tag>
      ))}
      {priceFrom && priceTo && (
        <Tag size='lg' borderRadius='lg' variant='outline' colorScheme='gray'>
          <TagLabel>
            {formatCurrency(priceFrom) + '-' + formatCurrency(priceTo)}
          </TagLabel>
          <TagCloseButton
            onClick={() => handleDeleteFilter('price', priceFrom)}
          />
        </Tag>
      )}
      {brandValues?.length > 0 ||
        categoryValues?.length > 0 ||
        priceFrom ||
        priceTo ? (
        <span>
          <button
            className='btn-transparent py-2 px-5 h-[40px] text-red-700'
            onClick={() => handleDeleteFilter('delete')}
          >
            Hapus Semua
          </button>
        </span>
      ) : (
        ''
      )}
    </HStack>
  </div>
);