@sledge-app/react-instant-search 1.0.126 → 1.0.128

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -87,7 +87,9 @@ const LOCAL_STORAGE_KEY = {
87
87
  EXPIRED_AUTH_APP: "sledge-expired-auth-app",
88
88
  RECENTLY_VIEWED_APP: "sledge-recently-viewed",
89
89
  LIMIT_PRODUCT: "sledge-limit-product",
90
- WISHLIST_BADGE_COUNTER: "sledge-wishlist-badge-counter"
90
+ WISHLIST_BADGE_COUNTER: "sledge-wishlist-badge-counter",
91
+ PRODUCT_FILTER_INIT_TOTAL_HITS: "sledge-product-filter-init-total-hits",
92
+ SEARCH_RESULT_INIT_TOTAL_HITS: "sledge-search-result-init-total-hits"
91
93
  };
92
94
  const INTERNAL_SELECTOR_VALUE = {
93
95
  ELEMENT_TOAST_NOTIFICATION: "toast-notification",
@@ -993,7 +995,7 @@ const rowRenderer = ({ virtualized, item, id, labelStyle }) => {
993
995
  ] });
994
996
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__radio-group-item-flex", children: content }, key || index);
995
997
  };
996
- const RadioGroup = ({ id, name, required, defaultValue, items, labelStyle = {}, onValueChange, useVirtualized = false, scrollElement, selector }) => {
998
+ const RadioGroup = ({ id, name, required, defaultValue, items, labelStyle = {}, onValueChange, useVirtualized = false, scrollElement, selector, parentRef }) => {
997
999
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__radio-group-wrapper", children: /* @__PURE__ */ jsxRuntimeExports.jsx("form", { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
998
1000
  $f99a8c78507165f7$export$be92b6f5f03c0fe9,
999
1001
  {
@@ -1018,7 +1020,8 @@ const RadioGroup = ({ id, name, required, defaultValue, items, labelStyle = {},
1018
1020
  labelStyle
1019
1021
  }),
1020
1022
  scrollElement,
1021
- selector
1023
+ selector,
1024
+ parentRef
1022
1025
  }
1023
1026
  ) : items.map(
1024
1027
  (item, index) => rowRenderer({
@@ -1351,22 +1354,25 @@ const Button = React__default.forwardRef((props, buttonRef) => {
1351
1354
  );
1352
1355
  });
1353
1356
  const SearchInputField$1 = "";
1354
- const SearchInputField = (props) => {
1357
+ const SearchInputField = React__default.memo((props) => {
1355
1358
  const { className = "", icon, value = "", withClearField, onChange, onResetField, fieldRef, ...otherProps } = props;
1356
- const handleResetField = () => {
1357
- (fieldRef == null ? void 0 : fieldRef.current) && fieldRef.current.focus();
1359
+ const inputRef = React__default.useRef(null);
1360
+ const handleResetField = React__default.useCallback(() => {
1361
+ var _a;
1362
+ const elementCurrent = (fieldRef == null ? void 0 : fieldRef.current) || (inputRef == null ? void 0 : inputRef.current);
1363
+ (_a = elementCurrent == null ? void 0 : elementCurrent.focus) == null ? void 0 : _a.call(elementCurrent);
1358
1364
  onChange && onChange({ value: "" });
1359
1365
  onResetField && onResetField();
1360
- };
1361
- const handleChangeField = (e) => {
1366
+ }, []);
1367
+ const handleChangeField = React__default.useCallback((e) => {
1362
1368
  onChange && onChange({ value: e.target.value });
1363
- };
1369
+ }, []);
1364
1370
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `sledge__search-input-field-wrapper ${className || ""}`, children: [
1365
1371
  !icon ? null : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__search-input-field-icon", children: icon }),
1366
- /* @__PURE__ */ jsxRuntimeExports.jsx("input", { className: "sledge__search-input-field", value, onChange: (e) => handleChangeField(e), ref: fieldRef, ...otherProps }),
1372
+ /* @__PURE__ */ jsxRuntimeExports.jsx("input", { className: "sledge__search-input-field", value, onChange: (e) => handleChangeField(e), ref: fieldRef || inputRef, ...otherProps }),
1367
1373
  value && withClearField ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__clear-field-wrapper", children: /* @__PURE__ */ jsxRuntimeExports.jsx("button", { className: "sledge__clear-field", type: "button", onClick: handleResetField, children: /* @__PURE__ */ jsxRuntimeExports.jsx(CloseIcon, { width: 14, height: 14, color: "#393d4e" }) }) }) : null
1368
1374
  ] });
1369
- };
1375
+ });
1370
1376
  const SelectField$1 = "";
1371
1377
  const ROTATE_FILTER_ARROW_ANIMATION = {
1372
1378
  open: { rotate: 180 },
@@ -3808,7 +3814,7 @@ const addToCartTrigger = async (data) => {
3808
3814
  return;
3809
3815
  });
3810
3816
  };
3811
- const ProductCard = (props) => {
3817
+ const ProductCard = React__default.memo((props) => {
3812
3818
  var _a, _b, _c;
3813
3819
  const {
3814
3820
  item,
@@ -4314,8 +4320,8 @@ ${selectedOption === item2 ? "sledge__product-variant-size-swatch-active" : ""}
4314
4320
  ] }) });
4315
4321
  }
4316
4322
  return /* @__PURE__ */ jsxRuntimeExports.jsx(React__default.Fragment, { children: component }, id);
4317
- };
4318
- const ProductGrid = (props) => {
4323
+ });
4324
+ const ProductGrid = React__default.memo((props) => {
4319
4325
  const { type, className = "", data, setting, sourceApp = null, useSlider = false, isFlyout = false, onAfterAddToCart, onAfterRenderProduct } = props;
4320
4326
  const { redirect_add_to_cart = true } = setting || {};
4321
4327
  const [clickedAddToCartId, setClickedAddToCartId] = React__default.useState(null);
@@ -4402,7 +4408,7 @@ const ProductGrid = (props) => {
4402
4408
  `sledge-product-card_${index}`
4403
4409
  );
4404
4410
  }) });
4405
- };
4411
+ });
4406
4412
  const TextAreaField = "";
4407
4413
  const InputField$1 = "";
4408
4414
  const InputField = (props) => {
@@ -4602,6 +4608,18 @@ const SkeletonItem = ({ width, height, rounded, color, style = {}, className = "
4602
4608
  ) : null });
4603
4609
  };
4604
4610
  const SkeletonProductGrid = ({ count, type, isFlyout = false }) => {
4611
+ var _a;
4612
+ const [dataSettings, setDataSettings] = React__default.useState({});
4613
+ const handleSettings = async (LOCAL_STORAGE_GENERAL_SETTING) => {
4614
+ let response;
4615
+ response = JSON.parse(LOCAL_STORAGE_GENERAL_SETTING);
4616
+ if (!response)
4617
+ return;
4618
+ setDataSettings(response);
4619
+ };
4620
+ React__default.useEffect(() => {
4621
+ handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.GENERAL_SETTING) || null);
4622
+ }, []);
4605
4623
  let components = [];
4606
4624
  for (let i = 0; i < count; i++) {
4607
4625
  components.push(
@@ -4654,7 +4672,7 @@ const SkeletonProductGrid = ({ count, type, isFlyout = false }) => {
4654
4672
  ] }, i)
4655
4673
  );
4656
4674
  }
4657
- return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__product-grid sledge__skeleton-product-grid sledge__skeleton-pointer-events-none", "data-grid-type": type, children: components });
4675
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: ((_a = dataSettings == null ? void 0 : dataSettings.skeleton) == null ? void 0 : _a.enable) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__product-grid sledge__skeleton-product-grid sledge__skeleton-pointer-events-none", "data-grid-type": type, children: components }) : null });
4658
4676
  };
4659
4677
  const SkeletonReviewGrid = ({ count, type, gridItemHeights = [] }) => {
4660
4678
  let components = [];
@@ -4989,14 +5007,14 @@ const getElement = ({ selector, setUsedScrollElement }) => {
4989
5007
  else
4990
5008
  setUsedScrollElement(element);
4991
5009
  };
4992
- const VirtualizedList = ({ scrollElement, rowCount, rowRenderer: rowRenderer2, selector }) => {
5010
+ const VirtualizedList = ({ scrollElement, rowCount, rowRenderer: rowRenderer2, selector, parentRef = null }) => {
4993
5011
  var _a;
4994
5012
  const [usedScrollElement, setUsedScrollElement] = React__default.useState(scrollElement);
4995
5013
  if (!usedScrollElement && selector)
4996
5014
  getElement({ selector, setUsedScrollElement });
4997
5015
  const virtualizer = useVirtualizer({
4998
5016
  count: rowCount,
4999
- getScrollElement: () => usedScrollElement,
5017
+ getScrollElement: () => (parentRef == null ? void 0 : parentRef.current) || usedScrollElement,
5000
5018
  estimateSize: () => 45
5001
5019
  });
5002
5020
  const items = virtualizer.getVirtualItems();
@@ -5936,6 +5954,130 @@ const handleFacetValues = ({
5936
5954
  });
5937
5955
  return facetValues;
5938
5956
  };
5957
+ const keyOpenFilters = ({ items = [] }) => {
5958
+ return (items == null ? void 0 : items.length) ? items.map((props, index) => {
5959
+ const { value, settings } = props;
5960
+ const { collapse } = settings || {};
5961
+ return collapse ? null : `${value}-${index}`;
5962
+ }).filter((item) => item) : [];
5963
+ };
5964
+ const handleSearchResponse = async (props) => {
5965
+ const {
5966
+ layoutType = "default",
5967
+ clickedTabIndexId,
5968
+ clickedTabIndexType = "product",
5969
+ keyword,
5970
+ sort = [],
5971
+ page = 1,
5972
+ limit = 1,
5973
+ isUseMultiSearch,
5974
+ facets,
5975
+ attributesToRetrieve = [],
5976
+ clickedFacets,
5977
+ setClickedFacets,
5978
+ allowedFilterSlider,
5979
+ hierarchicalFacetAliases,
5980
+ defaultFilterItems,
5981
+ setValueFilterPriceChange,
5982
+ setValueFilterOnSaleChange,
5983
+ setValueFilterSliderOthers,
5984
+ collectionId,
5985
+ hiddenTags,
5986
+ showOutOfStock,
5987
+ hierarchicalProductTypeSettings,
5988
+ hierarchicalCollectionsSettings,
5989
+ usePublishedFilter,
5990
+ tabs = []
5991
+ } = props;
5992
+ const isResultForProduct = clickedTabIndexType === "product";
5993
+ const isTypeCategoryHasPublished = ({ usePublishedFilter: usePublishedFilter2, type }) => Boolean(usePublishedFilter2 && type && ["collection", "page", "article"].includes(type));
5994
+ const { separator: hierarchical_separator, hiddens: hierarchical_hiddens } = hierarchicalProductTypeSettings || {};
5995
+ const {
5996
+ separator: hierarchical_collections_separator,
5997
+ hiddens: hierarchical_collections_hiddens,
5998
+ hidden_ids: hierarchical_collections_hidden_ids,
5999
+ structure: hierarchical_collections_structure
6000
+ } = hierarchicalCollectionsSettings || {};
6001
+ let response;
6002
+ let filterProduct = createQueryFilter({
6003
+ facets,
6004
+ facetsQueryStringObject: clickedFacets,
6005
+ callback: (facetsQueryStringObject) => {
6006
+ setClickedFacets == null ? void 0 : setClickedFacets(facetsQueryStringObject);
6007
+ if (facetsQueryStringObject["variants.price"])
6008
+ setValueFilterPriceChange == null ? void 0 : setValueFilterPriceChange(facetsQueryStringObject["variants.price"]);
6009
+ if (facetsQueryStringObject["variants.sale_percent"])
6010
+ setValueFilterOnSaleChange == null ? void 0 : setValueFilterOnSaleChange(facetsQueryStringObject["variants.sale_percent"]);
6011
+ allowedFilterSlider == null ? void 0 : allowedFilterSlider.map((filterSlider) => {
6012
+ if (!filterSlider || filterSlider && ["variants.price", "variants.sale_percent"].includes(filterSlider))
6013
+ return;
6014
+ if (facetsQueryStringObject[filterSlider])
6015
+ setValueFilterSliderOthers == null ? void 0 : setValueFilterSliderOthers((prevState) => ({ ...prevState, [filterSlider]: facetsQueryStringObject[filterSlider] }));
6016
+ });
6017
+ },
6018
+ separator: hierarchical_separator,
6019
+ separatorCollection: hierarchical_collections_separator,
6020
+ additional: [
6021
+ (hiddenTags == null ? void 0 : hiddenTags.length) ? `'tags' NOT IN ${JSON.stringify(hiddenTags)}` : null,
6022
+ collectionId ? `'collections.id' = '${collectionId}'` : null,
6023
+ !showOutOfStock ? `'availability' IN ${JSON.stringify(["in stock"])}` : null
6024
+ ],
6025
+ allowedFilterSlider,
6026
+ hierarchicalFacetAliases,
6027
+ defaultFilterItems
6028
+ });
6029
+ let filterCategory = "";
6030
+ if (isTypeCategoryHasPublished({ usePublishedFilter, type: clickedTabIndexType })) {
6031
+ filterCategory = DEFAULT_QUERY_PUBLISHED_FILTER;
6032
+ }
6033
+ let bodyProductOrCategory = isResultForProduct ? {
6034
+ q: keyword,
6035
+ sort,
6036
+ page,
6037
+ hitsPerPage: limit,
6038
+ facets,
6039
+ attributesToRetrieve,
6040
+ filter: filterProduct
6041
+ } : {
6042
+ q: keyword,
6043
+ sort,
6044
+ page,
6045
+ hitsPerPage: 12,
6046
+ filter: filterCategory
6047
+ };
6048
+ if (isResultForProduct && layoutType === "product-filter") {
6049
+ response = await search(clickedTabIndexId, bodyProductOrCategory);
6050
+ } else {
6051
+ if (isUseMultiSearch) {
6052
+ let getTabs = isUseMultiSearch ? tabs : tabs.filter(({ index }) => index == null ? void 0 : index.includes(clickedTabIndexId));
6053
+ let body = {
6054
+ queries: getTabs.map((tab) => {
6055
+ const { index, type } = tab;
6056
+ let isCurrentIndex = index.includes(clickedTabIndexId);
6057
+ let isProductIndex = type === "product";
6058
+ return {
6059
+ indexUid: index,
6060
+ ...isCurrentIndex ? bodyProductOrCategory : {
6061
+ q: keyword || "",
6062
+ hitsPerPage: 1,
6063
+ filter: isTypeCategoryHasPublished({ usePublishedFilter, type }) ? DEFAULT_QUERY_PUBLISHED_FILTER : isProductIndex ? filterProduct : "",
6064
+ attributesToRetrieve: [],
6065
+ limit: 0,
6066
+ page: 0,
6067
+ ...isProductIndex ? {
6068
+ facets
6069
+ } : {}
6070
+ }
6071
+ };
6072
+ })
6073
+ };
6074
+ response = await multiSearch(body);
6075
+ } else {
6076
+ response = await search(clickedTabIndexId, bodyProductOrCategory);
6077
+ }
6078
+ }
6079
+ return response;
6080
+ };
5939
6081
  const FacetComponent = (props) => {
5940
6082
  var _a, _b, _c, _d, _e;
5941
6083
  const {
@@ -5973,6 +6115,7 @@ const FacetComponent = (props) => {
5973
6115
  const [keywordFacet, setKeywordFacet] = React__default.useState("");
5974
6116
  const [showFacet, setShowFacet] = React__default.useState(false);
5975
6117
  const searchFacetRef = React__default.useRef(null);
6118
+ const ulListRef = React__default.useRef(null);
5976
6119
  const previousState = usePrevious({ keywordFacet });
5977
6120
  const { money_format, default_currency_symbol } = generalDataSettings || {};
5978
6121
  const { button_load_more } = (generalDataSettings == null ? void 0 : generalDataSettings.languages) || {};
@@ -6259,11 +6402,11 @@ const FacetComponent = (props) => {
6259
6402
  }),
6260
6403
  setValueChange: (valueChange) => {
6261
6404
  if (value === "variants.price") {
6262
- setValueFilterPriceChange(valueChange);
6405
+ setValueFilterPriceChange == null ? void 0 : setValueFilterPriceChange(valueChange);
6263
6406
  } else if (value === "variants.sale_percent") {
6264
- setValueFilterOnSaleChange(valueChange);
6407
+ setValueFilterOnSaleChange == null ? void 0 : setValueFilterOnSaleChange(valueChange);
6265
6408
  } else {
6266
- setValueFilterSliderOthers((prevState) => ({ ...prevState, [value]: valueChange }));
6409
+ setValueFilterSliderOthers == null ? void 0 : setValueFilterSliderOthers((prevState) => ({ ...prevState, [value]: valueChange }));
6267
6410
  }
6268
6411
  },
6269
6412
  wrapperClassName: "sledge-instant-search__result-filter-item-list-slider",
@@ -6283,7 +6426,8 @@ const FacetComponent = (props) => {
6283
6426
  rowRenderer: (props2) => handleFacetCheckbox({
6284
6427
  facetValues: currentItems,
6285
6428
  virtualized: props2
6286
- })
6429
+ }),
6430
+ parentRef: ulListRef
6287
6431
  }
6288
6432
  ) : /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: handleFacetCheckbox({
6289
6433
  facetValues: currentItems
@@ -6312,7 +6456,8 @@ const FacetComponent = (props) => {
6312
6456
  selector: scrollElementSelector,
6313
6457
  ...scrollElement && {
6314
6458
  scrollElement
6315
- }
6459
+ },
6460
+ parentRef: ulListRef
6316
6461
  }
6317
6462
  ) });
