@nuskin/react-search-components 1.0.0-comx-3067.8 → 1.0.0-widget-integration.2

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,13 +1,9 @@
1
- import React, { useState, useEffect, useId, useRef, useCallback, useMemo } from 'react';
2
- import styled6 from '@emotion/styled';
1
+ import React, { useState, useEffect, useId, useRef } from 'react';
2
+ import styled4 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, trackChatEntryPoint, trackSearchType, SEARCH_GTM_SEARCH_TYPES, trackProductSearch, trackErrorPopup, isSuggestionDisabled, useSearchHistoryStore, useVoiceSearch } from '@nuskin/react-search-sdk';
6
- export { createSearchService } from '@nuskin/react-search-sdk';
7
- import { createPortal } from 'react-dom';
8
- import { ProductCarousel, PRODUCT_CAROUSEL_ERROR_CODES } from '@nuskin/react-product-components';
9
- import { getStack } from '@ns/ns-contentstack-lib';
10
- import { keyframes } from '@emotion/react';
5
+ import { NsIcon } from '@nuskin/foundation-ui-components';
6
+ import { Modal } from '@mui/material';
11
7
 
12
8
  var __create = Object.create;
13
9
  var __defProp = Object.defineProperty;
@@ -407,7 +403,7 @@ var require_checkPropTypes = __commonJS({
407
403
  var ReactPropTypesSecret;
408
404
  var loggedTypeFailures;
409
405
  var has;
410
- function checkPropTypes(typeSpecs, values, location, componentName, getStack2) {
406
+ function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
411
407
  {
412
408
  for (var typeSpecName in typeSpecs) {
413
409
  if (has(typeSpecs, typeSpecName)) {
@@ -431,7 +427,7 @@ var require_checkPropTypes = __commonJS({
431
427
  }
432
428
  if (error instanceof Error && !(error.message in loggedTypeFailures)) {
433
429
  loggedTypeFailures[error.message] = true;
434
- var stack = getStack2 ? getStack2() : "";
430
+ var stack = getStack ? getStack() : "";
435
431
  printWarning(
436
432
  "Failed " + location + " type: " + error.message + (stack != null ? stack : "")
437
433
  );
@@ -2568,7 +2564,7 @@ function initializeContent(effects) {
2568
2564
  }
2569
2565
 
2570
2566
  // node_modules/micromark/lib/initialize/document.js
2571
- var document2 = {
2567
+ var document = {
2572
2568
  tokenize: initializeDocument
2573
2569
  };
2574
2570
  var containerConstruct = {
@@ -8262,14 +8258,14 @@ __export(constructs_exports, {
8262
8258
  attentionMarkers: () => attentionMarkers,
8263
8259
  contentInitial: () => contentInitial,
8264
8260
  disable: () => disable,
8265
- document: () => document3,
8261
+ document: () => document2,
8266
8262
  flow: () => flow2,
8267
8263
  flowInitial: () => flowInitial,
8268
8264
  insideSpan: () => insideSpan,
8269
8265
  string: () => string2,
8270
8266
  text: () => text2
8271
8267
  });
8272
- var document3 = {
8268
+ var document2 = {
8273
8269
  [42]: list,
8274
8270
  [43]: list,
8275
8271
  [45]: list,
@@ -8343,7 +8339,7 @@ function parse(options) {
8343
8339
  lazy: {},
8344
8340
  constructs: constructs2,
8345
8341
  content: create2(content),
8346
- document: create2(document2),
8342
+ document: create2(document),
8347
8343
  flow: create2(flow),
8348
8344
  string: create2(string),
8349
8345
  text: create2(text)
@@ -11973,13 +11969,13 @@ var SEARCH_MESSAGE_SENDERS = {
11973
11969
 
11974
11970
  // src/components/SearchMessage/SearchMessage.styled.tsx
11975
11971
  var { colors } = nuskinTheme;
11976
- var SearchMessageRoot = styled6.div`
11972
+ var SearchMessageRoot = styled4.div`
11977
11973
  display: flex;
11978
11974
  inline-size: 100%;
11979
11975
  justify-content: ${({ $sender }) => $sender === SEARCH_MESSAGE_SENDERS.USER ? "flex-end" : "flex-start"};
11980
11976
  min-inline-size: 0;
11981
11977
  `;
11982
- var SearchMessageContent = styled6.div`
11978
+ var SearchMessageContent = styled4.div`
11983
11979
  background-color: ${({ $sender }) => $sender === SEARCH_MESSAGE_SENDERS.USER ? colors.neutral[30] : "transparent"};
11984
11980
  border-radius: ${({ $sender }) => $sender === SEARCH_MESSAGE_SENDERS.USER ? "999px" : "0"};
11985
11981
  max-inline-size: ${({ $sender }) => $sender === SEARCH_MESSAGE_SENDERS.USER ? "min(100%, 40rem)" : "100%"};
@@ -12045,13 +12041,17 @@ var ICON_COLOR_BY_TYPE = {
12045
12041
  [ICON_TYPES.CHECK_VERIFIED]: "#5f86ad",
12046
12042
  [ICON_TYPES.STAR_GREY]: "#c9c9c9"
12047
12043
  };
12048
- var TEMPORARY_GLYPH_BY_ICON_TYPE = {
12049
- [ICON_TYPES.ARROW_DOWN]: "\u2193",
12050
- [ICON_TYPES.ARROW_LEFT]: "\u2190",
12051
- [ICON_TYPES.ARROW_RIGHT]: "\u2192",
12052
- [ICON_TYPES.ARROW_UP]: "\u2191",
12053
- [ICON_TYPES.CHECK_VERIFIED]: "\u2713",
12054
- [ICON_TYPES.CLOSE]: "\xD7"
12044
+ var FOUNDATION_ICON_NAME_BY_ICON_TYPE = {
12045
+ [ICON_TYPES.ARROW_DOWN]: "arrowDown",
12046
+ [ICON_TYPES.ARROW_LEFT]: "arrowLeft",
12047
+ [ICON_TYPES.ARROW_RIGHT]: "arrowRight",
12048
+ [ICON_TYPES.ARROW_UP]: "arrowUp",
12049
+ [ICON_TYPES.CHECK_VERIFIED]: "checkVerified",
12050
+ [ICON_TYPES.CLOSE]: "close"
12051
+ };
12052
+ var FOUNDATION_SIZE_BY_ICON_SIZE = {
12053
+ [ICON_SIZES.LARGE]: "large",
12054
+ [ICON_SIZES.SMALL]: "small"
12055
12055
  };
12056
12056
  function iconStyle(color2, cursor) {
12057
12057
  return {
@@ -12060,34 +12060,24 @@ function iconStyle(color2, cursor) {
12060
12060
  display: "block"
12061
12061
  };
12062
12062
  }
12063
- function TemporaryGlyphIcon({
12063
+ function FoundationIcon({
12064
12064
  className,
12065
12065
  color: color2,
12066
12066
  cursor,
12067
- glyph,
12067
+ name,
12068
12068
  size,
12069
12069
  testId
12070
12070
  }) {
12071
- const dimensions = SQUARE_SIZE_BY_ICON_SIZE[size];
12072
12071
  return /* @__PURE__ */ jsx(
12073
- "span",
12072
+ NsIcon,
12074
12073
  {
12075
- "aria-hidden": "true",
12076
- className,
12077
- "data-testid": testId,
12078
- style: {
12079
- ...iconStyle(color2, cursor),
12080
- alignItems: "center",
12081
- display: "inline-flex",
12082
- fontSize: dimensions,
12083
- fontWeight: 300,
12084
- height: dimensions,
12085
- justifyContent: "center",
12086
- lineHeight: 1,
12087
- textAlign: "center",
12088
- width: dimensions
12089
- },
12090
- children: glyph
12074
+ "aria-hidden": true,
12075
+ ...className === void 0 ? {} : { className },
12076
+ colorOverride: color2,
12077
+ cursor,
12078
+ name,
12079
+ size: FOUNDATION_SIZE_BY_ICON_SIZE[size],
12080
+ testId
12091
12081
  }
12092
12082
  );
12093
12083
  }
@@ -12455,16 +12445,16 @@ function Icon({
12455
12445
  size,
12456
12446
  testId: resolvedTestId
12457
12447
  };
12458
- const temporaryGlyph = TEMPORARY_GLYPH_BY_ICON_TYPE[type];
12459
- if (temporaryGlyph !== void 0) {
12460
- return /* @__PURE__ */ jsx(TemporaryGlyphIcon, { ...customProps, glyph: temporaryGlyph });
12448
+ const foundationName = FOUNDATION_ICON_NAME_BY_ICON_TYPE[type];
12449
+ if (foundationName !== void 0) {
12450
+ return /* @__PURE__ */ jsx(FoundationIcon, { ...customProps, name: foundationName });
12461
12451
  }
12462
12452
  const IconView = ICON_VIEW_BY_TYPE[type];
12463
12453
  return IconView === void 0 ? null : /* @__PURE__ */ jsx(IconView, { ...customProps });
12464
12454
  }
12465
12455
  var { colors: colors2 } = nuskinTheme;
12466
12456
  var voiceListeningColor = "#6964f1";
12467
- var SearchMessageInputRoot = styled6.form`
12457
+ var SearchMessageInputRoot = styled4.form`
12468
12458
  && {
12469
12459
  align-items: end;
12470
12460
  background-color: ${colors2.primary.white};
@@ -12472,7 +12462,7 @@ var SearchMessageInputRoot = styled6.form`
12472
12462
  border-radius: 1.5rem;
12473
12463
  display: grid;
12474
12464
  gap: 0.5rem;
12475
- grid-template-columns: minmax(0, 1fr) auto;
12465
+ grid-template-columns: ${({ $hasActions = true }) => $hasActions ? "minmax(0, 1fr) auto" : "minmax(0, 1fr)"};
12476
12466
  inline-size: 100%;
12477
12467
  padding: 0.5rem;
12478
12468
 
@@ -12487,7 +12477,7 @@ var SearchMessageInputRoot = styled6.form`
12487
12477
  }
12488
12478
  }
12489
12479
  `;
12490
- var SearchMessageInputField = styled6.textarea`
12480
+ var SearchMessageInputField = styled4.textarea`
12491
12481
  appearance: none;
12492
12482
  background: transparent;
12493
12483
  border: 0;
@@ -12506,19 +12496,19 @@ var SearchMessageInputField = styled6.textarea`
12506
12496
  opacity: 1;
12507
12497
  }
12508
12498
  `;
12509
- var SearchMessageInputActions = styled6.div`
12499
+ var SearchMessageInputActions = styled4.div`
12510
12500
  align-items: center;
12511
12501
  display: flex;
12512
12502
  gap: 0.375rem;
12513
12503
  `;
12514
- var SearchMessageInputActionButton = styled6.button`
12504
+ var SearchMessageInputActionButton = styled4.button`
12515
12505
  &&&& {
12516
12506
  align-items: center;
12517
12507
  appearance: none;
12518
- background-color: ${({ $active, $voiceListening }) => $voiceListening ? voiceListeningColor : $active ? colors2.neutral[30] : "transparent"};
12508
+ background-color: ${({ $voiceListening }) => $voiceListening ? voiceListeningColor : "transparent"};
12519
12509
  border: 0;
12520
12510
  border-radius: 50% !important;
12521
- color: ${({ $active, $voiceListening }) => $voiceListening ? colors2.primary.white : $active ? colors2.neutral[20] : "inherit"};
12511
+ color: ${({ $voiceListening }) => $voiceListening ? colors2.primary.white : "inherit"};
12522
12512
  cursor: pointer;
12523
12513
  display: inline-flex;
12524
12514
  flex: 0 0 auto;
@@ -12575,7 +12565,6 @@ function SearchMessageInput({
12575
12565
  onVoiceInput,
12576
12566
  placeholder,
12577
12567
  showVoiceInput = false,
12578
- submitLabel,
12579
12568
  value,
12580
12569
  voiceInputLabel,
12581
12570
  voiceListening = false,
@@ -12608,62 +12597,45 @@ function SearchMessageInput({
12608
12597
  submitMessage();
12609
12598
  }
12610
12599
  }
12611
- return /* @__PURE__ */ jsxs(SearchMessageInputRoot, { ...props, $voiceListening: voiceListening, onSubmit: handleSubmit, children: [
12612
- /* @__PURE__ */ jsx(
12613
- SearchMessageInputField,
12614
- {
12615
- "aria-label": inputLabel,
12616
- onChange: (event) => {
12617
- setDraft(event.target.value);
12618
- onChange == null ? void 0 : onChange(event.target.value);
12619
- },
12620
- onKeyDown: handleKeyDown,
12621
- placeholder: voiceListening && !draft ? voiceListeningLabel : placeholder,
12622
- rows: 1,
12623
- value: draft
12624
- }
12625
- ),
12626
- /* @__PURE__ */ jsxs(SearchMessageInputActions, { children: [
12627
- showVoiceInput ? /* @__PURE__ */ jsx(
12628
- SearchMessageInputActionButton,
12629
- {
12630
- "aria-label": voiceInputLabel,
12631
- "aria-pressed": voiceListening,
12632
- $voiceListening: voiceListening,
12633
- onClick: onVoiceInput,
12634
- type: "button",
12635
- children: /* @__PURE__ */ jsx(Icon, { cursor: ICON_CURSORS.POINTER, type: ICON_TYPES.VOICE })
12636
- }
12637
- ) : null,
12638
- /* @__PURE__ */ jsx(
12639
- SearchMessageInputActionButton,
12640
- {
12641
- $active: message.length > 0,
12642
- "aria-label": submitLabel,
12643
- disabled: message.length === 0,
12644
- type: "submit",
12645
- children: /* @__PURE__ */ jsx(
12646
- Icon,
12647
- {
12648
- cursor: ICON_CURSORS.POINTER,
12649
- type: message.length > 0 ? ICON_TYPES.ARROW_UP : ICON_TYPES.ASK_NUI
12650
- }
12651
- )
12652
- }
12653
- )
12654
- ] })
12655
- ] });
12600
+ return /* @__PURE__ */ jsxs(
12601
+ SearchMessageInputRoot,
12602
+ {
12603
+ ...props,
12604
+ $hasActions: showVoiceInput,
12605
+ $voiceListening: voiceListening,
12606
+ onSubmit: handleSubmit,
12607
+ children: [
12608
+ /* @__PURE__ */ jsx(
12609
+ SearchMessageInputField,
12610
+ {
12611
+ "aria-label": inputLabel,
12612
+ onChange: (event) => {
12613
+ setDraft(event.target.value);
12614
+ onChange == null ? void 0 : onChange(event.target.value);
12615
+ },
12616
+ onKeyDown: handleKeyDown,
12617
+ placeholder: voiceListening && !draft ? voiceListeningLabel : placeholder,
12618
+ rows: 1,
12619
+ value: draft
12620
+ }
12621
+ ),
12622
+ showVoiceInput ? /* @__PURE__ */ jsx(SearchMessageInputActions, { children: /* @__PURE__ */ jsx(
12623
+ SearchMessageInputActionButton,
12624
+ {
12625
+ "aria-label": voiceInputLabel,
12626
+ "aria-pressed": voiceListening,
12627
+ $voiceListening: voiceListening,
12628
+ onClick: onVoiceInput,
12629
+ type: "button",
12630
+ children: /* @__PURE__ */ jsx(Icon, { cursor: ICON_CURSORS.POINTER, type: ICON_TYPES.VOICE })
12631
+ }
12632
+ ) }) : null
12633
+ ]
12634
+ }
12635
+ );
12656
12636
  }
12657
12637
  var { colors: colors3 } = nuskinTheme;
12658
- var SearchModalOverlay = styled6.div`
12659
- position: fixed;
12660
- inset: 0;
12661
- z-index: 10000;
12662
- background: rgba(0, 0, 0, 0.3);
12663
- display: flex;
12664
- flex-direction: column;
12665
- `;
12666
- var SearchPanelRoot = styled6.section`
12638
+ var SearchPanelRoot = styled4.section`
12667
12639
  background-color: ${colors3.primary.white};
12668
12640
  border-block-end: 1px solid ${colors3.neutral[30]};
12669
12641
  color: ${colors3.primary.black};
@@ -12674,8 +12646,12 @@ var SearchPanelRoot = styled6.section`
12674
12646
  max-block-size: 92dvh;
12675
12647
  overflow: hidden;
12676
12648
  `}
12649
+ ${({ $agentMode }) => $agentMode && `
12650
+ /* a definite height, so an embedded agent that fills its host has room to lay out */
12651
+ block-size: 92dvh;
12652
+ `}
12677
12653
  `;
12678
- var SearchPanelInner = styled6.div`
12654
+ var SearchPanelInner = styled4.div`
12679
12655
  display: grid;
12680
12656
  gap: 1.5rem;
12681
12657
  inline-size: min(100%, 75rem);
@@ -12689,7 +12665,7 @@ var SearchPanelInner = styled6.div`
12689
12665
  overflow: hidden;
12690
12666
  `}
12691
12667
  `;
12692
- var SearchPanelScrollContent = styled6.div`
12668
+ var SearchPanelScrollContent = styled4.div`
12693
12669
  flex: 1;
12694
12670
  min-block-size: 0;
12695
12671
  overflow-y: auto;
@@ -12699,7 +12675,14 @@ var SearchPanelScrollContent = styled6.div`
12699
12675
  display: none;
12700
12676
  }
12701
12677
  `;
12702
- var SearchPanelHeader = styled6.header`
12678
+ var SearchPanelAgentContent = styled4.div`
12679
+ flex: 1;
12680
+ min-block-size: 0;
12681
+ min-inline-size: 0;
12682
+ overflow: hidden;
12683
+ position: relative;
12684
+ `;
12685
+ var SearchPanelHeader = styled4.header`
12703
12686
  display: flex;
12704
12687
  justify-content: space-between;
12705
12688
  align-items: center;
@@ -12708,12 +12691,12 @@ var SearchPanelHeader = styled6.header`
12708
12691
  justify-content: flex-end;
12709
12692
  `}
12710
12693
  `;
12711
- var SearchPanelLogoSlot = styled6.div`
12694
+ var SearchPanelLogoSlot = styled4.div`
12712
12695
  flex: 0 0 auto;
12713
12696
  /* when header is flex-end (chat mode), push the logo to the far left */
12714
12697
  margin-inline-end: auto;
12715
12698
  `;
12716
- var SearchPanelCloseButton = styled6.button`
12699
+ var SearchPanelCloseButton = styled4.button`
12717
12700
  align-items: center;
12718
12701
  appearance: none;
12719
12702
  background: transparent;
@@ -12730,16 +12713,17 @@ var SearchPanelCloseButton = styled6.button`
12730
12713
  outline-offset: 2px;
12731
12714
  }
12732
12715
  `;
12733
- var SearchPanelContent = styled6.div`
12716
+ var SearchPanelContent = styled4.div`
12734
12717
  min-inline-size: 0;
12735
12718
  `;
12736
- var SearchPanelMessageInput = styled6.div`
12719
+ var SearchPanelMessageInput = styled4.div`
12737
12720
  inline-size: min(100%, 44rem);
12738
12721
  justify-self: center;
12739
12722
  width: 100%;
12740
12723
  `;
12741
12724
  function SearchPanel({
12742
12725
  "aria-label": ariaLabel,
12726
+ agentMode = false,
12743
12727
  children,
12744
12728
  chatMode = false,
12745
12729
  closeLabel,
@@ -12750,83 +12734,245 @@ function SearchPanel({
12750
12734
  onClose,
12751
12735
  ...props
12752
12736
  }) {
12753
- const content3 = chatMode ? /* @__PURE__ */ jsx(SearchPanelScrollContent, { "data-scroll-container": "", children }) : /* @__PURE__ */ jsx(SearchPanelContent, { children });
12754
- return /* @__PURE__ */ jsx(SearchPanelRoot, { ...props, "aria-label": ariaLabel, $chatMode: chatMode, children: /* @__PURE__ */ jsxs(SearchPanelInner, { $chatMode: chatMode, children: [
12755
- /* @__PURE__ */ jsxs(SearchPanelHeader, { $chatMode: chatMode, children: [
12756
- logoSlot && /* @__PURE__ */ jsx(SearchPanelLogoSlot, { children: logoSlot }),
12757
- /* @__PURE__ */ jsxs(
12758
- SearchPanelCloseButton,
12737
+ const flexLayout = chatMode || agentMode;
12738
+ let content3;
12739
+ if (agentMode) {
12740
+ content3 = /* @__PURE__ */ jsx(SearchPanelAgentContent, { "data-agent-container": "", children });
12741
+ } else if (chatMode) {
12742
+ content3 = /* @__PURE__ */ jsx(SearchPanelScrollContent, { "data-scroll-container": "", children });
12743
+ } else {
12744
+ content3 = /* @__PURE__ */ jsx(SearchPanelContent, { children });
12745
+ }
12746
+ return /* @__PURE__ */ jsx(
12747
+ SearchPanelRoot,
12748
+ {
12749
+ ...props,
12750
+ "aria-label": ariaLabel,
12751
+ $chatMode: flexLayout,
12752
+ $agentMode: agentMode,
12753
+ children: /* @__PURE__ */ jsxs(SearchPanelInner, { $chatMode: flexLayout, children: [
12754
+ /* @__PURE__ */ jsxs(SearchPanelHeader, { $chatMode: flexLayout, children: [
12755
+ logoSlot && /* @__PURE__ */ jsx(SearchPanelLogoSlot, { children: logoSlot }),
12756
+ /* @__PURE__ */ jsxs(
12757
+ SearchPanelCloseButton,
12758
+ {
12759
+ type: "button",
12760
+ onMouseDown: (e) => e.preventDefault(),
12761
+ onClick: onClose,
12762
+ children: [
12763
+ /* @__PURE__ */ jsx(Icon, { cursor: ICON_CURSORS.POINTER, size: ICON_SIZES.SMALL, type: ICON_TYPES.CLOSE }),
12764
+ closeLabel
12765
+ ]
12766
+ }
12767
+ )
12768
+ ] }),
12769
+ !flexLayout && inputSlot && /* @__PURE__ */ jsx(SearchPanelMessageInput, { children: inputSlot }),
12770
+ !agentMode && initialPrompt && /* @__PURE__ */ jsx(SearchMessage, { sender: SEARCH_MESSAGE_SENDERS.USER, text: initialPrompt }),
12771
+ content3,
12772
+ !agentMode && (chatMode || !inputSlot && messageInputProps) && messageInputProps && /* @__PURE__ */ jsx(SearchPanelMessageInput, { children: /* @__PURE__ */ jsx(SearchMessageInput, { ...messageInputProps }) })
12773
+ ] })
12774
+ }
12775
+ );
12776
+ }
12777
+ var MOBILE_MAX_PX = 1024;
12778
+ var colors4 = {
12779
+ text: "#111827",
12780
+ muted: "#6b7280",
12781
+ hover: "#f3f4f6",
12782
+ surface: "#ffffff",
12783
+ borderLight: "#e5e7eb"
12784
+ };
12785
+ var SearchModalBackdropRoot = styled4.div`
12786
+ -webkit-tap-highlight-color: transparent;
12787
+ background-color: transparent;
12788
+ inset: 0;
12789
+ position: fixed;
12790
+ `;
12791
+ var SearchModalSurface = styled4.div`
12792
+ inline-size: 100%;
12793
+ outline: none;
12794
+ position: relative;
12795
+ z-index: 1;
12796
+ `;
12797
+ var SearchSuggestionsPanel = styled4.div`
12798
+ position: relative;
12799
+ width: 100%;
12800
+ margin-top: 8px;
12801
+ `;
12802
+ var SearchSuggestionsList = styled4.ul`
12803
+ display: flex;
12804
+ flex-direction: column;
12805
+ list-style: none;
12806
+ margin: 0;
12807
+ padding: 0;
12808
+ `;
12809
+ var SearchSuggestionOption = styled4.li`
12810
+ display: flex;
12811
+ align-items: center;
12812
+ width: 100%;
12813
+ min-height: 58px;
12814
+ padding: 4px 24px;
12815
+ box-sizing: border-box;
12816
+ color: ${colors4.text};
12817
+ `;
12818
+ var PassiveSuggestionOption = styled4(SearchSuggestionOption)`
12819
+ cursor: default;
12820
+ color: ${colors4.muted};
12821
+ `;
12822
+ var SuggestionSectionHeading = styled4.div`
12823
+ padding: 12px 24px 8px;
12824
+ margin-bottom: 4px;
12825
+ font-size: 16px;
12826
+ font-weight: 700;
12827
+ color: ${colors4.text};
12828
+ background: ${colors4.surface};
12829
+ border-bottom: 1px solid ${colors4.borderLight};
12830
+ `;
12831
+ var RecentSearchesSection = styled4.section`
12832
+ padding: 24px 35px 18px;
12833
+ background: ${colors4.surface};
12834
+
12835
+ @media (max-width: ${MOBILE_MAX_PX}px) {
12836
+ padding: 18px 20px 16px;
12837
+ }
12838
+ `;
12839
+ var RecentSearchesHeader = styled4.div`
12840
+ display: flex;
12841
+ align-items: center;
12842
+ justify-content: space-between;
12843
+ gap: 16px;
12844
+ margin-bottom: 13px;
12845
+ `;
12846
+ var RecentSearchesTitle = styled4.h3`
12847
+ margin: 0;
12848
+ font-size: 16px;
12849
+ font-weight: 700;
12850
+ color: ${colors4.text};
12851
+
12852
+ @media (max-width: ${MOBILE_MAX_PX}px) {
12853
+ font-size: 15px;
12854
+ line-height: 1.35;
12855
+ }
12856
+ `;
12857
+ var RecentSearchesClearButton = styled4.button`
12858
+ margin: 0;
12859
+ padding: 0;
12860
+ border: none;
12861
+ background: transparent;
12862
+ color: ${colors4.text};
12863
+ font-size: 16px;
12864
+ cursor: pointer;
12865
+
12866
+ &:focus-visible {
12867
+ outline: 2px solid ${colors4.text};
12868
+ outline-offset: 2px;
12869
+ border-radius: 4px;
12870
+ }
12871
+
12872
+ @media (max-width: ${MOBILE_MAX_PX}px) {
12873
+ font-size: 14px;
12874
+ }
12875
+ `;
12876
+ var RecentSearchesList = styled4.div`
12877
+ display: flex;
12878
+ flex-wrap: wrap;
12879
+ gap: 10px;
12880
+ `;
12881
+ var RecentSearchChip = styled4.button`
12882
+ display: inline-flex;
12883
+ align-items: center;
12884
+ justify-content: center;
12885
+ min-height: 40px;
12886
+ padding: 8px 16px;
12887
+ border: 1px solid ${colors4.borderLight};
12888
+ border-radius: 999px;
12889
+ background: ${colors4.surface};
12890
+ color: ${colors4.text};
12891
+ font-size: 16px;
12892
+ cursor: pointer;
12893
+
12894
+ &:hover {
12895
+ background: ${colors4.hover};
12896
+ }
12897
+
12898
+ &:focus-visible {
12899
+ outline: 2px solid ${colors4.text};
12900
+ outline-offset: 2px;
12901
+ }
12902
+
12903
+ @media (max-width: ${MOBILE_MAX_PX}px) {
12904
+ min-height: 36px;
12905
+ padding: 6px 14px;
12906
+ font-size: 14px;
12907
+ border-radius: 10px;
12908
+ }
12909
+ `;
12910
+ var MAX_RECENT = 6;
12911
+ function RecentSearches({
12912
+ items,
12913
+ title,
12914
+ clearLabel,
12915
+ onSelect,
12916
+ onClear
12917
+ }) {
12918
+ const [showAll, setShowAll] = useState(false);
12919
+ const visible = showAll ? items : items.slice(0, MAX_RECENT);
12920
+ return /* @__PURE__ */ jsxs(RecentSearchesSection, { "aria-label": title, children: [
12921
+ /* @__PURE__ */ jsxs(RecentSearchesHeader, { children: [
12922
+ /* @__PURE__ */ jsx(RecentSearchesTitle, { children: title }),
12923
+ /* @__PURE__ */ jsx(
12924
+ RecentSearchesClearButton,
12925
+ {
12926
+ type: "button",
12927
+ onMouseDown: (e) => e.preventDefault(),
12928
+ onClick: onClear,
12929
+ children: clearLabel
12930
+ }
12931
+ )
12932
+ ] }),
12933
+ /* @__PURE__ */ jsxs(RecentSearchesList, { children: [
12934
+ visible.map((query) => /* @__PURE__ */ jsx(
12935
+ RecentSearchChip,
12936
+ {
12937
+ type: "button",
12938
+ onMouseDown: (e) => e.preventDefault(),
12939
+ onClick: () => onSelect(query),
12940
+ children: query
12941
+ },
12942
+ query
12943
+ )),
12944
+ !showAll && items.length > MAX_RECENT && /* @__PURE__ */ jsxs(
12945
+ RecentSearchChip,
12759
12946
  {
12760
12947
  type: "button",
12761
12948
  onMouseDown: (e) => e.preventDefault(),
12762
- onClick: onClose,
12949
+ onClick: () => setShowAll(true),
12763
12950
  children: [
12764
- /* @__PURE__ */ jsx(Icon, { cursor: ICON_CURSORS.POINTER, size: ICON_SIZES.SMALL, type: ICON_TYPES.CLOSE }),
12765
- closeLabel
12951
+ "+",
12952
+ items.length - MAX_RECENT,
12953
+ " More"
12766
12954
  ]
12767
12955
  }
12768
12956
  )
12769
- ] }),
12770
- !chatMode && inputSlot && /* @__PURE__ */ jsx(SearchPanelMessageInput, { children: inputSlot }),
12771
- initialPrompt && /* @__PURE__ */ jsx(SearchMessage, { sender: SEARCH_MESSAGE_SENDERS.USER, text: initialPrompt }),
12772
- content3,
12773
- (chatMode || !inputSlot && messageInputProps) && messageInputProps && /* @__PURE__ */ jsx(SearchPanelMessageInput, { children: /* @__PURE__ */ jsx(SearchMessageInput, { ...messageInputProps }) })
12774
- ] }) });
12775
- }
12776
- var AI_CHAT_CONVERSATION_ID_KEY = "ai_chat_conversation_id";
12777
- function getStoredConversationId() {
12778
- try {
12779
- const raw = typeof window !== "undefined" ? window.sessionStorage.getItem(AI_CHAT_CONVERSATION_ID_KEY) : null;
12780
- if (!raw) return null;
12781
- const id = parseInt(raw, 10);
12782
- return Number.isNaN(id) ? null : id;
12783
- } catch {
12784
- return null;
12785
- }
12786
- }
12787
- function storeConversationId(id) {
12788
- try {
12789
- if (typeof window !== "undefined")
12790
- window.sessionStorage.setItem(AI_CHAT_CONVERSATION_ID_KEY, String(id));
12791
- } catch {
12792
- }
12793
- }
12794
- async function callAICommerceChat(config) {
12795
- var _a, _b;
12796
- const { searchTerm, market, language, salesAiAppKey, salesAiParentOrigin } = config;
12797
- const chatService = createChatService({
12798
- salesAiAppKey,
12799
- salesAiParentOrigin,
12800
- market,
12801
- language
12802
- });
12803
- let conversationId = getStoredConversationId();
12804
- if (conversationId === null) {
12805
- conversationId = await chatService.createConversation("Search Session");
12806
- storeConversationId(conversationId);
12807
- }
12808
- const result = await chatService.sendMessage(conversationId, searchTerm.trim());
12809
- return {
12810
- products: (_a = result == null ? void 0 : result.products) != null ? _a : [],
12811
- summary: (_b = result == null ? void 0 : result.summary) != null ? _b : ""
12812
- };
12957
+ ] })
12958
+ ] });
12813
12959
  }
12814
12960
  var SUGGESTION_MOBILE_MAX_PX = 1024;
12815
- var colors4 = {
12961
+ var colors5 = {
12816
12962
  text: "#111827",
12817
12963
  muted: "#6b7280",
12818
12964
  accent: "rgb(15, 118, 110)"
12819
12965
  };
12820
- var SuggestionOption = styled6.li`
12966
+ var SuggestionOption = styled4.li`
12821
12967
  display: flex;
12822
12968
  align-items: center;
12823
12969
  width: 100%;
12824
12970
  min-height: 58px;
12825
12971
  padding: 4px 24px;
12826
12972
  box-sizing: border-box;
12827
- color: ${colors4.text};
12973
+ color: ${colors5.text};
12828
12974
  `;
12829
- var SuggestionRow = styled6(SuggestionOption)`
12975
+ var SuggestionRow = styled4(SuggestionOption)`
12830
12976
  display: grid;
12831
12977
  grid-template-columns: minmax(0, 1fr) 18px;
12832
12978
  align-items: center;
@@ -12836,7 +12982,7 @@ var SuggestionRow = styled6(SuggestionOption)`
12836
12982
 
12837
12983
  &[data-selected='true'] {
12838
12984
  background: rgba(15, 118, 110, 0.08);
12839
- box-shadow: inset 3px 0 0 ${colors4.accent};
12985
+ box-shadow: inset 3px 0 0 ${colors5.accent};
12840
12986
  }
12841
12987
 
12842
12988
  &[data-highlighted='true'],
@@ -12847,7 +12993,7 @@ var SuggestionRow = styled6(SuggestionOption)`
12847
12993
  &[data-highlighted='true'][data-selected='true'] {
12848
12994
  background: rgba(15, 118, 110, 0.12);
12849
12995
  box-shadow:
12850
- inset 3px 0 0 ${colors4.accent},
12996
+ inset 3px 0 0 ${colors5.accent},
12851
12997
  inset 0 0 0 2px rgba(17, 24, 39, 0.12);
12852
12998
  }
12853
12999
 
@@ -12864,7 +13010,7 @@ var SuggestionRow = styled6(SuggestionOption)`
12864
13010
  column-gap: 8px;
12865
13011
  }
12866
13012
  `;
12867
- var SuggestionContentWrapper = styled6.div`
13013
+ var SuggestionContentWrapper = styled4.div`
12868
13014
  display: grid;
12869
13015
  grid-template-columns: 50px minmax(0, 1fr);
12870
13016
  align-items: center;
@@ -12886,7 +13032,7 @@ var SuggestionContentWrapper = styled6.div`
12886
13032
  }
12887
13033
 
12888
13034
  &:focus-visible {
12889
- outline: 2px solid ${colors4.text};
13035
+ outline: 2px solid ${colors5.text};
12890
13036
  outline-offset: 3px;
12891
13037
  }
12892
13038
 
@@ -12894,14 +13040,14 @@ var SuggestionContentWrapper = styled6.div`
12894
13040
  grid-template-columns: minmax(0, 1fr);
12895
13041
  }
12896
13042
  `;
12897
- var SuggestionThumbnail = styled6.img`
13043
+ var SuggestionThumbnail = styled4.img`
12898
13044
  width: 50px;
12899
13045
  height: 50px;
12900
13046
  object-fit: contain;
12901
13047
  flex-shrink: 0;
12902
13048
  align-self: center;
12903
13049
  `;
12904
- var SuggestionLabel = styled6.span`
13050
+ var SuggestionLabel = styled4.span`
12905
13051
  display: block;
12906
13052
  min-width: 0;
12907
13053
  line-height: 24px;
@@ -12909,25 +13055,25 @@ var SuggestionLabel = styled6.span`
12909
13055
  overflow-wrap: anywhere;
12910
13056
  word-break: break-word;
12911
13057
  font-size: 16px;
12912
- color: ${colors4.text};
13058
+ color: ${colors5.text};
12913
13059
 
12914
13060
  @media (max-width: ${SUGGESTION_MOBILE_MAX_PX}px) {
12915
13061
  font-size: 14px;
12916
13062
  line-height: 20px;
12917
13063
  }
12918
13064
  `;
12919
- var SuggestionActionIcon = styled6.span`
13065
+ var SuggestionActionIcon = styled4.span`
12920
13066
  display: inline-flex;
12921
13067
  align-items: center;
12922
13068
  justify-content: center;
12923
13069
  width: 24px;
12924
13070
  height: 24px;
12925
- color: var(--suggestion-icon-color, ${colors4.text});
13071
+ color: var(--suggestion-icon-color, ${colors5.text});
12926
13072
  flex-shrink: 0;
12927
13073
  align-self: center;
12928
13074
 
12929
13075
  &[data-cart-disabled='true'] {
12930
- color: var(--suggestion-muted, ${colors4.muted});
13076
+ color: var(--suggestion-muted, ${colors5.muted});
12931
13077
  }
12932
13078
 
12933
13079
  svg {
@@ -12936,7 +13082,7 @@ var SuggestionActionIcon = styled6.span`
12936
13082
  display: block;
12937
13083
  }
12938
13084
  `;
12939
- var SuggestionActionButton = styled6.button`
13085
+ var SuggestionActionButton = styled4.button`
12940
13086
  display: inline-flex;
12941
13087
  align-items: center;
12942
13088
  justify-content: center;
@@ -12946,13 +13092,13 @@ var SuggestionActionButton = styled6.button`
12946
13092
  padding: 0;
12947
13093
  border: none;
12948
13094
  background: transparent;
12949
- color: var(--suggestion-icon-color, ${colors4.text});
13095
+ color: var(--suggestion-icon-color, ${colors5.text});
12950
13096
  flex-shrink: 0;
12951
13097
  align-self: center;
12952
13098
  cursor: pointer;
12953
13099
 
12954
13100
  &:focus-visible {
12955
- outline: 2px solid ${colors4.text};
13101
+ outline: 2px solid ${colors5.text};
12956
13102
  outline-offset: 3px;
12957
13103
  border-radius: 4px;
12958
13104
  }
@@ -12963,6 +13109,38 @@ var SuggestionActionButton = styled6.button`
12963
13109
  display: block;
12964
13110
  }
12965
13111
  `;
13112
+
13113
+ // src/components/SuggestionRow/helpers.ts
13114
+ var CART_DISABLED_PRODUCT_STATUSES = /* @__PURE__ */ new Set([
13115
+ "discontinued",
13116
+ "preview",
13117
+ "previewproduct",
13118
+ "test",
13119
+ "stopped",
13120
+ "replacement",
13121
+ "bundleonly",
13122
+ "inactive",
13123
+ "notavailable"
13124
+ ]);
13125
+ function normalizeProductStatusValue(value) {
13126
+ const text4 = typeof value === "string" || typeof value === "number" ? String(value) : "";
13127
+ return text4.trim().toLowerCase().replace(/\s+/g, "");
13128
+ }
13129
+ function isNonSellableStatusValue(statusValue) {
13130
+ if (CART_DISABLED_PRODUCT_STATUSES.has(statusValue)) return true;
13131
+ return statusValue !== "sellable" && statusValue !== "active";
13132
+ }
13133
+ function isCartActionDisabled(option) {
13134
+ var _a;
13135
+ if ((_a = option["out_of_stock"]) != null ? _a : option["outOfStock"]) return true;
13136
+ const statusValues = [
13137
+ option["productStatus"],
13138
+ option["product_status"],
13139
+ option["status"],
13140
+ option["sku_status"]
13141
+ ].map(normalizeProductStatusValue).filter(Boolean);
13142
+ return statusValues.some(isNonSellableStatusValue);
13143
+ }
12966
13144
  function resolveImageSrc(option, isDidYouMean) {
12967
13145
  var _a, _b, _c;
12968
13146
  if (isDidYouMean) return "";
@@ -13155,12 +13333,12 @@ function SuggestionRow2({
13155
13333
  }
13156
13334
  );
13157
13335
  }
13158
- var colors5 = {
13336
+ var colors6 = {
13159
13337
  text: "#111827",
13160
13338
  surface: "#ffffff",
13161
13339
  borderLight: "#e5e7eb"
13162
13340
  };
13163
- var SeeMoreLinkContainer = styled6.div`
13341
+ var SeeMoreLinkContainer = styled4.div`
13164
13342
  position: relative;
13165
13343
  display: flex;
13166
13344
  align-items: center;
@@ -13169,7 +13347,7 @@ var SeeMoreLinkContainer = styled6.div`
13169
13347
  min-height: 48px;
13170
13348
  padding: 0 16px;
13171
13349
  box-sizing: border-box;
13172
- background: ${colors5.surface};
13350
+ background: ${colors6.surface};
13173
13351
 
13174
13352
  &::before {
13175
13353
  content: '';
@@ -13177,12 +13355,12 @@ var SeeMoreLinkContainer = styled6.div`
13177
13355
  top: 0;
13178
13356
  left: 50%;
13179
13357
  width: 100vw;
13180
- border-top: 1px solid ${colors5.borderLight};
13358
+ border-top: 1px solid ${colors6.borderLight};
13181
13359
  transform: translateX(-50%);
13182
13360
  pointer-events: none;
13183
13361
  }
13184
13362
  `;
13185
- var SeeMoreLinkText = styled6.button`
13363
+ var SeeMoreLinkText = styled4.button`
13186
13364
  width: auto;
13187
13365
  height: auto;
13188
13366
  padding: 8px 0;
@@ -13194,7 +13372,7 @@ var SeeMoreLinkText = styled6.button`
13194
13372
  text-decoration: underline;
13195
13373
  text-underline-offset: 2px;
13196
13374
  cursor: pointer;
13197
- color: ${colors5.text};
13375
+ color: ${colors6.text};
13198
13376
 
13199
13377
  &:hover {
13200
13378
  opacity: 0.8;
@@ -13205,7 +13383,7 @@ var SeeMoreLinkText = styled6.button`
13205
13383
  }
13206
13384
 
13207
13385
  &:focus-visible {
13208
- outline: 2px solid ${colors5.text};
13386
+ outline: 2px solid ${colors6.text};
13209
13387
  outline-offset: 2px;
13210
13388
  border-radius: 4px;
13211
13389
  }
@@ -13252,600 +13430,27 @@ function SeeMoreLink({
13252
13430
  }
13253
13431
  ) });
13254
13432
  }
13255
- var MOBILE_MAX_PX = 1024;
13256
- var colors6 = {
13257
- text: "#111827",
13258
- muted: "#6b7280",
13259
- hover: "#f3f4f6",
13260
- surface: "#ffffff",
13261
- borderLight: "#e5e7eb"
13262
- };
13263
- var SearchSuggestionsPanel = styled6.div`
13264
- position: relative;
13265
- width: 100%;
13266
- margin-top: 8px;
13267
- `;
13268
- var SearchSuggestionsList = styled6.ul`
13269
- display: flex;
13270
- flex-direction: column;
13271
- list-style: none;
13272
- margin: 0;
13273
- padding: 0;
13274
- `;
13275
- var SearchSuggestionOption = styled6.li`
13276
- display: flex;
13277
- align-items: center;
13278
- width: 100%;
13279
- min-height: 58px;
13280
- padding: 4px 24px;
13281
- box-sizing: border-box;
13282
- color: ${colors6.text};
13283
- `;
13284
- var PassiveSuggestionOption = styled6(SearchSuggestionOption)`
13285
- cursor: default;
13286
- color: ${colors6.muted};
13287
- `;
13288
- var AIStatusMessage = styled6.div`
13289
- padding: 12px 24px;
13290
- font-size: 14px;
13291
- font-style: italic;
13292
- color: ${colors6.muted};
13293
- min-height: 44px;
13294
- display: flex;
13295
- align-items: center;
13296
- gap: 4px;
13297
- `;
13298
- var AIStatusCursor = styled6.span`
13299
- display: inline-block;
13300
- width: 2px;
13301
- height: 1em;
13302
- background: currentColor;
13303
- margin-left: 1px;
13304
- vertical-align: text-bottom;
13305
- animation: blink 0.8s step-end infinite;
13306
- @keyframes blink {
13307
- 0%,
13308
- 100% {
13309
- opacity: 1;
13310
- }
13311
- 50% {
13312
- opacity: 0;
13313
- }
13314
- }
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
- `;
13344
- var SuggestionSectionHeading = styled6.div`
13345
- padding: 12px 24px 8px;
13346
- margin-bottom: 4px;
13347
- font-size: 16px;
13348
- font-weight: 700;
13349
- color: ${colors6.text};
13350
- background: ${colors6.surface};
13351
- border-bottom: 1px solid ${colors6.borderLight};
13352
- `;
13353
- var RecentSearchesSection = styled6.section`
13354
- padding: 24px 35px 18px;
13355
- background: ${colors6.surface};
13356
-
13357
- @media (max-width: ${MOBILE_MAX_PX}px) {
13358
- padding: 18px 20px 16px;
13359
- }
13360
- `;
13361
- var RecentSearchesHeader = styled6.div`
13362
- display: flex;
13363
- align-items: center;
13364
- justify-content: space-between;
13365
- gap: 16px;
13366
- margin-bottom: 13px;
13367
- `;
13368
- var RecentSearchesTitle = styled6.h3`
13369
- margin: 0;
13370
- font-size: 16px;
13371
- font-weight: 700;
13372
- color: ${colors6.text};
13373
-
13374
- @media (max-width: ${MOBILE_MAX_PX}px) {
13375
- font-size: 15px;
13376
- line-height: 1.35;
13377
- }
13378
- `;
13379
- var RecentSearchesClearButton = styled6.button`
13380
- margin: 0;
13381
- padding: 0;
13382
- border: none;
13383
- background: transparent;
13384
- color: ${colors6.text};
13385
- font-size: 16px;
13386
- cursor: pointer;
13387
-
13388
- &:focus-visible {
13389
- outline: 2px solid ${colors6.text};
13390
- outline-offset: 2px;
13391
- border-radius: 4px;
13392
- }
13393
-
13394
- @media (max-width: ${MOBILE_MAX_PX}px) {
13395
- font-size: 14px;
13396
- }
13397
- `;
13398
- var RecentSearchesList = styled6.div`
13399
- display: flex;
13400
- flex-wrap: wrap;
13401
- gap: 10px;
13402
- `;
13403
- var RecentSearchChip = styled6.button`
13404
- display: inline-flex;
13405
- align-items: center;
13406
- justify-content: center;
13407
- min-height: 40px;
13408
- padding: 8px 16px;
13409
- border: 1px solid ${colors6.borderLight};
13410
- border-radius: 999px;
13411
- background: ${colors6.surface};
13412
- color: ${colors6.text};
13413
- font-size: 16px;
13414
- cursor: pointer;
13415
-
13416
- &:hover {
13417
- background: ${colors6.hover};
13418
- }
13419
-
13420
- &:focus-visible {
13421
- outline: 2px solid ${colors6.text};
13422
- outline-offset: 2px;
13423
- }
13424
-
13425
- @media (max-width: ${MOBILE_MAX_PX}px) {
13426
- min-height: 36px;
13427
- padding: 6px 14px;
13428
- font-size: 14px;
13429
- border-radius: 10px;
13430
- }
13431
- `;
13432
- var { colors: colors7 } = nuskinTheme;
13433
- var ChatResultRoot = styled6.div`
13434
- display: flex;
13435
- flex-direction: column;
13436
- gap: 1.5rem;
13437
- min-block-size: 0;
13438
- overflow-y: auto;
13439
- padding-block-end: 2rem;
13440
- position: relative;
13441
- `;
13442
- var ProductCarouselWrapper = styled6.div`
13443
- display: flex;
13444
- flex-direction: column;
13445
- gap: 0.75rem;
13446
- `;
13447
- styled6.div`
13448
- display: flex;
13449
- gap: 1rem;
13450
- overflow-x: auto;
13451
- padding-block-end: 0.5rem;
13452
- scroll-snap-type: x mandatory;
13453
- -webkit-overflow-scrolling: touch;
13454
- scrollbar-width: none;
13455
- &::-webkit-scrollbar {
13456
- display: none;
13457
- }
13458
- `;
13459
- styled6.a`
13460
- display: flex;
13461
- flex: 0 0 auto;
13462
- flex-direction: column;
13463
- gap: 0.5rem;
13464
- scroll-snap-align: start;
13465
- text-decoration: none;
13466
- width: 9rem;
13467
- `;
13468
- styled6.img`
13469
- background: ${colors7.primary.gray};
13470
- border-radius: 0.5rem;
13471
- block-size: 9rem;
13472
- inline-size: 9rem;
13473
- object-fit: contain;
13474
- padding: 0.5rem;
13475
- `;
13476
- styled6.span`
13477
- color: ${colors7.primary.black};
13478
- display: -webkit-box;
13479
- font-size: 0.8125rem;
13480
- line-height: 1.4;
13481
- overflow: hidden;
13482
- -webkit-box-orient: vertical;
13483
- -webkit-line-clamp: 2;
13484
- `;
13485
- styled6.span`
13486
- color: ${colors7.neutral[70]};
13487
- font-size: 0.8125rem;
13488
- font-weight: 600;
13489
- `;
13490
- styled6.button`
13491
- align-items: center;
13492
- align-self: center;
13493
- appearance: none;
13494
- background: ${colors7.neutral[30]};
13495
- border: 0;
13496
- border-radius: 50%;
13497
- bottom: 0.75rem;
13498
- color: ${colors7.primary.black};
13499
- cursor: pointer;
13500
- display: inline-flex;
13501
- justify-content: center;
13502
- block-size: 2rem;
13503
- inline-size: 2rem;
13504
- padding: 0;
13505
- position: sticky;
13506
-
13507
- &:hover {
13508
- background: ${colors7.neutral[40]};
13509
- }
13510
- `;
13511
- function isDigit(char) {
13512
- return char !== void 0 && char >= "0" && char <= "9";
13513
- }
13514
- function isLetter(char) {
13515
- if (char === void 0) return false;
13516
- const lower = char.toLowerCase();
13517
- return lower >= "a" && lower <= "z";
13518
- }
13519
- function isPricingSpace(char) {
13520
- return char === " " || char === "\n" || char === "\r" || char === " " || char === "\f";
13521
- }
13522
- function findNumberEnd(text4, start, allowCommas) {
13523
- let cursor = start;
13524
- let hasDigit = false;
13525
- while (cursor < text4.length && (isDigit(text4[cursor]) || allowCommas && text4[cursor] === ",")) {
13526
- hasDigit = hasDigit || isDigit(text4[cursor]);
13527
- cursor += 1;
13528
- }
13529
- if (text4[cursor] === "." && isDigit(text4[cursor + 1])) {
13530
- cursor += 1;
13531
- while (cursor < text4.length && isDigit(text4[cursor])) {
13532
- cursor += 1;
13533
- }
13534
- }
13535
- return hasDigit ? cursor : start;
13536
- }
13537
- function removeCurrencyAmounts(text4) {
13538
- let result = "";
13539
- let cursor = 0;
13540
- while (cursor < text4.length) {
13541
- if (text4[cursor] === "$") {
13542
- const amountEnd = findNumberEnd(text4, cursor + 1, true);
13543
- if (amountEnd > cursor + 1) {
13544
- cursor = amountEnd;
13545
- continue;
13546
- }
13547
- }
13548
- result += text4[cursor];
13549
- cursor += 1;
13550
- }
13551
- return result;
13552
- }
13553
- function removeUnitAmounts(text4, unit) {
13554
- let result = "";
13555
- let cursor = 0;
13556
- while (cursor < text4.length) {
13557
- if (isDigit(text4[cursor])) {
13558
- const numberEnd = findNumberEnd(text4, cursor, false);
13559
- let unitStart = numberEnd;
13560
- while (isPricingSpace(text4[unitStart])) {
13561
- unitStart += 1;
13562
- }
13563
- const unitEnd = unitStart + unit.length;
13564
- if (text4.slice(unitStart, unitEnd).toUpperCase() === unit && !isLetter(text4[unitEnd])) {
13565
- cursor = unitEnd;
13566
- continue;
13567
- }
13568
- }
13569
- result += text4[cursor];
13570
- cursor += 1;
13571
- }
13572
- return result;
13573
- }
13574
- function removeEmptyPricingParentheses(text4) {
13575
- let result = "";
13576
- let cursor = 0;
13577
- while (cursor < text4.length) {
13578
- if (text4[cursor] === "(") {
13579
- const candidateStart = cursor;
13580
- cursor += 1;
13581
- while (isPricingSpace(text4[cursor]) || text4[cursor] === "," || text4[cursor] === ";") {
13582
- cursor += 1;
13583
- }
13584
- if (text4[cursor] === ")") {
13585
- cursor += 1;
13586
- continue;
13587
- }
13588
- result += text4.slice(candidateStart, cursor);
13589
- continue;
13590
- }
13591
- result += text4[cursor];
13592
- cursor += 1;
13593
- }
13594
- return result;
13595
- }
13596
- function normalizePricingSpace(text4) {
13597
- let result = "";
13598
- let previousWasWhitespace = false;
13599
- for (const char of text4) {
13600
- if (isPricingSpace(char)) {
13601
- if (!previousWasWhitespace) {
13602
- result += " ";
13603
- previousWasWhitespace = true;
13604
- }
13605
- continue;
13606
- }
13607
- result += char;
13608
- previousWasWhitespace = false;
13609
- }
13610
- return result.trim();
13611
- }
13612
- function stripPricingText(text4) {
13613
- return normalizePricingSpace(
13614
- removeEmptyPricingParentheses(
13615
- removeUnitAmounts(removeUnitAmounts(removeCurrencyAmounts(text4), "PV"), "CV")
13616
- )
13617
- );
13618
- }
13619
- function toCarouselItem(product, index2, showPricing, history) {
13620
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
13621
- const slotKey = `ai-${(_b = (_a = product.id) != null ? _a : product.sku) != null ? _b : index2}-${index2}`;
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}`;
13623
- if (!productName) {
13624
- return {
13625
- status: "error",
13626
- slotKey,
13627
- productId: String((_h = (_g = product.id) != null ? _g : product.sku) != null ? _h : index2),
13628
- error: {
13629
- code: PRODUCT_CAROUSEL_ERROR_CODES.PRODUCT_NOT_FOUND,
13630
- technicalMessage: "Missing product name"
13631
- }
13632
- };
13633
- }
13634
- const href = (_i = product.url) != null ? _i : "#";
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;
13638
- return {
13639
- status: "ready",
13640
- slotKey,
13641
- productId: String((_n = (_m = product.id) != null ? _m : product.sku) != null ? _n : index2),
13642
- cardProps: {
13643
- mode: "cta",
13644
- title: productName,
13645
- images: imageUrl ? [{ url: imageUrl, alt: productName }] : [],
13646
- productHref: href,
13647
- productAriaLabel: productName,
13648
- price: showPricing ? priceText : void 0,
13649
- addToCartLabel: "View Product",
13650
- addToCartAriaLabel: `View ${productName}`,
13651
- onProductClick: () => {
13652
- if (href === "#") return;
13653
- if (history && typeof history.push === "function") {
13654
- history.push(routeHref);
13655
- }
13656
- }
13657
- }
13658
- };
13659
- }
13660
- function SearchChatResult({
13661
- result,
13662
- showPricing = true,
13663
- history,
13664
- productsAriaLabel = "AI recommended products"
13665
- }) {
13666
- var _a;
13667
- const products = (_a = result.products) != null ? _a : [];
13668
- const carouselItems = products.map((p, i) => toCarouselItem(p, i, showPricing, history));
13669
- const summaryText = showPricing ? result.aiResponseText : stripPricingText(result.aiResponseText);
13670
- return /* @__PURE__ */ jsxs(ChatResultRoot, { "data-testid": "search-chat-result", children: [
13671
- /* @__PURE__ */ jsx(
13672
- SearchMessage,
13673
- {
13674
- sender: SEARCH_MESSAGE_SENDERS.USER,
13675
- text: result.userQuery,
13676
- "data-testid": "chat-user-query"
13677
- }
13678
- ),
13679
- /* @__PURE__ */ jsx(
13680
- SearchMessage,
13681
- {
13682
- sender: SEARCH_MESSAGE_SENDERS.AGENT,
13683
- text: summaryText,
13684
- "data-testid": "chat-ai-response"
13685
- }
13686
- ),
13687
- carouselItems.length > 0 && /* @__PURE__ */ jsx(ProductCarouselWrapper, { "data-testid": "chat-product-carousel", children: /* @__PURE__ */ jsx(ProductCarousel, { items: carouselItems, ariaLabel: productsAriaLabel }) })
13688
- ] });
13689
- }
13690
-
13691
- // src/components/SearchModal/SearchModalConstants.ts
13692
- var DEFAULT_AI_STATUS_LABELS = {
13693
- analyzing: "Analyzing your question...",
13694
- pulling: "Pulling up your analytics...",
13695
- routing: "Routing to specialist agents...",
13696
- thinking: "Thinking..."
13697
- };
13698
- var AI_CONV_KEY = "ai_chat_conversation_id";
13699
- function getSessionConversationId() {
13700
- try {
13701
- const raw = typeof window !== "undefined" ? window.sessionStorage.getItem(AI_CONV_KEY) : null;
13702
- if (!raw) return null;
13703
- const id = Number.parseInt(raw, 10);
13704
- return Number.isNaN(id) ? null : id;
13705
- } catch {
13706
- return null;
13707
- }
13708
- }
13709
- function storeSessionConversationId(id) {
13710
- try {
13711
- if (typeof window !== "undefined") window.sessionStorage.setItem(AI_CONV_KEY, String(id));
13712
- } catch (e) {
13713
- console.error("Error while setting key", e);
13714
- }
13715
- }
13716
- var MAX_RECENT = 6;
13717
- function getAIStatusLabels(copy) {
13718
- var _a, _b, _c, _d;
13719
- return {
13720
- analyzing: (_a = copy == null ? void 0 : copy.analyzing_label) != null ? _a : DEFAULT_AI_STATUS_LABELS.analyzing,
13721
- pulling: (_b = copy == null ? void 0 : copy.pulling_label) != null ? _b : DEFAULT_AI_STATUS_LABELS.pulling,
13722
- routing: (_c = copy == null ? void 0 : copy.routing_label) != null ? _c : DEFAULT_AI_STATUS_LABELS.routing,
13723
- thinking: (_d = copy == null ? void 0 : copy.thinking_label) != null ? _d : DEFAULT_AI_STATUS_LABELS.thinking
13724
- };
13725
- }
13726
- function getAIStatusLabel(text4, aiStatusLabels) {
13727
- const normalizedText = text4.trim().toLowerCase();
13728
- const defaultStatus = Object.entries(DEFAULT_AI_STATUS_LABELS).find(([, label]) => label.toLowerCase() === normalizedText);
13729
- return defaultStatus ? aiStatusLabels[defaultStatus[0]] : text4;
13730
- }
13731
- function getUniqueRecentSearches(entries) {
13732
- return entries.filter(
13733
- (entry, idx, arr) => arr.findIndex(
13734
- (e) => e.query.toLowerCase() === entry.query.toLowerCase()
13735
- ) === idx
13736
- );
13737
- }
13738
- function getProductId(rawId) {
13739
- return typeof rawId === "string" || typeof rawId === "number" ? String(rawId) : JSON.stringify(rawId);
13740
- }
13741
- function getProductName(product, productId) {
13742
- var _a;
13743
- return ((_a = product.name) == null ? void 0 : _a.trim()) || (typeof product.sku === "string" ? product.sku.trim() : "") || `Product ${productId}`;
13744
- }
13745
- function isVoiceSearchState(value) {
13746
- if (!value || typeof value !== "object") return false;
13747
- const candidate = value;
13748
- return typeof candidate.listening === "boolean" && typeof candidate.supported === "boolean" && typeof candidate.start === "function" && typeof candidate.stop === "function";
13749
- }
13750
- function SearchModalChatContent({
13751
- aiChatHistory,
13752
- resolvedShowPricing,
13753
- history,
13754
- chatResultRefs,
13755
- pendingQuery,
13756
- pendingQueryRef,
13757
- aiLoading,
13758
- typedStatus,
13759
- analyzingLabel,
13760
- chatEndRef
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
- }
13767
- return /* @__PURE__ */ jsxs(Fragment, { children: [
13768
- aiChatHistory.map((result, idx) => /* @__PURE__ */ jsx(
13769
- "div",
13770
- {
13771
- ref: (el) => {
13772
- if (el) chatResultRefs.current.set(result.userQuery, el);
13773
- else chatResultRefs.current.delete(result.userQuery);
13774
- },
13775
- style: { marginBottom: "1.5rem" },
13776
- children: /* @__PURE__ */ jsx(
13777
- SearchChatResult,
13778
- {
13779
- result,
13780
- showPricing: resolvedShowPricing,
13781
- history: history != null ? history : null
13782
- }
13783
- )
13784
- },
13785
- `${result.userQuery}-${idx}`
13786
- )),
13787
- pendingQuery && /* @__PURE__ */ jsx("div", { ref: pendingQueryRef, children: /* @__PURE__ */ jsx(SearchMessage, { sender: SEARCH_MESSAGE_SENDERS.USER, text: pendingQuery }) }),
13788
- aiLoading && /* @__PURE__ */ jsxs(AIStatusMessage, { "aria-live": "polite", children: [
13789
- typedStatus || analyzingLabel,
13790
- /* @__PURE__ */ jsx(AIStatusCursor, { "aria-hidden": "true" })
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
- ),
13809
- /* @__PURE__ */ jsx("div", { ref: chatEndRef })
13810
- ] });
13811
- }
13812
- function pushSearchPath(history, path2) {
13813
- if (path2 && path2 !== "action-handled" && path2 !== "action-pending" && history && typeof history.push === "function") {
13814
- history.push(path2);
13815
- }
13816
- }
13817
- function SearchModalSuggestionsContent({
13433
+ function SearchSuggestions({
13818
13434
  listboxId,
13819
13435
  ariaLabel,
13436
+ items,
13820
13437
  loading,
13438
+ showNoResults,
13821
13439
  showDidYouMean,
13440
+ hasMore,
13441
+ query,
13822
13442
  didYouMeanText,
13823
- visibleSuggestions,
13824
- highlightedIndex,
13825
- setHighlightedIndex,
13826
- runSuggestionAction,
13827
- selectOption,
13828
- suggestionRowRefs,
13829
- fallbackImageUrl,
13830
- showNoResults,
13831
13443
  noSuggestionsText,
13832
- showInlineAILoading,
13833
- typedStatus,
13834
- analyzingLabel,
13835
- hasMoreResults,
13836
- footerRef,
13837
- handleSeeMore,
13838
13444
  seeMoreText,
13839
- query,
13840
- showRecentSearches,
13841
- handleClearRecentSearches,
13842
- clearAllLabel,
13843
- showAllRecent,
13844
- recentSearches,
13845
- handleRecentSearchSelect,
13846
- setShowAllRecent
13445
+ fallbackImageUrl,
13446
+ onSelect,
13447
+ onRunAction,
13448
+ onSeeMore
13847
13449
  }) {
13848
- return /* @__PURE__ */ jsxs(SearchSuggestionsPanel, { "data-testid": "autocomplete-suggestions-panel", children: [
13450
+ const [highlightedIndex, setHighlightedIndex] = useState(-1);
13451
+ const footerRef = useRef(null);
13452
+ const suggestionRowRefs = useRef({});
13453
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
13849
13454
  /* @__PURE__ */ jsxs(
13850
13455
  SearchSuggestionsList,
13851
13456
  {
@@ -13855,15 +13460,15 @@ function SearchModalSuggestionsContent({
13855
13460
  "data-testid": "autocomplete-results-list",
13856
13461
  children: [
13857
13462
  showDidYouMean && /* @__PURE__ */ jsx(SuggestionSectionHeading, { "data-testid": "autocomplete-did-you-mean-heading", children: didYouMeanText }),
13858
- !loading && visibleSuggestions.map((option, index2) => /* @__PURE__ */ jsx(
13463
+ !loading && items.map((option, index2) => /* @__PURE__ */ jsx(
13859
13464
  SuggestionRow2,
13860
13465
  {
13861
13466
  inputRef: { current: null },
13862
13467
  isHighlighted: index2 === highlightedIndex,
13863
13468
  isSelected: false,
13864
13469
  onHighlightSuggestion: setHighlightedIndex,
13865
- onRunSuggestionAction: runSuggestionAction,
13866
- onSelectSuggestion: selectOption,
13470
+ onRunSuggestionAction: onRunAction,
13471
+ onSelectSuggestion: onSelect,
13867
13472
  registerSuggestionNode: (node2) => {
13868
13473
  if (node2) suggestionRowRefs.current[option.id] = node2;
13869
13474
  else delete suggestionRowRefs.current[option.id];
@@ -13875,15 +13480,11 @@ function SearchModalSuggestionsContent({
13875
13480
  },
13876
13481
  option.id
13877
13482
  )),
13878
- showNoResults && /* @__PURE__ */ jsx(PassiveSuggestionOption, { "data-highlighted": "false", children: noSuggestionsText }),
13879
- showInlineAILoading && /* @__PURE__ */ jsxs(AIStatusMessage, { "aria-live": "polite", children: [
13880
- typedStatus || analyzingLabel,
13881
- /* @__PURE__ */ jsx(AIStatusCursor, { "aria-hidden": "true" })
13882
- ] })
13483
+ showNoResults && /* @__PURE__ */ jsx(PassiveSuggestionOption, { "data-highlighted": "false", children: noSuggestionsText })
13883
13484
  ]
13884
13485
  }
13885
13486
  ),
13886
- !loading && hasMoreResults && !showDidYouMean && /* @__PURE__ */ jsx(
13487
+ !loading && hasMore && !showDidYouMean && /* @__PURE__ */ jsx(
13887
13488
  SeeMoreLink,
13888
13489
  {
13889
13490
  seeMoreLinkRef: footerRef,
@@ -13893,7 +13494,7 @@ function SearchModalSuggestionsContent({
13893
13494
  },
13894
13495
  onFocusSeeMoreLink: () => {
13895
13496
  },
13896
- onSeeMoreResults: handleSeeMore,
13497
+ onSeeMoreResults: onSeeMore,
13897
13498
  resetSeeMoreLinkFocus: () => {
13898
13499
  },
13899
13500
  restoreLastSuggestion: () => {
@@ -13901,667 +13502,101 @@ function SearchModalSuggestionsContent({
13901
13502
  seeMoreResultsText: seeMoreText,
13902
13503
  searchQuery: query
13903
13504
  }
13904
- ),
13905
- showRecentSearches && /* @__PURE__ */ jsxs(RecentSearchesSection, { "aria-label": "Recent searches", children: [
13906
- /* @__PURE__ */ jsxs(RecentSearchesHeader, { children: [
13907
- /* @__PURE__ */ jsx(RecentSearchesTitle, { children: "Recent searches" }),
13908
- /* @__PURE__ */ jsx(
13909
- RecentSearchesClearButton,
13910
- {
13911
- type: "button",
13912
- onMouseDown: (e) => e.preventDefault(),
13913
- onClick: handleClearRecentSearches,
13914
- children: clearAllLabel
13915
- }
13916
- )
13917
- ] }),
13918
- /* @__PURE__ */ jsxs(RecentSearchesList, { children: [
13919
- (showAllRecent ? recentSearches : recentSearches.slice(0, MAX_RECENT)).map((entry) => /* @__PURE__ */ jsx(
13920
- RecentSearchChip,
13921
- {
13922
- type: "button",
13923
- onMouseDown: (e) => e.preventDefault(),
13924
- onClick: () => handleRecentSearchSelect(entry),
13925
- children: entry.query
13926
- },
13927
- `${entry.query}-${entry.timestamp}`
13928
- )),
13929
- !showAllRecent && recentSearches.length > MAX_RECENT && /* @__PURE__ */ jsxs(
13930
- RecentSearchChip,
13931
- {
13932
- type: "button",
13933
- onMouseDown: (e) => e.preventDefault(),
13934
- onClick: () => setShowAllRecent(true),
13935
- children: [
13936
- "+",
13937
- recentSearches.length - MAX_RECENT,
13938
- " More"
13939
- ]
13940
- }
13941
- )
13942
- ] })
13943
- ] })
13505
+ )
13944
13506
  ] });
13945
13507
  }
13508
+ var SEARCH_MODAL_Z_INDEX = 1e4;
13509
+ var BACKDROP_PROPS = { "data-testid": "search-modal-backdrop" };
13510
+ var SearchModalBackdrop = React.forwardRef(function SearchModalBackdrop2({ open: _open, transitionDuration: _duration, ...rest }, ref) {
13511
+ return /* @__PURE__ */ jsx(SearchModalBackdropRoot, { ref, ...rest });
13512
+ });
13946
13513
  function SearchModal({
13947
13514
  isOpen,
13948
13515
  onClose,
13949
- service,
13950
- history,
13951
- copy = {},
13952
13516
  logo,
13953
13517
  cancelLabel = "Cancel",
13954
13518
  fallbackImageUrl = "",
13955
- enableAIChat = false,
13956
- aiChatConfig,
13957
- gtmContext,
13958
- showPricing = true,
13959
- aiChatHeaderContent
13519
+ copy = {},
13520
+ input,
13521
+ suggestions,
13522
+ recentSearches,
13523
+ agentPanel
13960
13524
  }) {
13961
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
13525
+ var _a, _b, _c, _d, _e, _f, _g, _h;
13962
13526
  const listboxId = useId();
13963
- const footerRef = useRef(null);
13964
- const suggestionRowRefs = useRef({});
13965
- const historyEntries = useSearchHistory().entries;
13966
- const selectHistory = useSearchHistoryStore;
13967
- const historyAddEntry = selectHistory((s) => s.addEntry);
13968
- const historyClearAll = selectHistory((s) => s.clearAll);
13969
- const [legacyRecentSearches, setLegacyRecentSearches] = useState([]);
13970
- const legacyEntries = legacyRecentSearches.map((q) => ({
13971
- query: q,
13972
- isAI: false,
13973
- timestamp: 0
13974
- }));
13975
- const recentSearches = getUniqueRecentSearches(enableAIChat ? historyEntries : legacyEntries);
13976
- const clearRecentSearches = useCallback(() => {
13977
- var _a2;
13978
- if (enableAIChat) {
13979
- historyClearAll();
13980
- setAiChatHistory([]);
13981
- } else {
13982
- (_a2 = service.clearRecentSearches) == null ? void 0 : _a2.call(service);
13983
- setLegacyRecentSearches([]);
13984
- }
13985
- }, [enableAIChat, historyClearAll, service]);
13986
- const [highlightedIndex, setHighlightedIndex] = useState(-1);
13987
- const [aiChatHistory, setAiChatHistory] = useState([]);
13988
- const [pendingQuery, setPendingQuery] = useState("");
13989
- const [aiLoading, setAiLoading] = useState(false);
13990
- const isInChatMode = aiChatHistory.length > 0 || pendingQuery !== "" || aiLoading;
13991
- const [aiStatus, setAiStatus] = useState("");
13992
- const [typedStatus, setTypedStatus] = useState("");
13993
- const [showAllRecent, setShowAllRecent] = useState(false);
13994
- const [highlightedQuery, setHighlightedQuery] = useState(null);
13995
- const chatResultRefs = useRef(/* @__PURE__ */ new Map());
13996
- const pendingQueryRef = useRef(null);
13997
- const aiChatConfigRef = useRef(aiChatConfig);
13998
- aiChatConfigRef.current = aiChatConfig;
13999
- const aiChatHeaderContentRef = useRef(aiChatHeaderContent);
14000
- aiChatHeaderContentRef.current = aiChatHeaderContent;
14001
- const gtmContextRef = useRef(gtmContext);
14002
- gtmContextRef.current = gtmContext;
14003
- const historyEntriesRef = useRef(historyEntries);
14004
- historyEntriesRef.current = historyEntries;
14005
- const chatEndRef = useRef(null);
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
- });
14029
- const {
14030
- didYouMean,
14031
- emptyFetched,
14032
- hasMoreResults,
14033
- hasQuery,
14034
- loading,
14035
- query,
14036
- suggestions,
14037
- updateQuery
14038
- } = searchSuggestions;
14039
- const suggestionFetchFailed = ((_a = searchSuggestions.suggestionFetchFailed) != null ? _a : false) || suggestionsRequestFailed;
14040
- const [searchInputValue, setSearchInputValue] = useState(query);
14041
- const searchInputValueRef = useRef(query);
14042
- const voiceInputBaseValueRef = useRef(query);
14043
- const setSearchInput = useCallback(
14044
- (value, updateVoiceBase = true, resetSuggestionFailure = true) => {
14045
- if (resetSuggestionFailure) {
14046
- setSuggestionsRequestFailed(false);
14047
- }
14048
- searchInputValueRef.current = value;
14049
- if (updateVoiceBase) {
14050
- voiceInputBaseValueRef.current = value;
14051
- }
14052
- setSearchInputValue(value);
14053
- updateQuery(value);
14054
- },
14055
- [updateQuery]
14056
- );
14057
- const getVoiceInputValue = useCallback((value) => {
14058
- const transcript = value.trim();
14059
- if (!transcript) return voiceInputBaseValueRef.current;
14060
- const currentValue = voiceInputBaseValueRef.current.trimEnd();
14061
- return currentValue ? `${currentValue} ${transcript}` : transcript;
14062
- }, []);
14063
- const previewVoiceResult = useCallback(
14064
- (value) => {
14065
- const nextValue = getVoiceInputValue(value);
14066
- if (!nextValue) return;
14067
- searchInputValueRef.current = nextValue;
14068
- setSearchInputValue(nextValue);
14069
- },
14070
- [getVoiceInputValue]
14071
- );
14072
- const appendVoiceResult = useCallback(
14073
- (value) => {
14074
- const nextValue = getVoiceInputValue(value);
14075
- if (!nextValue) return;
14076
- voiceInputBaseValueRef.current = nextValue;
14077
- setSearchInput(nextValue);
14078
- },
14079
- [getVoiceInputValue, setSearchInput]
14080
- );
14081
- useEffect(() => {
14082
- searchInputValueRef.current = query;
14083
- voiceInputBaseValueRef.current = query;
14084
- setSearchInputValue(query);
14085
- }, [query]);
14086
- const hasDidYouMean = didYouMean.length > 0;
14087
- const showDidYouMean = hasDidYouMean && !enableAIChat;
14088
- const visibleSuggestions = enableAIChat ? suggestions : getVisibleSuggestions({ didYouMean, suggestions });
14089
- const safeUseVoiceSearch = useVoiceSearch;
14090
- const voiceSearchRaw = safeUseVoiceSearch({
14091
- onInterimResult: previewVoiceResult,
14092
- onResult: appendVoiceResult
14093
- });
14094
- const voiceSearch = isVoiceSearchState(voiceSearchRaw) ? voiceSearchRaw : null;
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;
14097
- const startVoice = voiceSearch == null ? void 0 : voiceSearch.start;
14098
- const stopVoice = voiceSearch == null ? void 0 : voiceSearch.stop;
14099
- const toggleVoice = useCallback(() => {
14100
- if (voiceListening) {
14101
- stopVoice == null ? void 0 : stopVoice();
14102
- return;
14103
- }
14104
- voiceInputBaseValueRef.current = searchInputValueRef.current.trimEnd();
14105
- startVoice == null ? void 0 : startVoice();
14106
- }, [startVoice, stopVoice, voiceListening]);
14107
- const showPricingFromHeader = ((_e = (_d = aiChatHeaderContentRef.current) == null ? void 0 : _d.configurations) == null ? void 0 : _e.enablepricingpvsv) !== "false";
14108
- const resolvedShowPricing = aiChatHeaderContent ? showPricingFromHeader : showPricing;
14109
- const aiStatusLabels = getAIStatusLabels(copy);
14110
- function voiceSearchProps() {
14111
- var _a2;
14112
- if (!voiceSupported || !startVoice) return {};
14113
- return {
14114
- showVoiceInput: true,
14115
- voiceInputLabel: voiceListening ? "Listening\u2026" : "Search by voice",
14116
- voiceListening,
14117
- voiceListeningLabel: (_a2 = copy == null ? void 0 : copy.listening_label) != null ? _a2 : "Listening...",
14118
- onVoiceInput: toggleVoice
14119
- };
14120
- }
14121
- const buildGtmContext = useCallback(() => {
14122
- var _a2;
14123
- return (_a2 = gtmContextRef.current) != null ? _a2 : {};
14124
- }, []);
14125
- const chatEntryFiredRef = useRef(false);
14126
- useEffect(() => {
14127
- if (!isOpen) {
14128
- chatEntryFiredRef.current = false;
14129
- return;
14130
- }
14131
- if (!enableAIChat || chatEntryFiredRef.current) return;
14132
- chatEntryFiredRef.current = true;
14133
- trackChatEntryPoint(buildGtmContext());
14134
- }, [isOpen, enableAIChat, buildGtmContext]);
14135
- useEffect(() => {
14136
- if (isOpen) return;
14137
- updateQuery("");
14138
- setAiChatHistory([]);
14139
- setPendingQuery("");
14140
- setAiLoading(false);
14141
- setAiStatus("");
14142
- setTypedStatus("");
14143
- setShowAllRecent(false);
14144
- aiRequestCounterRef.current += 1;
14145
- }, [isOpen, updateQuery]);
13527
+ const surfaceRef = useRef(null);
13528
+ const hasAgent = agentPanel != null;
14146
13529
  useEffect(() => {
14147
- if (!aiStatus) {
14148
- setTypedStatus("");
14149
- return;
14150
- }
14151
- let i = 0;
14152
- setTypedStatus("");
14153
- const id = setInterval(() => {
14154
- i += 1;
14155
- setTypedStatus(aiStatus.slice(0, i));
14156
- if (i >= aiStatus.length) clearInterval(id);
14157
- }, 25);
14158
- return () => clearInterval(id);
14159
- }, [aiStatus]);
14160
- useEffect(() => {
14161
- var _a2;
14162
- if (!isInChatMode) return;
14163
- (_a2 = chatEndRef.current) == null ? void 0 : _a2.scrollIntoView({ behavior: "smooth" });
14164
- }, [aiChatHistory.length, isInChatMode]);
14165
- useEffect(() => {
14166
- var _a2;
14167
- if (!pendingQuery) return;
14168
- (_a2 = pendingQueryRef.current) == null ? void 0 : _a2.scrollIntoView({ behavior: "smooth", block: "start" });
14169
- }, [pendingQuery]);
14170
- useEffect(() => {
14171
- if (!highlightedQuery || aiChatHistory.length === 0) return;
14172
- const el = chatResultRefs.current.get(highlightedQuery);
14173
- el == null ? void 0 : el.scrollIntoView({ behavior: "smooth", block: "start" });
14174
- setHighlightedQuery(null);
14175
- }, [highlightedQuery, aiChatHistory]);
14176
- useEffect(() => {
14177
- var _a2, _b2;
14178
- if (enableAIChat || !isOpen) return;
14179
- setLegacyRecentSearches((_b2 = (_a2 = service.getRecentSearches) == null ? void 0 : _a2.call(service)) != null ? _b2 : []);
14180
- }, [enableAIChat, isOpen, service]);
14181
- useEffect(() => {
14182
- if (!isOpen) return void 0;
14183
- const onKeyDown = (e) => {
14184
- if (e.key === "Escape") onClose();
14185
- };
14186
- document.addEventListener("keydown", onKeyDown);
14187
- document.body.style.overflow = "hidden";
14188
- return () => {
14189
- document.removeEventListener("keydown", onKeyDown);
14190
- document.body.style.overflow = "";
14191
- };
14192
- }, [isOpen, onClose]);
14193
- const sendAIMessage = useCallback(
14194
- (queryText) => {
14195
- const config = aiChatConfigRef.current;
14196
- if (!config || !queryText.trim()) return;
14197
- setSearchInput("", true, false);
14198
- setPendingQuery(queryText.trim());
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
- });
14206
- const requestId = aiRequestCounterRef.current;
14207
- const productBasePath = `/${config.market.toLowerCase()}/${config.language.toLowerCase()}/product`;
14208
- const chatService = createChatService({
14209
- conversationsUrl: config.conversationsUrl,
14210
- messagesUrl: config.messagesUrl,
14211
- salesAiAppKey: config.salesAiAppKey,
14212
- salesAiParentOrigin: config.salesAiParentOrigin,
14213
- market: config.market,
14214
- language: config.language
14215
- });
14216
- setAiLoading(true);
14217
- const onChunk = (type, text4) => {
14218
- if (type === "status") setAiStatus(getAIStatusLabel(text4, aiStatusLabels));
14219
- };
14220
- const existingConvId = getSessionConversationId();
14221
- const conversationPromise = existingConvId !== null ? Promise.resolve(existingConvId) : chatService.createConversation("Search Session").then((id) => {
14222
- storeSessionConversationId(id);
14223
- return id;
14224
- });
14225
- conversationPromise.then(
14226
- (conversationId) => {
14227
- if (requestId !== aiRequestCounterRef.current) return Promise.resolve(null);
14228
- return chatService.sendMessage(conversationId, queryText.trim(), onChunk);
14229
- }
14230
- ).then((result) => {
14231
- if (!result || requestId !== aiRequestCounterRef.current) return;
14232
- const products = result.products.map((p, i) => {
14233
- var _a2, _b2;
14234
- const productId = getProductId((_b2 = (_a2 = p.id) != null ? _a2 : p.sku) != null ? _b2 : i);
14235
- const productName = getProductName(p, productId);
14236
- return {
14237
- id: productId,
14238
- sku: p.sku,
14239
- name: String(productName),
14240
- ...p.image_url ? { imageUrl: p.image_url, image_url: p.image_url } : {},
14241
- ...p.pv != null ? { pv: p.pv } : {},
14242
- ...p.retail_price != null ? { retail_price: p.retail_price } : {},
14243
- ...p.description ? { description: p.description } : {},
14244
- ...p.badge ? { badge: p.badge } : {},
14245
- ...p.sku != null ? {
14246
- url: `${productBasePath}/${p.sku}`,
14247
- routeUrl: `/product/${p.sku}`
14248
- } : {}
14249
- };
14250
- });
14251
- setAiStatus("");
14252
- setPendingQuery("");
14253
- const newResult = {
14254
- userQuery: queryText.trim(),
14255
- aiResponseText: result.summary,
14256
- products
14257
- };
14258
- const priorHistory = historyEntriesRef.current.filter((e) => e.isAI && e.aiResult != null).slice().reverse().map((e) => e.aiResult);
14259
- setAiChatHistory([...priorHistory, newResult]);
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
- });
14267
- }).catch(() => {
14268
- setPendingQuery("");
14269
- setAiStatus("");
14270
- trackErrorPopup({
14271
- ...buildGtmContext(),
14272
- searchType: SEARCH_GTM_SEARCH_TYPES.AI_AGENT
14273
- });
14274
- }).finally(() => {
14275
- if (requestId === aiRequestCounterRef.current) setAiLoading(false);
14276
- });
14277
- },
14278
- [aiStatusLabels, historyAddEntry, setSearchInput, buildGtmContext]
14279
- );
14280
- const selectOption = useCallback(
14281
- (option) => {
14282
- var _a2, _b2, _c2, _d2;
14283
- if (isSuggestionDisabled(option)) return;
14284
- const term = String((_b2 = (_a2 = option["value"]) != null ? _a2 : option["label"]) != null ? _b2 : "");
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
- }
14293
- const optionHref = service.getSuggestionHref(option);
14294
- if (optionHref) {
14295
- pushSearchPath(history, optionHref);
14296
- onClose();
14297
- return;
14298
- }
14299
- pushSearchPath(
14300
- history,
14301
- service.submitProductSearch(term, option)
14302
- );
14303
- if (!enableAIChat) setLegacyRecentSearches((_d2 = (_c2 = service.getRecentSearches) == null ? void 0 : _c2.call(service)) != null ? _d2 : []);
14304
- onClose();
14305
- },
14306
- [buildGtmContext, enableAIChat, service, onClose, historyAddEntry, history]
14307
- );
14308
- const runSuggestionAction = useCallback(
14309
- (option) => {
14310
- if (isSuggestionDisabled(option)) return;
14311
- const result = service.activateSuggestionAction(option);
14312
- void Promise.resolve(result).then((path2) => pushSearchPath(history, path2)).catch(() => {
14313
- });
14314
- },
14315
- [history, service]
14316
- );
14317
- const handleRecentSearchSelect = useCallback(
14318
- (entry) => {
13530
+ if (!isOpen || hasAgent) return void 0;
13531
+ const frame = requestAnimationFrame(() => {
14319
13532
  var _a2, _b2;
14320
- if (entry.isAI && entry.aiResult != null) {
14321
- const allAI = historyEntriesRef.current.filter((e) => e.isAI && e.aiResult != null).slice().reverse();
14322
- setAiChatHistory(allAI.map((e) => e.aiResult));
14323
- setHighlightedQuery(entry.query);
14324
- } else {
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
- }
14333
- const url = service.submitProductSearch(entry.query);
14334
- if (url && history && typeof history.push === "function") {
14335
- history.push(url);
14336
- }
14337
- if (!enableAIChat) setLegacyRecentSearches((_b2 = (_a2 = service.getRecentSearches) == null ? void 0 : _a2.call(service)) != null ? _b2 : []);
14338
- onClose();
14339
- }
14340
- },
14341
- [buildGtmContext, enableAIChat, service, onClose, historyAddEntry, history]
14342
- );
14343
- const handleClearRecentSearches = useCallback(() => {
14344
- clearRecentSearches();
14345
- }, [clearRecentSearches]);
14346
- const handleSeeMore = useCallback(() => {
14347
- if (query.trim()) {
14348
- pushSearchPath(history, service.viewMoreResults({ query: query.trim() }));
14349
- }
14350
- }, [history, service, query]);
14351
- const handleSearchSubmit = useCallback(
14352
- (value) => {
14353
- var _a2, _b2;
14354
- if (enableAIChat && suggestionFetchFailed) {
14355
- sendAIMessage(value);
14356
- return;
14357
- }
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
- }
14367
- const url = service.submitProductSearch(value);
14368
- pushSearchPath(history, url);
14369
- if (!enableAIChat) setLegacyRecentSearches((_b2 = (_a2 = service.getRecentSearches) == null ? void 0 : _a2.call(service)) != null ? _b2 : []);
14370
- onClose();
14371
- },
14372
- [
14373
- buildGtmContext,
14374
- enableAIChat,
14375
- history,
14376
- historyAddEntry,
14377
- onClose,
14378
- sendAIMessage,
14379
- service,
14380
- suggestionFetchFailed,
14381
- visibleSuggestions
14382
- ]
14383
- );
14384
- if (!isOpen) return null;
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";
14390
- const showRecentSearches = !hasQuery && !aiLoading && !isInChatMode && recentSearches.length > 0;
14391
- const showNoResults = !isInChatMode && !loading && emptyFetched && visibleSuggestions.length === 0 && !aiLoading;
13533
+ (_b2 = (_a2 = surfaceRef.current) == null ? void 0 : _a2.querySelector("textarea, input")) == null ? void 0 : _b2.focus();
13534
+ });
13535
+ return () => cancelAnimationFrame(frame);
13536
+ }, [isOpen, hasAgent]);
13537
+ const placeholder = (_a = copy.extended_search_textbox_desktop) != null ? _a : "Search";
13538
+ const ariaLabel = (_b = copy.extended_search_box_aria_label) != null ? _b : placeholder;
13539
+ const hasQuery = input.value.trim() !== "";
13540
+ const hasRecentSearches = ((_c = recentSearches == null ? void 0 : recentSearches.items.length) != null ? _c : 0) > 0;
14392
13541
  const searchInput = /* @__PURE__ */ jsx(
14393
13542
  SearchMessageInput,
14394
13543
  {
14395
13544
  inputLabel: ariaLabel,
14396
- onChange: setSearchInput,
14397
- onSubmit: handleSearchSubmit,
13545
+ onChange: input.onChange,
13546
+ onSubmit: input.onSubmit,
14398
13547
  placeholder,
14399
- submitLabel: placeholder,
14400
- value: searchInputValue,
13548
+ value: input.value,
14401
13549
  clearOnSubmit: false,
14402
- "data-testid": "search-modal-input",
14403
- ...voiceSearchProps()
13550
+ "data-testid": "search-modal-input"
14404
13551
  }
14405
13552
  );
14406
- const panelInputProps = isInChatMode ? {
14407
- messageInputProps: {
14408
- inputLabel: ariaLabel,
14409
- onChange: setSearchInput,
14410
- // triggers messages API on Enter / arrow click
14411
- onSubmit: sendAIMessage,
14412
- placeholder,
14413
- submitLabel: placeholder,
14414
- value: searchInputValue,
14415
- clearOnSubmit: true,
14416
- ...voiceSearchProps()
14417
- }
14418
- } : { inputSlot: searchInput };
14419
- return createPortal(
14420
- /* @__PURE__ */ jsx(
14421
- SearchModalOverlay,
14422
- {
14423
- onClick: (e) => {
14424
- if (e.target === e.currentTarget) onClose();
14425
- },
14426
- "data-testid": "search-modal-overlay",
14427
- children: /* @__PURE__ */ jsx(
14428
- SearchPanel,
14429
- {
14430
- "aria-label": ariaLabel,
14431
- closeLabel: cancelLabel,
14432
- onClose,
14433
- logoSlot: logo,
14434
- chatMode: isInChatMode,
14435
- ...panelInputProps,
14436
- children: isInChatMode ? /* @__PURE__ */ jsx(
14437
- SearchModalChatContent,
14438
- {
14439
- aiChatHistory,
14440
- resolvedShowPricing,
14441
- history,
14442
- chatResultRefs,
14443
- pendingQuery,
14444
- pendingQueryRef,
14445
- aiLoading,
14446
- typedStatus,
14447
- analyzingLabel: aiStatusLabels.analyzing,
14448
- chatEndRef
14449
- }
14450
- ) : /* @__PURE__ */ jsx(
14451
- SearchModalSuggestionsContent,
13553
+ return /* @__PURE__ */ jsx(
13554
+ Modal,
13555
+ {
13556
+ open: isOpen,
13557
+ onClose,
13558
+ style: { zIndex: SEARCH_MODAL_Z_INDEX },
13559
+ slots: { backdrop: SearchModalBackdrop },
13560
+ slotProps: { backdrop: BACKDROP_PROPS },
13561
+ "data-testid": "search-modal-overlay",
13562
+ children: /* @__PURE__ */ jsx(SearchModalSurface, { ref: surfaceRef, children: /* @__PURE__ */ jsx(
13563
+ SearchPanel,
13564
+ {
13565
+ role: "dialog",
13566
+ "aria-modal": "true",
13567
+ "aria-label": ariaLabel,
13568
+ closeLabel: cancelLabel,
13569
+ onClose,
13570
+ logoSlot: logo,
13571
+ agentMode: hasAgent,
13572
+ inputSlot: hasAgent ? void 0 : searchInput,
13573
+ children: agentPanel != null ? agentPanel : /* @__PURE__ */ jsxs(SearchSuggestionsPanel, { "data-testid": "autocomplete-suggestions-panel", children: [
13574
+ /* @__PURE__ */ jsx(
13575
+ SearchSuggestions,
14452
13576
  {
13577
+ ...suggestions,
14453
13578
  listboxId,
14454
13579
  ariaLabel,
14455
- loading,
14456
- showDidYouMean,
14457
- didYouMeanText,
14458
- visibleSuggestions,
14459
- highlightedIndex,
14460
- setHighlightedIndex,
14461
- runSuggestionAction,
14462
- selectOption,
14463
- suggestionRowRefs,
14464
- fallbackImageUrl,
14465
- showNoResults,
14466
- noSuggestionsText,
14467
- showInlineAILoading: !isInChatMode && aiLoading,
14468
- typedStatus,
14469
- analyzingLabel: aiStatusLabels.analyzing,
14470
- hasMoreResults,
14471
- footerRef,
14472
- handleSeeMore,
14473
- seeMoreText,
14474
- query,
14475
- showRecentSearches,
14476
- handleClearRecentSearches,
14477
- clearAllLabel: (_k = copy == null ? void 0 : copy.clear_all_label) != null ? _k : "Clear all",
14478
- showAllRecent,
14479
- recentSearches,
14480
- handleRecentSearchSelect,
14481
- setShowAllRecent
13580
+ didYouMeanText: (_d = copy.did_you_mean_text) != null ? _d : "Did You Mean?",
13581
+ noSuggestionsText: (_e = copy.no_suggestions_text) != null ? _e : "No suggestions",
13582
+ seeMoreText: (_f = copy.see_more_results_text) != null ? _f : "See More Results",
13583
+ fallbackImageUrl
13584
+ }
13585
+ ),
13586
+ !hasQuery && recentSearches && hasRecentSearches && /* @__PURE__ */ jsx(
13587
+ RecentSearches,
13588
+ {
13589
+ ...recentSearches,
13590
+ title: (_g = copy.recent_searches_label) != null ? _g : "Recent searches",
13591
+ clearLabel: (_h = copy.clear_all_label) != null ? _h : "Clear all"
14482
13592
  }
14483
13593
  )
14484
- }
14485
- )
14486
- }
14487
- ),
14488
- document.body
13594
+ ] })
13595
+ }
13596
+ ) })
13597
+ }
14489
13598
  );
14490
13599
  }
14491
- async function fetchAIChatHeaderContent(config) {
14492
- const { environment = "prod", country, language } = config;
14493
- if (!country || !language) {
14494
- throw new Error("country and language are required to fetch ai_chat_nuskin_header");
14495
- }
14496
- const stack = getStack(environment);
14497
- const entries = await stack.getSingletonEntries({
14498
- contentTypeUIDs: ["ai_chat_nuskin_header"],
14499
- country: country.toUpperCase(),
14500
- language: language.toLowerCase(),
14501
- camelcase: true
14502
- });
14503
- const [aiChatHeader] = entries;
14504
- return aiChatHeader != null ? aiChatHeader : null;
14505
- }
14506
- function useAIChatHeaderContent(config) {
14507
- const [content3, setContent] = useState(null);
14508
- const [loading, setLoading] = useState(false);
14509
- const [error, setError] = useState(null);
14510
- const country = config == null ? void 0 : config.country;
14511
- const language = config == null ? void 0 : config.language;
14512
- const environment = config == null ? void 0 : config.environment;
14513
- useEffect(() => {
14514
- if (!country || !language) return;
14515
- let cancelled = false;
14516
- setLoading(true);
14517
- setError(null);
14518
- fetchAIChatHeaderContent({
14519
- country,
14520
- language,
14521
- ...environment !== void 0 && { environment }
14522
- }).then((result) => {
14523
- if (!cancelled) setContent(result);
14524
- }).catch((err) => {
14525
- if (!cancelled) setError(err instanceof Error ? err : new Error(String(err)));
14526
- }).finally(() => {
14527
- if (!cancelled) setLoading(false);
14528
- });
14529
- return () => {
14530
- cancelled = true;
14531
- };
14532
- }, [country, language, environment]);
14533
- return { content: content3, loading, error };
14534
- }
14535
- var bounce = keyframes`
14536
- 0%, 60%, 100% {
14537
- transform: translateY(0);
14538
- opacity: 0.4;
14539
- }
14540
- 30% {
14541
- transform: translateY(-6px);
14542
- opacity: 1;
14543
- }
14544
- `;
14545
- var ChatLoadingRoot = styled6.div`
14546
- display: flex;
14547
- align-items: center;
14548
- gap: 6px;
14549
- padding: 10px 4px;
14550
- `;
14551
- var ChatLoadingDot = styled6.span`
14552
- display: block;
14553
- width: 10px;
14554
- height: 10px;
14555
- border-radius: 50%;
14556
- background-color: currentColor;
14557
- opacity: 0.4;
14558
- animation: ${bounce} 1.2s ease-in-out infinite;
14559
- animation-delay: ${({ $delay }) => $delay}ms;
14560
- `;
14561
- var DOTS = [0, 160, 320];
14562
- function ChatLoading({ label = "Loading\u2026", ...props }) {
14563
- return /* @__PURE__ */ jsx(ChatLoadingRoot, { ...props, "aria-label": label, children: DOTS.map((delay) => /* @__PURE__ */ jsx(ChatLoadingDot, { $delay: delay, "aria-hidden": "true" }, delay)) });
14564
- }
14565
13600
  /*! Bundled license information:
14566
13601
 
14567
13602
  is-buffer/index.js:
@@ -14601,6 +13636,6 @@ react-is/cjs/react-is.development.js:
14601
13636
  *)
14602
13637
  */
14603
13638
 
14604
- export { ChatLoading, SEARCH_MESSAGE_SENDERS, SearchChatResult, SearchMessage, SearchMessageInput, SearchModal, SearchPanel, SeeMoreLink, SuggestionRow2 as SuggestionRow, callAICommerceChat, fetchAIChatHeaderContent, getSuggestionDisplayData, useAIChatHeaderContent };
13639
+ export { SEARCH_MESSAGE_SENDERS, SearchMessage, SearchMessageInput, SearchModal, SearchPanel, SeeMoreLink, SuggestionRow2 as SuggestionRow, getSuggestionDisplayData };
14605
13640
  //# sourceMappingURL=index.mjs.map
14606
13641
  //# sourceMappingURL=index.mjs.map