@gobolt/genesis 0.3.5 → 0.3.6

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,468 @@ 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 PROCESSING_MESSAGE = "Processing your query...";
75753
+ const PREDEFINED_QUERIES = [
75754
+ "What are the most recent proposals?",
75755
+ "How many proposals does each owner have?",
75756
+ "Show me all proposals created in the last month",
75757
+ "What are the top 5 most active proposal owners?",
75758
+ "How many proposals were created in each month of this year?"
75759
+ ];
75760
+ const ChatContainer = styled.div`
75761
+ display: flex;
75762
+ flex-direction: column;
75763
+ position: relative;
75764
+ width: "100%";
75765
+ max-width: "800px";
75766
+ //overflow: hidden;
75767
+ `;
75768
+ const HeroContainer = styled.div`
75769
+ display: flex;
75770
+ align-items: center;
75771
+ justify-content: center;
75772
+ opacity: ${({ $isVisible }) => $isVisible ? 1 : 0};
75773
+ transition: opacity 0.3s ease;
75774
+ `;
75775
+ styled.h1`
75776
+ font-family: "Helvetica", "Arial", sans-serif;
75777
+ color: teal;
75778
+ font-size: 24px;
75779
+ text-align: center;
75780
+ `;
75781
+ const Subtitle = styled.p`
75782
+ font-family: "Helvetica", "Arial", sans-serif;
75783
+ color: #666;
75784
+ font-size: 16px;
75785
+ text-align: center;
75786
+ `;
75787
+ const ErrorMessage = styled(Subtitle)`
75788
+ color: red;
75789
+ `;
75790
+ const InputContainer = styled.div`
75791
+ display: flex;
75792
+ justify-content: center;
75793
+ align-items: center;
75794
+ padding: 8px;
75795
+ gap: 8px;
75796
+ `;
75797
+ const ChatButton = styled(Button$1)`
75798
+ display: flex;
75799
+ justify-content: flex-end;
75800
+ margin: 16px;
75801
+ `;
75802
+ const MessageList = styled.div`
75803
+ display: flex;
75804
+ flex-direction: column;
75805
+ padding: 16px;
75806
+ gap: 8px;
75807
+ max-height: 400px;
75808
+ overflow-y: auto;
75809
+ `;
75810
+ const ToggleContainer = styled.div`
75811
+ display: flex;
75812
+ align-items: center;
75813
+ gap: 10px;
75814
+ margin-bottom: 15px;
75815
+ padding: 0 16px;
75816
+ `;
75817
+ const ToggleSwitch = styled.label`
75818
+ position: relative;
75819
+ display: inline-block;
75820
+ width: 60px;
75821
+ height: 34px;
75822
+ `;
75823
+ const ToggleInput = styled.input`
75824
+ opacity: 0;
75825
+ width: 0;
75826
+ height: 0;
75827
+
75828
+ &:checked + span {
75829
+ background-color: teal;
75830
+ }
75831
+
75832
+ &:checked + span:before {
75833
+ transform: translateX(26px);
75834
+ }
75835
+ `;
75836
+ const ToggleSlider = styled.span`
75837
+ position: absolute;
75838
+ cursor: pointer;
75839
+ top: 0;
75840
+ left: 0;
75841
+ right: 0;
75842
+ bottom: 0;
75843
+ background-color: #ccc;
75844
+ transition: 0.4s;
75845
+ border-radius: 34px;
75846
+
75847
+ &:before {
75848
+ position: absolute;
75849
+ content: "";
75850
+ height: 26px;
75851
+ width: 26px;
75852
+ left: 4px;
75853
+ bottom: 4px;
75854
+ background-color: white;
75855
+ transition: 0.4s;
75856
+ border-radius: 50%;
75857
+ }
75858
+ `;
75859
+ const ToggleLabel = styled.span`
75860
+ font-family: "Helvetica", "Arial", sans-serif;
75861
+ color: #666;
75862
+ font-size: 14px;
75863
+ `;
75864
+ styled(Select)`
75865
+ width: 600px;
75866
+ margin-bottom: 8px;
75867
+ margin: 26px;
75868
+ `;
75869
+ const Chat = ({
75870
+ socketUrl = "http://localhost:3000",
75871
+ isOpen = false,
75872
+ messageHistory = [],
75873
+ title = null,
75874
+ isSimulated = false,
75875
+ authToken,
75876
+ overrideStyle,
75877
+ onChange
75878
+ }) => {
75879
+ const [isChatOpen, setIsChatOpen] = React.useState(isOpen);
75880
+ const [message2, setMessage] = React.useState("");
75881
+ const [messages2, setMessages] = React.useState(messageHistory);
75398
75882
  const [serverStatus, setServerStatus] = React.useState("unknown");
75399
75883
  const [serverError, setServerError] = React.useState("");
75400
75884
  const socketRef = React.useRef(null);
@@ -75404,6 +75888,9 @@ const Chat = ({
75404
75888
  const [isLocked, setIsLocked] = React.useState(false);
75405
75889
  const [messageStartTime, setMessageStartTime] = React.useState(null);
75406
75890
  const [currentQuestion, setCurrentQuestion] = React.useState("");
75891
+ const [isDataQueryMode, setIsDataQueryMode] = React.useState(false);
75892
+ const [hasReceivedResponse, setHasReceivedResponse] = React.useState(false);
75893
+ const timeoutRef = React.useRef(null);
75407
75894
  React.useEffect(() => {
75408
75895
  if (isSimulated) return;
75409
75896
  const socketUrlToUse = window.location.hostname === "localhost" && window.location.port === "6006" ? "http://localhost:3000" : socketUrl;
@@ -75468,27 +75955,46 @@ const Chat = ({
75468
75955
  serverReadyRef.current = true;
75469
75956
  });
75470
75957
  socket.on("message", (newMessage) => {
75958
+ console.log("\n=== Received Message Event ===");
75959
+ console.log("New Message:", newMessage);
75471
75960
  setMessages((prev2) => {
75472
75961
  if (newMessage.sender === "bot") {
75473
- if (newMessage.content === "Processing your message...") {
75962
+ if (newMessage.isThinking) {
75474
75963
  const hasThinkingMessage = prev2.some((msg) => msg.isThinking);
75475
75964
  if (hasThinkingMessage) {
75965
+ console.log("Already have thinking message, skipping");
75476
75966
  return prev2;
75477
75967
  }
75968
+ console.log("Adding thinking message");
75478
75969
  return [...prev2, { ...newMessage, isThinking: true }];
75479
75970
  }
75480
75971
  const thinkingMessage = prev2.find((msg) => msg.isThinking);
75481
75972
  if (thinkingMessage) {
75973
+ console.log("Replacing thinking message with final response");
75974
+ const updatedMessage = {
75975
+ ...newMessage,
75976
+ isThinking: false,
75977
+ content: newMessage.content || newMessage.response || "No response content"
75978
+ };
75482
75979
  return prev2.map(
75483
- (msg) => msg.isThinking ? { ...newMessage, isThinking: false } : msg
75980
+ (msg) => msg.isThinking ? updatedMessage : msg
75484
75981
  );
75485
75982
  }
75486
- return [...prev2, { ...newMessage, isThinking: false }];
75983
+ console.log("Adding new bot message");
75984
+ const messageToAdd = {
75985
+ ...newMessage,
75986
+ isThinking: false,
75987
+ content: newMessage.content || newMessage.response || "No response content"
75988
+ };
75989
+ console.log("messageToAdd", messageToAdd);
75990
+ return [...prev2, messageToAdd];
75487
75991
  }
75488
75992
  const lastUserMsg = [...prev2].reverse().find((msg) => msg.sender === "user");
75489
75993
  if (lastUserMsg && lastUserMsg.content === newMessage.content) {
75994
+ console.log("Duplicate user message, skipping");
75490
75995
  return prev2;
75491
75996
  }
75997
+ console.log("Adding new user message");
75492
75998
  return [...prev2, newMessage];
75493
75999
  });
75494
76000
  setIsLocked(false);
@@ -75519,6 +76025,44 @@ const Chat = ({
75519
76025
  setIsLocked(false);
75520
76026
  }
75521
76027
  }, 2e3);
76028
+ socket.on(
76029
+ "query_data_response",
76030
+ (response2) => {
76031
+ console.log("\n=== Received Query Data Response ===");
76032
+ console.log("Response:", response2);
76033
+ setMessages((prev2) => {
76034
+ const thinkingMessage = prev2.find((msg) => msg.isThinking);
76035
+ if (!thinkingMessage) {
76036
+ console.log("No thinking message found, adding new message");
76037
+ return [
76038
+ ...prev2,
76039
+ {
76040
+ id: `bot_${Date.now()}`,
76041
+ content: response2.error || response2.response,
76042
+ sender: "bot",
76043
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
76044
+ isThinking: false,
76045
+ data: response2.data,
76046
+ respondedBy: "ai"
76047
+ }
76048
+ ];
76049
+ }
76050
+ console.log("Replacing thinking message with response");
76051
+ return prev2.map(
76052
+ (msg) => msg.isThinking ? {
76053
+ id: msg.id,
76054
+ content: response2.error || response2.response,
76055
+ sender: "bot",
76056
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
76057
+ isThinking: false,
76058
+ data: response2.data,
76059
+ respondedBy: "ai"
76060
+ } : msg
76061
+ );
76062
+ });
76063
+ setIsLocked(false);
76064
+ }
76065
+ );
75522
76066
  return () => {
75523
76067
  console.log("Disconnecting socket");
75524
76068
  socket.disconnect();
@@ -75561,13 +76105,14 @@ const Chat = ({
75561
76105
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
75562
76106
  };
75563
76107
  setIsLocked(true);
76108
+ setHasReceivedResponse(false);
75564
76109
  setMessageStartTime(Date.now());
75565
76110
  setCurrentQuestion(message2);
75566
76111
  setMessages((prev2) => [...prev2, userMessage]);
75567
76112
  if ((_a = socketRef.current) == null ? void 0 : _a.connected) {
75568
76113
  const botMessageId = `bot_${timestamp}`;
75569
76114
  const thinkingMessage = {
75570
- content: "",
76115
+ content: PROCESSING_MESSAGE,
75571
76116
  sender: "bot",
75572
76117
  id: botMessageId,
75573
76118
  isThinking: true,
@@ -75580,20 +76125,72 @@ const Chat = ({
75580
76125
  setIsLocked(false);
75581
76126
  return;
75582
76127
  }
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);
76128
+ if (isDataQueryMode) {
76129
+ socketRef.current.emit(
76130
+ "query_data",
76131
+ { query: message2 },
76132
+ (response) => {
76133
+ console.log("\n=== Query Data Callback Response ===");
76134
+ console.log("Response:", response);
76135
+ if (timeoutRef.current) {
76136
+ clearTimeout(timeoutRef.current);
76137
+ timeoutRef.current = null;
76138
+ }
76139
+ setHasReceivedResponse(true);
76140
+ setMessages((prev2) => {
76141
+ const thinkingMessage = prev2.find((msg) => msg.isThinking);
76142
+ if (!thinkingMessage) {
76143
+ console.log("No thinking message found, adding new message");
76144
+ return [
76145
+ ...prev2,
76146
+ {
76147
+ id: `bot_${Date.now()}`,
76148
+ content: response.error || response.response,
76149
+ sender: "bot",
76150
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
76151
+ isThinking: false,
76152
+ data: response.data,
76153
+ respondedBy: "ai"
76154
+ }
76155
+ ];
76156
+ }
76157
+ console.log("Replacing thinking message with response");
76158
+ return prev2.map(
76159
+ (msg) => msg.isThinking ? {
76160
+ id: msg.id,
76161
+ content: response.error || response.response,
76162
+ sender: "bot",
76163
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
76164
+ isThinking: false,
76165
+ data: response.data,
76166
+ respondedBy: "ai"
76167
+ } : msg
76168
+ );
76169
+ });
76170
+ setIsLocked(false);
76171
+ }
76172
+ );
76173
+ timeoutRef.current = setTimeout(() => {
76174
+ if (!hasReceivedResponse) {
76175
+ setMessages((prev2) => {
76176
+ const thinkingMessage = prev2.find((msg) => msg.isThinking);
76177
+ if (thinkingMessage) {
76178
+ return prev2.map(
76179
+ (msg) => msg.isThinking ? {
76180
+ ...msg,
76181
+ content: "The query is taking longer than expected. Please try again or rephrase your question.",
76182
+ isThinking: false,
76183
+ respondedBy: "ai"
76184
+ } : msg
76185
+ );
76186
+ }
76187
+ return prev2;
76188
+ });
76189
+ setIsLocked(false);
76190
+ }
76191
+ }, 9e4);
76192
+ } else {
76193
+ socketRef.current.emit("message", userMessage);
75597
76194
  }
75598
76195
  setMessage("");
75599
76196
  };
@@ -75629,10 +76226,28 @@ const Chat = ({
75629
76226
  if (serverStatus === "error") {
75630
76227
  return /* @__PURE__ */ jsxRuntime.jsx(ErrorMessage, { children: "Network error" });
75631
76228
  }
75632
- const uniqueMessages = messages2.filter(
75633
- (msg, index2, self2) => index2 === self2.findIndex((t2) => t2.id === msg.id)
75634
- );
76229
+ const uniqueMessages = messages2.filter((msg, index2, self2) => {
76230
+ const duplicates = self2.filter((m) => m.id === msg.id);
76231
+ if (duplicates.length > 1) {
76232
+ if (msg.respondedBy === "ai" || msg.respondedBy === "search") return true;
76233
+ if (msg.isThinking || msg.content === PROCESSING_MESSAGE) {
76234
+ return !duplicates.some(
76235
+ (m) => m.respondedBy === "ai" || m.respondedBy === "search"
76236
+ );
76237
+ }
76238
+ return false;
76239
+ }
76240
+ return true;
76241
+ });
75635
76242
  console.log("uniqueMessages", uniqueMessages);
76243
+ console.log("messages", messages2);
76244
+ React.useEffect(() => {
76245
+ return () => {
76246
+ if (timeoutRef.current) {
76247
+ clearTimeout(timeoutRef.current);
76248
+ }
76249
+ };
76250
+ }, []);
75636
76251
  return /* @__PURE__ */ jsxRuntime.jsxs(ChatContainer, { style: overrideStyle || {}, children: [
75637
76252
  /* @__PURE__ */ jsxRuntime.jsx(HeroContainer, { $isVisible: !isChatOpen, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
75638
76253
  title && /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "heading3", children: title }),
@@ -75641,28 +76256,63 @@ const Chat = ({
75641
76256
  ] }) }),
75642
76257
  isChatOpen ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
75643
76258
  /* @__PURE__ */ jsxRuntime.jsx(HeroContainer, { $isVisible: true, children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: title ? /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "heading2", children: title }) : null }) }),
76259
+ /* @__PURE__ */ jsxRuntime.jsxs(ToggleContainer, { children: [
76260
+ /* @__PURE__ */ jsxRuntime.jsxs(ToggleSwitch, { children: [
76261
+ /* @__PURE__ */ jsxRuntime.jsx(
76262
+ ToggleInput,
76263
+ {
76264
+ type: "checkbox",
76265
+ checked: isDataQueryMode,
76266
+ onChange: (e2) => setIsDataQueryMode(e2.target.checked)
76267
+ }
76268
+ ),
76269
+ /* @__PURE__ */ jsxRuntime.jsx(ToggleSlider, {})
76270
+ ] }),
76271
+ /* @__PURE__ */ jsxRuntime.jsx(ToggleLabel, { children: isDataQueryMode ? "Data Query Mode" : "Regular Chat" })
76272
+ ] }),
75644
76273
  /* @__PURE__ */ jsxRuntime.jsx(MessageList, { ref: messageListRef, children: uniqueMessages.map((msg) => /* @__PURE__ */ jsxRuntime.jsx(
75645
76274
  Message$1,
75646
76275
  {
75647
76276
  message: msg.content,
75648
76277
  handle: msg.sender,
75649
- isThinking: msg.isThinking
76278
+ isThinking: msg.isThinking,
76279
+ data: msg.data
75650
76280
  },
75651
76281
  msg.id
75652
76282
  )) }),
75653
- /* @__PURE__ */ jsxRuntime.jsxs(InputContainer, { children: [
75654
- /* @__PURE__ */ jsxRuntime.jsx(
75655
- Input2,
76283
+ /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
76284
+ /* @__PURE__ */ jsxRuntime.jsxs(InputContainer, { children: [
76285
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { width: 600 }, children: /* @__PURE__ */ jsxRuntime.jsx(
76286
+ Input2,
76287
+ {
76288
+ type: "text",
76289
+ value: message2,
76290
+ onChange: handleInputChange,
76291
+ onKeyDown: handleKeyDown,
76292
+ placeholder: isDataQueryMode ? "Ask about proposals, views, or chat questions..." : "Type a message...",
76293
+ disabled: isLocked,
76294
+ style: { width: 600 }
76295
+ }
76296
+ ) }),
76297
+ /* @__PURE__ */ jsxRuntime.jsx(Button$1, { onClick: sendMessage, disabled: isLocked, children: "Send" })
76298
+ ] }),
76299
+ isDataQueryMode && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginTop: 8, marginLeft: 8 }, children: /* @__PURE__ */ jsxRuntime.jsx(
76300
+ Select,
75656
76301
  {
75657
- type: "text",
75658
- value: message2,
75659
- onChange: handleInputChange,
75660
- onKeyDown: handleKeyDown,
75661
- placeholder: "Type a message & press Enter or Send",
75662
- disabled: isLocked
76302
+ width: 400,
76303
+ options: PREDEFINED_QUERIES.map((query) => ({
76304
+ label: query,
76305
+ value: query
76306
+ })),
76307
+ placeholder: "Select a predefined query...",
76308
+ onChange: (selected) => {
76309
+ if (selected) {
76310
+ setMessage(selected);
76311
+ }
76312
+ },
76313
+ isSingleSelect: true
75663
76314
  }
75664
- ),
75665
- /* @__PURE__ */ jsxRuntime.jsx(Button$1, { onClick: sendMessage, disabled: isLocked, children: "Send" })
76315
+ ) })
75666
76316
  ] })
75667
76317
  ] }) : /* @__PURE__ */ jsxRuntime.jsx(ChatButton, { onClick: toggleChat, children: "Chat" })
75668
76318
  ] });
@@ -78729,338 +79379,6 @@ const SegmentedControls = ({
78729
79379
  }
78730
79380
  );
78731
79381
  };
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
79382
  const Circle2 = ({ fill = "#CF3237", dataTestId }) => /* @__PURE__ */ jsxRuntime.jsx(
79065
79383
  "svg",
79066
79384
  {