@nuskin/react-search-components 1.0.0-comx-3067.6 → 1.0.0-comx-3067.8

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.
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import React, { useState, useEffect, useRef, useId, useCallback } from 'react';
1
+ import React, { useState, useEffect, useId, useRef, useCallback, useMemo } from 'react';
2
2
  import styled6 from '@emotion/styled';
3
3
  import { nuskinTheme } from '@nuskin/foundation-theme';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
- import { createChatService, isCartActionDisabled, useSearchHistory, useSearchSuggestions, getVisibleSuggestions, isSuggestionDisabled, useSearchHistoryStore, useVoiceSearch } from '@nuskin/react-search-sdk';
5
+ import { createChatService, isCartActionDisabled, useSearchHistory, useSearchSuggestions, getVisibleSuggestions, trackChatEntryPoint, trackSearchType, SEARCH_GTM_SEARCH_TYPES, trackProductSearch, trackErrorPopup, isSuggestionDisabled, useSearchHistoryStore, useVoiceSearch } from '@nuskin/react-search-sdk';
6
6
  export { createSearchService } from '@nuskin/react-search-sdk';
7
7
  import { createPortal } from 'react-dom';
8
8
  import { ProductCarousel, PRODUCT_CAROUSEL_ERROR_CODES } from '@nuskin/react-product-components';
