@gobolt/genesis 0.3.5 → 0.3.7

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.cjs CHANGED
@@ -74916,11 +74916,96 @@ const ThinkingIndicator = () => /* @__PURE__ */ jsxRuntime.jsxs(ThinkingDots, {
74916
74916
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dot dot-2" }),
74917
74917
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "dot dot-3" })
74918
74918
  ] });
74919
- const Message$1 = ({ message: message2, handle, isThinking = false }) => {
74919
+ const DataTable = styled.table`
74920
+ width: 100%;
74921
+ border-collapse: collapse;
74922
+ margin-top: 10px;
74923
+ font-size: 14px;
74924
+ `;
74925
+ styled.th`
74926
+ background-color: #f8f9fa;
74927
+ padding: 8px;
74928
+ text-align: left;
74929
+ border-bottom: 1px solid #ddd;
74930
+ font-weight: 600;
74931
+ `;
74932
+ styled.td`
74933
+ padding: 8px;
74934
+ border-bottom: 1px solid #ddd;
74935
+ `;
74936
+ styled.tr`
74937
+ &:hover {
74938
+ background-color: #f5f5f5;
74939
+ }
74940
+ `;
74941
+ const DataContainer = styled.div`
74942
+ margin-top: 10px;
74943
+ `;
74944
+ const Message$1 = ({
74945
+ message: message2,
74946
+ handle,
74947
+ isThinking = false,
74948
+ data
74949
+ }) => {
74920
74950
  const isBot = handle === "bot";
74951
+ const renderData = () => {
74952
+ if (!data || data.length === 0) return null;
74953
+ const isProposalData = (item) => "title" in item && "proposal_json" in item;
74954
+ const isOwnerCountData = (item) => "owner_email" in item && "proposal_count" in item;
74955
+ const isMonthlyCountData = (item) => "creation_month" in item && "proposal_count" in item;
74956
+ if (isProposalData(data[0])) {
74957
+ return /* @__PURE__ */ jsxRuntime.jsx(DataContainer, { children: /* @__PURE__ */ jsxRuntime.jsxs(DataTable, { children: [
74958
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
74959
+ /* @__PURE__ */ jsxRuntime.jsx("th", { children: "Title" }),
74960
+ /* @__PURE__ */ jsxRuntime.jsx("th", { children: "Created At" }),
74961
+ /* @__PURE__ */ jsxRuntime.jsx("th", { children: "Updated At" })
74962
+ ] }) }),
74963
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: data.map((proposal, index2) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
74964
+ /* @__PURE__ */ jsxRuntime.jsx("td", { children: proposal.title }),
74965
+ /* @__PURE__ */ jsxRuntime.jsx("td", { children: new Date(proposal.created_at).toLocaleDateString() }),
74966
+ /* @__PURE__ */ jsxRuntime.jsx("td", { children: new Date(proposal.updated_at).toLocaleDateString() })
74967
+ ] }, proposal.id || index2)) })
74968
+ ] }) });
74969
+ }
74970
+ if (isOwnerCountData(data[0])) {
74971
+ return /* @__PURE__ */ jsxRuntime.jsx(DataContainer, { children: /* @__PURE__ */ jsxRuntime.jsxs(DataTable, { children: [
74972
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
74973
+ /* @__PURE__ */ jsxRuntime.jsx("th", { children: "Owner Email" }),
74974
+ /* @__PURE__ */ jsxRuntime.jsx("th", { children: "Number of Proposals" })
74975
+ ] }) }),
74976
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: data.map((row2, index2) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
74977
+ /* @__PURE__ */ jsxRuntime.jsx("td", { children: row2.owner_email }),
74978
+ /* @__PURE__ */ jsxRuntime.jsx("td", { children: row2.proposal_count })
74979
+ ] }, index2)) })
74980
+ ] }) });
74981
+ }
74982
+ if (isMonthlyCountData(data[0])) {
74983
+ return /* @__PURE__ */ jsxRuntime.jsx(DataContainer, { children: /* @__PURE__ */ jsxRuntime.jsxs(DataTable, { children: [
74984
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
74985
+ /* @__PURE__ */ jsxRuntime.jsx("th", { children: "Month" }),
74986
+ /* @__PURE__ */ jsxRuntime.jsx("th", { children: "Number of Proposals" })
74987
+ ] }) }),
74988
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: data.map((row2, index2) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
74989
+ /* @__PURE__ */ jsxRuntime.jsx("td", { children: new Date(2024, row2.creation_month - 1).toLocaleString(
74990
+ "default",
74991
+ { month: "long" }
74992
+ ) }),
74993
+ /* @__PURE__ */ jsxRuntime.jsx("td", { children: row2.proposal_count })
74994
+ ] }, index2)) })
74995
+ ] }) });
74996
+ }
74997
+ return /* @__PURE__ */ jsxRuntime.jsx(DataContainer, { children: /* @__PURE__ */ jsxRuntime.jsxs(DataTable, { children: [
74998
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsx("tr", { children: Object.keys(data[0]).map((key) => /* @__PURE__ */ jsxRuntime.jsx("th", { children: key }, key)) }) }),
74999
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: data.map((row2, index2) => /* @__PURE__ */ jsxRuntime.jsx("tr", { children: Object.values(row2).map((value2, i) => /* @__PURE__ */ jsxRuntime.jsx("td", { children: JSON.stringify(value2) }, i)) }, index2)) })
75000
+ ] }) });
75001
+ };
74921
75002
  return /* @__PURE__ */ jsxRuntime.jsxs(MessageContainer, { $isBot: isBot, children: [
74922
75003
  /* @__PURE__ */ jsxRuntime.jsx(IconContainer, { children: isBot ? /* @__PURE__ */ jsxRuntime.jsx(BotIcon, {}) : /* @__PURE__ */ jsxRuntime.jsx(UserIcon, {}) }),
74923
- /* @__PURE__ */ jsxRuntime.jsx(TextContainer, { $isBot: isBot, children: isThinking ? /* @__PURE__ */ jsxRuntime.jsx(ThinkingIndicator, {}) : handle === "bot" ? /* @__PURE__ */ jsxRuntime.jsx(Markdown, { children: message2 }) : /* @__PURE__ */ jsxRuntime.jsx(MessageText, { children: message2 }) })
75004
+ /* @__PURE__ */ jsxRuntime.jsx(TextContainer, { $isBot: isBot, children: isThinking || message2 === PROCESSING_MESSAGE ? /* @__PURE__ */ jsxRuntime.jsx(ThinkingIndicator, {}) : handle === "bot" ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
75005
+ /* @__PURE__ */ jsxRuntime.jsx(Markdown, { children: message2 }),
75006
+ data && renderData(),
75007
+ message2 === PROCESSING_MESSAGE && /* @__PURE__ */ jsxRuntime.jsx(ThinkingIndicator, {})
75008
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(MessageText, { children: message2 }) })
74924
75009
  ] });
74925
75010
  };
74926
75011
  const getStateColors = (colors2, type4, state) => {
@@ -75332,69 +75417,484 @@ const Typography = ({
75332
75417
  }
75333
75418
  );
75334
75419
  };
75335
- const ChatContainer = styled.div`
75420
+ const getBackgroundColor = (colors2, disabled2, $variant) => {
75421
+ if ($variant === "simple") return "#F4F4F4";
75422
+ if (disabled2) return "#F4F4F4";
75423
+ return "#fff";
75424
+ };
75425
+ const TriggerWrapper = styled.div`
75336
75426
  display: flex;