6318
6463
  } else if (display.toLowerCase() === "select" && (currentItems == null ? void 0 : currentItems.length)) {
@@ -6386,7 +6531,7 @@ const FacetComponent = (props) => {
6386
6531
  ),
6387
6532
  keywordFacet && totalItems && Number(totalItems) > 1 && !show_filter_list_when_search && !showFacet ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter-search-text", style: filter_option_style, children: searchFilterShowMoreResult ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { dangerouslySetInnerHTML: { __html: searchFilterShowMoreResult } }) : defaultSearchShowMoreFilter }) : null
6388
6533
  ] }) : null,
6389
- !show_search || show_search && (show_filter_list_when_search || !show_filter_list_when_search && (!totalItems || Number(totalItems) === 1 && keywordFacet) || showFacet) ? /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { className: ulClasses, children: blockComponent }) : null
6534
+ !show_search || show_search && (show_filter_list_when_search || !show_filter_list_when_search && (!totalItems || Number(totalItems) === 1 && keywordFacet) || showFacet) ? /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { ref: ulListRef, className: ulClasses, children: blockComponent }) : null
6390
6535
  ] });
6391
6536
  };
6392
6537
  const FilterVerticalComponent = (props) => {
@@ -6476,6 +6621,202 @@ const FilterHorizontalComponent = (props) => {
6476
6621
  }
6477
6622
  ) }, indexFilter) : null;
6478
6623
  };