@@ -12000,6 +12000,7 @@ function SearchMessage({ sender, text: text4, ...props }) {
12000
12000
 
12001
12001
  // src/components/Icon/iconConstants.ts
12002
12002
  var ICON_TYPES = {
12003
+ ARROW_DOWN: "arrowDown",
12003
12004
  ARROW_LEFT: "arrowLeft",
12004
12005
  ARROW_RIGHT: "arrowRight",
12005
12006
  ARROW_UP: "arrowUp",
@@ -12045,6 +12046,7 @@ var ICON_COLOR_BY_TYPE = {
12045
12046
  [ICON_TYPES.STAR_GREY]: "#c9c9c9"
12046
12047
  };
12047
12048
  var TEMPORARY_GLYPH_BY_ICON_TYPE = {
12049
+ [ICON_TYPES.ARROW_DOWN]: "\u2193",
12048
12050
  [ICON_TYPES.ARROW_LEFT]: "\u2190",
12049
12051
  [ICON_TYPES.ARROW_RIGHT]: "\u2192",
12050
12052
  [ICON_TYPES.ARROW_UP]: "\u2191",
@@ -12669,7 +12671,7 @@ var SearchPanelRoot = styled6.section`
12669
12671
  ${({ $chatMode }) => $chatMode && `
12670
12672
  display: flex;
12671
12673
  flex-direction: column;
12672
- max-height: 805px;
12674
+ max-block-size: 92dvh;
12673
12675
  overflow: hidden;
12674
12676
  `}
12675
12677
  `;
@@ -13311,6 +13313,34 @@ var AIStatusCursor = styled6.span`
13311
13313
  }
13312
13314
  }
13313
13315
  `;
13316
+ var ChatScrollIndicator = styled6.button`
13317
+ align-self: center;
13318
+ appearance: none;
13319
+ background: ${colors6.hover};
13320
+ border: 0;
13321
+ border-radius: 50%;
13322
+ color: ${colors6.text};
13323
+ cursor: pointer;
13324
+ display: grid;
13325
+ place-items: center;
13326
+ block-size: 2rem;
13327
+ inline-size: 2rem;
13328
+ margin-block: 0.25rem 0.75rem;
13329
+ margin-inline: auto;
13330
+ padding: 0;
13331
+ position: sticky;
13332
+ inset-block-end: 0.75rem;
13333
+ z-index: 1;
13334
+
13335
+ &:hover {
13336
+ background: ${colors6.borderLight};
13337
+ }
13338
+
13339
+ &:focus-visible {
13340
+ outline: 2px solid ${colors6.text};
13341
+ outline-offset: 2px;
13342
+ }
13343
+ `;
13314
13344
  var SuggestionSectionHeading = styled6.div`
13315
13345
  padding: 12px 24px 8px;
13316
13346
  margin-bottom: 4px;
@@ -13457,7 +13487,7 @@ styled6.span`
13457
13487
  font-size: 0.8125rem;
13458
13488
  font-weight: 600;
13459
13489
  `;
13460
- var ScrollIndicator = styled6.button`
13490
+ styled6.button`
13461
13491
  align-items: center;
13462
13492
  align-self: center;
13463
13493
  appearance: none;
@@ -13587,7 +13617,7 @@ function stripPricingText(text4) {
13587
13617
  );
13588
13618
  }
13589
13619
  function toCarouselItem(product, index2, showPricing, history) {
13590
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
13620
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
13591
13621
  const slotKey = `ai-${(_b = (_a = product.id) != null ? _a : product.sku) != null ? _b : index2}-${index2}`;
13592
13622
  const productName = (_f = (_d = (_c = product.name) == null ? void 0 : _c.trim()) != null ? _d : product.sku) != null ? _f : `Product ${(_e = product.id) != null ? _e : index2}`;
13593
13623
  if (!productName) {
@@ -13602,12 +13632,13 @@ function toCarouselItem(product, index2, showPricing, history) {
13602
13632
  };
13603
13633
  }
13604
13634
  const href = (_i = product.url) != null ? _i : "#";
13605
- const imageUrl = (_j = product.imageUrl) != null ? _j : product.image_url;
13606
- const priceText = (_k = product.price) != null ? _k : product.pv != null ? `${product.pv} PV` : void 0;
13635
+ const routeHref = (_j = product.routeUrl) != null ? _j : product.sku ? `/product/${product.sku}` : href;
13636
+ const imageUrl = (_k = product.imageUrl) != null ? _k : product.image_url;
13637
+ const priceText = (_l = product.price) != null ? _l : product.pv != null ? `${product.pv} PV` : void 0;
13607
13638
  return {
13608
13639
  status: "ready",
13609
13640
  slotKey,
13610
- productId: String((_m = (_l = product.id) != null ? _l : product.sku) != null ? _m : index2),
13641
+ productId: String((_n = (_m = product.id) != null ? _m : product.sku) != null ? _n : index2),
13611
13642
  cardProps: {
13612
13643
  mode: "cta",
13613
13644
  title: productName,
@@ -13617,11 +13648,10 @@ function toCarouselItem(product, index2, showPricing, history) {
13617
13648
  price: showPricing ? priceText : void 0,
13618
13649
  addToCartLabel: "View Product",
13619
13650
  addToCartAriaLabel: `View ${productName}`,
13620
- onProductClick: ({ event } = {}) => {
13651
+ onProductClick: () => {
13621
13652
  if (href === "#") return;
13622
- event == null ? void 0 : event.preventDefault();
13623
13653
  if (history && typeof history.push === "function") {
13624
- history.push(href);
13654
+ history.push(routeHref);
13625
13655
  }
13626
13656
  }
13627
13657
  }
@@ -13634,14 +13664,6 @@ function SearchChatResult({
13634
13664
  productsAriaLabel = "AI recommended products"
13635
13665
  }) {
13636
13666
  var _a;
13637
- const carouselWrapperRef = useRef(null);
13638
- function scrollDown() {
13639
- var _a2;
13640
- (_a2 = carouselWrapperRef.current) == null ? void 0 : _a2.scrollIntoView({
13641
- behavior: "smooth",
13642
- block: "nearest"
13643
- });
13644
- }
13645
13667
  const products = (_a = result.products) != null ? _a : [];
13646
13668
  const carouselItems = products.map((p, i) => toCarouselItem(p, i, showPricing, history));
13647
13669
  const summaryText = showPricing ? result.aiResponseText : stripPricingText(result.aiResponseText);
@@ -13662,42 +13684,11 @@ function SearchChatResult({
13662
13684
  "data-testid": "chat-ai-response"
13663
13685
  }
13664
13686
  ),
13665
- carouselItems.length > 0 && /* @__PURE__ */ jsxs(ProductCarouselWrapper, { ref: carouselWrapperRef, "data-testid": "chat-product-carousel", children: [
13666
- /* @__PURE__ */ jsx(ProductCarousel, { items: carouselItems, ariaLabel: productsAriaLabel }),
13667
- /* @__PURE__ */ jsx(
13668
- ScrollIndicator,
13669
- {
13670
- type: "button",
13671
- "aria-label": "Scroll to products",
13672
- onClick: scrollDown,
13673
- "data-testid": "chat-scroll-indicator",
13674
- children: /* @__PURE__ */ jsxs(
13675
- "svg",
13676
- {
13677
- xmlns: "http://www.w3.org/2000/svg",
13678
- viewBox: "0 0 24 24",
13679
- fill: "none",
13680
- stroke: "currentColor",
13681
- strokeWidth: 2,
13682
- strokeLinecap: "round",
13683
- strokeLinejoin: "round",
13684
- width: 16,
13685
- height: 16,
13686
- "aria-hidden": true,
13687
- children: [
13688
- /* @__PURE__ */ jsx("line", { x1: 12, y1: 5, x2: 12, y2: 19 }),
13689
- /* @__PURE__ */ jsx("polyline", { points: "19 12 12 19 5 12" })
13690
- ]
13691
- }
13692
- )
13693
- }
13694
- )
13695
- ] })
13687
+ carouselItems.length > 0 && /* @__PURE__ */ jsx(ProductCarouselWrapper, { "data-testid": "chat-product-carousel", children: /* @__PURE__ */ jsx(ProductCarousel, { items: carouselItems, ariaLabel: productsAriaLabel }) })
13696
13688
  ] });
13697
13689
  }
13698
13690
 
13699
13691
  // src/components/SearchModal/SearchModalConstants.ts
13700
- var DEFAULT_AI_AUTO_TRIGGER_DELAY_MS = 4e3;
13701
13692
  var DEFAULT_AI_STATUS_LABELS = {
13702
13693
  analyzing: "Analyzing your question...",
13703
13694
  pulling: "Pulling up your analytics...",
@@ -13744,9 +13735,6 @@ function getUniqueRecentSearches(entries) {
13744
13735
  ) === idx
13745
13736
  );
13746
13737
  }
13747
- function getAITriggerDelayMs(delayMs) {
13748
- return typeof delayMs === "number" && delayMs >= 0 ? delayMs : DEFAULT_AI_AUTO_TRIGGER_DELAY_MS;
13749
- }
13750
13738
  function getProductId(rawId) {
13751
13739
  return typeof rawId === "string" || typeof rawId === "number" ? String(rawId) : JSON.stringify(rawId);
13752
13740
  }
@@ -13771,6 +13759,11 @@ function SearchModalChatContent({
13771
13759
  analyzingLabel,
13772
13760
  chatEndRef
13773
13761
  }) {
13762
+ const hasChatResults = aiChatHistory.length > 0;
13763
+ function scrollToBottom() {
13764
+ var _a;
13765
+ (_a = chatEndRef.current) == null ? void 0 : _a.scrollIntoView({ behavior: "smooth", block: "end" });
13766
+ }
13774
13767
  return /* @__PURE__ */ jsxs(Fragment, { children: [
13775
13768
  aiChatHistory.map((result, idx) => /* @__PURE__ */ jsx(
13776
13769
  "div",
@@ -13796,6 +13789,23 @@ function SearchModalChatContent({
13796
13789
  typedStatus || analyzingLabel,
13797
13790
  /* @__PURE__ */ jsx(AIStatusCursor, { "aria-hidden": "true" })
13798
13791
  ] }),
13792
+ hasChatResults && /* @__PURE__ */ jsx(
13793
+ ChatScrollIndicator,
13794
+ {
13795
+ type: "button",
13796
+ "aria-label": "Scroll to bottom",
13797
+ onClick: scrollToBottom,
13798
+ "data-testid": "chat-scroll-indicator",
13799
+ children: /* @__PURE__ */ jsx(
13800
+ Icon,
13801
+ {
13802
+ cursor: ICON_CURSORS.POINTER,
13803
+ size: ICON_SIZES.SMALL,
13804
+ type: ICON_TYPES.ARROW_DOWN
13805
+ }
13806
+ )
13807
+ }
13808
+ ),
13799
13809
  /* @__PURE__ */ jsx("div", { ref: chatEndRef })
13800
13810
  ] });
13801
13811
  }
@@ -13944,10 +13954,11 @@ function SearchModal({
13944
13954
  fallbackImageUrl = "",
13945
13955
  enableAIChat = false,
13946
13956
  aiChatConfig,
13957
+ gtmContext,
13947
13958
  showPricing = true,
13948
13959
  aiChatHeaderContent
13949
13960
  }) {
13950
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
13961
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
13951
13962
  const listboxId = useId();
13952
13963
  const footerRef = useRef(null);
13953
13964
  const suggestionRowRefs = useRef({});
@@ -13976,7 +13987,6 @@ function SearchModal({
13976
13987
  const [aiChatHistory, setAiChatHistory] = useState([]);
13977
13988
  const [pendingQuery, setPendingQuery] = useState("");
13978
13989
  const [aiLoading, setAiLoading] = useState(false);
13979
- const [isWaitingForAIFallback, setIsWaitingForAIFallback] = useState(false);
13980
13990
  const isInChatMode = aiChatHistory.length > 0 || pendingQuery !== "" || aiLoading;
13981
13991
  const [aiStatus, setAiStatus] = useState("");
13982
13992
  const [typedStatus, setTypedStatus] = useState("");
@@ -13988,11 +13998,34 @@ function SearchModal({
13988
13998
  aiChatConfigRef.current = aiChatConfig;
13989
13999
  const aiChatHeaderContentRef = useRef(aiChatHeaderContent);
13990
14000
  aiChatHeaderContentRef.current = aiChatHeaderContent;
14001
+ const gtmContextRef = useRef(gtmContext);
14002
+ gtmContextRef.current = gtmContext;
13991
14003
  const historyEntriesRef = useRef(historyEntries);
13992
14004
  historyEntriesRef.current = historyEntries;
13993
14005
  const chatEndRef = useRef(null);
13994
- const aiFallbackTimeoutRef = useRef(null);
13995
14006
  const aiRequestCounterRef = useRef(0);
14007
+ const [suggestionsRequestFailed, setSuggestionsRequestFailed] = useState(false);
14008
+ const suggestionAwareService = useMemo(
14009
+ () => ({
14010
+ ...service,
14011
+ async fetchSuggestions(searchTerm) {
14012
+ setSuggestionsRequestFailed(false);
14013
+ try {
14014
+ const response = await service.fetchSuggestions(searchTerm);
14015
+ setSuggestionsRequestFailed(false);
14016
+ return response;
14017
+ } catch (error) {
14018
+ setSuggestionsRequestFailed(true);
14019
+ throw error;
14020
+ }
14021
+ }
14022
+ }),
14023
+ [service]
14024
+ );
14025
+ const searchSuggestions = useSearchSuggestions({
14026
+ service: suggestionAwareService,
14027
+ enabled: isOpen && !isInChatMode
14028
+ });
13996
14029
  const {
13997
14030
  didYouMean,
13998
14031
  emptyFetched,
@@ -14002,12 +14035,16 @@ function SearchModal({
14002
14035
  query,
14003
14036
  suggestions,
14004
14037
  updateQuery
14005
- } = useSearchSuggestions({ service, enabled: isOpen && !isInChatMode });
14038
+ } = searchSuggestions;
14039
+ const suggestionFetchFailed = ((_a = searchSuggestions.suggestionFetchFailed) != null ? _a : false) || suggestionsRequestFailed;
14006
14040
  const [searchInputValue, setSearchInputValue] = useState(query);
14007
14041
  const searchInputValueRef = useRef(query);
14008
14042
  const voiceInputBaseValueRef = useRef(query);
14009
14043
  const setSearchInput = useCallback(
14010
- (value, updateVoiceBase = true) => {
14044
+ (value, updateVoiceBase = true, resetSuggestionFailure = true) => {
14045
+ if (resetSuggestionFailure) {
14046
+ setSuggestionsRequestFailed(false);
14047
+ }
14011
14048
  searchInputValueRef.current = value;
14012
14049
  if (updateVoiceBase) {
14013
14050
  voiceInputBaseValueRef.current = value;
@@ -14049,20 +14086,14 @@ function SearchModal({
14049
14086
  const hasDidYouMean = didYouMean.length > 0;
14050
14087
  const showDidYouMean = hasDidYouMean && !enableAIChat;
14051
14088
  const visibleSuggestions = enableAIChat ? suggestions : getVisibleSuggestions({ didYouMean, suggestions });
14052
- const visibleSuggestionsRef = useRef(visibleSuggestions);
14053
- visibleSuggestionsRef.current = visibleSuggestions;
14054
- const hasDidYouMeanRef = useRef(hasDidYouMean);
14055
- hasDidYouMeanRef.current = hasDidYouMean;
14056
- const loadingRef = useRef(loading);
14057
- loadingRef.current = loading;
14058
14089
  const safeUseVoiceSearch = useVoiceSearch;
14059
14090
  const voiceSearchRaw = safeUseVoiceSearch({
14060
14091
  onInterimResult: previewVoiceResult,
14061
14092
  onResult: appendVoiceResult
14062
14093
  });
14063
14094
  const voiceSearch = isVoiceSearchState(voiceSearchRaw) ? voiceSearchRaw : null;
14064
- const voiceListening = (_a = voiceSearch == null ? void 0 : voiceSearch.listening) != null ? _a : false;
14065
- const voiceSupported = (_b = voiceSearch == null ? void 0 : voiceSearch.supported) != null ? _b : false;
14095
+ const voiceListening = (_b = voiceSearch == null ? void 0 : voiceSearch.listening) != null ? _b : false;
14096
+ const voiceSupported = (_c = voiceSearch == null ? void 0 : voiceSearch.supported) != null ? _c : false;
14066
14097
  const startVoice = voiceSearch == null ? void 0 : voiceSearch.start;
14067
14098
  const stopVoice = voiceSearch == null ? void 0 : voiceSearch.stop;
14068
14099
  const toggleVoice = useCallback(() => {
@@ -14073,10 +14104,9 @@ function SearchModal({
14073
14104
  voiceInputBaseValueRef.current = searchInputValueRef.current.trimEnd();
14074
14105
  startVoice == null ? void 0 : startVoice();
14075
14106
  }, [startVoice, stopVoice, voiceListening]);
14076
- const showPricingFromHeader = ((_d = (_c = aiChatHeaderContentRef.current) == null ? void 0 : _c.configurations) == null ? void 0 : _d.enablepricingpvsv) !== "false";
14107
+ const showPricingFromHeader = ((_e = (_d = aiChatHeaderContentRef.current) == null ? void 0 : _d.configurations) == null ? void 0 : _e.enablepricingpvsv) !== "false";
14077
14108
  const resolvedShowPricing = aiChatHeaderContent ? showPricingFromHeader : showPricing;
14078
14109
  const aiStatusLabels = getAIStatusLabels(copy);
14079
- const aiAutoTriggerDelayMs = getAITriggerDelayMs(aiChatConfig == null ? void 0 : aiChatConfig.aiAutoTriggerDelayMs);
14080
14110
  function voiceSearchProps() {
14081
14111
  var _a2;
14082
14112
  if (!voiceSupported || !startVoice) return {};
@@ -14088,12 +14118,22 @@ function SearchModal({
14088
14118
  onVoiceInput: toggleVoice
14089
14119
  };
14090
14120
  }
14121
+ const buildGtmContext = useCallback(() => {
14122
+ var _a2;
14123
+ return (_a2 = gtmContextRef.current) != null ? _a2 : {};
14124
+ }, []);
14125
+ const chatEntryFiredRef = useRef(false);
14091
14126
  useEffect(() => {
14092
- if (isOpen) return;
14093
- if (aiFallbackTimeoutRef.current) {
14094
- clearTimeout(aiFallbackTimeoutRef.current);
14095
- aiFallbackTimeoutRef.current = null;
14127
+ if (!isOpen) {
14128
+ chatEntryFiredRef.current = false;
14129
+ return;
14096
14130
  }
14131
+ if (!enableAIChat || chatEntryFiredRef.current) return;
14132
+ chatEntryFiredRef.current = true;
14133
+ trackChatEntryPoint(buildGtmContext());
14134
+ }, [isOpen, enableAIChat, buildGtmContext]);
14135
+ useEffect(() => {
14136
+ if (isOpen) return;
14097
14137
  updateQuery("");
14098
14138
  setAiChatHistory([]);
14099
14139
  setPendingQuery("");
@@ -14150,43 +14190,19 @@ function SearchModal({
14150
14190
  document.body.style.overflow = "";
14151
14191
  };
14152
14192
  }, [isOpen, onClose]);
14153
- useEffect(() => {
14154
- if (aiFallbackTimeoutRef.current) {
14155
- clearTimeout(aiFallbackTimeoutRef.current);
14156
- aiFallbackTimeoutRef.current = null;
14157
- }
14158
- setIsWaitingForAIFallback(false);
14159
- if (!enableAIChat || !isOpen || isInChatMode || !hasQuery) return void 0;
14160
- const trimmedQuery = query.trim();
14161
- if (!trimmedQuery) return void 0;
14162
- const alreadyAnswered = historyEntriesRef.current.some(
14163
- (e) => e.isAI && e.query.toLowerCase() === trimmedQuery.toLowerCase()
14164
- );
14165
- if (alreadyAnswered) return void 0;
14166
- setIsWaitingForAIFallback(true);
14167
- aiFallbackTimeoutRef.current = setTimeout(() => {
14168
- aiFallbackTimeoutRef.current = null;
14169
- setIsWaitingForAIFallback(false);
14170
- if (!loadingRef.current && visibleSuggestionsRef.current.length > 0 && !hasDidYouMeanRef.current) {
14171
- return;
14172
- }
14173
- sendAIMessage(trimmedQuery);
14174
- }, aiAutoTriggerDelayMs);
14175
- return () => {
14176
- if (aiFallbackTimeoutRef.current) {
14177
- clearTimeout(aiFallbackTimeoutRef.current);
14178
- aiFallbackTimeoutRef.current = null;
14179
- }
14180
- setIsWaitingForAIFallback(false);
14181
- };
14182
- }, [enableAIChat, isOpen, isInChatMode, hasQuery, query]);
14183
14193
  const sendAIMessage = useCallback(
14184
14194
  (queryText) => {
14185
14195
  const config = aiChatConfigRef.current;
14186
14196
  if (!config || !queryText.trim()) return;
14187
- setSearchInput("");
14197
+ setSearchInput("", true, false);
14188
14198
  setPendingQuery(queryText.trim());
14189
14199
  setAiStatus(aiStatusLabels.analyzing);
14200
+ const trimmedQuery = queryText.trim();
14201
+ trackSearchType({
14202
+ ...buildGtmContext(),
14203
+ searchType: SEARCH_GTM_SEARCH_TYPES.AI_AGENT,
14204
+ searchResponse: trimmedQuery
14205
+ });
14190
14206
  const requestId = aiRequestCounterRef.current;
14191
14207
  const productBasePath = `/${config.market.toLowerCase()}/${config.language.toLowerCase()}/product`;
14192
14208
  const chatService = createChatService({
@@ -14242,14 +14258,24 @@ function SearchModal({
14242
14258
  const priorHistory = historyEntriesRef.current.filter((e) => e.isAI && e.aiResult != null).slice().reverse().map((e) => e.aiResult);
14243
14259
  setAiChatHistory([...priorHistory, newResult]);
14244
14260
  historyAddEntry({ query: queryText.trim(), isAI: true, aiResult: newResult });
14261
+ trackProductSearch({
14262
+ ...buildGtmContext(),
14263
+ searchType: SEARCH_GTM_SEARCH_TYPES.AI_AGENT,
14264
+ productResults: products.length,
14265
+ productResultsData: products
14266
+ });
14245
14267
  }).catch(() => {
14246
14268
  setPendingQuery("");
14247
14269
  setAiStatus("");
14270
+ trackErrorPopup({
14271
+ ...buildGtmContext(),
14272
+ searchType: SEARCH_GTM_SEARCH_TYPES.AI_AGENT
14273
+ });
14248
14274
  }).finally(() => {
14249
14275
  if (requestId === aiRequestCounterRef.current) setAiLoading(false);
14250
14276
  });
14251
14277
  },
14252
- [aiStatusLabels, historyAddEntry, setSearchInput]
14278
+ [aiStatusLabels, historyAddEntry, setSearchInput, buildGtmContext]
14253
14279
  );
14254
14280
  const selectOption = useCallback(
14255
14281
  (option) => {
@@ -14257,9 +14283,16 @@ function SearchModal({
14257
14283
  if (isSuggestionDisabled(option)) return;
14258
14284
  const term = String((_b2 = (_a2 = option["value"]) != null ? _a2 : option["label"]) != null ? _b2 : "");
14259
14285
  historyAddEntry({ query: term, isAI: false });
14286
+ if (term.trim()) {
14287
+ trackProductSearch({
14288
+ ...buildGtmContext(),
14289
+ searchType: SEARCH_GTM_SEARCH_TYPES.SEMANTIC,
14290
+ productResultsData: [option]
14291
+ });
14292
+ }
14260
14293
  const optionHref = service.getSuggestionHref(option);
14261
- if (optionHref && history && typeof history.push === "function") {
14262
- history.push(optionHref);
14294
+ if (optionHref) {
14295
+ pushSearchPath(history, optionHref);
14263
14296
  onClose();
14264
14297
  return;
14265
14298
  }
@@ -14270,7 +14303,7 @@ function SearchModal({
14270
14303
  if (!enableAIChat) setLegacyRecentSearches((_d2 = (_c2 = service.getRecentSearches) == null ? void 0 : _c2.call(service)) != null ? _d2 : []);
14271
14304
  onClose();
14272
14305
  },
14273
- [enableAIChat, service, onClose, historyAddEntry, history]
14306
+ [buildGtmContext, enableAIChat, service, onClose, historyAddEntry, history]
14274
14307
  );
14275
14308
  const runSuggestionAction = useCallback(
14276
14309
  (option) => {
@@ -14290,6 +14323,13 @@ function SearchModal({
14290
14323
  setHighlightedQuery(entry.query);
14291
14324
  } else {
14292
14325
  historyAddEntry({ query: entry.query, isAI: false });
14326
+ if (entry.query.trim()) {
14327
+ trackProductSearch({
14328
+ ...buildGtmContext(),
14329
+ searchType: SEARCH_GTM_SEARCH_TYPES.SEMANTIC,
14330
+ productResultsData: { query: entry.query.trim() }
14331
+ });
14332
+ }
14293
14333
  const url = service.submitProductSearch(entry.query);
14294
14334
  if (url && history && typeof history.push === "function") {
14295
14335
  history.push(url);
@@ -14298,7 +14338,7 @@ function SearchModal({
14298
14338
  onClose();
14299
14339
  }
14300
14340
  },
14301
- [enableAIChat, service, onClose, historyAddEntry, history]
14341
+ [buildGtmContext, enableAIChat, service, onClose, historyAddEntry, history]
14302
14342
  );
14303
14343
  const handleClearRecentSearches = useCallback(() => {
14304
14344
  clearRecentSearches();
@@ -14311,22 +14351,44 @@ function SearchModal({
14311
14351
  const handleSearchSubmit = useCallback(
14312
14352
  (value) => {
14313
14353
  var _a2, _b2;
14354
+ if (enableAIChat && suggestionFetchFailed) {
14355
+ sendAIMessage(value);
14356
+ return;
14357
+ }
14314
14358
  historyAddEntry({ query: value, isAI: false });
14359
+ const trimmed = value.trim();
14360
+ if (trimmed) {
14361
+ trackProductSearch({
14362
+ ...buildGtmContext(),
14363
+ searchType: SEARCH_GTM_SEARCH_TYPES.SEMANTIC,
14364
+ productResultsData: visibleSuggestions.length > 0 ? visibleSuggestions : { query: trimmed }
14365
+ });
14366
+ }
14315
14367
  const url = service.submitProductSearch(value);
14316
14368
  pushSearchPath(history, url);
14317
14369
  if (!enableAIChat) setLegacyRecentSearches((_b2 = (_a2 = service.getRecentSearches) == null ? void 0 : _a2.call(service)) != null ? _b2 : []);
14318
14370
  onClose();
14319
14371
  },
14320
- [enableAIChat, history, historyAddEntry, onClose, service]
14372
+ [
14373
+ buildGtmContext,
14374
+ enableAIChat,
14375
+ history,
14376
+ historyAddEntry,
14377
+ onClose,
14378
+ sendAIMessage,
14379
+ service,
14380
+ suggestionFetchFailed,
14381
+ visibleSuggestions
14382
+ ]
14321
14383
  );
14322
14384
  if (!isOpen) return null;
14323
- const placeholder = (_e = copy == null ? void 0 : copy.extended_search_textbox_desktop) != null ? _e : "Search";
14324
- const ariaLabel = (_f = copy == null ? void 0 : copy.extended_search_box_aria_label) != null ? _f : placeholder;
14325
- const didYouMeanText = (_g = copy == null ? void 0 : copy.did_you_mean_text) != null ? _g : "Did You Mean?";
14326
- const noSuggestionsText = (_h = copy == null ? void 0 : copy.no_suggestions_text) != null ? _h : "No suggestions";
14327
- const seeMoreText = (_i = copy == null ? void 0 : copy.see_more_results_text) != null ? _i : "See More Results";
14385
+ const placeholder = (_f = copy == null ? void 0 : copy.extended_search_textbox_desktop) != null ? _f : "Search";
14386
+ const ariaLabel = (_g = copy == null ? void 0 : copy.extended_search_box_aria_label) != null ? _g : placeholder;
14387
+ const didYouMeanText = (_h = copy == null ? void 0 : copy.did_you_mean_text) != null ? _h : "Did You Mean?";
14388
+ const noSuggestionsText = (_i = copy == null ? void 0 : copy.no_suggestions_text) != null ? _i : "No suggestions";
14389
+ const seeMoreText = (_j = copy == null ? void 0 : copy.see_more_results_text) != null ? _j : "See More Results";
14328
14390
  const showRecentSearches = !hasQuery && !aiLoading && !isInChatMode && recentSearches.length > 0;
14329
- const showNoResults = !isInChatMode && !loading && emptyFetched && visibleSuggestions.length === 0 && !aiLoading && !(enableAIChat && isWaitingForAIFallback);
14391
+ const showNoResults = !isInChatMode && !loading && emptyFetched && visibleSuggestions.length === 0 && !aiLoading;
14330
14392
  const searchInput = /* @__PURE__ */ jsx(
14331
14393
  SearchMessageInput,
14332
14394
  {
@@ -14412,7 +14474,7 @@ function SearchModal({
14412
14474
  query,
14413
14475
  showRecentSearches,
14414
14476
  handleClearRecentSearches,
14415
- clearAllLabel: (_j = copy == null ? void 0 : copy.clear_all_label) != null ? _j : "Clear all",
14477
+ clearAllLabel: (_k = copy == null ? void 0 : copy.clear_all_label) != null ? _k : "Clear all",
14416
14478
  showAllRecent,
14417
14479
  recentSearches,
14418
14480
  handleRecentSearchSelect,