75337
- flex-direction: column;
75427
+ align-items: center;
75428
+ justify-content: space-between;
75429
+ cursor: ${({ $disabled }) => $disabled ? "not-allowed" : "pointer"};
75430
+ opacity: ${({ $disabled }) => $disabled ? 0.4 : 1};
75338
75431
  position: relative;
75339
- width: "100%";
75340
- max-width: "800px";
75341
- overflow: hidden;
75432
+ box-shadow: ${({ $variant }) => $variant === "simple" ? "none" : "0px 1px 2px 0px rgba(0, 0, 0, 0.12)"};
75433
+ transition: all 0.2s ease-in-out;
75434
+ min-height: ${({ $variant }) => $variant === "simple" ? "32px" : "40px"};
75435
+
75436
+ &:focus-visible {
75437
+ outline: none;
75438
+ }
75439
+
75440
+ &:focus {
75441
+ box-shadow:
75442
+ 0px 1px 2px 0px rgba(0, 0, 0, 0.12),
75443
+ 0 0 0 3px
75444
+ ${({ theme, $themeType = "primary" }) => theme.colors[$themeType].focussed.ringColor};
75445
+ }
75446
+
75447
+ ${({ $variant, theme, $disabled }) => {
75448
+ var _a;
75449
+ return $variant === "simple" ? `
75450
+ padding: ${theme.sizing.Size1} ${theme.sizing.Size2};
75451
+ background: ${$disabled ? theme.colors.inputs.surface.disabled : "rgba(0, 0, 0, 0.04)"};
75452
+ border: none;
75453
+ border-radius: ${theme.borderRadius.BorderRadiusSm}px;
75454
+ min-height: ${({ $variant: $variant2 }) => $variant2 === "simple" ? "32px" : "40px"};
75455
+
75456
+ &:hover {
75457
+ border: none;
75458
+ }
75459
+ ` : `
75460
+ padding: ${theme.sizing.Size1} ${theme.sizing.Size2};
75461
+ background: ${$disabled ? theme.colors.inputs.surface.disabled : (_a = theme.colors.surface.default) == null ? void 0 : _a.backgroundColor};
75462
+ border: 1px solid #9a9a9a;
75463
+ border-radius: ${theme.borderRadius.BorderRadiusSm}px;
75464
+ min-height: ${({ $variant: $variant2 }) => $variant2 === "simple" ? "32px" : "40px"};
75465
+
75466
+ &:hover {
75467
+ border-color: rgba(0, 0, 0, 0.2);
75468
+ }
75469
+ `;
75470
+ }}
75342
75471
  `;
75343
- const HeroContainer = styled.div`
75472
+ const ValueContainer = styled.div`
75344
75473
  display: flex;
75345
75474
  align-items: center;
75346
- justify-content: center;
75347
- opacity: ${({ $isVisible }) => $isVisible ? 1 : 0};
75348
- transition: opacity 0.3s ease;
75349
- `;
75350
- styled.h1`
75351
- font-family: "Helvetica", "Arial", sans-serif;
75352
- color: teal;
75353
- font-size: 24px;
75354
- text-align: center;
75355
- `;
75356
- const Subtitle = styled.p`
75357
- font-family: "Helvetica", "Arial", sans-serif;
75358
- color: #666;
75359
- font-size: 16px;
75360
- text-align: center;
75361
- `;
75362
- const ErrorMessage = styled(Subtitle)`
75363
- color: red;
75475
+ gap: ${({ theme }) => theme.sizing.Size2}px;
75476
+ flex: 1;
75477
+ padding: 4px 8px;
75364
75478
  `;
75365
- const InputContainer = styled.div`
75479
+ const ChevronContainer = styled.div`
75366
75480
  display: flex;
75367
- justify-content: center;
75368
75481
  align-items: center;
75369
- padding: 8px;
75370
- gap: 8px;
75482
+ justify-content: center;
75483
+ margin-right: ${({ $variant }) => $variant === "simple" ? "4px" : "4px"};
75484
+ margin-left: ${({ $variant }) => $variant === "simple" ? "4px" : "0"};
75371
75485
  `;
75372
- const ChatButton = styled(Button$1)`
75373
- display: flex;
75374
- justify-content: flex-end;
75375
- margin: 16px;
75486
+ const SelectTrigger2 = ({
75487
+ type: type4 = "primary",
75488
+ theme,
75489
+ state,
75490
+ value: value2,
75491
+ placeholder = "Select...",
75492
+ open,
75493
+ onClick,
75494
+ renderValue,
75495
+ options = [],
75496
+ disabled: disabled2 = false,
75497
+ variant = "none"
75498
+ }) => {
75499
+ const handleClick = React.useCallback(() => {
75500
+ if (disabled2) return;
75501
+ onClick == null ? void 0 : onClick();
75502
+ }, [disabled2, onClick]);
75503
+ const displayValue = React.useMemo(() => {
75504
+ if (!value2) return null;
75505
+ if (renderValue) return renderValue(value2);
75506
+ if (Array.isArray(value2)) {
75507
+ if (value2.length === 0) return null;
75508
+ const selectedLabels = value2.map(String).map((v) => {
75509
+ var _a;
75510
+ return (_a = options.find((opt) => opt.value === v)) == null ? void 0 : _a.label;
75511
+ }).filter(Boolean);
75512
+ return selectedLabels.length > 0 ? selectedLabels.join(", ") : `${value2.length} selected`;
75513
+ }
75514
+ const selectedOption = options.find((opt) => opt.value === String(value2));
75515
+ return (selectedOption == null ? void 0 : selectedOption.label) || value2.toString();
75516
+ }, [value2, renderValue, options]);
75517
+ return /* @__PURE__ */ jsxRuntime.jsxs(
75518
+ TriggerWrapper,
75519
+ {
75520
+ $themeType: type4,
75521
+ $state: state,
75522
+ onClick: handleClick,
75523
+ tabIndex: disabled2 ? -1 : 0,
75524
+ role: "button",
75525
+ $disabled: disabled2,
75526
+ $variant: variant,
75527
+ style: {
75528
+ backgroundColor: getBackgroundColor(theme, disabled2, variant)
75529
+ },
75530
+ children: [
75531
+ /* @__PURE__ */ jsxRuntime.jsx(ValueContainer, { $variant: variant, children: displayValue ? /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "body2", color: disabled2 ? "copy-light" : "copy", children: displayValue }) : /* @__PURE__ */ jsxRuntime.jsx(
75532
+ Typography,
75533
+ {
75534
+ variant: "body2",
75535
+ color: disabled2 ? "copy-light" : "copy-light",
75536
+ children: placeholder
75537
+ }
75538
+ ) }),
75539
+ /* @__PURE__ */ jsxRuntime.jsx(ChevronContainer, { $variant: variant, children: /* @__PURE__ */ jsxRuntime.jsx(DropdownChevron, {}) })
75540
+ ]
75541
+ }
75542
+ );
75543
+ };
75544
+ const SelectWrapper = styled.div`
75545
+ position: relative;
75546
+ background-color: transparent;
75547
+ border-radius: 8px;
75548
+ width: auto;
75549
+
75550
+ ${({ $isFocused, theme, type: type4 = "primary" }) => $isFocused && `
75551
+ background-color: transparent;
75552
+ `}
75553
+
75554
+ ${({ disabled: disabled2, theme }) => disabled2 && `
75555
+ cursor: not-allowed;
75556
+
75557
+ &:hover {
75558
+ border-color: ${theme.colors.inputs.surface.border};
75559
+ }
75560
+ `}
75376
75561
  `;
