@gobolt/genesis 0.3.4 → 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,73 +75417,480 @@ 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: 600px;
75340
- 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
+ }}
75341
75471
  `;
75342
- const HeroContainer = styled.div`
75472
+ const ValueContainer = styled.div`
75343
75473
  display: flex;
75344
75474
  align-items: center;
75345
- justify-content: center;
75346
- opacity: ${({ $isVisible }) => $isVisible ? 1 : 0};
75347
- transition: opacity 0.3s ease;
75348
- `;
75349
- styled.h1`
75350
- font-family: "Helvetica", "Arial", sans-serif;
75351
- color: teal;
75352
- font-size: 24px;
75353
- text-align: center;
75354
- `;
75355
- const Subtitle = styled.p`
75356
- font-family: "Helvetica", "Arial", sans-serif;
75357
- color: #666;
75358
- font-size: 16px;
75359
- text-align: center;
75360
- `;
75361
- const ErrorMessage = styled(Subtitle)`
75362
- color: red;
75475
+ gap: ${({ theme }) => theme.sizing.Size2}px;
75476
+ flex: 1;
75477
+ padding: 4px 8px;
75363
75478
  `;
75364
- const InputContainer = styled.div`
75479
+ const ChevronContainer = styled.div`
75365
75480
  display: flex;
75366
- justify-content: center;
75367
75481
  align-items: center;
75368
- padding: 8px;
75369
- gap: 8px;
75482
+ justify-content: center;
75483
+ margin-right: ${({ $variant }) => $variant === "simple" ? "4px" : "4px"};
75484
+ margin-left: ${({ $variant }) => $variant === "simple" ? "4px" : "0"};
75370
75485
  `;
75371
- const ChatButton = styled(Button$1)`
75372
- display: flex;
75373
- justify-content: flex-end;
75374
- 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
+ `}
75375
75561
  `;
75376
- 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};
75377
75589
  display: flex;
75378
- flex-direction: column;
75379
- padding: 16px;
75380
- gap: 8px;
75381
- max-height: 400px;
75382
- 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
+ `}
75383
75606
  `;
75384
- const Chat = ({
75385
- socketUrl = "http://localhost:3000",
75386
- isOpen = false,
75387
- messageHistory = [],
75388
- title = null,
75389
- isSimulated = false,
75390
- authToken
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
75391
75622
  }) => {
75392
- const [isChatOpen, setIsChatOpen] = React.useState(isOpen);
75393
- const [message2, setMessage] = React.useState("");
75394
- const [messages2, setMessages] = React.useState(messageHistory);
75395
- const [serverStatus, setServerStatus] = React.useState("unknown");
75396
- const [serverError, setServerError] = React.useState("");
75397
- const socketRef = React.useRef(null);
75398
- const messageListRef = React.useRef(null);
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);
75882
+ const [serverStatus, setServerStatus] = React.useState("unknown");
75883
+ const [serverError, setServerError] = React.useState("");
75884
+ const socketRef = React.useRef(null);
75885
+ const messageListRef = React.useRef(null);
75399
75886
  const serverReadyRef = React.useRef(false);
75400
75887
  const handle = "user";
75401
75888
  const [isLocked, setIsLocked] = React.useState(false);