6624
+ const Sort = React__default.memo(
6625
+ (props) => {
6626
+ const { label = "", options = [], clickedOption = "", handleChangeOption = null, overridePlaceholderOnMobile = null } = props;
6627
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: (options == null ? void 0 : options.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
6628
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "sledge-instant-search__result-data-summary-select-field-sort", children: [
6629
+ label || "Sort by",
6630
+ ":"
6631
+ ] }),
6632
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
6633
+ SelectField,
6634
+ {
6635
+ align: "end",
6636
+ prefixLabel: /* @__PURE__ */ jsxRuntimeExports.jsx("svg", { width: 18, height: 18, viewBox: "0 0 18 18", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
6637
+ "path",
6638
+ {
6639
+ d: "M12.6296 4.34737C12.9144 4.34737 13.1497 4.55898 13.1869 4.83354L13.1921 4.90987L13.192 13.7599L15.2892 11.6543C15.5083 11.4341 15.8645 11.4333 16.0847 11.6525C16.2848 11.8517 16.3037 12.1641 16.1408 12.3847L16.0865 12.4479L13.0282 15.5204C13.0097 15.5386 12.991 15.555 12.9712 15.5701L13.0282 15.5204C13.0006 15.5482 12.9708 15.5724 12.9394 15.5932C12.9285 15.6 12.9171 15.607 12.9055 15.6135C12.8946 15.62 12.8837 15.6258 12.8725 15.6311C12.8615 15.6359 12.8504 15.6408 12.8391 15.6454C12.8247 15.6515 12.8099 15.6568 12.795 15.6613C12.7862 15.6637 12.7772 15.6662 12.7681 15.6685C12.7519 15.673 12.7357 15.6763 12.7193 15.6789C12.7116 15.6798 12.7036 15.6809 12.6955 15.6819C12.677 15.6844 12.6587 15.6857 12.6404 15.686C12.6368 15.6857 12.6332 15.6857 12.6296 15.6857L12.6186 15.686C12.6003 15.6857 12.582 15.6844 12.5637 15.6823L12.6296 15.6857C12.5989 15.6857 12.5689 15.6833 12.5396 15.6785C12.5233 15.6763 12.5071 15.673 12.4909 15.6689C12.4824 15.6663 12.4738 15.6639 12.4654 15.6614C12.4493 15.6569 12.4332 15.6512 12.4174 15.6448C12.4088 15.6408 12.4005 15.6372 12.3922 15.6333C12.3793 15.6278 12.3663 15.6211 12.3535 15.6139C12.342 15.6069 12.3307 15.6 12.3196 15.5926C12.3109 15.5875 12.3024 15.5815 12.294 15.5752L12.288 15.5701C12.2682 15.555 12.2494 15.5386 12.2318 15.5209L12.2308 15.5204L9.1725 12.4479C8.95334 12.2278 8.95416 11.8716 9.17434 11.6525C9.3745 11.4532 9.68704 11.4358 9.90687 11.5997L9.96983 11.6543L12.067 13.7614L12.0671 4.90987C12.0671 4.59921 12.3189 4.34737 12.6296 4.34737ZM5.18325 2.3122L5.19421 2.31189C5.21254 2.31224 5.23085 2.31348 5.24908 2.31562L5.18325 2.3122C5.21389 2.3122 5.24396 2.31465 5.27328 2.31937C5.28931 2.32156 5.3054 2.32487 5.32136 2.32889C5.33074 2.33164 5.3403 2.33433 5.34975 2.33725C5.36452 2.34142 5.37882 2.34648 5.39293 2.35213C5.40313 2.35668 5.41346 2.36119 5.42362 2.366C5.4357 2.37123 5.4476 2.37737 5.45931 2.38397C5.46933 2.39014 5.47926 2.39616 5.48898 2.40246C5.49898 2.40841 5.50899 2.41537 5.51882 2.42269L5.582 2.47746L8.64033 5.54996C8.85949 5.77013 8.85867 6.12629 8.63849 6.34545C8.43833 6.54469 8.12579 6.56212 7.90596 6.39822L7.843 6.34361L5.74525 4.23564L5.74575 13.088C5.74575 13.3987 5.49391 13.6505 5.18325 13.6505C4.89848 13.6505 4.66313 13.4389 4.62588 13.1644L4.62075 13.088L4.62025 4.23639L2.52367 6.34361C2.32443 6.54377 2.01197 6.56265 1.79139 6.39977L1.72817 6.34545C1.52801 6.14621 1.50914 5.83376 1.67202 5.61317L1.72633 5.54996L4.78467 2.47746L4.81779 2.44709C4.82557 2.44043 4.83353 2.43399 4.84167 2.42776L4.78467 2.47746C4.81226 2.44974 4.84202 2.42549 4.87341 2.40473C4.88436 2.39791 4.89574 2.39094 4.90738 2.38438C4.91819 2.37787 4.92917 2.37215 4.9403 2.36682C4.95128 2.36196 4.96242 2.35706 4.97375 2.35251C4.98814 2.34636 5.00289 2.34115 5.0178 2.33657C5.02687 2.33414 5.03616 2.33154 5.04555 2.32918C5.06066 2.32503 5.07593 2.32186 5.09129 2.31932C5.10053 2.31817 5.10959 2.31691 5.11871 2.31586C5.13607 2.31348 5.15388 2.31227 5.17171 2.3119C5.17564 2.31224 5.17944 2.3122 5.18325 2.3122Z",
6640
+ fill: "black"
6641
+ }
6642
+ ) }),
6643
+ options: options.map((item) => {
6644
+ const { label: label2, value } = item;
6645
+ return {
6646
+ label: label2,
6647
+ value
6648
+ };
6649
+ }),
6650
+ value: clickedOption,
6651
+ onChange: ({ value }) => handleChangeOption == null ? void 0 : handleChangeOption(value),
6652
+ overridePlaceholderOnMobile,
6653
+ className: "sledge-instant-search__result-select-field-sort"
6654
+ }
6655
+ )
6656
+ ] }) : null });
6657
+ }
6658
+ );
6659
+ const Limit = React__default.memo(
6660
+ (props) => {
6661
+ const { label = "", options = [], clickedOption = "", handleChangeOption = null, overridePlaceholderOnMobile = null } = props;
6662
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: (options == null ? void 0 : options.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
6663
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "sledge-instant-search__result-data-summary-select-field-limit", children: [
6664
+ label || "Limit",
6665
+ ":"
6666
+ ] }),
6667
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
6668
+ SelectField,
6669
+ {
6670
+ align: "end",
6671
+ options: options.map((item) => {
6672
+ return {
6673
+ label: item,
6674
+ value: item
6675
+ };
6676
+ }),
6677
+ value: clickedOption,
6678
+ onChange: ({ value }) => handleChangeOption == null ? void 0 : handleChangeOption(value),
6679
+ overridePlaceholderOnMobile,
6680
+ className: "sledge-instant-search__result-select-field-limit"
6681
+ }
6682
+ )
6683
+ ] }) : null });
6684
+ }
6685
+ );
6686
+ const Search = React__default.memo((props) => {
6687
+ const { placeholder = "", value = "", handleChangeSearch = null } = props;
6688
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
6689
+ SearchInputField,
6690
+ {
6691
+ type: "text",
6692
+ icon: /* @__PURE__ */ jsxRuntimeExports.jsx(SearchIcon, { width: 18, height: 18, color: "#868686" }),
6693
+ placeholder: placeholder || "Search products...",
6694
+ value: value || "",
6695
+ onChange: ({ value: value2 }) => handleChangeSearch == null ? void 0 : handleChangeSearch(value2),
6696
+ onResetField: () => handleChangeSearch == null ? void 0 : handleChangeSearch(""),
6697
+ className: "sledge-instant-search__result-data-keyword-form",
6698
+ withClearField: true
6699
+ }
6700
+ );
6701
+ });
6702
+ const FacetBlockSelected = React__default.memo(
6703
+ (props) => {
6704
+ var _a, _b, _c, _d, _e, _f, _g;
6705
+ const {
6706
+ label,
6707
+ name,
6708
+ value: valueProp,
6709
+ index,
6710
+ defaultFilterItems = [],
6711
+ generalDataSettings = {},
6712
+ languageSettings = {},
6713
+ hierarchicalCollectionsSettings = {},
6714
+ hierarchicalProductTypeSettings = {},
6715
+ displaySettings = {},
6716
+ settings = {},
6717
+ handleFilterChange,
6718
+ allowedFilterSlider
6719
+ } = props;
6720
+ const { money_format } = generalDataSettings || {};
6721
+ const { separator: hierarchical_collections_separator } = hierarchicalCollectionsSettings || {};
6722
+ const {
6723
+ color: filter_option_color,
6724
+ font_size: filter_option_font_size,
6725
+ font_weight: filter_option_font_weight,
6726
+ text_transform: filter_option_text_transform
6727
+ } = ((_a = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _a.option) || {};
6728
+ const filter_option_style = {
6729
+ ...filter_option_color && { color: filter_option_color },
6730
+ ...filter_option_font_size && { fontSize: filter_option_font_size },
6731
+ ...filter_option_font_weight && { fontWeight: filter_option_font_weight },
6732
+ ...filter_option_text_transform && { textTransform: filter_option_text_transform }
6733
+ };
6734
+ let value = valueProp;
6735
+ if (name === HIERARCHICAL_FACET_OBJECT_ALIASES.collections) {
6736
+ if ((_b = String(value)) == null ? void 0 : _b.includes(hierarchical_collections_separator)) {
6737
+ let arrValue = String(value).split(hierarchical_collections_separator);
6738
+ value = (arrValue == null ? void 0 : arrValue.length) ? arrValue.map((item) => {
6739
+ var _a2;
6740
+ return ((_a2 = parseFacetObject({ facet: item })) == null ? void 0 : _a2.collection_title) || item;
6741
+ }).join(hierarchical_collections_separator) : valueProp;
6742
+ } else {
6743
+ value = ((_c = parseFacetObject({ facet: valueProp })) == null ? void 0 : _c.collection_title) || valueProp;
6744
+ }
6745
+ }
6746
+ let valueText = (languageSettings == null ? void 0 : languageSettings[value]) || value;
6747
+ let isRange = allowedFilterSlider == null ? void 0 : allowedFilterSlider.includes(name);
6748
+ let getLabel = label;
6749
+ let getSettings = {};
6750
+ let isPriceValue = false;
6751
+ let isSalePercent = false;
6752
+ if (name === "variants.price") {
6753
+ isPriceValue = true;
6754
+ } else if (name === "variants.sale_percent") {
6755
+ isSalePercent = true;
6756
+ }
6757
+ if (defaultFilterItems == null ? void 0 : defaultFilterItems.length) {
6758
+ defaultFilterItems.map((defaultFilterItem) => {
6759
+ const { label: defaultFilterItemLabel, items, settings: defaultFilterItemSettings } = defaultFilterItem;
6760
+ if (items == null ? void 0 : items.includes(value)) {
6761
+ getLabel = defaultFilterItemLabel;
6762
+ getSettings = defaultFilterItemSettings;
6763
+ }
6764
+ });
6765
+ }
6766
+ (_d = getSettings == null ? void 0 : getSettings.delete_prefix) == null ? void 0 : _d.map((deletePrefix) => {
6767
+ if (String(valueText).startsWith(deletePrefix))
6768
+ valueText = String(valueText).replace(deletePrefix, "");
6769
+ });
6770
+ if (isRange) {
6771
+ const getValueRange = new Set(value).size === 1 ? [value[0]] : value;
6772
+ valueText = (_e = getValueRange == null ? void 0 : getValueRange.map((valueItem) => isPriceValue ? shopifyFormatMoney(valueItem * 100, money_format) : isSalePercent ? `${valueItem}%` : valueItem)) == null ? void 0 : _e.join(" - ");
6773
+ } else {
6774
+ valueText = (_f = String(valueText)) == null ? void 0 : _f.replaceAll(hierarchical_collections_separator, " > ");
6775
+ }
6776
+ valueText = (_g = String(valueText)) == null ? void 0 : _g.replaceAll("_", " ");
6777
+ let aliases = {};
6778
+ let aliasValue = "";
6779
+ let aliasSeparator = "";
6780
+ if (name === HIERARCHICAL_FACET_OBJECT_ALIASES.collections) {
6781
+ aliases = settings.collectionAliases || {};
6782
+ aliasSeparator = hierarchicalCollectionsSettings.separator;
6783
+ }
6784
+ if (name === HIERARCHICAL_FACET_OBJECT_ALIASES.product_type) {
6785
+ aliases = settings.productTypeAliases || {};
6786
+ aliasSeparator = hierarchicalProductTypeSettings.separator;
6787
+ }
6788
+ if ([HIERARCHICAL_FACET_OBJECT_ALIASES.collections, HIERARCHICAL_FACET_OBJECT_ALIASES.product_type].includes(name) && aliasSeparator) {
6789
+ const splitedValues = value.split(aliasSeparator);
6790
+ let newSplitedValues = [];
6791
+ for (const splitedValue of splitedValues) {
6792
+ newSplitedValues.push(aliases[splitedValue.trim()] || splitedValue);
6793
+ }
6794
+ aliasValue = newSplitedValues.join(" > ");
6795
+ }
6796
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-filter-item-refine-selected", style: filter_option_style, children: [
6797
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "sledge-instant-search__result-filter-item-title-refine-list", dangerouslySetInnerHTML: { __html: `${getLabel}: ${aliasValue || valueText}` } }),
6798
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
6799
+ "span",
6800
+ {
6801
+ className: "sledge-instant-search__result-filter-item-refine-title-clear",
6802
+ onClick: () => handleFilterChange == null ? void 0 : handleFilterChange({
6803
+ parentId: name,
6804
+ value
6805
+ }),
6806
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx("svg", { width: 12, height: 12, viewBox: "0 0 15 15", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
6807
+ "path",
6808
+ {
6809
+ d: "M11.7816 4.03157C12.0062 3.80702 12.0062 3.44295 11.7816 3.2184C11.5571 2.99385 11.193 2.99385 10.9685 3.2184L7.50005 6.68682L4.03164 3.2184C3.80708 2.99385 3.44301 2.99385 3.21846 3.2184C2.99391 3.44295 2.99391 3.80702 3.21846 4.03157L6.68688 7.49999L3.21846 10.9684C2.99391 11.193 2.99391 11.557 3.21846 11.7816C3.44301 12.0061 3.80708 12.0061 4.03164 11.7816L7.50005 8.31316L10.9685 11.7816C11.193 12.0061 11.5571 12.0061 11.7816 11.7816C12.0062 11.557 12.0062 11.193 11.7816 10.9684L8.31322 7.49999L11.7816 4.03157Z",
6810
+ fill: "currentColor",
6811
+ fillRule: "evenodd",
6812
+ clipRule: "evenodd"
6813
+ }
6814
+ ) })
6815
+ }
6816
+ )
6817
+ ] }, index);
6818
+ }
6819
+ );
6479
6820
  const ButtonLoadMore = ({ text, onClick, isInfiniteScroll, currentPage, totalPage, totalResult, pageInfo: pageInfoProp, isVisibleLoadMore, ...otherProps }) => {
6480
6821
  const [ref, entry] = useIntersectionObserver({
6481
6822
  threshold: 0,
@@ -6532,9 +6873,11 @@ const SearchResultWidget = (props) => {
6532
6873
  data: propsData,
6533
6874
  sledgeSettings
6534
6875
  } = props;
6535
- const isFirstRender = useIsFirstRender();
6876
+ useIsFirstRender();
6536
6877
  const queryKeyword = (query == null ? void 0 : query.keyword) ? query.keyword : DEFAULT_QUERY_PARAM.KEYWORD;
6537
6878
  const querySortBy = (query == null ? void 0 : query.sortBy) ? query.sortBy : DEFAULT_QUERY_PARAM.SORT_BY;
6879
+ const queryPage = (query == null ? void 0 : query.page) ? query.page : DEFAULT_QUERY_PARAM.PAGE;
6880
+ const queryLimit = (query == null ? void 0 : query.limit) ? query.limit : DEFAULT_QUERY_PARAM.LIMIT;
6538
6881
  const { collectionId } = params || {};
6539
6882
  const searchParams = typeof document !== "undefined" ? new URLSearchParams((_a = document == null ? void 0 : document.location) == null ? void 0 : _a.search) : null;
6540
6883
  const [settings] = React__default.useState(typeof localStorage !== "undefined" ? JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || "{}") : {});
@@ -6549,6 +6892,7 @@ const SearchResultWidget = (props) => {
6549
6892
  const [allowedSorts, setAllowedSorts] = React__default.useState(((_b = sledgeSettings == null ? void 0 : sledgeSettings.instantsearch) == null ? void 0 : _b.allowed_sorts) || []);
6550
6893
  const [allowedFilter, setAllowedFilter] = React__default.useState([]);
6551
6894
  const [allowedTabs, setAllowedTabs] = React__default.useState([]);
6895
+ const [tabs, setTabs] = React__default.useState([]);
6552
6896
  const [facets, setFacets] = React__default.useState([]);
6553
6897
  const [indexProduct, setIndexProduct] = React__default.useState(((_c = sledgeSettings == null ? void 0 : sledgeSettings.instantsearch) == null ? void 0 : _c.index_product) || "");
6554
6898
  const [hiddenTags, setHiddenTags] = React__default.useState(((_d = sledgeSettings == null ? void 0 : sledgeSettings.instantsearch) == null ? void 0 : _d.hidden_tags) || []);
@@ -6579,6 +6923,9 @@ const SearchResultWidget = (props) => {
6579
6923
  const [hierarchicalFacetAliases, setHierarchicalFacetAliases] = React__default.useState([]);
6580
6924
  const [usePublishedFilter, setUsePublishedFilter] = React__default.useState(false);
6581
6925
  const [showOutOfStock, setShowOutOfStock] = React__default.useState(false);
6926
+ const [valueFilterPriceChange, setValueFilterPriceChange] = React__default.useState([]);
6927
+ const [valueFilterOnSaleChange, setValueFilterOnSaleChange] = React__default.useState([]);
6928
+ const [valueFilterSliderOthers, setValueFilterSliderOthers] = React__default.useState({});
6582
6929
  const debouncedKeyword = useDebounce(keyword, 500);
6583
6930
  let productCardsComponent = null;
6584
6931
  let collectionCardsComponent = null;
@@ -6605,82 +6952,116 @@ const SearchResultWidget = (props) => {
6605
6952
  const { value: valueRenderInstantSearchResult, trigger: triggerRenderInstantSearchResult } = ((_l = triggerRenderMultipleComponent == null ? void 0 : triggerRenderMultipleComponent.instantSearch) == null ? void 0 : _l.searchResult) || {};
6606
6953
  const searchResultContainerRef = React__default.useRef(null);
6607
6954
  const previousState = usePrevious({ keyword });
6608
- const handleChangeTabIndex = (params2) => {
6609
- const { id, name, type } = params2;
6610
- setClickedTabIndexId(id);
6611
- setClickedTabIndexName(name);
6612
- setClickedTabIndexType(type);
6613
- setResultComponent(id.includes(indexProduct) ? /* @__PURE__ */ jsxRuntimeExports.jsx(ResultProduct, {}) : /* @__PURE__ */ jsxRuntimeExports.jsx(ResultCategory, {}));
6614
- };
6615
- const handleInitStates = async (data) => {
6616
- var _a2, _b2, _c2, _d2, _e2;
6617
- const { filters, index_product, tabs, hidden_tags, show_out_of_stock, display, use_published_filter } = data;
6618
- let getTabs = layoutType === "product-filter" ? tabs.filter(({ index }) => index == null ? void 0 : index.includes(index_product)) : tabs;
6619
- let response;
6620
- let body = {
6621
- queries: getTabs.map((tab) => {
6622
- const { index, type } = tab;
6623
- const isTypeCategoryHasPublished = Boolean(use_published_filter && type && ["collection", "page", "article"].includes(type));
6624
- let filter = "";
6625
- let isSetFilter = false;
6626
- let getFacets = [];
6627
- if (!isSetFilter)
6628
- filters == null ? void 0 : filters.map((filter2) => {
6629
- const { active, collections, items } = filter2;
6630
- if (!active)
6631
- return;
6632
- const newItems = items == null ? void 0 : items.map(({ value, ...otherItem }) => (otherItem == null ? void 0 : otherItem.display) === "tree" ? HIERARCHICAL_FACET_OBJECT_ALIASES[value] || value : value);
6633
- if (collectionId && (collections == null ? void 0 : collections.includes(String(collectionId)))) {
6634
- isSetFilter = true;
6635
- getFacets = newItems;
6636
- } else {
6637
- if (collections == null ? void 0 : collections.includes("all")) {
6638
- isSetFilter = true;
6639
- getFacets = newItems;
6640
- }
6641
- }
6642
- });
6643
- let isProductIndex = index.includes(index_product);
6644
- let isHasProductFacets = isProductIndex && getFacets.length;
6645
- let additionalFilter = [];
6646
- if (hidden_tags == null ? void 0 : hidden_tags.length)
6647
- additionalFilter.push(`'tags' NOT IN ${JSON.stringify(hidden_tags)}`);
6648
- if (!show_out_of_stock)
6649
- additionalFilter.push(`'availability' IN ${JSON.stringify(["in stock"])}`);
6650
- if (collectionId)
6651
- additionalFilter.push(`'collections.id' = '${collectionId}'`);
6652
- if (isHasProductFacets)
6653
- setFacets(getFacets);
6654
- if (isProductIndex) {
6655
- filter = [...new Set(additionalFilter.concat(DEFAULT_QUERY_PRODUCT_MEILISEARCH))].join(" AND ");
6656
- } else if (isTypeCategoryHasPublished) {
6657
- filter = DEFAULT_QUERY_PUBLISHED_FILTER;
6955
+ const handleChangeTabIndex = React__default.useCallback(
6956
+ (params2) => {
6957
+ const { id, name, type } = params2;
6958
+ setClickedTabIndexId(id);
6959
+ setClickedTabIndexName(name);
6960
+ setClickedTabIndexType(type);
6961
+ setResultComponent(id.includes(indexProduct) ? /* @__PURE__ */ jsxRuntimeExports.jsx(ResultProduct, {}) : /* @__PURE__ */ jsxRuntimeExports.jsx(ResultCategory, {}));
6962
+ },
6963
+ [indexProduct]
6964
+ );
6965
+ const handleFilterStates = ({ data = {}, valueSearchResultFacets = {} }) => {
6966
+ var _a2, _b2, _c2;
6967
+ const { filters } = data;
6968
+ let allowedFilters = ((_b2 = (_a2 = sledgeSettings == null ? void 0 : sledgeSettings.instantsearch) == null ? void 0 : _a2.filters) == null ? void 0 : _b2.length) ? (_c2 = sledgeSettings == null ? void 0 : sledgeSettings.instantsearch) == null ? void 0 : _c2.filters : (filters == null ? void 0 : filters.length) ? filters : [];
6969
+ let isSetFilter = false;
6970
+ let valueAllowedFilter = [];
6971
+ let valueDefaultFilterItems = [];
6972
+ let valueAllowedFilterSlider = [];
6973
+ let valueHierarchicalFacetAliases = [];
6974
+ if (!isSetFilter) {
6975
+ allowedFilters == null ? void 0 : allowedFilters.map((filter) => {
6976
+ const { active, collections, items } = filter;
6977
+ if (!active)
6978
+ return;
6979
+ const newItems = items == null ? void 0 : items.map(({ value, ...otherItem }) => {
6980
+ return {
6981
+ ...otherItem,
6982
+ value: (otherItem == null ? void 0 : otherItem.display) === "tree" ? HIERARCHICAL_FACET_OBJECT_ALIASES[value] || value : value
6983
+ };
6984
+ });
6985
+ if (collectionId && (collections == null ? void 0 : collections.includes(String(collectionId)))) {
6986
+ isSetFilter = true;
6987
+ valueAllowedFilter = newItems;
6988
+ } else {
6989
+ if (collections == null ? void 0 : collections.includes("all")) {
6990
+ isSetFilter = true;
6991
+ valueAllowedFilter = newItems;
6992
+ }
6993
+ }
6994
+ });
6995
+ }
6996
+ if (valueAllowedFilter == null ? void 0 : valueAllowedFilter.length) {
6997
+ valueDefaultFilterItems = valueAllowedFilter.map((filter) => {
6998
+ var _a3;
6999
+ const { value, label, display, settings: settings2 } = filter;
7000
+ const { prefix, filter_list, selected_filter } = settings2 || {};
7001
+ const isDisplaySlider = ["slider", "input_range", "slider_with_input_range"].includes(display.toLowerCase());
7002
+ if (isDisplaySlider)
7003
+ return;
7004
+ let items = [];
7005
+ if (display.toLowerCase() === "tree") {
7006
+ for (let level = 0; level < MAX_LIMIT_HIERARCHICAL; level++) {
7007
+ items = [...items, ...(valueSearchResultFacets == null ? void 0 : valueSearchResultFacets[`${value}.lvl${level}`]) || []];
7008
+ }
7009
+ } else {
7010
+ items = valueSearchResultFacets == null ? void 0 : valueSearchResultFacets[value];
6658
7011
  }
6659
7012
  return {
6660
- indexUid: index,
6661
- q: keyword || "",
6662
- hitsPerPage: 1,
6663
- facets: isHasProductFacets ? getFacets : [],
6664
- filter,
6665
- attributesToRetrieve: [],
6666
- limit: 0,
6667
- page: 0
7013
+ value,
7014
+ label,
7015
+ settings: settings2,
7016
+ items: (_a3 = items == null ? void 0 : items.map((item) => {
7017
+ const isManualFilter = item && filter_list === "manual" && !(selected_filter == null ? void 0 : selected_filter.includes(item == null ? void 0 : item.value));
7018
+ const isPrefixFilter = item && filter_list === "prefix" && !(prefix == null ? void 0 : prefix.find((prefixItem) => {
7019
+ var _a4;
7020
+ return (_a4 = item == null ? void 0 : item.value) == null ? void 0 : _a4.startsWith(prefixItem);
7021
+ }));
7022
+ if (!item || isManualFilter || isPrefixFilter)
7023
+ return;
7024
+ return item.value;
7025
+ })) == null ? void 0 : _a3.filter((item) => item)
6668
7026
  };
6669
- })
7027
+ }).filter((item) => item);
7028
+ valueAllowedFilterSlider = valueAllowedFilter.map((filter) => {
7029
+ const { value, display } = filter;
7030
+ const isDisplaySlider = ["slider", "input_range", "slider_with_input_range"].includes(display.toLowerCase());
7031
+ if (!isDisplaySlider)
7032
+ return;
7033
+ return value;
7034
+ }).filter((item) => item);
7035
+ valueHierarchicalFacetAliases = valueAllowedFilter.map((filter) => {
7036
+ const { value, display } = filter;
7037
+ const isDisplayTree = display.toLowerCase() === "tree";
7038
+ if (!isDisplayTree)
7039
+ return;
7040
+ return value;
7041
+ }).filter((item) => item);
7042
+ }
7043
+ return {
7044
+ isSetFilter,
7045
+ valueAllowedFilter,
7046
+ valueDefaultFilterItems,
7047
+ valueAllowedFilterSlider,
7048
+ valueHierarchicalFacetAliases
6670
7049
  };
6671
- if (propsData && initStatesFirstTime) {
6672
- response = propsData.result;
6673
- setInitStatesFirstTime(false);
6674
- } else
6675
- response = await multiSearch(body);
6676
- if (!response)
6677
- return;
6678
- const { results } = response;
6679
- setIsFirstLoading(false);
6680
- setIsLoading(false);
6681
- const { facetStats, totalHits, facetDistribution } = (results == null ? void 0 : results.find(({ indexUid }) => indexUid.includes(index_product))) || {};
7050
+ };
7051
+ const handleSetInitStates = ({ results = {}, data = {}, callback }) => {
7052
+ var _a2, _b2, _c2;
7053
+ const { filters, index_product, tabs: tabs2, hidden_tags, show_out_of_stock, display, use_published_filter } = data;
7054
+ const { facetStats, totalHits: totalHitsResult, facetDistribution } = layoutType === "default" ? ((_a2 = results == null ? void 0 : results.find) == null ? void 0 : _a2.call(results, ({ indexUid }) => indexUid.includes(index_product))) || {} : results || {};
7055
+ let totalHits = totalHitsResult || 0;
7056
+ if (typeof localStorage !== "undefined") {
7057
+ const INIT_TOTAL_HITS = Number(localStorage.getItem(layoutType === "default" ? LOCAL_STORAGE_KEY.SEARCH_RESULT_INIT_TOTAL_HITS : LOCAL_STORAGE_KEY.PRODUCT_FILTER_INIT_TOTAL_HITS) || 0);
7058
+ if (!(INIT_TOTAL_HITS > 1)) {
7059
+ localStorage.setItem(layoutType === "default" ? LOCAL_STORAGE_KEY.SEARCH_RESULT_INIT_TOTAL_HITS : LOCAL_STORAGE_KEY.PRODUCT_FILTER_INIT_TOTAL_HITS, totalHits);
7060
+ }
7061
+ totalHits = totalHits <= 1 ? INIT_TOTAL_HITS : totalHits;
7062
+ }
6682
7063
  setTotalHitsProduct(totalHits || 0);
6683
- let valueHideFilterWhenOneValue = ((_a2 = display == null ? void 0 : display.filter) == null ? void 0 : _a2.hide_when_one_value) && totalHits <= 1;
7064
+ let valueHideFilterWhenOneValue = ((_b2 = display == null ? void 0 : display.filter) == null ? void 0 : _b2.hide_when_one_value) && totalHits <= 1;
6684
7065
  let valueSearchResultFacets = facetDistribution ? Object.fromEntries(
6685
7066
  Object.entries(facetDistribution).map((facet) => {
6686
7067
  let value = facet[0];
@@ -6707,96 +7088,79 @@ const SearchResultWidget = (props) => {
6707
7088
  setSearchResultFacets(valueSearchResultFacets);
6708
7089
  setDefaultFacetStats(facetStats);
6709
7090
  setHideFilterWhenOneValue(valueHideFilterWhenOneValue);
6710
- let allowedFilters = ((_c2 = (_b2 = sledgeSettings == null ? void 0 : sledgeSettings.instantsearch) == null ? void 0 : _b2.filters) == null ? void 0 : _c2.length) ? (_d2 = sledgeSettings == null ? void 0 : sledgeSettings.instantsearch) == null ? void 0 : _d2.filters : (filters == null ? void 0 : filters.length) ? filters : [];
6711
- if (!(!((_e2 = display == null ? void 0 : display.filter) == null ? void 0 : _e2.enable_on_search) || valueHideFilterWhenOneValue)) {
6712
- let isSetFilter = false;
6713
- let valueAllowedFilter = [];
6714
- if (!isSetFilter)
6715
- allowedFilters == null ? void 0 : allowedFilters.map((filter) => {
6716
- const { active, collections, items } = filter;
6717
- if (!active)
6718
- return;
6719
- const newItems = items == null ? void 0 : items.map(({ value, ...otherItem }) => {
6720
- return {
6721
- ...otherItem,
6722
- value: (otherItem == null ? void 0 : otherItem.display) === "tree" ? HIERARCHICAL_FACET_OBJECT_ALIASES[value] || value : value
6723
- };
6724
- });
6725
- if (collectionId && (collections == null ? void 0 : collections.includes(String(collectionId)))) {
6726
- isSetFilter = true;
6727
- valueAllowedFilter = newItems;
6728
- } else {
6729
- if (collections == null ? void 0 : collections.includes("all")) {
6730
- isSetFilter = true;
6731
- valueAllowedFilter = newItems;
6732
- }
6733
- }
6734
- });
7091
+ const { isSetFilter, valueAllowedFilter, valueDefaultFilterItems, valueAllowedFilterSlider, valueHierarchicalFacetAliases } = handleFilterStates({
7092
+ data,
7093
+ valueSearchResultFacets
7094
+ });
7095
+ if (!(!((_c2 = display == null ? void 0 : display.filter) == null ? void 0 : _c2.enable_on_search) || valueHideFilterWhenOneValue)) {
6735
7096
  if (isSetFilter)
6736
7097
  setAllowedFilter(valueAllowedFilter);
6737
7098
  if (valueAllowedFilter == null ? void 0 : valueAllowedFilter.length) {
6738
- let valueDefaultFilterItems = valueAllowedFilter.map((filter) => {
6739
- var _a3;
6740
- const { value, label, display: display2, settings: settings2 } = filter;
6741
- const { prefix, filter_list, selected_filter } = settings2 || {};
6742
- const isDisplaySlider = ["slider", "input_range", "slider_with_input_range"].includes(display2.toLowerCase());
6743
- if (isDisplaySlider)
6744
- return;
6745
- let items = [];
6746
- if (display2.toLowerCase() === "tree") {
6747
- for (let level = 0; level < MAX_LIMIT_HIERARCHICAL; level++) {
6748
- items = [...items, ...(valueSearchResultFacets == null ? void 0 : valueSearchResultFacets[`${value}.lvl${level}`]) || []];
6749
- }
6750
- } else {
6751
- items = valueSearchResultFacets[value];
6752
- }
6753
- return {
6754
- value,
6755
- label,
6756
- settings: settings2,
6757
- items: (_a3 = items == null ? void 0 : items.map((item) => {
6758
- const isManualFilter = item && filter_list === "manual" && !(selected_filter == null ? void 0 : selected_filter.includes(item == null ? void 0 : item.value));
6759
- const isPrefixFilter = item && filter_list === "prefix" && !(prefix == null ? void 0 : prefix.find((prefixItem) => {
6760
- var _a4;
6761
- return (_a4 = item == null ? void 0 : item.value) == null ? void 0 : _a4.startsWith(prefixItem);
6762
- }));
6763
- if (!item || isManualFilter || isPrefixFilter)
6764
- return;
6765
- return item.value;
6766
- })) == null ? void 0 : _a3.filter((item) => item)
6767
- };
6768
- }).filter((item) => item);
6769
- let valueAllowedFilterSlider = valueAllowedFilter.map((filter) => {
6770
- const { value, display: display2 } = filter;
6771
- const isDisplaySlider = ["slider", "input_range", "slider_with_input_range"].includes(display2.toLowerCase());
6772
- if (!isDisplaySlider)
6773
- return;
6774
- return value;
6775
- }).filter((item) => item);
6776
- let valueHierarchicalFacetAliases = valueAllowedFilter.map((filter) => {
6777
- const { value, display: display2 } = filter;
6778
- const isDisplayTree = display2.toLowerCase() === "tree";
6779
- if (!isDisplayTree)
6780
- return;
6781
- return value;
6782
- }).filter((item) => item);
6783
7099
  setDefaultFilterItems(valueDefaultFilterItems);
6784
7100
  setAllowedFilterSlider(valueAllowedFilterSlider);
6785
7101
  setHierarchicalFacetAliases(valueHierarchicalFacetAliases);
6786
7102
  }
6787
7103
  }
6788
- setAllowedTabs(
6789
- tabs == null ? void 0 : tabs.map((tab) => {
6790
- const { index } = tab;
6791
- const { totalHits: totalHits2 } = (results == null ? void 0 : results.find(({ indexUid }) => indexUid === index)) || {};
6792
- return {
6793
- ...tab,
6794
- ...{
6795
- total: totalHits2
7104
+ if (layoutType === "default") {
7105
+ setAllowedTabs(
7106
+ tabs2 == null ? void 0 : tabs2.map((tab) => {
7107
+ var _a3;
7108
+ const { index } = tab;
7109
+ const { totalHits: totalHits2 } = ((_a3 = results == null ? void 0 : results.find) == null ? void 0 : _a3.call(results, ({ indexUid }) => indexUid === index)) || {};
7110
+ return {
7111
+ ...tab,
7112
+ ...{
7113
+ total: totalHits2
7114
+ }
7115
+ };
7116
+ })
7117
+ );
7118
+ }
7119
+ callback == null ? void 0 : callback({
7120
+ valueAllowedFilter
7121
+ });
7122
+ };
7123
+ const handleInitStates = async (data) => {
7124
+ const { filters, index_product, tabs: tabs2, hidden_tags, show_out_of_stock, display, use_published_filter } = data;
7125
+ let getTabs = layoutType === "product-filter" ? tabs2.filter(({ index }) => index == null ? void 0 : index.includes(index_product)) : tabs2;
7126
+ getTabs.map((tab) => {
7127
+ const { index } = tab;
7128
+ let isSetFilter2 = false;
7129
+ let getFacets = [];
7130
+ if (!isSetFilter2)
7131
+ filters == null ? void 0 : filters.map((filter) => {
7132
+ const { active, collections, items } = filter;
7133
+ if (!active)
7134
+ return;
7135
+ const newItems = items == null ? void 0 : items.map(({ value, ...otherItem }) => (otherItem == null ? void 0 : otherItem.display) === "tree" ? HIERARCHICAL_FACET_OBJECT_ALIASES[value] || value : value);
7136
+ if (collectionId && (collections == null ? void 0 : collections.includes(String(collectionId)))) {
7137
+ isSetFilter2 = true;
7138
+ getFacets = newItems;
7139
+ } else {
7140
+ if (collections == null ? void 0 : collections.includes("all")) {
7141
+ isSetFilter2 = true;
7142
+ getFacets = newItems;
7143
+ }
6796
7144
  }
6797
- };
6798
- })
6799
- );
7145
+ });
7146
+ let isProductIndex = index.includes(index_product);
7147
+ let isHasProductFacets = isProductIndex && getFacets.length;
7148
+ if (isHasProductFacets)
7149
+ setFacets(getFacets);
7150
+ });
7151
+ const { isSetFilter, valueAllowedFilter, valueDefaultFilterItems, valueAllowedFilterSlider, valueHierarchicalFacetAliases } = handleFilterStates({
7152
+ data
7153
+ });
7154
+ if (isSetFilter)
7155
+ setAllowedFilter(valueAllowedFilter);
7156
+ if (valueAllowedFilter == null ? void 0 : valueAllowedFilter.length) {
7157
+ setDefaultFilterItems(valueDefaultFilterItems);
7158
+ setAllowedFilterSlider(valueAllowedFilterSlider);
7159
+ setHierarchicalFacetAliases(valueHierarchicalFacetAliases);
7160
+ }
7161
+ setIsFirstLoading(false);
7162
+ setIsLoading(false);
7163
+ return;
6800
7164
  };
6801
7165
  const handleSettings = (LOCAL_STORAGE_INSTANT_SEARCH_SETTING) => {
6802
7166
  var _a2;
@@ -6815,7 +7179,7 @@ const SearchResultWidget = (props) => {
6815
7179
  allowed_sorts,
6816
7180
  default_sort,
6817
7181
  index_product,
6818
- tabs,
7182
+ tabs: tabs2,
6819
7183
  hidden_tags,
6820
7184
  display,
6821
7185
  colors,
@@ -6859,7 +7223,8 @@ const SearchResultWidget = (props) => {
6859
7223
  setAttributesToRetrieve(attributes_to_retrieve);
6860
7224
  setUsePublishedFilter(use_published_filter);
6861
7225
  setShowOutOfStock(show_out_of_stock);
6862
- getFirstIndex = tabs.find(({ index }) => index.includes(index_product));
7226
+ setTabs(tabs2);
7227
+ getFirstIndex = tabs2.find(({ index }) => index.includes(index_product));
6863
7228
  if (Object.keys(getFirstIndex).length) {
6864
7229
  setClickedTabIndexId(getFirstIndex.index);
6865
7230
  setClickedTabIndexName(getFirstIndex.name);
@@ -6867,18 +7232,22 @@ const SearchResultWidget = (props) => {
6867
7232
  }
6868
7233
  setIsLoadingSetting(false);
6869
7234
  };
6870
- const handleChangeKeyword = (value) => {
7235
+ const handleChangeKeyword = React__default.useCallback((value) => {
6871
7236
  const searchParams2 = new URLSearchParams(document.location.search);
6872
7237
  searchParams2.set(queryKeyword, value);
6873
7238
  setKeyword(value);
6874
7239
  window.history.pushState(null, "", `${document.location.pathname}?${searchParams2.toString()}`);
7240
+ }, []);
7241
+ const initStates = () => {
7242
+ const INSTANT_SEARCH_SETTING = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
7243
+ if (INSTANT_SEARCH_SETTING)
7244
+ handleInitStates(INSTANT_SEARCH_SETTING);
6875
7245
  };
6876
7246
  useEffectCallback(() => {
6877
7247
  var _a2, _b2, _c2, _d2;
6878
7248
  if (!isRenderAppInstantSearch)
6879
7249
  return;
6880
- const searchParams2 = new URLSearchParams(document.location.search);
6881
- setKeyword((searchParams2 == null ? void 0 : searchParams2.get(queryKeyword)) || "");
7250
+ initStates();
6882
7251
  handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
6883
7252
  if (typeof window !== "undefined") {
6884
7253
  if (layoutType === "default") {
@@ -6901,13 +7270,9 @@ const SearchResultWidget = (props) => {
6901
7270
  triggerRenderInstantSearchResult("");
6902
7271
  setKeyword(valueRenderInstantSearchResult);
6903
7272
  }, [valueRenderInstantSearchResult]);
6904
- useEffectCallback(() => {
6905
- if (isFirstRender || isLoadingSetting)
6906
- return;
6907
- const INSTANT_SEARCH_SETTING = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
6908
- if (INSTANT_SEARCH_SETTING)
6909
- handleInitStates(INSTANT_SEARCH_SETTING);
6910
- }, [debouncedKeyword, isFirstRender, isLoadingSetting]);
7273
+ useEffectOnChange(() => {
7274
+ initStates();
7275
+ }, [debouncedKeyword]);
6911
7276
  const filterHorizontalSkeletonComponent = /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter-horizontal-skeleton", children: [1, 2, 3, 4, 5, 6, 7].map((index) => /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.Item, { width: "106px", height: "42px", rounded: "md", color: "lighten" }, index)) });
6912
7277
  const tabSkeleton = layoutType === "default" ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-tab-list sledge-instant-search__result-tab-list-skeleton", children: [1, 2, 3, 4, 5].map((index) => /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.Item, { width: "122px", height: "28px", rounded: "md", color: "lighten" }, index)) }) : null;
6913
7278
  const filterHorizontalSkeleton = ((_m = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _m.enable_on_search) && ((_n = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _n.layout) === "horizontal" && !hideFilterWhenOneValue ? filterHorizontalSkeletonComponent : null;
@@ -7271,16 +7636,32 @@ const SearchResultWidget = (props) => {
7271
7636
  allowedFilterSlider,
7272
7637
  hierarchicalFacetAliases,
7273
7638
  usePublishedFilter,
7274
- showOutOfStock
7639
+ showOutOfStock,
7640
+ handleSetInitStates,
7641
+ querySortBy,
7642
+ queryPage,
7643
+ queryLimit,
7644
+ valueFilterPriceChange,
7645
+ setValueFilterPriceChange,
7646
+ valueFilterOnSaleChange,
7647
+ setValueFilterOnSaleChange,
7648
+ valueFilterSliderOthers,
7649
+ setValueFilterSliderOthers,
7650
+ tabs,
7651
+ initStatesFirstTime,
7652
+ setInitStatesFirstTime,
7653
+ allowedTabs,
7654
+ setAllowedTabs
7275
7655
  })
7276
7656
  ] });
7277
7657
  };
7278
- const ResultProduct = (props) => {
7279
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D;
7658
+ const ResultProduct = React__default.memo((props) => {
7659
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
7280
7660
  const {
7281
7661
  layoutType,
7282
7662
  keyword,
7283
7663
  clickedTabIndexId,
7664
+ clickedTabIndexType,
7284
7665
  isLoadingSetting,
7285
7666
  allowedSorts,
7286
7667
  allowedFilter,
@@ -7336,11 +7717,24 @@ const ResultProduct = (props) => {
7336
7717
  attributesToRetrieve,
7337
7718
  allowedFilterSlider,
7338
7719
  hierarchicalFacetAliases,
7339
- showOutOfStock
7720
+ showOutOfStock,
7721
+ handleSetInitStates,
7722
+ querySortBy = "",
7723
+ queryPage = "",
7724
+ queryLimit = "",
7725
+ valueFilterPriceChange,
7726
+ setValueFilterPriceChange,
7727
+ valueFilterOnSaleChange,
7728
+ setValueFilterOnSaleChange,
7729
+ valueFilterSliderOthers,
7730
+ setValueFilterSliderOthers,
7731
+ usePublishedFilter,
7732
+ tabs,
7733
+ initStatesFirstTime,
7734
+ setInitStatesFirstTime,
7735
+ allowedTabs,
7736
+ setAllowedTabs
7340
7737
  } = props || {};
7341
- const querySortBy = (query == null ? void 0 : query.sortBy) ? query.sortBy : DEFAULT_QUERY_PARAM.SORT_BY;
7342
- const queryPage = (query == null ? void 0 : query.page) ? query.page : DEFAULT_QUERY_PARAM.PAGE;
7343
- const queryLimit = (query == null ? void 0 : query.limit) ? query.limit : DEFAULT_QUERY_PARAM.LIMIT;
7344
7738
  const { collectionId, collectionName } = params || {};
7345
7739
  const isLoadMore = ["load_more", "infinite_scroll"].includes((_a = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _a.pagination_type);
7346
7740
  const [isLoadingProduct, setIsLoadingProduct] = React__default.useState(!propsData);
@@ -7348,11 +7742,9 @@ const ResultProduct = (props) => {
7348
7742
  const [clickedSortId, setClickedSortId] = React__default.useState(defaultSort || "");
7349
7743
  const [clickedLimitId, setClickedLimitId] = React__default.useState(Number((searchParams == null ? void 0 : searchParams.get(queryLimit)) || defaultLimit || DEFAULT_LIMIT_VALUE[0]));
7350
7744
  const [clickedOpenFilters, setClickedOpenFilters] = React__default.useState(
7351
- (allowedFilter == null ? void 0 : allowedFilter.length) ? allowedFilter.map((props2, index) => {
7352
- const { value, settings: settings2 } = props2;
7353
- const { collapse } = settings2 || {};
7354
- return collapse ? null : `${value}-${index}`;
7355
- }).filter((item) => item) : []
7745
+ keyOpenFilters({
7746
+ items: allowedFilter
7747
+ })
7356
7748
  );
7357
7749
  const [triggerClickedFacets, setTriggerClickedFacets] = React__default.useState(false);
7358
7750
  const [searchResult, setSearchResult] = React__default.useState(((_d = (_c = (_b = propsData == null ? void 0 : propsData.result) == null ? void 0 : _b.results) == null ? void 0 : _c[0]) == null ? void 0 : _d.hits) || []);
@@ -7360,9 +7752,6 @@ const ResultProduct = (props) => {
7360
7752
  const [currentPage, setCurrentPage] = React__default.useState(Number(searchParams == null ? void 0 : searchParams.get(queryPage)) && !isLoadMore ? Number(searchParams == null ? void 0 : searchParams.get(queryPage)) : 1);
7361
7753
  const [totalPage, setTotalPage] = React__default.useState(0);
7362
7754
  const [totalSearchResult, setTotalSearchResult] = React__default.useState(((_g = (_f = (_e = propsData == null ? void 0 : propsData.result) == null ? void 0 : _e.results) == null ? void 0 : _f[0]) == null ? void 0 : _g.totalHits) || 0);
7363
- const [valueFilterPriceChange, setValueFilterPriceChange] = React__default.useState([]);
7364
- const [valueFilterOnSaleChange, setValueFilterOnSaleChange] = React__default.useState([]);
7365
- const [valueFilterSliderOthers, setValueFilterSliderOthers] = React__default.useState({});
7366
7755
  const [handleSearchResultFirstTime, setHandleSearchResultFirstTime] = React__default.useState(true);
7367
7756
  const [searchFacetDistribution, setSearchFacetDistribution] = React__default.useState({});
7368
7757
  const [isLoadingButtonLoadMore, setIsLoadingButtonLoadMore] = React__default.useState(false);
@@ -7385,7 +7774,6 @@ const ResultProduct = (props) => {
7385
7774
  hidden_ids: hierarchical_collections_hidden_ids,
7386
7775
  structure: hierarchical_collections_structure
7387
7776
  } = hierarchicalCollectionsSettings || {};
7388
- const { money_format } = generalDataSettings || {};
7389
7777
  const { button_load_more, button_loading, mobile_sort_placeholder } = (generalDataSettings == null ? void 0 : generalDataSettings.languages) || {};
7390
7778
  const summaryTextGenerator = (totalResult) => {
7391
7779
  var _a2;
@@ -7440,12 +7828,12 @@ const ResultProduct = (props) => {
7440
7828
  ...filter_title_font_weight && { fontWeight: filter_title_font_weight },
7441
7829
  ...filter_title_text_transform && { textTransform: filter_title_text_transform }
7442
7830
  };
7443
- const filter_option_style = {
7831
+ ({
7444
7832
  ...filter_option_color && { color: filter_option_color },
7445
7833
  ...filter_option_font_size && { fontSize: filter_option_font_size },
7446
7834
  ...filter_option_font_weight && { fontWeight: filter_option_font_weight },
7447
7835
  ...filter_option_text_transform && { textTransform: filter_option_text_transform }
7448
- };
7836
+ });
7449
7837
  ({
7450
7838
  ...filter_button_text_color && { color: filter_button_text_color },
7451
7839
  ...filter_button_border_color && { borderColor: filter_button_border_color },
@@ -7481,98 +7869,140 @@ const ResultProduct = (props) => {
7481
7869
  }).toString();
7482
7870
  window.history.pushState(null, "", `${document.location.pathname}${(newQueryString == null ? void 0 : newQueryString.length) ? `?${newQueryString}` : ""}`);
7483
7871
  };
7484
- const handleChangeSort = (value) => {
7872
+ const handleChangeSort = React__default.useCallback((value) => {
7485
7873
  const searchParams2 = new URLSearchParams(document.location.search);
7486
7874
  searchParams2.set(querySortBy, value);
7487
7875
  setClickedSortId(value);
7488
7876
  window.history.pushState(null, "", `${document.location.pathname}?${searchParams2.toString()}`);
7489
- };
7490
- const handleChangeLimit = (value) => {
7877
+ }, []);
7878
+ const handleChangeLimit = React__default.useCallback((value) => {
7491
7879
  const searchParams2 = new URLSearchParams(document.location.search);
7492
7880
  searchParams2.set(queryLimit, String(value));
7493
7881
  setClickedLimitId(Number(value));
7494
7882
  localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_KEY.LIMIT_PRODUCT, value);
7495
7883
  window.history.pushState(null, "", `${document.location.pathname}?${searchParams2.toString()}`);
7496
- };
7497
- const handleOpenFilterVertical = (id) => {
7498
- let valueClickedOpenFilters = clickedOpenFilters;
7499
- if (valueClickedOpenFilters.includes(id)) {
7500
- const findIndex = valueClickedOpenFilters.indexOf(id);
7501
- if (findIndex > -1)
7502
- valueClickedOpenFilters.splice(findIndex, 1);
7503
- } else {
7504
- valueClickedOpenFilters.push(id);
7505
- }
7506
- setClickedOpenFilters(valueClickedOpenFilters);
7507
- setTimeout(() => {
7508
- setSeparatedFilterItem == null ? void 0 : setSeparatedFilterItem((old) => {
7509
- const fixState = {
7510
- ...old,
7511
- [id]: null
7512
- };
7513
- return fixState;
7514
- });
7515
- }, 100);
7516
- };
7517
- const handleFilterReset = () => {
7884
+ }, []);
7885
+ const handleOpenFilterVertical = React__default.useCallback(
7886
+ (id) => {
7887
+ let valueClickedOpenFilters = clickedOpenFilters;
7888
+ if (valueClickedOpenFilters.includes(id)) {
7889
+ const findIndex = valueClickedOpenFilters.indexOf(id);
7890
+ if (findIndex > -1)
7891
+ valueClickedOpenFilters.splice(findIndex, 1);
7892
+ } else {
7893
+ valueClickedOpenFilters.push(id);
7894
+ }
7895
+ setClickedOpenFilters(valueClickedOpenFilters);
7896
+ setTimeout(() => {
7897
+ setSeparatedFilterItem == null ? void 0 : setSeparatedFilterItem((old) => {
7898
+ const fixState = {
7899
+ ...old,
7900
+ [id]: null
7901
+ };
7902
+ return fixState;
7903
+ });
7904
+ }, 100);
7905
+ },
7906
+ [clickedOpenFilters]
7907
+ );
7908
+ const handleFilterReset = React__default.useCallback(() => {
7518
7909
  setClickedFacets == null ? void 0 : setClickedFacets({});
7519
7910
  setTriggerClickedFacets(!triggerClickedFacets);
7520
7911
  handleQueryStringFilter({});
7521
- setValueFilterPriceChange([]);
7522
- setValueFilterOnSaleChange([]);
7523
- setValueFilterSliderOthers({});
7524
- };
7525
- const handleFilterChange = ({ parentId, value, force = false }) => {
7526
- var _a2;
7527
- let facets2 = [value];
7528
- let isRange = allowedFilterSlider == null ? void 0 : allowedFilterSlider.includes(parentId);
7529
- let isHierarchical = hierarchicalFacetAliases == null ? void 0 : hierarchicalFacetAliases.includes(parentId);
7530
- if (clickedFacets) {
7531
- if (force) {
7532
- facets2 = [value];
7533
- } else {
7534
- if ((_a2 = clickedFacets[parentId]) == null ? void 0 : _a2.includes(value)) {
7535
- facets2 = clickedFacets[parentId].filter((facet) => facet !== value);
7536
- if (isHierarchical)
7537
- facets2 = facets2.filter((facet) => !facet.startsWith(value));
7912
+ setValueFilterPriceChange == null ? void 0 : setValueFilterPriceChange([]);
7913
+ setValueFilterOnSaleChange == null ? void 0 : setValueFilterOnSaleChange([]);
7914
+ setValueFilterSliderOthers == null ? void 0 : setValueFilterSliderOthers({});
7915
+ }, [triggerClickedFacets]);
7916
+ const handleFilterChange = React__default.useCallback(
7917
+ ({ parentId, value, force = false }) => {
7918
+ var _a2;
7919
+ let facets2 = [value];
7920
+ let isRange = allowedFilterSlider == null ? void 0 : allowedFilterSlider.includes(parentId);
7921
+ let isHierarchical = hierarchicalFacetAliases == null ? void 0 : hierarchicalFacetAliases.includes(parentId);
7922
+ if (clickedFacets) {
7923
+ if (force) {
7924
+ facets2 = [value];
7538
7925
  } else {
7539
- if (isRange) {
7540
- if (clickedFacets[parentId], clickedFacets[parentId] === value) {
7541
- facets2 = [];
7542
- if (parentId === "variants.price") {
7543
- setValueFilterPriceChange([]);
7544
- } else if (parentId === "variants.sale_percent") {
7545
- setValueFilterOnSaleChange([]);
7926
+ if ((_a2 = clickedFacets[parentId]) == null ? void 0 : _a2.includes(value)) {
7927
+ facets2 = clickedFacets[parentId].filter((facet) => facet !== value);
7928
+ if (isHierarchical)
7929
+ facets2 = facets2.filter((facet) => !facet.startsWith(value));
7930
+ } else {
7931
+ if (isRange) {
7932
+ if (clickedFacets[parentId], clickedFacets[parentId] === value) {
7933
+ facets2 = [];
7934
+ if (parentId === "variants.price") {
7935
+ setValueFilterPriceChange == null ? void 0 : setValueFilterPriceChange([]);
7936
+ } else if (parentId === "variants.sale_percent") {
7937
+ setValueFilterOnSaleChange == null ? void 0 : setValueFilterOnSaleChange([]);
7938
+ } else {
7939
+ setValueFilterSliderOthers == null ? void 0 : setValueFilterSliderOthers((prevState) => ({ ...prevState, [parentId]: [] }));
7940
+ }
7546
7941
  } else {
7547
- setValueFilterSliderOthers((prevState) => ({ ...prevState, [parentId]: [] }));
7942
+ facets2 = (value == null ? void 0 : value.length) === 1 ? [...value, ...value] : value;
7548
7943
  }
7549
7944
  } else {
7550
- facets2 = (value == null ? void 0 : value.length) === 1 ? [...value, ...value] : value;
7945
+ facets2 = clickedFacets[parentId] ? [...clickedFacets[parentId], value] : [value];
7551
7946
  }
7552
- } else {
7553
- facets2 = clickedFacets[parentId] ? [...clickedFacets[parentId], value] : [value];
7554
7947
  }
7555
7948
  }
7556
7949
  }
7557
- }
7558
- let valueClickedFacets = {
7559
- ...clickedFacets,
7560
- ...{
7561
- [parentId]: facets2
7562
- }
7563
- };
7564
- let handleQueryStringFilterProp = valueClickedFacets;
7565
- if (Object.hasOwn(handleQueryStringFilterProp, "variants.inventory_quantity"))
7566
- handleQueryStringFilterProp == null ? true : delete handleQueryStringFilterProp["variants.inventory_quantity"];
7567
- handleQueryStringFilter(handleQueryStringFilterProp);
7568
- setClickedFacets == null ? void 0 : setClickedFacets(valueClickedFacets);
7569
- setTriggerClickedFacets(!triggerClickedFacets);
7570
- };
7950
+ let valueClickedFacets = {
7951
+ ...clickedFacets,
7952
+ ...{
7953
+ [parentId]: facets2
7954
+ }
7955
+ };
7956
+ let handleQueryStringFilterProp = valueClickedFacets;
7957
+ if (Object.hasOwn(handleQueryStringFilterProp, "variants.inventory_quantity"))
7958
+ handleQueryStringFilterProp == null ? true : delete handleQueryStringFilterProp["variants.inventory_quantity"];
7959
+ handleQueryStringFilter(handleQueryStringFilterProp);
7960
+ setClickedFacets == null ? void 0 : setClickedFacets(valueClickedFacets);
7961
+ setTriggerClickedFacets(!triggerClickedFacets);
7962
+ },
7963
+ [allowedFilterSlider, hierarchicalFacetAliases, clickedFacets, triggerClickedFacets]
7964
+ );
7571
7965
  const handleSearchResultData = (props2) => {
7572
- const { isLoadMore: isLoadMore2 = false, result, onSearch } = props2;
7966
+ var _a2;
7967
+ const { isLoadMore: isLoadMore2 = false, result: resultProp, onSearch } = props2;
7968
+ const INSTANT_SEARCH_SETTING = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
7969
+ const { index_product } = INSTANT_SEARCH_SETTING || {};
7970
+ const isFirstTimeOrOnSearch = handleSearchResultFirstTime && initStatesFirstTime || onSearch;
7971
+ const resultData = layoutType === "default" && isFirstTimeOrOnSearch ? resultProp == null ? void 0 : resultProp.results : resultProp;
7972
+ const result = layoutType === "default" && isFirstTimeOrOnSearch ? (_a2 = resultData == null ? void 0 : resultData.find) == null ? void 0 : _a2.call(resultData, ({ indexUid }) => indexUid.includes(index_product)) : resultData;
7573
7973
  if (!result)
7574
7974
  return;
7575
7975
  const { hits, processingTimeMs, totalHits, totalPages, facetDistribution } = result;
7976
+ if (isFirstTimeOrOnSearch) {
7977
+ handleSetInitStates == null ? void 0 : handleSetInitStates({
7978
+ results: resultData,
7979
+ data: INSTANT_SEARCH_SETTING,
7980
+ callback: ({ valueAllowedFilter }) => {
7981
+ if (handleSearchResultFirstTime || onSearch && !(clickedOpenFilters == null ? void 0 : clickedOpenFilters.length)) {
7982
+ setClickedOpenFilters(
7983
+ keyOpenFilters({
7984
+ items: valueAllowedFilter
7985
+ })
7986
+ );
7987
+ }
7988
+ }
7989
+ });
7990
+ } else {
7991
+ if (allowedTabs == null ? void 0 : allowedTabs.length) {
7992
+ setAllowedTabs == null ? void 0 : setAllowedTabs(
7993
+ allowedTabs.map((tab) => {
7994
+ const { index, total } = tab;
7995
+ let isCurrentIndex = index.includes(clickedTabIndexId);
7996
+ return {
7997
+ ...tab,
7998
+ ...{
7999
+ total: isCurrentIndex ? totalHits : total
8000
+ }
8001
+ };
8002
+ })
8003
+ );
8004
+ }
8005
+ }
7576
8006
  if (onSearch && (keyword == null ? void 0 : keyword.length)) {
7577
8007
  searchTrigger({
7578
8008
  keyword,
@@ -7594,7 +8024,7 @@ const ResultProduct = (props) => {
7594
8024
  var _a2, _b2;
7595
8025
  if (!clickedTabIndexId)
7596
8026
  return;
7597
- const { isLoadMore: isLoadMore2 = false, isReplaceData = false } = props2;
8027
+ const { isLoadMore: isLoadMore2 = false, isReplaceData = false, onSearch } = props2;
7598
8028
  if (isReplaceData) {
7599
8029
  setCurrentPage(1);
7600
8030
  setSearchResult([]);
@@ -7605,56 +8035,48 @@ const ResultProduct = (props) => {
7605
8035
  }
7606
8036
  setIsLoading(isReplaceData ? true : !isLoadMore2);
7607
8037
  let response;
7608
- let filter = createQueryFilter({
7609
- facets,
7610
- facetsQueryStringObject: clickedFacets,
7611
- callback: (facetsQueryStringObject) => {
7612
- setClickedFacets == null ? void 0 : setClickedFacets(facetsQueryStringObject);
7613
- if (facetsQueryStringObject["variants.price"])
7614
- setValueFilterPriceChange(facetsQueryStringObject["variants.price"]);
7615
- if (facetsQueryStringObject["variants.sale_percent"])
7616
- setValueFilterOnSaleChange(facetsQueryStringObject["variants.sale_percent"]);
7617
- allowedFilterSlider == null ? void 0 : allowedFilterSlider.map((filterSlider) => {
7618
- if (!filterSlider || filterSlider && ["variants.price", "variants.sale_percent"].includes(filterSlider))
7619
- return;
7620
- if (facetsQueryStringObject[filterSlider])
7621
- setValueFilterSliderOthers((prevState) => ({ ...prevState, [filterSlider]: facetsQueryStringObject[filterSlider] }));
7622
- });
7623
- },
7624
- separator: hierarchical_separator,
7625
- separatorCollection: hierarchical_collections_separator,
7626
- additional: [
7627
- (hiddenTags == null ? void 0 : hiddenTags.length) ? `'tags' NOT IN ${JSON.stringify(hiddenTags)}` : null,
7628
- collectionId ? `'collections.id' = '${collectionId}'` : null,
7629
- !showOutOfStock ? `'availability' IN ${JSON.stringify(["in stock"])}` : null
7630
- ],
7631
- allowedFilterSlider,
7632
- hierarchicalFacetAliases,
7633
- defaultFilterItems
7634
- });
7635
8038
  let sort = soldProductAtEnd ? ["availability:asc"] : [];
7636
8039
  if (clickedSortId)
7637
8040
  sort.push(clickedSortId);
7638
- let body = {
7639
- q: keyword,
7640
- sort,
7641
- page: isReplaceData ? 1 : currentPage,
7642
- hitsPerPage: clickedLimitId,
7643
- facets,
7644
- attributesToRetrieve,
7645
- filter
7646
- };
7647
8041
  if (propsData && handleSearchResultFirstTime) {
7648
8042
  response = (_b2 = (_a2 = propsData == null ? void 0 : propsData.result) == null ? void 0 : _a2.results) == null ? void 0 : _b2[0];
7649
- setHandleSearchResultFirstTime(false);
7650
- } else
7651
- response = await search(clickedTabIndexId, body);
8043
+ } else {
8044
+ response = await handleSearchResponse({
8045
+ layoutType,
8046
+ clickedTabIndexId,
8047
+ clickedTabIndexType,
8048
+ keyword,
8049
+ sort,
8050
+ page: isReplaceData ? 1 : currentPage,
8051
+ limit: clickedLimitId,
8052
+ isUseMultiSearch: handleSearchResultFirstTime && initStatesFirstTime || onSearch,
8053
+ facets,
8054
+ attributesToRetrieve,
8055
+ clickedFacets,
8056
+ setClickedFacets,
8057
+ allowedFilterSlider,
8058
+ hierarchicalFacetAliases,
8059
+ defaultFilterItems,
8060
+ setValueFilterPriceChange,
8061
+ setValueFilterOnSaleChange,
8062
+ setValueFilterSliderOthers,
8063
+ collectionId,
8064
+ hiddenTags,
8065
+ showOutOfStock,
8066
+ hierarchicalProductTypeSettings,
8067
+ hierarchicalCollectionsSettings,
8068
+ usePublishedFilter,
8069
+ tabs
8070
+ });
8071
+ }
8072
+ setHandleSearchResultFirstTime(false);
8073
+ setInitStatesFirstTime == null ? void 0 : setInitStatesFirstTime(false);
7652
8074
  handleSearchResultData({
7653
8075
  result: response,
7654
8076
  ...props2
7655
8077
  });
7656
8078
  };
7657
- const handlePageChange = (page) => {
8079
+ const handlePageChange = React__default.useCallback((page) => {
7658
8080
  const searchParams2 = new URLSearchParams(document.location.search);
7659
8081
  searchParams2.set(queryPage, String(page));
7660
8082
  searchParams2.set(queryLimit, String(clickedLimitId));
@@ -7667,12 +8089,12 @@ const ResultProduct = (props) => {
7667
8089
  });
7668
8090
  }, 200);
7669
8091
  window.history.pushState(null, "", `${document.location.pathname}?${searchParams2.toString()}`);
7670
- };
7671
- const handleLoadMore = () => {
8092
+ }, []);
8093
+ const handleLoadMore = React__default.useCallback(() => {
7672
8094
  setCurrentPage(currentPage + 1);
7673
8095
  setIsLoadingButtonLoadMore(true);
7674
8096
  setIsReplaceWidgetList == null ? void 0 : setIsReplaceWidgetList(true);
7675
- };
8097
+ }, []);
7676
8098
  React__default.useEffect(() => {
7677
8099
  var _a2, _b2, _c2, _d2;
7678
8100
  if (typeof window !== "undefined") {
@@ -7750,93 +8172,6 @@ const ResultProduct = (props) => {
7750
8172
  if ((_a2 = filter == null ? void 0 : filter.settings) == null ? void 0 : _a2.keep_counter)
7751
8173
  keepCounterFacets.push(filter == null ? void 0 : filter.value);
7752
8174
  });
7753
- const facetBlockSelected = ({ label, name, value: valueProp, index }) => {
7754
- var _a2, _b2, _c2, _d2, _e2, _f2;
7755
- let value = valueProp;
7756
- if (name === HIERARCHICAL_FACET_OBJECT_ALIASES.collections) {
7757
- if ((_a2 = String(value)) == null ? void 0 : _a2.includes(hierarchical_collections_separator)) {
7758
- let arrValue = String(value).split(hierarchical_collections_separator);
7759
- value = (arrValue == null ? void 0 : arrValue.length) ? arrValue.map((item) => {
7760
- var _a3;
7761
- return ((_a3 = parseFacetObject({ facet: item })) == null ? void 0 : _a3.collection_title) || item;
7762
- }).join(hierarchical_collections_separator) : valueProp;
7763
- } else {
7764
- value = ((_b2 = parseFacetObject({ facet: valueProp })) == null ? void 0 : _b2.collection_title) || valueProp;
7765
- }
7766
- }
7767
- let valueText = (languageSettings == null ? void 0 : languageSettings[value]) || value;
7768
- let isRange = allowedFilterSlider == null ? void 0 : allowedFilterSlider.includes(name);
7769
- let getLabel = label;
7770
- let getSettings = {};
7771
- let isPriceValue = false;
7772
- let isSalePercent = false;
7773
- if (name === "variants.price") {
7774
- isPriceValue = true;
7775
- } else if (name === "variants.sale_percent") {
7776
- isSalePercent = true;
7777
- }
7778
- if (defaultFilterItems == null ? void 0 : defaultFilterItems.length) {
7779
- defaultFilterItems.map((defaultFilterItem) => {
7780
- const { label: defaultFilterItemLabel, items, settings: defaultFilterItemSettings } = defaultFilterItem;
7781
- if (items == null ? void 0 : items.includes(value)) {
7782
- getLabel = defaultFilterItemLabel;
7783
- getSettings = defaultFilterItemSettings;
7784
- }
7785
- });
7786
- }
7787
- (_c2 = getSettings == null ? void 0 : getSettings.delete_prefix) == null ? void 0 : _c2.map((deletePrefix) => {
7788
- if (String(valueText).startsWith(deletePrefix))
7789
- valueText = String(valueText).replace(deletePrefix, "");
7790
- });
7791
- if (isRange) {
7792
- const getValueRange = new Set(value).size === 1 ? [value[0]] : value;
7793
- valueText = (_d2 = getValueRange == null ? void 0 : getValueRange.map((valueItem) => isPriceValue ? shopifyFormatMoney(valueItem * 100, money_format) : isSalePercent ? `${valueItem}%` : valueItem)) == null ? void 0 : _d2.join(" - ");
7794
- } else {
7795
- valueText = (_e2 = String(valueText)) == null ? void 0 : _e2.replaceAll(hierarchical_collections_separator, " > ");
7796
- }
7797
- valueText = (_f2 = String(valueText)) == null ? void 0 : _f2.replaceAll("_", " ");
7798
- let aliases = {};
7799
- let aliasValue = "";
7800
- let aliasSeparator = "";
7801
- if (name === HIERARCHICAL_FACET_OBJECT_ALIASES.collections) {
7802
- aliases = settings.collectionAliases || {};
7803
- aliasSeparator = hierarchicalCollectionsSettings.separator;
7804
- }
7805
- if (name === HIERARCHICAL_FACET_OBJECT_ALIASES.product_type) {
7806
- aliases = settings.productTypeAliases || {};
7807
- aliasSeparator = hierarchicalProductTypeSettings.separator;
7808
- }
7809
- if ([HIERARCHICAL_FACET_OBJECT_ALIASES.collections, HIERARCHICAL_FACET_OBJECT_ALIASES.product_type].includes(name) && aliasSeparator) {
7810
- const splitedValues = value.split(aliasSeparator);
7811
- let newSplitedValues = [];
7812
- for (const splitedValue of splitedValues) {
7813
- newSplitedValues.push(aliases[splitedValue.trim()] || splitedValue);
7814
- }
7815
- aliasValue = newSplitedValues.join(" > ");
7816
- }
7817
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-filter-item-refine-selected", style: filter_option_style, children: [
7818
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "sledge-instant-search__result-filter-item-title-refine-list", dangerouslySetInnerHTML: { __html: `${getLabel}: ${aliasValue || valueText}` } }),
7819
- /* @__PURE__ */ jsxRuntimeExports.jsx(
7820
- "span",
7821
- {
7822
- className: "sledge-instant-search__result-filter-item-refine-title-clear",
7823
- onClick: () => handleFilterChange({
7824
- parentId: name,
7825
- value
7826
- }),
7827
- children: /* @__PURE__ */ jsxRuntimeExports.jsx("svg", { width: 12, height: 12, viewBox: "0 0 15 15", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
7828
- "path",
7829
- {
7830
- d: "M11.7816 4.03157C12.0062 3.80702 12.0062 3.44295 11.7816 3.2184C11.5571 2.99385 11.193 2.99385 10.9685 3.2184L7.50005 6.68682L4.03164 3.2184C3.80708 2.99385 3.44301 2.99385 3.21846 3.2184C2.99391 3.44295 2.99391 3.80702 3.21846 4.03157L6.68688 7.49999L3.21846 10.9684C2.99391 11.193 2.99391 11.557 3.21846 11.7816C3.44301 12.0061 3.80708 12.0061 4.03164 11.7816L7.50005 8.31316L10.9685 11.7816C11.193 12.0061 11.5571 12.0061 11.7816 11.7816C12.0062 11.557 12.0062 11.193 11.7816 10.9684L8.31322 7.49999L11.7816 4.03157Z",
7831
- fill: "currentColor",
7832
- fillRule: "evenodd",
7833
- clipRule: "evenodd"
7834
- }
7835
- ) })
7836
- }
7837
- )
7838
- ] }, index);
7839
- };
7840
8175
  const filterSettings = ({
7841
8176
  filter,
7842
8177
  scrollElementSelector
@@ -7944,12 +8279,24 @@ const ResultProduct = (props) => {
7944
8279
  ] }),
7945
8280
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter-item-refine-selected-flex", children: dataClickedFacets.map((itemClickedFacet, index) => {
7946
8281
  const { label, name, value } = itemClickedFacet;
7947
- return facetBlockSelected({
7948
- label,
7949
- name,
7950
- value,
7951
- index
7952
- });
8282
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
8283
+ FacetBlockSelected,
8284
+ {
8285
+ label,
8286
+ name,
8287
+ value,
8288
+ index,
8289
+ defaultFilterItems,
8290
+ generalDataSettings,
8291
+ languageSettings,
8292
+ hierarchicalCollectionsSettings,
8293
+ hierarchicalProductTypeSettings,
8294
+ displaySettings,
8295
+ settings,
8296
+ handleFilterChange,
8297
+ allowedFilterSlider
8298
+ }
8299
+ );
7953
8300
  }) })
7954
8301
  ] }) : null;
7955
8302
  const filterVerticalComponents = ({ filterLayoutType }) => allowedFilter == null ? void 0 : allowedFilter.map((filter, indexFilter) => /* @__PURE__ */ jsxRuntimeExports.jsx(
@@ -8026,29 +8373,29 @@ const ResultProduct = (props) => {
8026
8373
  ),
8027
8374
  dataClickedFacets.map((itemClickedFacet, index) => {
8028
8375
  const { label, name, value } = itemClickedFacet;
8029
- return facetBlockSelected({
8030
- label,
8031
- name,
8032
- value,
8033
- index
8034
- });
8376
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
8377
+ FacetBlockSelected,
8378
+ {
8379
+ label,
8380
+ name,
8381
+ value,
8382
+ index,
8383
+ defaultFilterItems,
8384
+ generalDataSettings,
8385
+ languageSettings,
8386
+ hierarchicalCollectionsSettings,
8387
+ hierarchicalProductTypeSettings,
8388
+ displaySettings,
8389
+ settings,
8390
+ handleFilterChange,
8391
+ allowedFilterSlider
8392
+ }
8393
+ );
8035
8394
  })
8036
8395
  ] }) : null
8037
8396
  ] }) }) }) : null;
8038
8397
  };
8039
- const searchInputFieldComponent = /* @__PURE__ */ jsxRuntimeExports.jsx(
8040
- SearchInputField,
8041
- {
8042
- type: "text",
8043
- icon: /* @__PURE__ */ jsxRuntimeExports.jsx(SearchIcon, { width: 18, height: 18, color: "#868686" }),
8044
- placeholder: (language_search_form_placeholder == null ? void 0 : language_search_form_placeholder.product) || "Search products...",
8045
- value: keyword,
8046
- onChange: ({ value }) => handleChangeKeyword == null ? void 0 : handleChangeKeyword(value),
8047
- onResetField: () => handleChangeKeyword == null ? void 0 : handleChangeKeyword(""),
8048
- className: "sledge-instant-search__result-data-keyword-form",
8049
- withClearField: true
8050
- }
8051
- );
8398
+ const searchInputFieldComponent = /* @__PURE__ */ jsxRuntimeExports.jsx(Search, { placeholder: language_search_form_placeholder == null ? void 0 : language_search_form_placeholder.product, value: keyword, handleChangeSearch: handleChangeKeyword });
8052
8399
  const renderFilterLayoutOnMobile = () => {
8053
8400
  var _a2;
8054
8401
  switch ((_a2 = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _a2.mobile_layout) {
@@ -8088,7 +8435,7 @@ const ResultProduct = (props) => {
8088
8435
  ),
8089
8436
  ((_q = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _q.enable_on_search) && ((_r = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _r.layout) === "horizontal" && (allowedFilter == null ? void 0 : allowedFilter.length) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__hide-element-lg-on-mobile", children: filterHorizontalBlockComponent({ deviceType: "desktop" }) }) : null,
8090
8437
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-wrapper", "data-filter-layout": (_s = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _s.layout, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
8091
- /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: ((_t = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _t.enable_on_search) && ((_u = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _u.layout) === "vertical" && !hideFilterWhenOneValue ? !(allowedFilter == null ? void 0 : allowedFilter.find(({ display }) => (display == null ? void 0 : display.toLowerCase()) === "tree")) && isFirstLoading || (allowedFilter == null ? void 0 : allowedFilter.find(({ display }) => (display == null ? void 0 : display.toLowerCase()) === "tree")) && isLoadingProduct ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter sledge__hide-element-lg-on-mobile", children: filterVerticalSkeleton }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter sledge__hide-element-lg-on-mobile", children: isLoadingSetting ? filterVerticalSkeleton : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
8438
+ /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: ((_t = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _t.enable_on_search) && ((_u = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _u.layout) === "vertical" && !hideFilterWhenOneValue ? !(allowedFilter == null ? void 0 : allowedFilter.find(({ display }) => (display == null ? void 0 : display.toLowerCase()) === "tree")) && isFirstLoading || (allowedFilter == null ? void 0 : allowedFilter.find(({ display }) => (display == null ? void 0 : display.toLowerCase()) === "tree")) && isLoadingProduct ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter sledge__hide-element-lg-on-mobile", children: filterVerticalSkeleton }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter sledge__hide-element-lg-on-mobile", children: isLoadingSetting || handleSearchResultFirstTime ? filterVerticalSkeleton : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
8092
8439
  filterVerticalSelected,
8093
8440
  filterVerticalComponents({
8094
8441
  filterLayoutType: "standard"
@@ -8114,64 +8461,24 @@ const ResultProduct = (props) => {
8114
8461
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__hide-element-lg-on-mobile sledge-instant-search__search-field-lg", children: searchInputFieldComponent }),
8115
8462
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__hide-element-mobile-on-lg sledge-instant-search__filter-horizontal-block-mobile", children: renderFilterLayoutOnMobile() }),
8116
8463
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-data-summary-item sledge-instant-search__result-data-summary-select-field", children: [
8117
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-data-summary-select-field-item", children: [
8118
- /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "sledge-instant-search__result-data-summary-select-field-sort", children: [
8119
- language_sort_by || "Sort by",
8120
- ":"
8121
- ] }),
8122
- allowedSorts && Boolean(allowedSorts == null ? void 0 : allowedSorts.length) && /* @__PURE__ */ jsxRuntimeExports.jsx(
8123
- SelectField,
8124
- {
8125
- align: "end",
8126
- prefixLabel: /* @__PURE__ */ jsxRuntimeExports.jsx("svg", { width: 18, height: 18, viewBox: "0 0 18 18", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
8127
- "path",
8128
- {
8129
- d: "M12.6296 4.34737C12.9144 4.34737 13.1497 4.55898 13.1869 4.83354L13.1921 4.90987L13.192 13.7599L15.2892 11.6543C15.5083 11.4341 15.8645 11.4333 16.0847 11.6525C16.2848 11.8517 16.3037 12.1641 16.1408 12.3847L16.0865 12.4479L13.0282 15.5204C13.0097 15.5386 12.991 15.555 12.9712 15.5701L13.0282 15.5204C13.0006 15.5482 12.9708 15.5724 12.9394 15.5932C12.9285 15.6 12.9171 15.607 12.9055 15.6135C12.8946 15.62 12.8837 15.6258 12.8725 15.6311C12.8615 15.6359 12.8504 15.6408 12.8391 15.6454C12.8247 15.6515 12.8099 15.6568 12.795 15.6613C12.7862 15.6637 12.7772 15.6662 12.7681 15.6685C12.7519 15.673 12.7357 15.6763 12.7193 15.6789C12.7116 15.6798 12.7036 15.6809 12.6955 15.6819C12.677 15.6844 12.6587 15.6857 12.6404 15.686C12.6368 15.6857 12.6332 15.6857 12.6296 15.6857L12.6186 15.686C12.6003 15.6857 12.582 15.6844 12.5637 15.6823L12.6296 15.6857C12.5989 15.6857 12.5689 15.6833 12.5396 15.6785C12.5233 15.6763 12.5071 15.673 12.4909 15.6689C12.4824 15.6663 12.4738 15.6639 12.4654 15.6614C12.4493 15.6569 12.4332 15.6512 12.4174 15.6448C12.4088 15.6408 12.4005 15.6372 12.3922 15.6333C12.3793 15.6278 12.3663 15.6211 12.3535 15.6139C12.342 15.6069 12.3307 15.6 12.3196 15.5926C12.3109 15.5875 12.3024 15.5815 12.294 15.5752L12.288 15.5701C12.2682 15.555 12.2494 15.5386 12.2318 15.5209L12.2308 15.5204L9.1725 12.4479C8.95334 12.2278 8.95416 11.8716 9.17434 11.6525C9.3745 11.4532 9.68704 11.4358 9.90687 11.5997L9.96983 11.6543L12.067 13.7614L12.0671 4.90987C12.0671 4.59921 12.3189 4.34737 12.6296 4.34737ZM5.18325 2.3122L5.19421 2.31189C5.21254 2.31224 5.23085 2.31348 5.24908 2.31562L5.18325 2.3122C5.21389 2.3122 5.24396 2.31465 5.27328 2.31937C5.28931 2.32156 5.3054 2.32487 5.32136 2.32889C5.33074 2.33164 5.3403 2.33433 5.34975 2.33725C5.36452 2.34142 5.37882 2.34648 5.39293 2.35213C5.40313 2.35668 5.41346 2.36119 5.42362 2.366C5.4357 2.37123 5.4476 2.37737 5.45931 2.38397C5.46933 2.39014 5.47926 2.39616 5.48898 2.40246C5.49898 2.40841 5.50899 2.41537 5.51882 2.42269L5.582 2.47746L8.64033 5.54996C8.85949 5.77013 8.85867 6.12629 8.63849 6.34545C8.43833 6.54469 8.12579 6.56212 7.90596 6.39822L7.843 6.34361L5.74525 4.23564L5.74575 13.088C5.74575 13.3987 5.49391 13.6505 5.18325 13.6505C4.89848 13.6505 4.66313 13.4389 4.62588 13.1644L4.62075 13.088L4.62025 4.23639L2.52367 6.34361C2.32443 6.54377 2.01197 6.56265 1.79139 6.39977L1.72817 6.34545C1.52801 6.14621 1.50914 5.83376 1.67202 5.61317L1.72633 5.54996L4.78467 2.47746L4.81779 2.44709C4.82557 2.44043 4.83353 2.43399 4.84167 2.42776L4.78467 2.47746C4.81226 2.44974 4.84202 2.42549 4.87341 2.40473C4.88436 2.39791 4.89574 2.39094 4.90738 2.38438C4.91819 2.37787 4.92917 2.37215 4.9403 2.36682C4.95128 2.36196 4.96242 2.35706 4.97375 2.35251C4.98814 2.34636 5.00289 2.34115 5.0178 2.33657C5.02687 2.33414 5.03616 2.33154 5.04555 2.32918C5.06066 2.32503 5.07593 2.32186 5.09129 2.31932C5.10053 2.31817 5.10959 2.31691 5.11871 2.31586C5.13607 2.31348 5.15388 2.31227 5.17171 2.3119C5.17564 2.31224 5.17944 2.3122 5.18325 2.3122Z",
8130
- fill: "black"
8131
- }
8132
- ) }),
8133
- options: allowedSorts.map((item) => {
8134
- const { label, value } = item;
8135
- return {
8136
- label,
8137
- value
8138
- };
8139
- }),
8140
- value: clickedSortId,
8141
- onChange: ({ value }) => handleChangeSort(value),
8142
- ...!mobileShowSelectedSort ? {
8143
- overridePlaceholderOnMobile: mobile_sort_placeholder || "Sort"
8144
- } : {}
8145
- }
8146
- )
8147
- ] }),
8148
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-data-summary-select-field-item", children: [
8149
- /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { children: [
8150
- language_limit || "Limit",
8151
- ":"
8152
- ] }),
8153
- ((_x = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _x.allowed_limit) && Boolean((_z = (_y = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _y.allowed_limit) == null ? void 0 : _z.length) && /* @__PURE__ */ jsxRuntimeExports.jsx(
8154
- SelectField,
8155
- {
8156
- align: "end",
8157
- options: displaySettings.search.allowed_limit.map((item) => {
8158
- return {
8159
- label: item,
8160
- value: item
8161
- };
8162
- }),
8163
- value: clickedLimitId,
8164
- onChange: ({ value }) => handleChangeLimit(value)
8165
- }
8166
- )
8167
- ] })
8464
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-summary-select-field-item", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
8465
+ Sort,
8466
+ {
8467
+ label: language_sort_by,
8468
+ options: allowedSorts,
8469
+ clickedOption: clickedSortId,
8470
+ handleChangeOption: handleChangeSort,
8471
+ overridePlaceholderOnMobile: !mobileShowSelectedSort ? mobile_sort_placeholder || "Sort" : null
8472
+ }
8473
+ ) }),
8474
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-summary-select-field-item", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Limit, { label: language_limit, options: (_x = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _x.allowed_limit, clickedOption: clickedLimitId, handleChangeOption: handleChangeLimit }) })
8168
8475
  ] })
8169
8476
  ] }),
8170
8477
  isLoading ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
8171
8478
  productGridSkeleton,
8172
8479
  (searchResult == null ? void 0 : searchResult.length) ? paginationComponent : null
8173
8480
  ] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
8174
- ((_A = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _A.layout) === "vertical" && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__hide-element-lg-on-mobile", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-summary sledge-instant-search__result-data-summary-filter-vertical", children: summaryText }) }),
8481
+ ((_y = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _y.layout) === "vertical" && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__hide-element-lg-on-mobile", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-summary sledge-instant-search__result-data-summary-filter-vertical", children: summaryText }) }),
8175
8482
  (searchResult == null ? void 0 : searchResult.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
8176
8483
  /* @__PURE__ */ jsxRuntimeExports.jsx(
8177
8484
  ProductGrid,
@@ -8186,9 +8493,9 @@ const ResultProduct = (props) => {
8186
8493
  };
8187
8494
  }),