75377
- const MessageList = styled.div`
75562
+ const SelectDropdown = styled.div`
75563
+ padding: 0px;
75564
+ border-radius: 0px;
75565
+ animation-duration: ${({ theme }) => `${theme.motion.veryfast}s`};
75566
+ transition: all ${({ theme }) => `${theme.motion.veryfast}s`}
75567
+ cubic-bezier(0.645, 0.045, 0.355, 1);
75568
+
75569
+ &.entering {
75570
+ opacity: 0;
75571
+ transform: scaleY(0.8);
75572
+ }
75573
+
75574
+ &.entered {
75575
+ opacity: 1;
75576
+ transform: scaleY(1);
75577
+ }
75578
+
75579
+ &.exiting {
75580
+ opacity: 0;
75581
+ transform: scaleY(0.8);
75582
+ }
75583
+ `;
75584
+ const MenuItem = styled.div`
75585
+ padding: 8px 12px;
75586
+ cursor: ${({ disabled: disabled2 }) => disabled2 ? "not-allowed" : "pointer"};
75587
+ background-color: ${({ $isSelected, theme, type: type4 = "primary" }) => $isSelected ? theme.colors[type4].hover.backgroundColor : "transparent"};
75588
+ color: ${({ $isSelected, disabled: disabled2, theme, type: type4 = "primary" }) => disabled2 ? theme.colors.inputs.onsurface.disabled : $isSelected ? theme.colors[type4].hover.color : theme.colors.onsurface.copy};
75378
75589
  display: flex;