75889
+ const [messageStartTime, setMessageStartTime] = React.useState(null);
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);
75402
75894
  React.useEffect(() => {
75403
75895
  if (isSimulated) return;
75404
75896
  const socketUrlToUse = window.location.hostname === "localhost" && window.location.port === "6006" ? "http://localhost:3000" : socketUrl;
@@ -75463,27 +75955,46 @@ const Chat = ({
75463
75955
  serverReadyRef.current = true;
75464
75956
  });
75465
75957
  socket.on("message", (newMessage) => {
75958
+ console.log("\n=== Received Message Event ===");
75959
+ console.log("New Message:", newMessage);
75466
75960
  setMessages((prev2) => {
75467
75961
  if (newMessage.sender === "bot") {
75468
- if (newMessage.content === "Processing your message...") {
75962
+ if (newMessage.isThinking) {
75469
75963
  const hasThinkingMessage = prev2.some((msg) => msg.isThinking);
75470
75964
  if (hasThinkingMessage) {
75965
+ console.log("Already have thinking message, skipping");
75471
75966
  return prev2;
75472
75967
  }
75968
+ console.log("Adding thinking message");
75473
75969
  return [...prev2, { ...newMessage, isThinking: true }];
75474
75970
  }
75475
75971
  const thinkingMessage = prev2.find((msg) => msg.isThinking);
75476
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
+ };
75477
75979
  return prev2.map(
75478
- (msg) => msg.isThinking ? { ...newMessage, isThinking: false } : msg
75980
+ (msg) => msg.isThinking ? updatedMessage : msg
75479
75981
  );
75480
75982
  }
75481
- 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];
75482
75991
  }
75483
75992
  const lastUserMsg = [...prev2].reverse().find((msg) => msg.sender === "user");
75484
75993
  if (lastUserMsg && lastUserMsg.content === newMessage.content) {
75994
+ console.log("Duplicate user message, skipping");
75485
75995
  return prev2;
75486
75996
  }
75997
+ console.log("Adding new user message");
75487
75998
  return [...prev2, newMessage];
75488
75999
  });
75489
76000
  setIsLocked(false);
@@ -75514,6 +76025,44 @@ const Chat = ({
75514
76025
  setIsLocked(false);
75515
76026
  }
75516
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
+ );
75517
76066
  return () => {
75518
76067
  console.log("Disconnecting socket");
75519
76068
  socket.disconnect();
@@ -75556,11 +76105,14 @@ const Chat = ({
75556
76105
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
75557
76106
  };
75558
76107
  setIsLocked(true);
76108
+ setHasReceivedResponse(false);
76109
+ setMessageStartTime(Date.now());
76110
+ setCurrentQuestion(message2);
75559
76111
  setMessages((prev2) => [...prev2, userMessage]);
75560
76112
  if ((_a = socketRef.current) == null ? void 0 : _a.connected) {
75561
76113
  const botMessageId = `bot_${timestamp}`;
75562
76114
  const thinkingMessage = {
75563
- content: "",
76115
+ content: PROCESSING_MESSAGE,
75564
76116
  sender: "bot",
75565
76117
  id: botMessageId,
75566
76118
  isThinking: true,
@@ -75573,23 +76125,98 @@ const Chat = ({
75573
76125
  setIsLocked(false);
75574
76126
  return;
75575
76127
  }
75576
- socketRef.current.emit("message", userMessage);
75577
- if (socketRef.current.connected) {
75578
- setTimeout(() => {
75579
- setMessages(
75580
- (prev2) => prev2.map(
75581
- (msg) => msg.isThinking ? { ...msg, content: "Processing your message..." } : msg
75582
- )
75583
- );
75584
- }, 300);
75585
- setTimeout(() => {
75586
- setMessages((prev2) => prev2.filter((msg) => !msg.isThinking));
75587
- setServerError("No response from server");
75588
- setIsLocked(false);
75589
- }, 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);
75590
76194
  }
75591
76195
  setMessage("");
75592
76196
  };
76197
+ React.useEffect(() => {
76198
+ const lastMessage = messages2.at(-1);
76199
+ if (!lastMessage || !messageStartTime || !currentQuestion) return;
76200
+ if (lastMessage.sender === "bot" && !lastMessage.isThinking) {
76201
+ const timeToRespond = Date.now() - messageStartTime;
76202
+ const chatHistoryRecord = {
76203
+ visitorId: "user",
76204
+ // You might want to get this from props or context
76205
+ visitorEmail: "",
76206
+ // You might want to get this from props or context
76207
+ name: handle,
76208
+ question: currentQuestion,
76209
+ response: lastMessage.content,
76210
+ timeToRespond,
76211
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
76212
+ responseBy: lastMessage.respondedBy || "ai"
76213
+ // Use the respondedBy from the message, default to "ai"
76214
+ };
76215
+ onChange == null ? void 0 : onChange(chatHistoryRecord);
76216
+ setMessageStartTime(null);
76217
+ setCurrentQuestion("");
76218
+ }
76219
+ }, [messages2, messageStartTime, currentQuestion, onChange, handle]);
75593
76220
  const toggleChat = () => {
75594
76221
  setIsChatOpen(!isChatOpen);
75595
76222
  };
@@ -75599,40 +76226,93 @@ const Chat = ({
75599
76226
  if (serverStatus === "error") {
75600
76227
  return /* @__PURE__ */ jsxRuntime.jsx(ErrorMessage, { children: "Network error" });
75601
76228
  }
75602
- const uniqueMessages = messages2.filter(
75603
- (msg, index2, self2) => index2 === self2.findIndex((t2) => t2.id === msg.id)
75604
- );
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
+ });
75605
76242
  console.log("uniqueMessages", uniqueMessages);
75606
- return /* @__PURE__ */ jsxRuntime.jsxs(ChatContainer, { children: [
75607
- /* @__PURE__ */ jsxRuntime.jsx(HeroContainer, { $isVisible: !isChatOpen, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
75608
- title ? /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "heading3", children: title }) : null,
76243
+ console.log("messages", messages2);
76244
+ React.useEffect(() => {
76245
+ return () => {
76246
+ if (timeoutRef.current) {
76247
+ clearTimeout(timeoutRef.current);
76248
+ }
76249
+ };
76250
+ }, []);
76251
+ return /* @__PURE__ */ jsxRuntime.jsxs(ChatContainer, { style: overrideStyle || {}, children: [
76252
+ /* @__PURE__ */ jsxRuntime.jsx(HeroContainer, { $isVisible: !isChatOpen, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
76253
+ title && /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "heading3", children: title }),
75609
76254
  /* @__PURE__ */ jsxRuntime.jsx(Subtitle, { children: "Click the Chat Icon below to begin" }),
75610
76255
  serverError ? /* @__PURE__ */ jsxRuntime.jsx(ErrorMessage, { children: serverError }) : null
75611
76256
  ] }) }),
75612
76257
  isChatOpen ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
75613
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
+ ] }),
75614
76273
  /* @__PURE__ */ jsxRuntime.jsx(MessageList, { ref: messageListRef, children: uniqueMessages.map((msg) => /* @__PURE__ */ jsxRuntime.jsx(
75615
76274
  Message$1,
75616
76275
  {
75617
76276
  message: msg.content,
75618
76277
  handle: msg.sender,
75619
- isThinking: msg.isThinking
76278
+ isThinking: msg.isThinking,
76279
+ data: msg.data
75620
76280
  },
75621
76281
  msg.id
75622
76282
  )) }),
75623
- /* @__PURE__ */ jsxRuntime.jsxs(InputContainer, { children: [
75624
- /* @__PURE__ */ jsxRuntime.jsx(
75625
- 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,
75626
76301
  {
75627
- type: "text",
75628
- value: message2,
75629
- onChange: handleInputChange,
75630
- onKeyDown: handleKeyDown,
75631
- placeholder: "Type a message & press Enter or Send",
75632
- 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
75633
76314
  }
75634
- ),
75635
- /* @__PURE__ */ jsxRuntime.jsx(Button$1, { onClick: sendMessage, disabled: isLocked, children: "Send" })
76315
+ ) })
75636
76316
  ] })
75637
76317
  ] }) : /* @__PURE__ */ jsxRuntime.jsx(ChatButton, { onClick: toggleChat, children: "Chat" })