8188
8495
  setting: {
8189
- show_vendor: (_B = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _B.show_vendor,
8190
- show_sku: (_C = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _C.show_sku,
8191
- show_price: (_D = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _D.show_price,
8496
+ show_vendor: (_z = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _z.show_vendor,
8497
+ show_sku: (_A = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _A.show_sku,
8498
+ show_price: (_B = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _B.show_price,
8192
8499
  language_button_add_to_cart: language_add_to_cart,
8193
8500
  language_button_out_of_stock: languageSettings && languageSettings["out of stock"] ? languageSettings["out of stock"] : ""
8194
8501
  },
@@ -8209,9 +8516,10 @@ const ResultProduct = (props) => {
8209
8516
  ] })
8210
8517
  ] }) })
8211
8518
  ] });
8212
- };
8213
- const ResultCategory = (props) => {
8519
+ });
8520
+ const ResultCategory = React__default.memo((props) => {
8214
8521
  const {
8522
+ layoutType,
8215
8523
  keyword,
8216
8524
  debouncedKeyword,
8217
8525
  clickedTabIndexId,
@@ -8232,9 +8540,28 @@ const ResultCategory = (props) => {
8232
8540
  isReplaceWidgetList,
8233
8541
  setIsReplaceWidgetList,
8234
8542
  handleChangeKeyword,
8235
- usePublishedFilter
8543
+ usePublishedFilter,
8544
+ handleSetInitStates,
8545
+ facets,
8546
+ params,
8547
+ clickedFacets,
8548
+ setClickedFacets,
8549
+ allowedFilterSlider,
8550
+ hierarchicalProductTypeSettings,
8551
+ hierarchicalCollectionsSettings,
8552
+ hiddenTags,
8553
+ showOutOfStock,
8554
+ hierarchicalFacetAliases,
8555
+ defaultFilterItems,
8556
+ setValueFilterPriceChange,
8557
+ setValueFilterOnSaleChange,
8558
+ setValueFilterSliderOthers,
8559
+ tabs,
8560
+ initStatesFirstTime,
8561
+ setInitStatesFirstTime,
8562
+ parentPreviousState
8236
8563
  } = props || {};
8237
- const isTypeCategoryHasPublished = Boolean(usePublishedFilter && clickedTabIndexType && ["collection", "page", "article"].includes(clickedTabIndexType));
8564
+ const { collectionId, collectionName } = params || {};
8238
8565
  const [isFirstLoading, setIsFirstLoading] = React__default.useState(true);
8239
8566
  const [isLoading, setIsLoading] = React__default.useState(true);
8240
8567
  const [searchResult, setSearchResult] = React__default.useState([]);
@@ -8272,9 +8599,22 @@ const ResultCategory = (props) => {
8272
8599
  getSummaryText = getSummaryText.replaceAll(OBJECT_DATA_STRING_KEY.TOTAL_RESULT, totalResult);
8273
8600
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-summary-item", children: ((_a = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _a.show_total_products) ? /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "sledge-instant-search__result-data-summary-text", children: isSummaryTextFromLanguage ? getSummaryText : defaultSummaryText }) : null });
8274
8601
  };
8275
- const handleSearchResultData = (result) => {
8602
+ const handleSearchResultData = (props2) => {
8603
+ var _a;
8604
+ const { isReplaceData = false, result: resultProp, onSearch } = props2;
8605
+ const INSTANT_SEARCH_SETTING = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
8606
+ const handleSearchResultFirstTime = isFirstLoading;
8607
+ const isFirstTimeOrOnSearch = handleSearchResultFirstTime && initStatesFirstTime || onSearch;
8608
+ const resultData = isFirstTimeOrOnSearch ? resultProp == null ? void 0 : resultProp.results : resultProp;
8609
+ const result = isFirstTimeOrOnSearch ? (_a = resultData == null ? void 0 : resultData.find) == null ? void 0 : _a.call(resultData, ({ indexUid }) => indexUid.includes(clickedTabIndexId)) : resultData;
8276
8610
  if (!result)
8277
8611
  return;
8612
+ if (isFirstTimeOrOnSearch) {
8613
+ handleSetInitStates == null ? void 0 : handleSetInitStates({
8614
+ results: resultData,
8615
+ data: INSTANT_SEARCH_SETTING
8616
+ });
8617
+ }
8278
8618
  const { hits, processingTimeMs, totalHits, totalPages } = result;
8279
8619
  setIsFirstLoading(false);
8280
8620
  setIsLoading(false);
@@ -8285,26 +8625,44 @@ const ResultCategory = (props) => {
8285
8625
  setTotalSearchResult(totalHits || 0);
8286
8626
  setSummaryText(summaryTextGenerator(totalHits));
8287
8627
  };
8288
- const handleSearchResult = async (isReplaceData = false) => {
8628
+ const handleSearchResult = async (props2) => {
8629
+ const { isReplaceData = false, onSearch } = props2;
8630
+ const handleSearchResultFirstTime = isFirstLoading;
8289
8631
  if (!clickedTabIndexId)
8290
8632
  return;
8291
8633
  if (isReplaceData)
8292
8634
  setCurrentPage(1);
8293
- let filter = "";
8294
- if (isTypeCategoryHasPublished) {
8295
- filter = DEFAULT_QUERY_PUBLISHED_FILTER;
8296
- }
8297
8635
  setIsLoading(true);
8298
- let response;
8299
- let body = {
8300
- q: keyword,
8301
- sort: [],
8636
+ let response = await handleSearchResponse({
8637
+ layoutType,
8638
+ clickedTabIndexId,
8639
+ clickedTabIndexType,
8640
+ keyword,
8302
8641
  page: isReplaceData ? 1 : currentPage,
8303
- hitsPerPage: 12,
8304
- filter
8305
- };
8306
- response = await search(clickedTabIndexId, body);
8307
- handleSearchResultData(response);
8642
+ limit: 12,
8643
+ isUseMultiSearch: handleSearchResultFirstTime && initStatesFirstTime || onSearch,
8644
+ facets,
8645
+ clickedFacets,
8646
+ setClickedFacets,
8647
+ allowedFilterSlider,
8648
+ hierarchicalFacetAliases,
8649
+ defaultFilterItems,
8650
+ setValueFilterPriceChange,
8651
+ setValueFilterOnSaleChange,
8652
+ setValueFilterSliderOthers,
8653
+ collectionId,
8654
+ hiddenTags,
8655
+ showOutOfStock,
8656
+ hierarchicalProductTypeSettings,
8657
+ hierarchicalCollectionsSettings,
8658
+ usePublishedFilter,
8659
+ tabs
8660
+ });
8661
+ setInitStatesFirstTime == null ? void 0 : setInitStatesFirstTime(false);
8662
+ handleSearchResultData({
8663
+ result: response,
8664
+ ...props2
8665
+ });
8308
8666
  };
8309
8667
  const handlePageChange = (page) => {
8310
8668
  setCurrentPage(page);
@@ -8317,25 +8675,34 @@ const ResultCategory = (props) => {
8317
8675
  }, 200);
8318
8676
  };
8319
8677
  React__default.useEffect(() => {
8320
- handleSearchResult();
8321
- }, [debouncedKeyword]);
8678
+ let isKeywordChanged = Boolean(parentPreviousState && parentPreviousState.keyword !== keyword);
8679
+ if (isKeywordChanged) {
8680
+ const delayDebounceFn = setTimeout(() => {
8681
+ handleSearchResult({
8682
+ onSearch: true
8683
+ });
8684
+ }, 500);
8685
+ return () => clearTimeout(delayDebounceFn);
8686
+ } else {
8687
+ handleSearchResult({
8688
+ onSearch: false
8689
+ });
8690
+ }
8691
+ }, [keyword]);
8322
8692
  React__default.useEffect(() => {
8323
8693
  let isRefreshSearchResult = Boolean(previousState && (previousState == null ? void 0 : previousState.clickedTabIndexId) !== clickedTabIndexId);
8324
8694
  if (isReplaceWidgetList || isRefreshSearchResult) {
8325
- handleSearchResult(isRefreshSearchResult);
8695
+ handleSearchResult({
8696
+ isReplaceData: isRefreshSearchResult
8697
+ });
8326
8698
  }
8327
8699
  }, [isReplaceWidgetList, clickedTabIndexId]);
8328
8700
  const searchKeywordComponent = /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-keyword sledge-instant-search__result-data-keyword-category", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
8329
- SearchInputField,
8701
+ Search,
8330
8702
  {
8331
- type: "text",
8332
- icon: /* @__PURE__ */ jsxRuntimeExports.jsx(SearchIcon, { width: 18, height: 18, color: "#868686" }),
8333
8703
  placeholder: clickedTabIndexType && language_search_form_placeholder[clickedTabIndexType] ? language_search_form_placeholder[clickedTabIndexType] : `Search ${clickedTabIndexName ? clickedTabIndexName.toLowerCase() : ""}...`,
8334
8704
  value: keyword,
8335
- onChange: ({ value }) => handleChangeKeyword == null ? void 0 : handleChangeKeyword(value),
8336
- onResetField: () => handleChangeKeyword == null ? void 0 : handleChangeKeyword(""),
8337
- className: "sledge-instant-search__result-data-keyword-form",
8338
- withClearField: true
8705
+ handleChangeSearch: handleChangeKeyword
8339
8706
  }
8340
8707
  ) });