75379
- flex-direction: column;
75380
- padding: 16px;
75381
- gap: 8px;
75382
- max-height: 400px;
75383
- overflow-y: auto;
75590
+ justify-content: space-between;
75591
+ align-items: center;
75592
+ transition: all ${({ theme }) => `${theme.motion.veryfast}s`} ease-in-out;
75593
+ opacity: ${({ disabled: disabled2 }) => disabled2 ? 0.5 : 1};
75594
+
75595
+ ${({ disabled: disabled2 }) => !disabled2 && `
75596
+ &:hover {
75597
+ background-color: ${({ $isSelected, theme, type: type4 = "primary" }) => $isSelected ? theme.colors[type4].hover.backgroundColor : "rgba(0, 0, 0, 0.04)"};
75598
+ color: ${({ $isSelected, theme, type: type4 = "primary" }) => $isSelected ? theme.colors[type4].hover.color : theme.colors.onsurface["copy-dark"]};
75599
+ }
75600
+
75601
+ &:active {
75602
+ background-color: ${({ theme, type: type4 = "primary" }) => theme.colors[type4].hover.backgroundColor};
75603
+ color: ${({ theme, type: type4 = "primary" }) => theme.colors[type4].hover.color};
75604
+ }
75605
+ `}
75384
75606
  `;
75385
- const Chat = ({
75386
- socketUrl = "http://localhost:3000",
75387
- isOpen = false,
75388
- messageHistory = [],
75389
- title = null,
75390
- isSimulated = false,
75391
- authToken,
75392
- overrideStyle,
75393
- onChange
75607
+ const Select = ({
75608
+ type: type4 = TYPE.primary,
75609
+ state,
75610
+ variant = "none",
75611
+ defaultValue,
75612
+ onChange,
75613
+ size = "normal",
75614
+ width = "100%",
75615
+ value: value2,
75616
+ options = [],
75617
+ placeholder,
75618
+ selectDisplayMode = "count",
75619
+ isSingleSelect = false,
75620
+ disabled: disabled2 = false,
75621
+ ...rest
75394
75622
  }) => {
75395
- const [isChatOpen, setIsChatOpen] = React.useState(isOpen);
75396
- const [message2, setMessage] = React.useState("");
75397
- const [messages2, setMessages] = React.useState(messageHistory);
75623
+ const [isOpen, setIsOpen] = React.useState(false);
75624
+ const [isFocused, setIsFocused] = React.useState(false);
75625
+ const [dropdownAnimation, setDropdownAnimation] = React.useState("entered");
75626
+ const selectReference = React.useRef(null);
75627
+ const { theme } = useGenesis();
75628
+ React.useEffect(() => {
75629
+ const handleClickOutside = (event) => {
75630
+ if (selectReference.current && !selectReference.current.contains(event.target)) {
75631
+ handleClose();
75632
+ setIsFocused(false);
75633
+ }
75634
+ };
75635
+ if (isOpen) {
75636
+ document.addEventListener("mousedown", handleClickOutside);
75637
+ }
75638
+ return () => {
75639
+ document.removeEventListener("mousedown", handleClickOutside);
75640
+ };
75641
+ }, [isOpen]);
75642
+ const handleClose = () => {
75643
+ setDropdownAnimation("exiting");
75644
+ setTimeout(() => {
75645
+ setIsOpen(false);
75646
+ setDropdownAnimation("entered");
75647
+ }, 200);
75648
+ };
75649
+ const handleTriggerClick = () => {
75650
+ if (disabled2) return;
75651
+ setIsFocused(true);
75652
+ if (isOpen) {
75653
+ handleClose();
75654
+ } else {
75655
+ setIsOpen(true);
75656
+ setDropdownAnimation("entering");
75657
+ setTimeout(() => {
75658
+ setDropdownAnimation("entered");
75659
+ }, 0);
75660
+ }
75661
+ };
75662
+ const handleOptionSelect = (optionValue) => {
75663
+ if (disabled2) return;
75664
+ let newValue;
75665
+ if (Array.isArray(value2)) {
75666
+ const stringValue = value2.map(String);
75667
+ newValue = stringValue.includes(optionValue) ? stringValue.filter((v) => v !== optionValue) : [...stringValue, optionValue];
75668
+ } else {
75669
+ newValue = optionValue;
75670
+ }
75671
+ onChange == null ? void 0 : onChange(newValue);
75672
+ if (isSingleSelect) {
75673
+ handleClose();
75674
+ }
75675
+ };
75676
+ const getSelectModeValue = (value22) => {
75677
+ if (Array.isArray(value22)) {
75678
+ if (selectDisplayMode === "count") {
75679
+ return `${value22.length} selected`;
75680
+ }
75681
+ return value22;
75682
+ }
75683
+ return value22;
75684
+ };
75685
+ const modeValue = getSelectModeValue(value2);
75686
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { position: "relative", width }, children: /* @__PURE__ */ jsxRuntime.jsxs(
75687
+ SelectWrapper,
75688
+ {
75689
+ ref: selectReference,
75690
+ $isFocused: isFocused,
75691
+ type: type4,
75692
+ disabled: disabled2,
75693
+ onFocus: () => !disabled2 && setIsFocused(true),
75694
+ onBlur: () => !isOpen && setIsFocused(false),
75695
+ tabIndex: disabled2 ? -1 : 0,
75696
+ children: [
75697
+ /* @__PURE__ */ jsxRuntime.jsx(
75698
+ SelectTrigger2,
75699
+ {
75700
+ theme,
75701
+ type: type4,
75702
+ state,
75703
+ value: modeValue,
75704
+ placeholder,
75705
+ open: isOpen,
75706
+ onClick: handleTriggerClick,
75707
+ options,
75708
+ disabled: disabled2,
75709
+ variant
75710
+ }
75711
+ ),
75712
+ isOpen && !disabled2 && /* @__PURE__ */ jsxRuntime.jsx(
75713
+ SelectDropdown,
75714
+ {
75715
+ type: type4,
75716
+ state,
75717
+ className: dropdownAnimation,
75718
+ style: {
75719
+ position: "absolute",
75720
+ top: "calc(100% + 4px)",
75721
+ left: 0,
75722
+ right: 0,
75723
+ zIndex: 1e3,
75724
+ backgroundColor: "white",
75725
+ boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)",
75726
+ border: "1px solid #d9d9d9",
75727
+ transformOrigin: "top"
75728
+ },
75729
+ children: options.map((option) => {
75730
+ const isSelected = Array.isArray(value2) ? value2.map(String).includes(option.value) : String(value2) === option.value;
75731
+ return /* @__PURE__ */ jsxRuntime.jsxs(
75732
+ MenuItem,
75733
+ {
75734
+ onClick: () => handleOptionSelect(option.value),
75735
+ $isSelected: isSelected,
75736
+ type: type4,
75737
+ disabled: disabled2,
75738
+ children: [
75739
+ option.label,
75740
+ isSelected && /* @__PURE__ */ jsxRuntime.jsx("span", { style: { marginLeft: "8px" }, children: "✓" })
75741
+ ]
75742
+ },
75743
+ option.value
75744
+ );
75745
+ })
75746
+ }
75747
+ )
75748
+ ]
75749
+ }
75750
+ ) });
75751
+ };
75752
+ const getUniqueMessages = (messages2) => {
75753
+ const uniqueMessages = messages2.filter((msg, index2, self2) => {
75754
+ const duplicates = self2.filter((m) => m.id === msg.id);
75755
+ if (duplicates.length > 1) {
75756
+ if (msg.respondedBy === "ai" || msg.respondedBy === "search") return true;
75757
+ if (msg.isThinking || msg.content === PROCESSING_MESSAGE) {
75758
+ return !duplicates.some(
75759
+ (m) => m.respondedBy === "ai" || m.respondedBy === "search"
75760
+ );
75761
+ }
75762
+ return false;
75763
+ }
75764
+ return true;
75765
+ });
75766
+ return uniqueMessages;
75767
+ };
75768
+ const PROCESSING_MESSAGE = "Processing your query...";
75769
+ const PREDEFINED_QUERIES = [
75770
+ "What are the most recent proposals?",
75771
+ "How many proposals does each owner have?",
75772
+ "Show me all proposals created in the last month",
75773
+ "What are the top 5 most active proposal owners?",
75774
+ "How many proposals were created in each month of this year?"
75775
+ ];
75776
+ const ChatContainer = styled.div`
75777
+ display: flex;
75778
+ flex-direction: column;
75779
+ position: relative;
75780
+ width: "100%";
75781
+ max-width: "800px";
75782
+ //overflow: hidden;
75783
+ `;
75784
+ const HeroContainer = styled.div`
75785
+ display: flex;
75786
+ align-items: center;
75787
+ justify-content: center;
75788
+ opacity: ${({ $isVisible }) => $isVisible ? 1 : 0};
75789
+ transition: opacity 0.3s ease;
75790
+ `;
75791
+ styled.h1`
75792
+ font-family: "Helvetica", "Arial", sans-serif;
75793
+ color: teal;
75794
+ font-size: 24px;
75795
+ text-align: center;
75796
+ `;
75797
+ const Subtitle = styled.p`
75798
+ font-family: "Helvetica", "Arial", sans-serif;
75799
+ color: #666;
75800
+ font-size: 16px;
75801
+ text-align: center;
75802
+ `;
75803
+ const ErrorMessage = styled(Subtitle)`
75804
+ color: red;
75805
+ `;
75806
+ const InputContainer = styled.div`
75807
+ display: flex;
75808
+ justify-content: center;
75809
+ align-items: center;
75810
+ padding: 8px;
75811
+ gap: 8px;
75812
+ `;
75813
+ const ChatButton = styled(Button$1)`
75814
+ display: flex;
75815
+ justify-content: flex-end;
75816
+ margin: 16px;
75817
+ `;
75818
+ const MessageList = styled.div`
75819
+ display: flex;
75820
+ flex-direction: column;
75821
+ padding: 16px;
75822
+ gap: 8px;
75823
+ max-height: 400px;
75824
+ overflow-y: auto;
75825
+ `;
75826
+ const ToggleContainer = styled.div`
75827
+ display: flex;
75828
+ align-items: center;
75829
+ gap: 10px;
75830
+ margin-bottom: 15px;
75831
+ padding: 0 16px;
75832
+ `;
75833
+ const ToggleSwitch = styled.label`
75834
+ position: relative;
75835
+ display: inline-block;
75836
+ width: 60px;
75837
+ height: 34px;
75838
+ `;
75839
+ const ToggleInput = styled.input`
75840
+ opacity: 0;
75841
+ width: 0;
75842
+ height: 0;
75843
+
75844
+ &:checked + span {
75845
+ background-color: teal;
75846
+ }
75847
+
75848
+ &:checked + span:before {
75849
+ transform: translateX(26px);
75850
+ }
75851
+ `;
75852
+ const ToggleSlider = styled.span`
75853
+ position: absolute;
75854
+ cursor: pointer;
75855
+ top: 0;
75856
+ left: 0;
75857
+ right: 0;
75858
+ bottom: 0;
75859
+ background-color: #ccc;
75860
+ transition: 0.4s;
75861
+ border-radius: 34px;
75862
+
75863
+ &:before {
75864
+ position: absolute;
75865
+ content: "";
75866
+ height: 26px;
75867
+ width: 26px;
75868
+ left: 4px;
75869
+ bottom: 4px;
75870
+ background-color: white;
75871
+ transition: 0.4s;
75872
+ border-radius: 50%;
75873
+ }
75874
+ `;
75875
+ const ToggleLabel = styled.span`
75876
+ font-family: "Helvetica", "Arial", sans-serif;
75877
+ color: #666;
75878
+ font-size: 14px;
75879
+ `;
75880
+ styled(Select)`
75881
+ width: 600px;
75882
+ margin-bottom: 8px;
75883
+ margin: 26px;
75884
+ `;
75885
+ const Chat = ({
75886
+ socketUrl = "http://localhost:3000",
75887
+ isOpen = false,
75888
+ messageHistory = [],
75889
+ title = null,
75890
+ isSimulated = false,
75891
+ authToken,
75892
+ overrideStyle,
75893
+ onChange
75894
+ }) => {
75895
+ const [isChatOpen, setIsChatOpen] = React.useState(isOpen);
75896
+ const [message2, setMessage] = React.useState("");
75897
+ const [messages2, setMessages] = React.useState(messageHistory);
75398
75898
  const [serverStatus, setServerStatus] = React.useState("unknown");
75399
75899
  const [serverError, setServerError] = React.useState("");
75400
75900
  const socketRef = React.useRef(null);
@@ -75404,10 +75904,11 @@ const Chat = ({
75404
75904
  const [isLocked, setIsLocked] = React.useState(false);
75405
75905
  const [messageStartTime, setMessageStartTime] = React.useState(null);
75406
75906
  const [currentQuestion, setCurrentQuestion] = React.useState("");
75907
+ const [isDataQueryMode, setIsDataQueryMode] = React.useState(false);
75908
+ const [hasReceivedResponse, setHasReceivedResponse] = React.useState(false);
75909
+ const timeoutRef = React.useRef(null);
75407
75910
  React.useEffect(() => {
75408
75911
  if (isSimulated) return;
75409
- const socketUrlToUse = window.location.hostname === "localhost" && window.location.port === "6006" ? "http://localhost:3000" : socketUrl;
75410
- console.log("Connecting to socket server at:", socketUrlToUse);
75411
75912
  const validateToken = async () => {
75412
75913
  try {
75413
75914
  const response = await fetch(
@@ -75421,7 +75922,7 @@ const Chat = ({
75421
75922
  if (!response.ok) {
75422
75923
  throw new Error("Invalid token");
75423
75924
  }
75424
- socketRef.current = lookup(socketUrlToUse, {
75925
+ socketRef.current = lookup(socketUrl, {
75425
75926
  transports: ["polling", "websocket"],
75426
75927
  reconnection: true,
75427
75928
  reconnectionAttempts: 5,
@@ -75468,27 +75969,46 @@ const Chat = ({
75468
75969
  serverReadyRef.current = true;
75469
75970
  });
75470
75971
  socket.on("message", (newMessage) => {
75972
+ console.log("\n=== Received Message Event ===");
75973
+ console.log("New Message:", newMessage);
75471
75974
  setMessages((prev2) => {
75472
75975
  if (newMessage.sender === "bot") {
75473
- if (newMessage.content === "Processing your message...") {
75976
+ if (newMessage.isThinking) {
75474
75977
  const hasThinkingMessage = prev2.some((msg) => msg.isThinking);
75475
75978
  if (hasThinkingMessage) {
75979
+ console.log("Already have thinking message, skipping");
75476
75980
  return prev2;
75477
75981
  }
75982
+ console.log("Adding thinking message");
75478
75983
  return [...prev2, { ...newMessage, isThinking: true }];
75479
75984
  }
75480
75985
  const thinkingMessage = prev2.find((msg) => msg.isThinking);
75481
75986
  if (thinkingMessage) {
75987
+ console.log("Replacing thinking message with final response");
75988
+ const updatedMessage = {
75989
+ ...newMessage,
75990
+ isThinking: false,
75991
+ content: newMessage.content || newMessage.response || "No response content"
75992
+ };
75482
75993
  return prev2.map(
75483
- (msg) => msg.isThinking ? { ...newMessage, isThinking: false } : msg
75994
+ (msg) => msg.isThinking ? updatedMessage : msg
75484
75995
  );
75485
75996
  }
75486
- return [...prev2, { ...newMessage, isThinking: false }];
75997
+ console.log("Adding new bot message");
75998
+ const messageToAdd = {
75999
+ ...newMessage,
76000
+ isThinking: false,
76001
+ content: newMessage.content || newMessage.response || "No response content"
76002
+ };
76003
+ console.log("messageToAdd", messageToAdd);
76004
+ return [...prev2, messageToAdd];
75487
76005
  }
75488
76006
  const lastUserMsg = [...prev2].reverse().find((msg) => msg.sender === "user");
75489
76007
  if (lastUserMsg && lastUserMsg.content === newMessage.content) {
76008
+ console.log("Duplicate user message, skipping");
75490
76009
  return prev2;
75491
76010
  }
76011
+ console.log("Adding new user message");
75492
76012
  return [...prev2, newMessage];
75493
76013
  });
75494
76014
  setIsLocked(false);
@@ -75519,6 +76039,44 @@ const Chat = ({
75519
76039
  setIsLocked(false);
75520
76040
  }
75521
76041
  }, 2e3);
76042
+ socket.on(
76043
+ "query_data_response",
76044
+ (response2) => {
76045
+ console.log("\n=== Received Query Data Response ===");
76046
+ console.log("Response:", response2);
76047
+ setMessages((prev2) => {
76048
+ const thinkingMessage = prev2.find((msg) => msg.isThinking);
76049
+ if (!thinkingMessage) {
76050
+ console.log("No thinking message found, adding new message");
76051
+ return [
76052
+ ...prev2,
76053
+ {
76054
+ id: `bot_${Date.now()}`,
76055
+ content: response2.error || response2.response,
76056
+ sender: "bot",
76057
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
76058
+ isThinking: false,
76059
+ data: response2.data,
76060
+ respondedBy: "ai"
76061
+ }
76062
+ ];
76063
+ }
76064
+ console.log("Replacing thinking message with response");
76065
+ return prev2.map(
76066
+ (msg) => msg.isThinking ? {
76067
+ id: msg.id,
76068
+ content: response2.error || response2.response,
76069
+ sender: "bot",
76070
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
76071
+ isThinking: false,
76072
+ data: response2.data,
76073
+ respondedBy: "ai"
76074
+ } : msg
76075
+ );
76076
+ });
76077
+ setIsLocked(false);
76078
+ }
76079
+ );
75522
76080
  return () => {
75523
76081
  console.log("Disconnecting socket");
75524
76082
  socket.disconnect();
@@ -75561,13 +76119,14 @@ const Chat = ({
75561
76119
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
75562
76120
  };
75563
76121
  setIsLocked(true);
76122
+ setHasReceivedResponse(false);
75564
76123
  setMessageStartTime(Date.now());
75565
76124
  setCurrentQuestion(message2);
75566
76125
  setMessages((prev2) => [...prev2, userMessage]);
75567
76126
  if ((_a = socketRef.current) == null ? void 0 : _a.connected) {
75568
76127
  const botMessageId = `bot_${timestamp}`;
75569
76128
  const thinkingMessage = {
75570
- content: "",
76129
+ content: PROCESSING_MESSAGE,
75571
76130
  sender: "bot",
75572
76131
  id: botMessageId,
75573
76132
  isThinking: true,
@@ -75580,20 +76139,72 @@ const Chat = ({
75580
76139
  setIsLocked(false);
75581
76140
  return;
75582
76141
  }
75583
- socketRef.current.emit("message", userMessage);
75584
- if (socketRef.current.connected) {
75585
- setTimeout(() => {
75586
- setMessages(
75587
- (prev2) => prev2.map(
75588
- (msg) => msg.isThinking ? { ...msg, content: "Processing your message..." } : msg
75589
- )
75590
- );
75591
- }, 300);
75592
- setTimeout(() => {
75593
- setMessages((prev2) => prev2.filter((msg) => !msg.isThinking));
75594
- setServerError("No response from server");
75595
- setIsLocked(false);
75596
- }, 1e4);
76142
+ if (isDataQueryMode) {
76143
+ socketRef.current.emit(
76144
+ "query_data",
76145
+ { query: message2 },
76146
+ (response) => {
76147
+ console.log("\n=== Query Data Callback Response ===");
76148
+ console.log("Response:", response);
76149
+ if (timeoutRef.current) {
76150
+ clearTimeout(timeoutRef.current);
76151
+ timeoutRef.current = null;
76152
+ }
76153
+ setHasReceivedResponse(true);
76154
+ setMessages((prev2) => {
76155
+ const thinkingMessage = prev2.find((msg) => msg.isThinking);
76156
+ if (!thinkingMessage) {
76157
+ console.log("No thinking message found, adding new message");
76158
+ return [
76159
+ ...prev2,
76160
+ {
76161
+ id: `bot_${Date.now()}`,
76162
+ content: response.error || response.response,
76163
+ sender: "bot",
76164
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
76165
+ isThinking: false,
76166
+ data: response.data,
76167
+ respondedBy: "ai"
76168
+ }
76169
+ ];
76170
+ }
76171
+ console.log("Replacing thinking message with response");
76172
+ return prev2.map(
76173
+ (msg) => msg.isThinking ? {
76174
+ id: msg.id,
76175
+ content: response.error || response.response,
76176
+ sender: "bot",
76177
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
76178
+ isThinking: false,
76179
+ data: response.data,
76180
+ respondedBy: "ai"
76181
+ } : msg
76182
+ );
76183
+ });
76184
+ setIsLocked(false);
76185
+ }
76186
+ );
76187
+ timeoutRef.current = setTimeout(() => {
76188
+ if (!hasReceivedResponse) {
76189
+ setMessages((prev2) => {
76190
+ const thinkingMessage = prev2.find((msg) => msg.isThinking);
76191
+ if (thinkingMessage) {
76192
+ return prev2.map(
76193
+ (msg) => msg.isThinking ? {
76194
+ ...msg,
76195
+ content: "The query is taking longer than expected. Please try again or rephrase your question.",
76196
+ isThinking: false,
76197
+ respondedBy: "ai"
76198
+ } : msg
76199
+ );
76200
+ }
76201
+ return prev2;
76202
+ });
76203
+ setIsLocked(false);
76204
+ }
76205
+ }, 9e4);
76206
+ } else {
76207
+ socketRef.current.emit("message", userMessage);
75597
76208
  }
75598
76209
  setMessage("");
75599
76210
  };
@@ -75629,40 +76240,82 @@ const Chat = ({
75629
76240
  if (serverStatus === "error") {
75630
76241
  return /* @__PURE__ */ jsxRuntime.jsx(ErrorMessage, { children: "Network error" });
75631
76242
  }
75632
- const uniqueMessages = messages2.filter(
75633
- (msg, index2, self2) => index2 === self2.findIndex((t2) => t2.id === msg.id)
75634
- );
76243
+ const uniqueMessages = React.useMemo(() => {
76244
+ return getUniqueMessages(messages2);
76245
+ }, [messages2]);
75635
76246
  console.log("uniqueMessages", uniqueMessages);
75636
- return /* @__PURE__ */ jsxRuntime.jsxs(ChatContainer, { style: overrideStyle || {}, children: [
75637
- /* @__PURE__ */ jsxRuntime.jsx(HeroContainer, { $isVisible: !isChatOpen, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
75638
- title && /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "heading3", children: title }),
75639
- /* @__PURE__ */ jsxRuntime.jsx(Subtitle, { children: "Click the Chat Icon below to begin" }),
76247
+ React.useEffect(() => {
76248
+ return () => {
76249
+ if (timeoutRef.current) {
76250
+ clearTimeout(timeoutRef.current);
76251
+ }
76252
+ };
76253
+ }, []);
76254
+ return /* @__PURE__ */ jsxRuntime.jsxs(ChatContainer, { style: overrideStyle || {}, children: [
76255
+ /* @__PURE__ */ jsxRuntime.jsx(HeroContainer, { $isVisible: !isChatOpen, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
76256
+ title && /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "heading3", children: title }),
76257
+ /* @__PURE__ */ jsxRuntime.jsx(Subtitle, { children: "Click the Chat Icon below to begin" }),
75640
76258
  serverError ? /* @__PURE__ */ jsxRuntime.jsx(ErrorMessage, { children: serverError }) : null
75641
76259
  ] }) }),
75642
76260
  isChatOpen ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
75643
76261
  /* @__PURE__ */ jsxRuntime.jsx(HeroContainer, { $isVisible: true, children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: title ? /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "heading2", children: title }) : null }) }),
76262
+ /* @__PURE__ */ jsxRuntime.jsxs(ToggleContainer, { children: [
76263
+ /* @__PURE__ */ jsxRuntime.jsxs(ToggleSwitch, { children: [
76264
+ /* @__PURE__ */ jsxRuntime.jsx(
76265
+ ToggleInput,
76266
+ {
76267
+ type: "checkbox",
76268
+ checked: isDataQueryMode,
76269
+ onChange: (e2) => setIsDataQueryMode(e2.target.checked)
76270
+ }
76271
+ ),
76272
+ /* @__PURE__ */ jsxRuntime.jsx(ToggleSlider, {})
76273
+ ] }),
76274
+ /* @__PURE__ */ jsxRuntime.jsx(ToggleLabel, { children: isDataQueryMode ? "Data Query Mode" : "Regular Chat" })
76275
+ ] }),
75644
76276
  /* @__PURE__ */ jsxRuntime.jsx(MessageList, { ref: messageListRef, children: uniqueMessages.map((msg) => /* @__PURE__ */ jsxRuntime.jsx(
75645
76277
  Message$1,
75646
76278
  {
75647
76279
  message: msg.content,
75648
76280
  handle: msg.sender,
75649
- isThinking: msg.isThinking
76281
+ isThinking: msg.isThinking,
76282
+ data: msg.data
75650
76283
  },
75651
76284
  msg.id
75652
76285
  )) }),
75653
- /* @__PURE__ */ jsxRuntime.jsxs(InputContainer, { children: [
75654
- /* @__PURE__ */ jsxRuntime.jsx(
75655
- Input2,
76286
+ /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
76287
+ /* @__PURE__ */ jsxRuntime.jsxs(InputContainer, { children: [
76288
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { width: 600 }, children: /* @__PURE__ */ jsxRuntime.jsx(
76289
+ Input2,
76290
+ {
76291
+ type: "text",
76292
+ value: message2,
76293
+ onChange: handleInputChange,
76294
+ onKeyDown: handleKeyDown,
76295
+ placeholder: isDataQueryMode ? "Ask about proposals, views, or chat questions..." : "Type a message...",
76296
+ disabled: isLocked,
76297
+ style: { width: 600 }
76298
+ }
76299
+ ) }),
76300
+ /* @__PURE__ */ jsxRuntime.jsx(Button$1, { onClick: sendMessage, disabled: isLocked, children: "Send" })
76301
+ ] }),
76302
+ isDataQueryMode && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginTop: 8, marginLeft: 8 }, children: /* @__PURE__ */ jsxRuntime.jsx(
76303
+ Select,
75656
76304
  {
75657
- type: "text",
75658
- value: message2,
75659
- onChange: handleInputChange,
75660
- onKeyDown: handleKeyDown,
75661
- placeholder: "Type a message & press Enter or Send",
75662
- disabled: isLocked
76305
+ width: 400,
76306
+ options: PREDEFINED_QUERIES.map((query) => ({
76307
+ label: query,
76308
+ value: query
76309
+ })),
76310
+ placeholder: "Select a predefined query...",
76311
+ onChange: (selected) => {
76312
+ if (selected) {
76313
+ setMessage(selected);
76314
+ }
76315
+ },
76316
+ isSingleSelect: true
75663
76317
  }
75664
- ),
75665
- /* @__PURE__ */ jsxRuntime.jsx(Button$1, { onClick: sendMessage, disabled: isLocked, children: "Send" })
76318
+ ) })
75666
76319
  ] })
75667
76320
  ] }) : /* @__PURE__ */ jsxRuntime.jsx(ChatButton, { onClick: toggleChat, children: "Chat" })
75668
76321
  ] });
@@ -78729,338 +79382,6 @@ const SegmentedControls = ({
78729
79382
  }
78730
79383
  );
78731
79384
  };
78732
- const getBackgroundColor = (colors2, disabled2, $variant) => {
78733
- if ($variant === "simple") return "#F4F4F4";
78734
- if (disabled2) return "#F4F4F4";
78735
- return "#fff";
78736
- };
78737
- const TriggerWrapper = styled.div`
78738
- display: flex;
78739
- align-items: center;
78740
- justify-content: space-between;
78741
- cursor: ${({ $disabled }) => $disabled ? "not-allowed" : "pointer"};
78742
- opacity: ${({ $disabled }) => $disabled ? 0.4 : 1};
78743
- position: relative;
78744
- box-shadow: ${({ $variant }) => $variant === "simple" ? "none" : "0px 1px 2px 0px rgba(0, 0, 0, 0.12)"};
78745
- transition: all 0.2s ease-in-out;
78746
- min-height: ${({ $variant }) => $variant === "simple" ? "32px" : "40px"};
78747
-
78748
- &:focus-visible {
78749
- outline: none;
78750
- }
78751
-
78752
- &:focus {
78753
- box-shadow:
78754
- 0px 1px 2px 0px rgba(0, 0, 0, 0.12),
78755
- 0 0 0 3px
78756
- ${({ theme, $themeType = "primary" }) => theme.colors[$themeType].focussed.ringColor};
78757
- }
78758
-
78759
- ${({ $variant, theme, $disabled }) => {
78760
- var _a;
78761
- return $variant === "simple" ? `
78762
- padding: ${theme.sizing.Size1} ${theme.sizing.Size2};
78763
- background: ${$disabled ? theme.colors.inputs.surface.disabled : "rgba(0, 0, 0, 0.04)"};
78764
- border: none;
78765
- border-radius: ${theme.borderRadius.BorderRadiusSm}px;
78766
- min-height: ${({ $variant: $variant2 }) => $variant2 === "simple" ? "32px" : "40px"};
78767
-
78768
- &:hover {
78769
- border: none;
78770
- }
78771
- ` : `
78772
- padding: ${theme.sizing.Size1} ${theme.sizing.Size2};
78773
- background: ${$disabled ? theme.colors.inputs.surface.disabled : (_a = theme.colors.surface.default) == null ? void 0 : _a.backgroundColor};
78774
- border: 1px solid #9a9a9a;
78775
- border-radius: ${theme.borderRadius.BorderRadiusSm}px;
78776
- min-height: ${({ $variant: $variant2 }) => $variant2 === "simple" ? "32px" : "40px"};
78777
-
78778
- &:hover {
78779
- border-color: rgba(0, 0, 0, 0.2);
78780
- }
78781
- `;
78782
- }}
78783
- `;
78784
- const ValueContainer = styled.div`
78785
- display: flex;
78786
- align-items: center;
78787
- gap: ${({ theme }) => theme.sizing.Size2}px;
78788
- flex: 1;
78789
- padding: 4px 8px;
78790
- `;
78791
- const ChevronContainer = styled.div`
78792
- display: flex;
78793
- align-items: center;
78794
- justify-content: center;
78795
- margin-right: ${({ $variant }) => $variant === "simple" ? "4px" : "4px"};
78796
- margin-left: ${({ $variant }) => $variant === "simple" ? "4px" : "0"};
78797
- `;
78798
- const SelectTrigger2 = ({
78799
- type: type4 = "primary",
78800
- theme,
78801
- state,
78802
- value: value2,
78803
- placeholder = "Select...",
78804
- open,
78805
- onClick,
78806
- renderValue,
78807
- options = [],
78808
- disabled: disabled2 = false,
78809
- variant = "none"
78810
- }) => {
78811
- const handleClick = React.useCallback(() => {
78812
- if (disabled2) return;
78813
- onClick == null ? void 0 : onClick();
78814
- }, [disabled2, onClick]);
78815
- const displayValue = React.useMemo(() => {
78816
- if (!value2) return null;
78817
- if (renderValue) return renderValue(value2);
78818
- if (Array.isArray(value2)) {
78819
- if (value2.length === 0) return null;
78820
- const selectedLabels = value2.map(String).map((v) => {
78821
- var _a;
78822
- return (_a = options.find((opt) => opt.value === v)) == null ? void 0 : _a.label;
78823
- }).filter(Boolean);
78824
- return selectedLabels.length > 0 ? selectedLabels.join(", ") : `${value2.length} selected`;
78825
- }
78826
- const selectedOption = options.find((opt) => opt.value === String(value2));
78827
- return (selectedOption == null ? void 0 : selectedOption.label) || value2.toString();
78828
- }, [value2, renderValue, options]);
78829
- return /* @__PURE__ */ jsxRuntime.jsxs(
78830
- TriggerWrapper,
78831
- {
78832
- $themeType: type4,
78833
- $state: state,
78834
- onClick: handleClick,
78835
- tabIndex: disabled2 ? -1 : 0,
78836
- role: "button",
78837
- $disabled: disabled2,
78838
- $variant: variant,
78839
- style: {
78840
- backgroundColor: getBackgroundColor(theme, disabled2, variant)
78841
- },
78842
- children: [
78843
- /* @__PURE__ */ jsxRuntime.jsx(ValueContainer, { $variant: variant, children: displayValue ? /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "body2", color: disabled2 ? "copy-light" : "copy", children: displayValue }) : /* @__PURE__ */ jsxRuntime.jsx(
78844
- Typography,
78845
- {
78846
- variant: "body2",
78847
- color: disabled2 ? "copy-light" : "copy-light",
78848
- children: placeholder
78849
- }
78850
- ) }),
78851
- /* @__PURE__ */ jsxRuntime.jsx(ChevronContainer, { $variant: variant, children: /* @__PURE__ */ jsxRuntime.jsx(DropdownChevron, {}) })
78852
- ]
78853
- }
78854
- );
78855
- };
78856
- const SelectWrapper = styled.div`
78857
- position: relative;
78858
- background-color: transparent;
78859
- border-radius: 8px;
78860
- width: auto;
78861
-
78862
- ${({ $isFocused, theme, type: type4 = "primary" }) => $isFocused && `
78863
- background-color: transparent;
78864
- `}
78865
-
78866
- ${({ disabled: disabled2, theme }) => disabled2 && `
78867
- cursor: not-allowed;
78868
-
78869
- &:hover {
78870
- border-color: ${theme.colors.inputs.surface.border};
78871
- }
78872
- `}
78873
- `;
78874
- const SelectDropdown = styled.div`
78875
- padding: 0px;
78876
- border-radius: 0px;
78877
- animation-duration: ${({ theme }) => `${theme.motion.veryfast}s`};
78878
- transition: all ${({ theme }) => `${theme.motion.veryfast}s`}
78879
- cubic-bezier(0.645, 0.045, 0.355, 1);
78880
-
78881
- &.entering {
78882
- opacity: 0;
78883
- transform: scaleY(0.8);
78884
- }
78885
-
78886
- &.entered {
78887
- opacity: 1;
78888
- transform: scaleY(1);
78889
- }
78890
-
78891
- &.exiting {
78892
- opacity: 0;
78893
- transform: scaleY(0.8);
78894
- }
78895
- `;
78896
- const MenuItem = styled.div`
78897
- padding: 8px 12px;
78898
- cursor: ${({ disabled: disabled2 }) => disabled2 ? "not-allowed" : "pointer"};
78899
- background-color: ${({ $isSelected, theme, type: type4 = "primary" }) => $isSelected ? theme.colors[type4].hover.backgroundColor : "transparent"};
78900
- color: ${({ $isSelected, disabled: disabled2, theme, type: type4 = "primary" }) => disabled2 ? theme.colors.inputs.onsurface.disabled : $isSelected ? theme.colors[type4].hover.color : theme.colors.onsurface.copy};
78901
- display: flex;
78902
- justify-content: space-between;
78903
- align-items: center;
78904
- transition: all ${({ theme }) => `${theme.motion.veryfast}s`} ease-in-out;
78905
- opacity: ${({ disabled: disabled2 }) => disabled2 ? 0.5 : 1};
78906
-
78907
- ${({ disabled: disabled2 }) => !disabled2 && `
78908
- &:hover {
78909
- background-color: ${({ $isSelected, theme, type: type4 = "primary" }) => $isSelected ? theme.colors[type4].hover.backgroundColor : "rgba(0, 0, 0, 0.04)"};
78910
- color: ${({ $isSelected, theme, type: type4 = "primary" }) => $isSelected ? theme.colors[type4].hover.color : theme.colors.onsurface["copy-dark"]};
78911
- }
78912
-
78913
- &:active {
78914
- background-color: ${({ theme, type: type4 = "primary" }) => theme.colors[type4].hover.backgroundColor};
78915
- color: ${({ theme, type: type4 = "primary" }) => theme.colors[type4].hover.color};
78916
- }
78917
- `}
78918
- `;
78919
- const Select = ({
78920
- type: type4 = TYPE.primary,
78921
- state,
78922
- variant = "none",
78923
- defaultValue,
78924
- onChange,
78925
- size = "normal",
78926
- width = "100%",
78927
- value: value2,
78928
- options = [],
78929
- placeholder,
78930
- selectDisplayMode = "count",
78931
- isSingleSelect = false,
78932
- disabled: disabled2 = false,
78933
- ...rest
78934
- }) => {
78935
- const [isOpen, setIsOpen] = React.useState(false);
78936
- const [isFocused, setIsFocused] = React.useState(false);
78937
- const [dropdownAnimation, setDropdownAnimation] = React.useState("entered");
78938
- const selectReference = React.useRef(null);
78939
- const { theme } = useGenesis();
78940
- React.useEffect(() => {
78941
- const handleClickOutside = (event) => {
78942
- if (selectReference.current && !selectReference.current.contains(event.target)) {
78943
- handleClose();
78944
- setIsFocused(false);
78945
- }
78946
- };
78947
- if (isOpen) {
78948
- document.addEventListener("mousedown", handleClickOutside);
78949
- }
78950
- return () => {
78951
- document.removeEventListener("mousedown", handleClickOutside);
78952
- };
78953
- }, [isOpen]);
78954
- const handleClose = () => {
78955
- setDropdownAnimation("exiting");
78956
- setTimeout(() => {
78957
- setIsOpen(false);
78958
- setDropdownAnimation("entered");
78959
- }, 200);
78960
- };
78961
- const handleTriggerClick = () => {
78962
- if (disabled2) return;
78963
- setIsFocused(true);
78964
- if (isOpen) {
78965
- handleClose();
78966
- } else {
78967
- setIsOpen(true);
78968
- setDropdownAnimation("entering");
78969
- setTimeout(() => {
78970
- setDropdownAnimation("entered");
78971
- }, 0);
78972
- }
78973
- };
78974
- const handleOptionSelect = (optionValue) => {
78975
- if (disabled2) return;
78976
- let newValue;
78977
- if (Array.isArray(value2)) {
78978
- const stringValue = value2.map(String);
78979
- newValue = stringValue.includes(optionValue) ? stringValue.filter((v) => v !== optionValue) : [...stringValue, optionValue];
78980
- } else {
78981
- newValue = optionValue;
78982
- }
78983
- onChange == null ? void 0 : onChange(newValue);
78984
- if (isSingleSelect) {
78985
- handleClose();
78986
- }
78987
- };
78988
- const getSelectModeValue = (value22) => {
78989
- if (Array.isArray(value22)) {
78990
- if (selectDisplayMode === "count") {
78991
- return `${value22.length} selected`;
78992
- }
78993
- return value22;
78994
- }
78995
- return value22;
78996
- };
78997
- const modeValue = getSelectModeValue(value2);
78998
- return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { position: "relative", width }, children: /* @__PURE__ */ jsxRuntime.jsxs(
78999
- SelectWrapper,
79000
- {
79001
- ref: selectReference,
79002
- $isFocused: isFocused,
79003
- type: type4,
79004
- disabled: disabled2,
79005
- onFocus: () => !disabled2 && setIsFocused(true),
79006
- onBlur: () => !isOpen && setIsFocused(false),
79007
- tabIndex: disabled2 ? -1 : 0,
79008
- children: [
79009
- /* @__PURE__ */ jsxRuntime.jsx(
79010
- SelectTrigger2,
79011
- {
79012
- theme,
79013
- type: type4,
79014
- state,
79015
- value: modeValue,
79016
- placeholder,
79017
- open: isOpen,
79018
- onClick: handleTriggerClick,
79019
- options,
79020
- disabled: disabled2,
79021
- variant
79022
- }
79023
- ),
79024
- isOpen && !disabled2 && /* @__PURE__ */ jsxRuntime.jsx(
79025
- SelectDropdown,
79026
- {
79027
- type: type4,
79028
- state,
79029
- className: dropdownAnimation,
79030
- style: {
79031
- position: "absolute",
79032
- top: "calc(100% + 4px)",
79033
- left: 0,
79034
- right: 0,
79035
- zIndex: 1e3,
79036
- backgroundColor: "white",
79037
- boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)",
79038
- border: "1px solid #d9d9d9",
79039
- transformOrigin: "top"
79040
- },
79041
- children: options.map((option) => {
79042
- const isSelected = Array.isArray(value2) ? value2.map(String).includes(option.value) : String(value2) === option.value;
79043
- return /* @__PURE__ */ jsxRuntime.jsxs(
79044
- MenuItem,
79045
- {
79046
- onClick: () => handleOptionSelect(option.value),
79047
- $isSelected: isSelected,
79048
- type: type4,
79049
- disabled: disabled2,
79050
- children: [
79051
- option.label,
79052
- isSelected && /* @__PURE__ */ jsxRuntime.jsx("span", { style: { marginLeft: "8px" }, children: "✓" })
79053
- ]
79054
- },
79055
- option.value
79056
- );
79057
- })
79058
- }
79059
- )
79060
- ]
79061
- }
79062
- ) });
79063
- };
79064
79385
  const Circle2 = ({ fill = "#CF3237", dataTestId }) => /* @__PURE__ */ jsxRuntime.jsx(
79065
79386
  "svg",
79066
79387
  {