75638
76318
  ] });
@@ -78699,338 +79379,6 @@ const SegmentedControls = ({
78699
79379
  }
78700
79380
  );
78701
79381
  };
78702
- const getBackgroundColor = (colors2, disabled2, $variant) => {
78703
- if ($variant === "simple") return "#F4F4F4";
78704
- if (disabled2) return "#F4F4F4";
78705
- return "#fff";
78706
- };
78707
- const TriggerWrapper = styled.div`
78708
- display: flex;
78709
- align-items: center;
78710
- justify-content: space-between;
78711
- cursor: ${({ $disabled }) => $disabled ? "not-allowed" : "pointer"};
78712
- opacity: ${({ $disabled }) => $disabled ? 0.4 : 1};
78713
- position: relative;
78714
- box-shadow: ${({ $variant }) => $variant === "simple" ? "none" : "0px 1px 2px 0px rgba(0, 0, 0, 0.12)"};
78715
- transition: all 0.2s ease-in-out;
78716
- min-height: ${({ $variant }) => $variant === "simple" ? "32px" : "40px"};
78717
-
78718
- &:focus-visible {
78719
- outline: none;
78720
- }
78721
-
78722
- &:focus {
78723
- box-shadow:
78724
- 0px 1px 2px 0px rgba(0, 0, 0, 0.12),
78725
- 0 0 0 3px
78726
- ${({ theme, $themeType = "primary" }) => theme.colors[$themeType].focussed.ringColor};
78727
- }
78728
-
78729
- ${({ $variant, theme, $disabled }) => {
78730
- var _a;
78731
- return $variant === "simple" ? `
78732
- padding: ${theme.sizing.Size1} ${theme.sizing.Size2};
78733
- background: ${$disabled ? theme.colors.inputs.surface.disabled : "rgba(0, 0, 0, 0.04)"};
78734
- border: none;
78735
- border-radius: ${theme.borderRadius.BorderRadiusSm}px;
78736
- min-height: ${({ $variant: $variant2 }) => $variant2 === "simple" ? "32px" : "40px"};
78737
-
78738
- &:hover {
78739
- border: none;
78740
- }
78741
- ` : `
78742
- padding: ${theme.sizing.Size1} ${theme.sizing.Size2};
78743
- background: ${$disabled ? theme.colors.inputs.surface.disabled : (_a = theme.colors.surface.default) == null ? void 0 : _a.backgroundColor};
78744
- border: 1px solid #9a9a9a;
78745
- border-radius: ${theme.borderRadius.BorderRadiusSm}px;
78746
- min-height: ${({ $variant: $variant2 }) => $variant2 === "simple" ? "32px" : "40px"};
78747
-
78748
- &:hover {
78749
- border-color: rgba(0, 0, 0, 0.2);
78750
- }
78751
- `;
78752
- }}
78753
- `;
78754
- const ValueContainer = styled.div`
78755
- display: flex;
78756
- align-items: center;
78757
- gap: ${({ theme }) => theme.sizing.Size2}px;
78758
- flex: 1;
78759
- padding: 4px 8px;
78760
- `;
78761
- const ChevronContainer = styled.div`
78762
- display: flex;
78763
- align-items: center;
78764
- justify-content: center;
78765
- margin-right: ${({ $variant }) => $variant === "simple" ? "4px" : "4px"};
78766
- margin-left: ${({ $variant }) => $variant === "simple" ? "4px" : "0"};
78767
- `;
78768
- const SelectTrigger2 = ({
78769
- type: type4 = "primary",
78770
- theme,
78771
- state,
78772
- value: value2,
78773
- placeholder = "Select...",
78774
- open,
78775
- onClick,
78776
- renderValue,
78777
- options = [],
78778
- disabled: disabled2 = false,
78779
- variant = "none"
78780
- }) => {
78781
- const handleClick = React.useCallback(() => {
78782
- if (disabled2) return;
78783
- onClick == null ? void 0 : onClick();
78784
- }, [disabled2, onClick]);
78785
- const displayValue = React.useMemo(() => {
78786
- if (!value2) return null;
78787
- if (renderValue) return renderValue(value2);
78788
- if (Array.isArray(value2)) {
78789
- if (value2.length === 0) return null;
78790
- const selectedLabels = value2.map(String).map((v) => {
78791
- var _a;
78792
- return (_a = options.find((opt) => opt.value === v)) == null ? void 0 : _a.label;
78793
- }).filter(Boolean);
78794
- return selectedLabels.length > 0 ? selectedLabels.join(", ") : `${value2.length} selected`;
78795
- }
78796
- const selectedOption = options.find((opt) => opt.value === String(value2));
78797
- return (selectedOption == null ? void 0 : selectedOption.label) || value2.toString();
78798
- }, [value2, renderValue, options]);
78799
- return /* @__PURE__ */ jsxRuntime.jsxs(
78800
- TriggerWrapper,
78801
- {
78802
- $themeType: type4,
78803
- $state: state,
78804
- onClick: handleClick,
78805
- tabIndex: disabled2 ? -1 : 0,
78806
- role: "button",
78807
- $disabled: disabled2,
78808
- $variant: variant,
78809
- style: {
78810
- backgroundColor: getBackgroundColor(theme, disabled2, variant)
78811
- },
78812
- children: [
78813
- /* @__PURE__ */ jsxRuntime.jsx(ValueContainer, { $variant: variant, children: displayValue ? /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "body2", color: disabled2 ? "copy-light" : "copy", children: displayValue }) : /* @__PURE__ */ jsxRuntime.jsx(
78814
- Typography,
78815
- {
78816
- variant: "body2",
78817
- color: disabled2 ? "copy-light" : "copy-light",
78818
- children: placeholder
78819
- }
78820
- ) }),
78821
- /* @__PURE__ */ jsxRuntime.jsx(ChevronContainer, { $variant: variant, children: /* @__PURE__ */ jsxRuntime.jsx(DropdownChevron, {}) })
78822
- ]
78823
- }
78824
- );
78825
- };
78826
- const SelectWrapper = styled.div`
78827
- position: relative;
78828
- background-color: transparent;
78829
- border-radius: 8px;
78830
- width: auto;
78831
-
78832
- ${({ $isFocused, theme, type: type4 = "primary" }) => $isFocused && `
78833
- background-color: transparent;
78834
- `}
78835
-
78836
- ${({ disabled: disabled2, theme }) => disabled2 && `
78837
- cursor: not-allowed;
78838
-
78839
- &:hover {
78840
- border-color: ${theme.colors.inputs.surface.border};
78841
- }
78842
- `}
78843
- `;
78844
- const SelectDropdown = styled.div`
78845
- padding: 0px;
78846
- border-radius: 0px;
78847
- animation-duration: ${({ theme }) => `${theme.motion.veryfast}s`};
78848
- transition: all ${({ theme }) => `${theme.motion.veryfast}s`}
78849
- cubic-bezier(0.645, 0.045, 0.355, 1);
78850
-
78851
- &.entering {
78852
- opacity: 0;
78853
- transform: scaleY(0.8);
78854
- }
78855
-
78856
- &.entered {
78857
- opacity: 1;
78858
- transform: scaleY(1);
78859
- }
78860
-
78861
- &.exiting {
78862
- opacity: 0;
78863
- transform: scaleY(0.8);
78864
- }
78865
- `;
78866
- const MenuItem = styled.div`
78867
- padding: 8px 12px;
78868
- cursor: ${({ disabled: disabled2 }) => disabled2 ? "not-allowed" : "pointer"};
78869
- background-color: ${({ $isSelected, theme, type: type4 = "primary" }) => $isSelected ? theme.colors[type4].hover.backgroundColor : "transparent"};
78870
- color: ${({ $isSelected, disabled: disabled2, theme, type: type4 = "primary" }) => disabled2 ? theme.colors.inputs.onsurface.disabled : $isSelected ? theme.colors[type4].hover.color : theme.colors.onsurface.copy};
78871
- display: flex;
78872
- justify-content: space-between;
78873
- align-items: center;
78874
- transition: all ${({ theme }) => `${theme.motion.veryfast}s`} ease-in-out;
78875
- opacity: ${({ disabled: disabled2 }) => disabled2 ? 0.5 : 1};
78876
-
78877
- ${({ disabled: disabled2 }) => !disabled2 && `
78878
- &:hover {
78879
- background-color: ${({ $isSelected, theme, type: type4 = "primary" }) => $isSelected ? theme.colors[type4].hover.backgroundColor : "rgba(0, 0, 0, 0.04)"};
78880
- color: ${({ $isSelected, theme, type: type4 = "primary" }) => $isSelected ? theme.colors[type4].hover.color : theme.colors.onsurface["copy-dark"]};
78881
- }
78882
-
78883
- &:active {
78884
- background-color: ${({ theme, type: type4 = "primary" }) => theme.colors[type4].hover.backgroundColor};
78885
- color: ${({ theme, type: type4 = "primary" }) => theme.colors[type4].hover.color};
78886
- }
78887
- `}
78888
- `;
78889
- const Select = ({
78890
- type: type4 = TYPE.primary,
78891
- state,
78892
- variant = "none",
78893
- defaultValue,
78894
- onChange,
78895
- size = "normal",
78896
- width = "100%",
78897
- value: value2,
78898
- options = [],
78899
- placeholder,
78900
- selectDisplayMode = "count",
78901
- isSingleSelect = false,
78902
- disabled: disabled2 = false,
78903
- ...rest
78904
- }) => {
78905
- const [isOpen, setIsOpen] = React.useState(false);
78906
- const [isFocused, setIsFocused] = React.useState(false);
78907
- const [dropdownAnimation, setDropdownAnimation] = React.useState("entered");
78908
- const selectReference = React.useRef(null);
78909
- const { theme } = useGenesis();
78910
- React.useEffect(() => {
78911
- const handleClickOutside = (event) => {
78912
- if (selectReference.current && !selectReference.current.contains(event.target)) {
78913
- handleClose();
78914
- setIsFocused(false);
78915
- }
78916
- };
78917
- if (isOpen) {
78918
- document.addEventListener("mousedown", handleClickOutside);
78919
- }
78920
- return () => {
78921
- document.removeEventListener("mousedown", handleClickOutside);
78922
- };
78923
- }, [isOpen]);
78924
- const handleClose = () => {
78925
- setDropdownAnimation("exiting");
78926
- setTimeout(() => {
78927
- setIsOpen(false);
78928
- setDropdownAnimation("entered");
78929
- }, 200);
78930
- };
78931
- const handleTriggerClick = () => {
78932
- if (disabled2) return;
78933
- setIsFocused(true);
78934
- if (isOpen) {
78935
- handleClose();
78936
- } else {
78937
- setIsOpen(true);
78938
- setDropdownAnimation("entering");
78939
- setTimeout(() => {
78940
- setDropdownAnimation("entered");
78941
- }, 0);
78942
- }
78943
- };
78944
- const handleOptionSelect = (optionValue) => {
78945
- if (disabled2) return;
78946
- let newValue;
78947
- if (Array.isArray(value2)) {
78948
- const stringValue = value2.map(String);
78949
- newValue = stringValue.includes(optionValue) ? stringValue.filter((v) => v !== optionValue) : [...stringValue, optionValue];
78950
- } else {
78951
- newValue = optionValue;
78952
- }
78953
- onChange == null ? void 0 : onChange(newValue);
78954
- if (isSingleSelect) {
78955
- handleClose();
78956
- }
78957
- };
78958
- const getSelectModeValue = (value22) => {
78959
- if (Array.isArray(value22)) {
78960
- if (selectDisplayMode === "count") {
78961
- return `${value22.length} selected`;
78962
- }
78963
- return value22;
78964
- }
78965
- return value22;
78966
- };
78967
- const modeValue = getSelectModeValue(value2);
78968
- return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { position: "relative", width }, children: /* @__PURE__ */ jsxRuntime.jsxs(
78969
- SelectWrapper,
78970
- {
78971
- ref: selectReference,
78972
- $isFocused: isFocused,
78973
- type: type4,
78974
- disabled: disabled2,
78975
- onFocus: () => !disabled2 && setIsFocused(true),
78976
- onBlur: () => !isOpen && setIsFocused(false),
78977
- tabIndex: disabled2 ? -1 : 0,
78978
- children: [
78979
- /* @__PURE__ */ jsxRuntime.jsx(
78980
- SelectTrigger2,
78981
- {
78982
- theme,
78983
- type: type4,
78984
- state,
78985
- value: modeValue,
78986
- placeholder,
78987
- open: isOpen,
78988
- onClick: handleTriggerClick,
78989
- options,
78990
- disabled: disabled2,
78991
- variant
78992
- }
78993
- ),
78994
- isOpen && !disabled2 && /* @__PURE__ */ jsxRuntime.jsx(
78995
- SelectDropdown,
78996
- {
78997
- type: type4,
78998
- state,
78999
- className: dropdownAnimation,
79000
- style: {
79001
- position: "absolute",
79002
- top: "calc(100% + 4px)",
79003
- left: 0,
79004
- right: 0,
79005
- zIndex: 1e3,
79006
- backgroundColor: "white",
79007
- boxShadow: "0 2px 8px rgba(0, 0, 0, 0.15)",
79008
- border: "1px solid #d9d9d9",
79009
- transformOrigin: "top"
79010
- },
79011
- children: options.map((option) => {
79012
- const isSelected = Array.isArray(value2) ? value2.map(String).includes(option.value) : String(value2) === option.value;
79013
- return /* @__PURE__ */ jsxRuntime.jsxs(
79014
- MenuItem,
79015
- {
79016
- onClick: () => handleOptionSelect(option.value),
79017
- $isSelected: isSelected,
79018
- type: type4,
79019
- disabled: disabled2,
79020
- children: [
79021
- option.label,
79022
- isSelected && /* @__PURE__ */ jsxRuntime.jsx("span", { style: { marginLeft: "8px" }, children: "✓" })
79023
- ]
79024
- },
79025
- option.value
79026
- );
79027
- })
79028
- }
79029
- )
79030
- ]
79031
- }
79032
- ) });
79033
- };
79034
79382
  const Circle2 = ({ fill = "#CF3237", dataTestId }) => /* @__PURE__ */ jsxRuntime.jsx(
79035
79383
  "svg",
79036
79384
  {