8341
8708
  const summaryTextSkeleton = /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-summary", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.Item, { width: "117px", height: "28px", color: "lighten", rounded: "md" }) });
@@ -8346,30 +8713,31 @@ const ResultCategory = (props) => {
8346
8713
  skeletonLoadingComponent
8347
8714
  ] });
8348
8715
  const ProvideElementLoading = () => /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
8349
- searchKeywordComponent,
8350
8716
  summaryTextSkeleton,
8351
8717
  skeletonLoadingComponent
8352
8718
  ] });
8353
8719
  const ProvideElement = (elementProps) => clickedTabIndexType === "collection" ? /* @__PURE__ */ jsxRuntimeExports.jsx(CollectionGrid, { cards: collectionCardsComponent, onAfterRenderCollection, ...elementProps }) : clickedTabIndexType === "page" ? /* @__PURE__ */ jsxRuntimeExports.jsx(PageGrid, { cards: pageCardsComponent, onAfterRenderPage, ...elementProps }) : clickedTabIndexType === "blog" ? /* @__PURE__ */ jsxRuntimeExports.jsx(BlogGrid, { cards: blogCardsComponent, onAfterRenderBlog, ...elementProps }) : clickedTabIndexType === "article" ? /* @__PURE__ */ jsxRuntimeExports.jsx(ArticleGrid, { cards: articleCardsComponent, onAfterRenderArticle, ...elementProps }) : null;
8354
- return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-wrapper", children: isFirstLoading ? /* @__PURE__ */ jsxRuntimeExports.jsx(ProvideElementFirstLoading, {}) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-category-wrapper", children: isLoading ? /* @__PURE__ */ jsxRuntimeExports.jsx(ProvideElementLoading, {}) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
8720
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-wrapper", children: isFirstLoading ? /* @__PURE__ */ jsxRuntimeExports.jsx(ProvideElementFirstLoading, {}) : /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-data-category-wrapper", children: [
8355
8721
  searchKeywordComponent,
8356
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-summary", children: summaryText }),
8357
- (searchResult == null ? void 0 : searchResult.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
8358
- /* @__PURE__ */ jsxRuntimeExports.jsx(ProvideElement, { data: searchResult, isComponentJsVersion: isJsVersion }),
8359
- /* @__PURE__ */ jsxRuntimeExports.jsx(
8360
- Pagination,
8361
- {
8362
- currentPage,
8363
- totalPage,
8364
- totalResult: totalSearchResult,
8365
- onChange: (page) => handlePageChange(page),
8366
- pageInfo: language_pagination_info
8367
- }
8368
- )
8369
- ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx(ResultEmpty, { ...props })
8370
- ] }) }) });
8371
- };
8372
- const ResultEmpty = (props) => {
8722
+ isLoading ? /* @__PURE__ */ jsxRuntimeExports.jsx(ProvideElementLoading, {}) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
8723
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-summary", children: summaryText }),
8724
+ (searchResult == null ? void 0 : searchResult.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
8725
+ /* @__PURE__ */ jsxRuntimeExports.jsx(ProvideElement, { data: searchResult, isComponentJsVersion: isJsVersion }),
8726
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
8727
+ Pagination,
8728
+ {
8729
+ currentPage,
8730
+ totalPage,
8731
+ totalResult: totalSearchResult,
8732
+ onChange: (page) => handlePageChange(page),
8733
+ pageInfo: language_pagination_info
8734
+ }
8735
+ )
8736
+ ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx(ResultEmpty, { ...props })
8737
+ ] })
8738
+ ] }) });
8739
+ });
8740
+ const ResultEmpty = React__default.memo((props) => {
8373
8741
  const { languageSettings } = props || {};
8374
8742
  const { title_no_result: language_title_no_result, text_no_result: language_text_no_result } = languageSettings || {};
8375
8743
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-empty", children: [
@@ -8382,7 +8750,7 @@ const ResultEmpty = (props) => {
8382
8750
  }
8383
8751
  )
8384
8752
  ] });
8385
- };
8753
+ });
8386
8754
  const SearchWidget = (props) => {
8387
8755
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
8388
8756
  const { isRenderApp, isJsVersion } = React__default.useContext(SledgeContext);