quantum-component-library 1.4.47-qa → 1.4.48-1

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.
Files changed (77) hide show
  1. package/README.md +115 -115
  2. package/dist/components.cjs +1 -1
  3. package/dist/components.js +1531 -1411
  4. package/dist/{dnd-core-vendor-CErAmYu_.js → dnd-core-vendor-CEbjUoFs.js} +2 -2
  5. package/dist/{dnd-core-vendor-2Ve0kqUN.cjs → dnd-core-vendor-gqRN0Czq.cjs} +1 -1
  6. package/dist/generated/gql.d.ts +17 -2
  7. package/dist/generated/graphql.d.ts +65 -1
  8. package/dist/generated-graphql.cjs +1 -1
  9. package/dist/generated-graphql.js +47 -44
  10. package/dist/generated.cjs +1 -1
  11. package/dist/generated.js +56 -53
  12. package/dist/graphql/fragments/index.d.ts +1 -0
  13. package/dist/graphql/fragments/metadata.d.ts +2 -0
  14. package/dist/graphql/queries/index.d.ts +1 -0
  15. package/dist/graphql/queries/metadata.d.ts +3 -0
  16. package/dist/{graphql-C6M9oyU0.cjs → graphql-Ce2MNCsk.cjs} +72 -49
  17. package/dist/{graphql-CvUc6Vdv.js → graphql-_vGi4u4K.js} +95 -70
  18. package/dist/graphql-vendor-AFHxLsy8.cjs +14 -0
  19. package/dist/graphql-vendor-hJezYUeG.js +669 -0
  20. package/dist/hooks.cjs +1 -1
  21. package/dist/hooks.js +61 -51
  22. package/dist/index.cjs +1 -1
  23. package/dist/index.js +139 -131
  24. package/dist/lib/hooks/index.d.ts +1 -0
  25. package/dist/lib/hooks/use-ui-label-context.d.ts +6 -0
  26. package/dist/lib/providers/index.d.ts +1 -0
  27. package/dist/lib/providers/ui-label-provider/context.d.ts +9 -0
  28. package/dist/lib/providers/ui-label-provider/index.d.ts +2 -0
  29. package/dist/lib/providers/ui-label-provider/provider.d.ts +2 -0
  30. package/dist/lib/services/rom.json.d.ts +223 -223
  31. package/dist/lib/utils/cn.d.ts +2 -0
  32. package/dist/lib/utils/index.d.ts +1 -2
  33. package/dist/{lodash-vendor-CR237hSU.cjs → lodash-vendor-CF0pV_0E.cjs} +1 -1
  34. package/dist/{lodash-vendor-D4ZPCr77.js → lodash-vendor-apNdTTav.js} +1 -1
  35. package/dist/other-D9ROT7p0.js +20 -0
  36. package/dist/other-DyoApG-9.cjs +1 -0
  37. package/dist/providers.cjs +1 -1
  38. package/dist/providers.js +41 -8
  39. package/dist/quantum-component-library.css +1 -1
  40. package/dist/{react-dnd-vendor-D4nn9Mqx.js → react-dnd-vendor-BCrg2QCX.js} +2 -2
  41. package/dist/{react-dnd-vendor-BPzSDojS.cjs → react-dnd-vendor-PwwXhPmK.cjs} +1 -1
  42. package/dist/react-icons-vendor-BF_sZq07.cjs +1 -0
  43. package/dist/{react-icons-vendor-TETORdU9.js → react-icons-vendor-CMsTQrA0.js} +51 -43
  44. package/dist/{react-select-vendor-D_Q2fL5j.cjs → react-select-vendor-BeWvSe2q.cjs} +1 -1
  45. package/dist/{react-select-vendor-BlY9Il4Q.js → react-select-vendor-BxbsY5Z-.js} +1 -1
  46. package/dist/services-action-CfZFwhy-.js +40 -0
  47. package/dist/services-action-DBOzfgMl.cjs +1 -0
  48. package/dist/services-human-B98qxeuS.js +798 -0
  49. package/dist/services-human-CnvSTmoF.cjs +1 -0
  50. package/dist/services-rom-DmV5X8yu.cjs +1 -0
  51. package/dist/services-rom-omMeC-vQ.js +18 -0
  52. package/dist/services.cjs +1 -1
  53. package/dist/services.js +52 -844
  54. package/dist/types.cjs +1 -1
  55. package/dist/types.js +11 -11
  56. package/dist/utils-cn-CgdSr4hO.js +7 -0
  57. package/dist/utils-cn-FIKrq5Mb.cjs +1 -0
  58. package/dist/utils-conversion-CWypeWsT.cjs +1 -0
  59. package/dist/utils-conversion-ChFbq8I2.js +94 -0
  60. package/dist/utils-memo-BJJP2KfI.cjs +1 -0
  61. package/dist/utils-memo-DtXdOqCT.js +13 -0
  62. package/dist/utils-parameters-BBFuBK2B.js +21 -0
  63. package/dist/utils-parameters-dwKmz1VU.cjs +1 -0
  64. package/dist/utils-text-CN3zLiZ7.js +5 -0
  65. package/dist/utils-text-lORqO4uI.cjs +1 -0
  66. package/dist/utils.cjs +1 -1
  67. package/dist/utils.js +29 -126
  68. package/dist/vendor-BOD7IxCS.js +421 -0
  69. package/dist/vendor-IPtJZCbx.cjs +1 -0
  70. package/package.json +133 -133
  71. package/dist/graphql-vendor-B-QTAQSb.cjs +0 -19
  72. package/dist/graphql-vendor-B0NjgbDB.js +0 -1284
  73. package/dist/other-C4VnLmM6.js +0 -15
  74. package/dist/other-Dp3RPYfF.cjs +0 -1
  75. package/dist/react-icons-vendor-D2s8zw9h.cjs +0 -1
  76. package/dist/vendor-BjLvygDR.cjs +0 -1
  77. package/dist/vendor-VALJ9W3p.js +0 -526
package/README.md CHANGED
@@ -1,115 +1,115 @@
1
- # Quantum Component Library
2
-
3
- A modular React component library built with TypeScript and Vite, featuring code splitting for optimal bundle sizes.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install quantum-component-library
9
- ```
10
-
11
- ## Usage
12
-
13
- ### Full Library Import (Default)
14
-
15
- ```typescript
16
- // Import everything (not recommended for production)
17
- import * from 'quantum-component-library';
18
- ```
19
-
20
- ### Modular Imports (Recommended)
21
-
22
- The library is split into several modules for optimal tree-shaking and bundle sizes:
23
-
24
- #### Components
25
- ```typescript
26
- // Import only UI components
27
- import { UpsertActivityForm, ParameterEditList } from 'quantum-component-library/components';
28
- ```
29
-
30
- #### Hooks
31
- ```typescript
32
- // Import only custom hooks
33
- import { useGraphqlClient, useJointsForLimbIds } from 'quantum-component-library/hooks';
34
- ```
35
-
36
- #### Types
37
- ```typescript
38
- // Import only type definitions
39
- import type { Activity, Analysis, Human } from 'quantum-component-library/types';
40
- ```
41
-
42
- #### Authentication
43
- ```typescript
44
- // Import only auth utilities
45
- import { useAuthContext, useIsAuthenticated } from 'quantum-component-library/auth';
46
- ```
47
-
48
- #### GraphQL
49
- ```typescript
50
- // Import only GraphQL fragments and operations
51
- import { ActivityFragment, SessionQueries } from 'quantum-component-library/graphql';
52
- ```
53
-
54
- #### Generated GraphQL Code
55
- ```typescript
56
- // Import only generated GraphQL types and utilities
57
- import { FragmentMasking, gql } from 'quantum-component-library/generated';
58
- ```
59
-
60
- #### Utilities
61
- ```typescript
62
- // Import only utility functions
63
- import { convertUnits, memoizeWithExpiry } from 'quantum-component-library/utils';
64
- ```
65
-
66
- #### Services
67
- ```typescript
68
- // Import only service functions
69
- import { humanService } from 'quantum-component-library/services';
70
- ```
71
-
72
- ## Code Splitting Benefits
73
-
74
- - **Reduced Bundle Size**: Import only what you need
75
- - **Better Tree Shaking**: Webpack and other bundlers can eliminate unused code more effectively
76
- - **Faster Loading**: Smaller initial bundles load faster
77
- - **Better Caching**: Changes to one module don't invalidate others
78
-
79
- ## Build Configuration
80
-
81
- This library uses Vite with multiple entry points and manual chunk splitting:
82
-
83
- - **Multiple Entry Points**: Each module has its own entry point for granular imports
84
- - **Manual Chunk Splitting**: Vendor dependencies are split into logical chunks (UI, GraphQL, React, etc.)
85
- - **Automatic Type Generation**: TypeScript definitions are generated for all entry points
86
-
87
- ### Available Modules
88
-
89
- | Module | Entry Point | Description |
90
- |--------|-------------|-------------|
91
- | `components` | `src/components/index.ts` | UI components |
92
- | `hooks` | `src/lib/hooks/index.ts` | Custom React hooks |
93
- | `types` | `src/lib/types/index.ts` | TypeScript type definitions |
94
- | `auth` | `src/lib/auth/index.ts` | Authentication utilities |
95
- | `graphql` | `src/graphql/index.ts` | GraphQL fragments and operations |
96
- | `generated` | `src/generated/index.ts` | Generated GraphQL code |
97
- | `utils` | `src/lib/utils/index.ts` | Utility functions |
98
- | `services` | `src/lib/services/index.ts` | Service functions |
99
-
100
- ## Development
101
-
102
- ```bash
103
- # Install dependencies
104
- npm install
105
-
106
- # Start development server
107
- npm run dev
108
-
109
- # Build the library
110
- npm run build
111
-
112
- # Build for specific environments
113
- npm run build:admin-prod
114
- npm run build:client-qa
115
- ```
1
+ # Quantum Component Library
2
+
3
+ A modular React component library built with TypeScript and Vite, featuring code splitting for optimal bundle sizes.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install quantum-component-library
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Full Library Import (Default)
14
+
15
+ ```typescript
16
+ // Import everything (not recommended for production)
17
+ import * from 'quantum-component-library';
18
+ ```
19
+
20
+ ### Modular Imports (Recommended)
21
+
22
+ The library is split into several modules for optimal tree-shaking and bundle sizes:
23
+
24
+ #### Components
25
+ ```typescript
26
+ // Import only UI components
27
+ import { UpsertActivityForm, ParameterEditList } from 'quantum-component-library/components';
28
+ ```
29
+
30
+ #### Hooks
31
+ ```typescript
32
+ // Import only custom hooks
33
+ import { useGraphqlClient, useJointsForLimbIds } from 'quantum-component-library/hooks';
34
+ ```
35
+
36
+ #### Types
37
+ ```typescript
38
+ // Import only type definitions
39
+ import type { Activity, Analysis, Human } from 'quantum-component-library/types';
40
+ ```
41
+
42
+ #### Authentication
43
+ ```typescript
44
+ // Import only auth utilities
45
+ import { useAuthContext, useIsAuthenticated } from 'quantum-component-library/auth';
46
+ ```
47
+
48
+ #### GraphQL
49
+ ```typescript
50
+ // Import only GraphQL fragments and operations
51
+ import { ActivityFragment, SessionQueries } from 'quantum-component-library/graphql';
52
+ ```
53
+
54
+ #### Generated GraphQL Code
55
+ ```typescript
56
+ // Import only generated GraphQL types and utilities
57
+ import { FragmentMasking, gql } from 'quantum-component-library/generated';
58
+ ```
59
+
60
+ #### Utilities
61
+ ```typescript
62
+ // Import only utility functions
63
+ import { convertUnits, memoizeWithExpiry } from 'quantum-component-library/utils';
64
+ ```
65
+
66
+ #### Services
67
+ ```typescript
68
+ // Import only service functions
69
+ import { humanService } from 'quantum-component-library/services';
70
+ ```
71
+
72
+ ## Code Splitting Benefits
73
+
74
+ - **Reduced Bundle Size**: Import only what you need
75
+ - **Better Tree Shaking**: Webpack and other bundlers can eliminate unused code more effectively
76
+ - **Faster Loading**: Smaller initial bundles load faster
77
+ - **Better Caching**: Changes to one module don't invalidate others
78
+
79
+ ## Build Configuration
80
+
81
+ This library uses Vite with multiple entry points and manual chunk splitting:
82
+
83
+ - **Multiple Entry Points**: Each module has its own entry point for granular imports
84
+ - **Manual Chunk Splitting**: Vendor dependencies are split into logical chunks (UI, GraphQL, React, etc.)
85
+ - **Automatic Type Generation**: TypeScript definitions are generated for all entry points
86
+
87
+ ### Available Modules
88
+
89
+ | Module | Entry Point | Description |
90
+ |--------|-------------|-------------|
91
+ | `components` | `src/components/index.ts` | UI components |
92
+ | `hooks` | `src/lib/hooks/index.ts` | Custom React hooks |
93
+ | `types` | `src/lib/types/index.ts` | TypeScript type definitions |
94
+ | `auth` | `src/lib/auth/index.ts` | Authentication utilities |
95
+ | `graphql` | `src/graphql/index.ts` | GraphQL fragments and operations |
96
+ | `generated` | `src/generated/index.ts` | Generated GraphQL code |
97
+ | `utils` | `src/lib/utils/index.ts` | Utility functions |
98
+ | `services` | `src/lib/services/index.ts` | Service functions |
99
+
100
+ ## Development
101
+
102
+ ```bash
103
+ # Install dependencies
104
+ npm install
105
+
106
+ # Start development server
107
+ npm run dev
108
+
109
+ # Build the library
110
+ npm run build
111
+
112
+ # Build for specific environments
113
+ npm run build:admin-prod
114
+ npm run build:client-qa
115
+ ```
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./react-jsx-runtime-vendor-Dszzpdy0.cjs"),t=require("@chakra-ui/react"),r=require("react"),ge=require("./ufuzzy-vendor-7qHa_k39.cjs"),X=require("./react-select-vendor-D_Q2fL5j.cjs"),de=require("./react-icons-vendor-D2s8zw9h.cjs"),q=require("./graphql-vendor-B-QTAQSb.cjs"),$=require("./generated.cjs"),y=require("./graphql-C6M9oyU0.cjs"),le=require("./react-dnd-vendor-BPzSDojS.cjs"),F=require("./generated-graphql.cjs"),K=require("./services.cjs"),oe=require("./types.cjs"),re=require("./utils.cjs"),Ee=require("./hooks.cjs"),Re=({setSearch:o,actions:n,updateUseCases:l,hideUseCaseFilter:d=!1})=>{const m=r.useMemo(()=>n?.flatMap(c=>c.useCases).filter((c,x,f)=>f.findIndex(i=>i.id===c.id)===x).map(c=>({label:c.name,value:c.id}))||[],[n]);return e.jsxRuntimeExports.jsxs(t.Flex,{width:"100%",alignContent:"space-evenly",gap:4,children:[e.jsxRuntimeExports.jsxs(t.InputGroup,{size:"md",flex:1,children:[e.jsxRuntimeExports.jsx(t.InputLeftElement,{children:e.jsxRuntimeExports.jsx(t.Icon,{as:de.FaSearch,color:"gray.300"})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"Search by name...",width:"100%",maxW:d?void 0:"30rem",onChange:c=>o(c.target.value)})]}),!d&&e.jsxRuntimeExports.jsx(t.InputGroup,{size:"md",children:e.jsxRuntimeExports.jsx(X.st,{size:"md",chakraStyles:{container:c=>({...c,width:"100%"})},menuPortalTarget:document.body,placeholder:"Filter use case",isMulti:!0,options:m,onChange:c=>l(c.map(x=>x.value))})})]})},Z=({children:o})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:o}),fe=({value:o,onChange:n})=>{const l=r.useState(()=>Math.random().toString(36).substring(2,15))[0],d=r.useCallback((m,c)=>{n(x=>{const f=[...x],[i]=f.splice(m,1);return f.splice(c,0,i),f})},[n]);return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsx(le.DndProvider,{backend:le.HTML5Backend,children:e.jsxRuntimeExports.jsx(t.TableContainer,{children:e.jsxRuntimeExports.jsxs(t.Table,{variant:"simple",size:"md",children:[e.jsxRuntimeExports.jsx(t.Thead,{children:e.jsxRuntimeExports.jsxs(t.Tr,{children:[e.jsxRuntimeExports.jsx(t.Th,{children:"Order"}),e.jsxRuntimeExports.jsx(t.Th,{children:"Name"})]})}),e.jsxRuntimeExports.jsx(t.Tbody,{children:o.map((m,c)=>e.jsxRuntimeExports.jsx(be,{listKey:l,index:c,id:m.id,name:m.name,move:d},m.id))})]})})})})},be=({listKey:o,index:n,id:l,name:d,move:m})=>{const c=r.useRef(null),[{handlerId:x},f]=le.useDrop({accept:o,collect:p=>({handlerId:p.getHandlerId()?.toString()??""}),hover:(p,C)=>{if(!c.current)return;const a=p.index,u=n;if(a===u)return;const j=c.current?.getBoundingClientRect(),g=(j.bottom-j.top)/2,T=C.getClientOffset().y-j.top;a<u&&T<g||a>u&&T>g||(m(a,u),p.index=u)}}),[{isDragging:i},N]=le.useDrag({type:o,item:()=>({id:l,index:n}),collect:p=>({isDragging:p.isDragging()})}),E=i?.6:1,M=i?"grabbing":"grab";return N(f(c)),e.jsxRuntimeExports.jsxs(t.Tr,{ref:c,style:{opacity:E,cursor:M},"data-handler-id":x,children:[e.jsxRuntimeExports.jsx(t.Td,{children:n+1}),e.jsxRuntimeExports.jsx(t.Td,{children:d})]})},ve=({items:o,onChange:n,selectedItem:l,isDisabled:d,selectedProps:m,buttonProps:c})=>{const x=i=>i===l||i.value===l,f=i=>x(i)?{...c,...m}:c;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:d,children:o.map((i,N)=>e.jsxRuntimeExports.jsx(t.Tooltip,{label:i.tooltip,openDelay:50,closeDelay:200,placement:"top",visibility:i.tooltip?"visible":"hidden",hasArrow:!0,children:e.jsxRuntimeExports.jsx(t.Button,{onClick:()=>x(i)?null:n(i,N),isDisabled:i.disabled,...f(i),children:i.label})},N))})},ie=(o,n)=>n<0?-1*Math.abs(o):Math.abs(o),ye=({isReversed:o,min:n,max:l,value:d,onChange:m,inputProps:c,size:x,zeroMarker:f,formatValue:i,valueLabel:N,positiveNegativeLabels:E,isDisabled:M,...p})=>{const[C,a]=r.useState([void 0,void 0]),u=C[0],j=C[1],g=f&&n<-5&&l>5,b=Number(d?.[0]??j??n)>0?1:-1,T=Number(d?.[1]??j??l)<0?-1:1,z=E?.[0]===E?.[1],D=d?.[0],A=d?.[1];r.useEffect(()=>{D!==void 0&&A!==void 0&&a([D.toFixed(0),A.toFixed(0)])},[D,A,a]);const L=r.useCallback(([v,G])=>{v<G&&a([v.toFixed(0),G.toFixed(0)])},[a]),_=r.useCallback(([v,G])=>{v<G&&m([v,G])},[m]),P=r.useCallback(()=>{a(([v,G])=>{const J=isNaN(Number(v))?n:Number(v),s=isNaN(Number(G))?l:Number(G),h=ie(Number(J),b),S=ie(Number(s),T),I=b<0?Math.max(h,n):Math.min(h,l),B=T<0?Math.max(S,n):Math.min(S,l);return I>B?(m([B,I]),[B.toFixed(0),I.toFixed(0)]):(m([I,B]),[I.toFixed(0),B.toFixed(0)])})},[m,a,b,T,n,l]),R=r.useCallback(v=>{const G=v===""||isNaN(Number(v))?v:ie(Number(v),b);a(([J,s])=>[G.toString(),s])},[a,b]),w=r.useCallback(v=>{const G=v===""||isNaN(Number(v))?v:ie(Number(v),T);a(([J,s])=>[J,G.toString()])},[a,T]),k=r.useMemo(()=>x==="xs"?"0.75rem":void 0,[x]),H=r.useCallback((v,G)=>{const J=Number(G.target.value);if(!u||!j||![-1,1].includes(J))return;const s=I=>J<0?-1*Math.abs(I):Math.abs(I),h=v?s(Number(u)):Number(u),S=v?Number(j):s(Number(j));h>S?m([S,h]):m([h,S])},[u,j,m]);return e.jsxRuntimeExports.jsxs(t.Flex,{direction:"column",...p,children:[e.jsxRuntimeExports.jsx(t.Box,{pt:"1em",mb:"-0.5em",children:e.jsxRuntimeExports.jsxs(t.RangeSlider,{"aria-label":["min","max"],isReversed:o,value:[Number(u??n),Number(j??l)],max:l,min:n,minStepsBetweenThumbs:3,step:1,onChange:L,onChangeEnd:_,isDisabled:M,children:[e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:n,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:x??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:i?i?.(n):n})}),e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:l,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:x??"sm",fontWeight:"semibold",style:{transform:"translateX(-100%)"},whiteSpace:"nowrap",children:i?i(l):l})}),g&&e.jsxRuntimeExports.jsxs(t.RangeSliderMark,{value:0,top:"-1em",pos:"relative",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:x,fontWeight:"semibold",children:i?.(0)??"0"}),e.jsxRuntimeExports.jsx(t.Box,{position:"absolute",width:"2px",height:"1em",top:"90%",left:"20%",backgroundColor:"var(--chakra-colors-gray-300)"})]}),e.jsxRuntimeExports.jsx(t.RangeSliderTrack,{children:e.jsxRuntimeExports.jsx(t.RangeSliderFilledTrack,{})}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:0,w:k,h:k}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:1,w:k,h:k})]})}),N&&e.jsxRuntimeExports.jsxs(t.Flex,{direction:o?"row-reverse":"row",justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:x??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:N(n)}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:x??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:N(l)})]}),e.jsxRuntimeExports.jsxs(t.Flex,{direction:o?"row-reverse":"row",justifyContent:"center",alignItems:"center",gap:"0.125em",children:[E&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:x,fontWeight:"bold",value:b,onChange:v=>H(!0,v),isDisabled:z||M,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:E[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:E[1]})]}),e.jsxRuntimeExports.jsx(t.NumberInput,{precision:0,size:x??"sm",min:0,max:b<0?Math.abs(n):A??l,value:u===""?"":Math.abs(Number(u??n)),onChange:R,onBlur:P,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:M,...c,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),e.jsxRuntimeExports.jsx(t.NumberInput,{size:x??"sm",min:0,max:T<0?Math.abs(D??n):l,precision:0,value:j===""?"":Math.abs(Number(j??l)),onChange:w,onBlur:P,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:M,...c,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),E&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:x,fontWeight:"bold",value:T,onChange:v=>H(!1,v),isDisabled:z||M,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:E[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:E[1]})]})]})]})},Ce=({tags:o,containerProps:n,...l})=>e.jsxRuntimeExports.jsx(t.HStack,{...n,children:o.map((d,m)=>e.jsxRuntimeExports.jsx(t.Tag,{...l,children:d},m))}),Te=new ge.uFuzzy({}),Se=({action:o,quantumIconSrc:n})=>o.quantumOwned?e.jsxRuntimeExports.jsx(t.Tooltip,{label:"This activity is owned by Quantum","aria-label":"Quantum owned",children:e.jsxRuntimeExports.jsx(t.Box,{boxSize:"1.5em",borderRadius:"full",bg:"black",display:"flex",alignItems:"center",justifyContent:"center",children:e.jsxRuntimeExports.jsx(t.Image,{src:n,boxSize:"1em",alt:"Quantum-owned activity"})})}):null,Me=(o,n)=>{if(!n||!n.trim().length)return o;const l=o.map(m=>m.name??"");return Te.filter(l,n)?.map(m=>o[m])??[]},Ae=o=>!o||o.length===0?"None":o.map(n=>n.replace(/([A-Z])/g," $1").trim()).join(", "),we=(o,n)=>!n||n.length==0?o:o.filter(l=>l.useCases?.some(d=>n.includes(d.id))??!1),xe=({actions:o,totalActions:n,onCreate:l,onDelete:d,onEdit:m,onView:c,onSelected:x,onDuplicate:f,disableMultiSelect:i,disableDelete:N,disableEdit:E,disableCreate:M,hideUseCase:p=!0,tableProps:C,containerProps:a,quantumIconSrc:u="/favicon.ico"})=>{const[j,g]=r.useState(""),[b,T]=r.useState(),z=r.useMemo(()=>{if(!o)return;const R=Me(o,j);return p?R:we(R,b)},[o,j,b,p]),D=r.useCallback(()=>{if(!d)return;const w=o.filter(k=>k.selected&&!k.quantumOwned).map(k=>k.id);d(w)},[o,d]),A=r.useCallback(()=>{if(!f)return;const R=o.filter(w=>w.selected);f(R.map(w=>w.id)),x&&R.forEach(w=>x(w,!1))},[o,f,x]),L=r.useMemo(()=>o.some(R=>R.selected&&!R.quantumOwned),[o]),_=r.useMemo(()=>o.some(R=>R.selected),[o]),P=r.useMemo(()=>o.some(R=>R.selected&&R.quantumOwned),[o]);return e.jsxRuntimeExports.jsxs(t.Box,{...a,children:[e.jsxRuntimeExports.jsxs(t.Flex,{alignContent:"space-between",gap:4,children:[(l||d||f)&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mb:"1rem",gap:4,children:[l&&e.jsxRuntimeExports.jsx(t.Button,{isDisabled:!l||M,colorScheme:"blackAlpha",backgroundColor:"gray.700",onClick:l,children:"Create New Activity"}),d&&!i&&e.jsxRuntimeExports.jsx(t.Tooltip,{label:P?L?"Quantum-owned activities are selected and will be skipped":"Selected activities are quantum-owned and cannot be deleted":void 0,shouldWrapChildren:!0,children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!L||!d||N,onClick:D,children:"Delete Selected"})}),f&&!i&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!_,onClick:A,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx(Re,{setSearch:g,actions:o,updateUseCases:T,hideUseCaseFilter:p})]}),e.jsxRuntimeExports.jsx(t.TableContainer,{mr:"2rem",overflowX:"hidden",...C,children:e.jsxRuntimeExports.jsxs(t.Table,{size:"md",variant:"simple",children:[e.jsxRuntimeExports.jsx(t.Thead,{position:"sticky",top:0,bg:"white",zIndex:1,children:e.jsxRuntimeExports.jsxs(t.Tr,{children:[e.jsxRuntimeExports.jsxs(t.Th,{fontWeight:"normal",children:["(showing ",z?.length??0," of"," ",n??o.length,")"]}),e.jsxRuntimeExports.jsx(t.Th,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Th,{children:"Sensor Locations"}),!p&&e.jsxRuntimeExports.jsx(t.Th,{children:"Use Case"}),e.jsxRuntimeExports.jsx(t.Th,{})]})}),e.jsxRuntimeExports.jsx(t.Tbody,{children:z?.map(R=>e.jsxRuntimeExports.jsxs(t.Tr,{title:i&&R.selected?"This activity is selected. Click it again to deselect.":void 0,bg:i&&R.selected?"gray.200":void 0,_hover:{bg:i&&!R.selected?"#f7f7f7":void 0},cursor:i?"pointer":"default",onClick:()=>i?x?.(R,!R.selected):void 0,children:[e.jsxRuntimeExports.jsx(t.Td,{children:e.jsxRuntimeExports.jsxs(t.Flex,{children:[x&&!i&&e.jsxRuntimeExports.jsx(t.Checkbox,{isChecked:R.selected,"aria-label":"Select activity",onChange:w=>x(R,w.target.checked)}),(R.quantumOwned||!m)&&c&&e.jsxRuntimeExports.jsx(t.Button,{ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:()=>c(R.id),children:"View"}),!R.quantumOwned&&m&&e.jsxRuntimeExports.jsx(t.Button,{isDisabled:E,ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:()=>m(R.id),children:"Edit"})]})}),e.jsxRuntimeExports.jsx(t.Td,{whiteSpace:"break-spaces",children:e.jsxRuntimeExports.jsxs(t.Flex,{align:"center",gap:2,children:[e.jsxRuntimeExports.jsx(Se,{action:R,quantumIconSrc:u}),R.name]})}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",whiteSpace:"break-spaces",children:Ae(R.sensorLocations)}),!p&&e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:e.jsxRuntimeExports.jsx(Ce,{containerProps:{flexWrap:"wrap"},tags:R.useCases?.map(w=>w.name)??[]})})]},R.id))})]})})]})},Oe=({onSave:o,onCancel:n,onError:l,hideButtons:d=!1,setButtonDisabled:m,setButtonOnClick:c,quantumOwned:x})=>{const f=t.useToast(),[i,N]=r.useState("copy"),[E,M]=r.useState(""),[p,C]=r.useState([]),[a,u]=r.useState(!1),[j]=q.useQuery({query:y.GET_GROUPS}),[g]=q.useQuery({query:y.GET_ACTIONS_BY_GROUP,variables:{groupId:E},pause:!E}),[,b]=q.useMutation(y.CREATE_ACTION),[,T]=q.useMutation(y.CONVERT_ACTION_TO_QUANTUM_OWNED),z=r.useMemo(()=>j.data?.groups?j.data.groups.map(s=>$.getFragmentData(y.GROUP_FRAGMENT,s)):[],[j.data]),D=r.useMemo(()=>g.data?g.data.actions.map(h=>$.getFragmentData(y.ACTION_FRAGMENT,h)):[],[g.data]),A=r.useMemo(()=>D.filter(s=>p.includes(s.id)),[D,p]),L=r.useCallback(s=>{const h=s?.value||"";M(h),C([])},[]),_=r.useCallback(s=>{const h=s.map(S=>S.value);C(h)},[]),P=r.useCallback(async s=>{const h=$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,s.categories),S={...s,name:`${s.name} (Copy)`,description:s.description||void 0,instructionsPointOfInterest:s.instructionsPointOfInterest||void 0,instructionsMovementReport:s.instructionsMovementReport||void 0,laterality:s.laterality,activityKind:s.activityKind,sensorLocations:s.sensorLocations,thresholds:s.thresholds.map(B=>({...B,id:void 0})),categories:h?.map(B=>B.id),quantumOwned:x,id:void 0},I=await b({fields:S});if(I.error)throw new Error(I.error.message);if(I.data?.createAction)return $.getFragmentData(y.ACTION_FRAGMENT,I.data.createAction);throw new Error("No action data returned")},[b,x]),R=r.useCallback(async s=>{const h=await T({id:s.id});if(h.error)throw new Error(h.error.message);if(h.data?.convertActionToQuantumOwned)return $.getFragmentData(y.ACTION_FRAGMENT,h.data.convertActionToQuantumOwned);throw new Error("No action data returned")},[T]),w=r.useCallback(async()=>{if(u(!0),!A.length){const s=new Error(`No activities selected for ${i==="copy"?"copying":"converting"}`);l?.(s),u(!1);return}try{const s=[];let h=0;const S=i==="copy"?P:R,I=i==="copy"?"copy":"convert";for(const B of A)try{const U=await S(B);s.push(U)}catch(U){console.error(`Failed to ${I} activity "${B.name}":`,U),h++}if(s.length>0){const B=s.length,U=A.length,Y=i==="copy"?"copied":"converted",Q=i==="copy"?"copy":"convert";f({title:h>0?`Partial ${Q} completed`:`Activities ${Y} successfully`,description:h>0?`${B} of ${U} activities ${Y} successfully`:`${B} activit${B>1?"ies":"y"} ${Y} successfully`,status:h>0?"warning":"success",duration:3e3,isClosable:!0}),o?.(),M(""),C([])}else throw new Error(`Failed to ${I} any activities`)}catch(s){const h=i==="copy"?"copy":"convert",S=s instanceof Error?s.message:`Failed to ${h} activities`;f({title:`${i==="copy"?"Copy":"Convert"} failed`,description:S,status:"error",duration:5e3,isClosable:!0}),l?.(s instanceof Error?s:new Error(S))}finally{u(!1)}},[A,i,P,R,f,o,l]),k=r.useCallback(()=>{M(""),C([]),N("copy"),n?.()},[n]);r.useEffect(()=>{m&&m({cancelButton:!1,saveButton:A.length===0||a})},[A.length,a,m]),r.useEffect(()=>{c&&c({cancelButton:k,saveButton:w})},[c,k,w]);const H=r.useMemo(()=>z.map(s=>({value:s.id,label:s.name})),[z]),v=r.useMemo(()=>D.filter(s=>i==="copy"?!0:!s.quantumOwned).map(s=>({value:s.id,label:s.name,isQuantumOwned:s.quantumOwned})),[D,i]),G=j.fetching,J=g.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[x&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:i,onChange:s=>{N(s),C([])},children:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:6,children:[e.jsxRuntimeExports.jsx(t.Radio,{value:"copy",colorScheme:"blue",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"medium",children:"Copy Activities"}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.600",children:"Create new activities based on selected ones"})]})}),e.jsxRuntimeExports.jsx(t.Radio,{value:"convert",colorScheme:"green",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"medium",children:"Convert to Quantum Owned"}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.600",children:"Convert existing activities to quantum-owned"})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(X.st,{placeholder:"Choose a group...",options:H,value:H.find(s=>s.value===E)||null,onChange:L,isLoading:G,isDisabled:G,isClearable:!0}),j.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",j.error.message]})]})]}),E&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsxs(Z,{children:["Select Activities to"," ",i==="copy"?"Copy":"Convert"]}),J?e.jsxRuntimeExports.jsxs(t.HStack,{children:[e.jsxRuntimeExports.jsx(t.Spinner,{size:"sm"}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.600",children:"Loading activities..."})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(X.st,{placeholder:`Choose activities to ${i}...`,options:v,value:v.filter(s=>p.includes(s.value)),onChange:_,isDisabled:v.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(s,{context:h})=>e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",w:"100%",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(t.Text,{children:s.label}),h==="value"&&s.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),s.isQuantumOwned&&h==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),v.length===0&&e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:"No activities found"})]}),g.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load activities: ",g.error.message]})]})]}),A.length>0&&e.jsxRuntimeExports.jsxs(t.Box,{p:4,bg:"gray.50",borderRadius:"md",children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"semibold",mb:3,children:A.length===1?`Activity to ${i==="copy"?"Copy":"Convert"}:`:`${A.length} Activities to ${i==="copy"?"Copy":"Convert"}:`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[A.map((s,h)=>e.jsxRuntimeExports.jsxs(t.Box,{w:"100%",p:3,bg:"white",borderRadius:"md",border:"1px solid",borderColor:"gray.200",children:[e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",align:"start",mb:2,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"medium",fontSize:"sm",children:[h+1,". ",s.name]}),s.quantumOwned&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,fontSize:"sm",color:"gray.600",children:[s.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",s.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Type:"})," ",s.activityKind]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Laterality:"})," ",s.laterality]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Sensor Locations:"})," ",s.sensorLocations.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Thresholds:"})," ",s.thresholds.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Use Cases:"})," ",s.useCases.map(S=>S.name).join(", ")||"None"]})]})]},s.id)),A.length>1&&e.jsxRuntimeExports.jsx(t.Box,{w:"100%",p:2,bg:"blue.50",borderRadius:"md",border:"1px solid",borderColor:"blue.200",children:e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",fontWeight:"medium",color:"blue.800",children:["Total: ",A.length," activities will be"," ",i==="copy"?"copied":"converted"]})})]})]}),!d&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:k,isDisabled:a,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:i==="copy"?"blue":"green",onClick:w,isDisabled:A.length===0||a,isLoading:a,loadingText:`${i==="copy"?"Copying":"Converting"}...`,children:[i==="copy"?"Copy":"Convert"," ",A.length===1?"Activity":`${A.length} Activities`]})]})]})})},Fe=({onSave:o,onCancel:n,onError:l,hideButtons:d=!1,setButtonDisabled:m,setButtonOnClick:c,quantumOwned:x})=>{const f=t.useToast(),[i,N]=r.useState(""),[E,M]=r.useState([]),[p,C]=r.useState(!1),[a,u]=r.useState("copy"),[j]=q.useQuery({query:y.GET_GROUPS}),[g]=q.useQuery({query:y.GET_MODULES_BY_GROUP,variables:{groupId:i},pause:!i}),[,b]=q.useMutation(y.CREATE_MODULE),[,T]=q.useMutation(y.UPDATE_MODULE),[,z]=q.useMutation(y.CREATE_ACTION),[,D]=q.useMutation(y.CONVERT_ACTION_TO_QUANTUM_OWNED),A=r.useMemo(()=>j.data?.groups?j.data.groups.map(s=>$.getFragmentData(y.GROUP_FRAGMENT,s)):[],[j.data]),L=r.useMemo(()=>g.data?.modules?$.getFragmentData(y.ACTION_MODULE_FRAGMENT,g.data?.modules).map(h=>{const S=$.getFragmentData(y.MODULE_ACTION_FRAGMENT,h.moduleActions);return{...h,moduleActions:S.map(I=>({...I,action:$.getFragmentData(y.ACTION_FRAGMENT,I.action)})),categories:$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,h.categories)}}):[],[g.data]),_=r.useMemo(()=>L.filter(s=>E.includes(s.id)),[L,E]),P=r.useCallback(s=>{const h=s?.value||"";N(h),M([])},[]),R=r.useCallback(s=>{const h=s.map(S=>S.value);M(h)},[]),w=r.useCallback(async()=>{if(C(!0),!_.length){C(!1);const s=new Error(`No modules selected for ${a==="convert"?"converting":"copying"}`);l?.(s);return}try{const s=[];let h=0;for(const S of _)try{let I=S.moduleActions.map(B=>B.actionId);if(x){const B=S.moduleActions.map(Q=>Q.action),U=async Q=>{if(a==="copy"){if(Q.quantumOwned)return Q;const ce=$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,Q.categories),ne={...Q,quantumOwned:!0,thresholds:Q.thresholds.map(O=>({...O,id:void 0})),categories:ce?.map(O=>O.id),id:void 0},se=await z({fields:ne});return se.error||!se.data?.createAction?null:$.getFragmentData(y.ACTION_FRAGMENT,se.data.createAction)}if(Q.quantumOwned)return Q;const te=await D({id:Q.id});return te.error||!te.data?.convertActionToQuantumOwned?null:$.getFragmentData(y.ACTION_FRAGMENT,te.data.convertActionToQuantumOwned)};I=(await Promise.all(B.map(U))).filter(Q=>!!Q).map(Q=>Q.id)}if(a==="convert"){const B={name:S.name,description:S.description||void 0,actions:I,categories:S.categories.map(Y=>Y.id),quantumOwned:!0},U=await T({id:S.id,input:B});if(U.error)throw new Error(U.error.message);if(U.data?.updateModule){const Y=$.getFragmentData(y.ACTION_MODULE_FRAGMENT,U.data.updateModule);s.push(Y)}}else{const B={name:`${S.name} (Copy)`,description:S.description||void 0,actions:I,categories:S.categories.map(Y=>Y.id),quantumOwned:x},U=await b({input:B});if(U.error)throw new Error(U.error.message);if(U.data?.createModule){const Y=$.getFragmentData(y.ACTION_MODULE_FRAGMENT,U.data.createModule);s.push(Y)}}}catch(I){console.error(`Failed to ${a==="convert"?"convert":"copy"} module "${S.name}":`,I),h++}if(s.length>0){const S=s.length,I=_.length;f({title:h>0?`Partial ${a==="convert"?"convert":"copy"} completed`:`Modules ${a==="convert"?"converted":"copied"} successfully`,description:h>0?`${S} of ${I} modules ${a==="convert"?"converted":"copied"} successfully`:`${S} module${S>1?"s":""} ${a==="convert"?"converted":"copied"} successfully`,status:h>0?"warning":"success",duration:3e3,isClosable:!0}),s.length>0&&o?.(),N(""),M([])}else throw new Error(`Failed to ${a==="convert"?"convert":"copy"} any modules`)}catch(s){const h=s instanceof Error?s.message:`Failed to ${a==="convert"?"convert":"copy"} modules`;f({title:a==="convert"?"Convert failed":"Copy failed",description:h,status:"error",duration:5e3,isClosable:!0}),l?.(s instanceof Error?s:new Error(h))}finally{C(!1)}},[_,b,T,f,o,l,x,z,D,a]),k=r.useCallback(()=>{N(""),M([]),u("copy"),n?.()},[n]);r.useEffect(()=>{m&&m({cancelButton:!1,saveButton:_.length===0||p})},[_.length,p,m]),r.useEffect(()=>{c&&c({cancelButton:k,saveButton:w})},[c,k,w]);const H=r.useMemo(()=>A.map(s=>({value:s.id,label:s.name})),[A]),v=r.useMemo(()=>L.filter(s=>a==="copy"?!0:!s.quantumOwned).map(s=>({value:s.id,label:s.name,isQuantumOwned:s.quantumOwned})),[L,a]),G=j.fetching,J=g.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[x&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:a,onChange:s=>{u(s),M([])},children:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:6,children:[e.jsxRuntimeExports.jsx(t.Radio,{value:"copy",colorScheme:"blue",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"medium",children:"Copy Modules"}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.600",children:"Create new modules based on selected ones"})]})}),e.jsxRuntimeExports.jsx(t.Radio,{value:"convert",colorScheme:"green",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"medium",children:"Convert to Quantum Owned"}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.600",children:"Convert existing modules to quantum-owned"})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(X.st,{placeholder:"Choose a group...",options:H,value:H.find(s=>s.value===i)||null,onChange:P,isLoading:G,isDisabled:G,isClearable:!0}),j.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",j.error.message]})]})]}),i&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:a==="convert"?"Select Module to Convert":"Select Module to Copy"}),J?e.jsxRuntimeExports.jsxs(t.HStack,{children:[e.jsxRuntimeExports.jsx(t.Spinner,{size:"sm"}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.600",children:"Loading modules..."})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(X.st,{placeholder:a==="convert"?"Choose modules to convert...":"Choose modules to copy...",options:v,value:v.filter(s=>E.includes(s.value)),onChange:R,isDisabled:v.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(s,{context:h})=>e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",w:"100%",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(t.Text,{children:s.label}),h==="value"&&s.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),s.isQuantumOwned&&h==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),v.length===0&&e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:"No modules found in this group"})]}),g.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load modules: ",g.error.message]})]})]}),_.length>0&&e.jsxRuntimeExports.jsxs(t.Box,{p:4,bg:"gray.50",borderRadius:"md",children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"semibold",mb:3,children:_.length===1?`Module to ${a==="copy"?"Copy":"Convert"}`:`${_.length} Modules to ${a==="copy"?"Copy":"Convert"}`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[_.map((s,h)=>e.jsxRuntimeExports.jsxs(t.Box,{w:"100%",p:3,bg:"white",borderRadius:"md",border:"1px solid",borderColor:"gray.200",children:[e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",align:"start",mb:2,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"medium",fontSize:"sm",children:[h+1,". ",s.name]}),s.quantumOwned&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,fontSize:"sm",color:"gray.600",children:[s.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",s.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Actions:"})," ",s.moduleActions.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Categories:"})," ",s.categories.map(S=>S.name).join(", ")||"None"]})]})]},s.id)),_.length>1&&e.jsxRuntimeExports.jsx(t.Box,{w:"100%",p:2,bg:"blue.50",borderRadius:"md",border:"1px solid",borderColor:"blue.200",children:e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",fontWeight:"medium",color:"blue.800",children:["Total: ",_.length," modules will be"," ",a==="copy"?"copied":"converted"]})}),x&&_.filter(s=>s.moduleActions.some(h=>!h.action.quantumOwned)).length>0&&e.jsxRuntimeExports.jsx(t.Box,{p:2,bg:"yellow.50",borderRadius:"md",border:"1px solid",borderColor:"yellow.200",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",fontWeight:"medium",color:"yellow.800",children:a==="convert"?"Converting Modules will convert non QM-Owned Actions to QM-Owned":"Copying Modules with Non QM-Owned Actions will create corresponding QM-Owned Actions"})})]})]}),!d&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:k,isDisabled:p,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:a==="copy"?"blue":"green",onClick:w,isDisabled:_.length===0||p,isLoading:p,loadingText:`${a==="copy"?"Copying":"Converting"}...`,children:[a==="copy"?"Copy":"Convert"," ",_.length===1?"Module":`${_.length} Modules`]})]})]})})},me=({name:o,setName:n,actions:l,selectedActionIds:d,setSelectedActionIds:m,availableCategories:c,selectedCategoryIds:x,setSelectedCategoryIds:f,description:i,setDescription:N,...E})=>{const M=t.useDisclosure(),p=r.useMemo(()=>l.map(b=>({...b,selected:d.includes(b.id)})),[l,d]),C=r.useMemo(()=>l.reduce((b,T)=>(b[T.id]=T,b),{}),[l]),a=r.useMemo(()=>d.map(b=>C[b]),[d,C]),u=r.useCallback((b,T)=>{m(T?[...d,b.id]:d.filter(z=>z!==b.id))},[d,m]),j=r.useCallback(b=>{n(b.target.value)},[n]),g=r.useCallback(b=>{N?.(b.target.value)},[N]);return e.jsxRuntimeExports.jsxs(t.Box,{...E,children:[e.jsxRuntimeExports.jsxs(t.HStack,{gap:"2rem",children:[e.jsxRuntimeExports.jsx(Ne,{name:o??"",onInputChange:j}),e.jsxRuntimeExports.jsx(Le,{availableCategories:c,value:x,onChange:f})]}),e.jsxRuntimeExports.jsx(ke,{description:i??"",onInputChange:g}),e.jsxRuntimeExports.jsx(Ie,{value:a,onChange:m,onAdjustActivities:()=>M.onOpen()}),e.jsxRuntimeExports.jsxs(t.Modal,{isOpen:M.isOpen,onClose:M.onClose,size:"6xl",children:[e.jsxRuntimeExports.jsx(t.ModalOverlay,{}),e.jsxRuntimeExports.jsxs(t.ModalContent,{children:[e.jsxRuntimeExports.jsx(t.ModalHeader,{children:"Select Activities"}),e.jsxRuntimeExports.jsx(t.ModalCloseButton,{}),e.jsxRuntimeExports.jsx(t.ModalBody,{children:e.jsxRuntimeExports.jsx(xe,{actions:p,onSelected:u,disableCreate:!0,disableDelete:!0,tableProps:{height:"28rem",overflowY:"auto"}})}),e.jsxRuntimeExports.jsx(t.ModalFooter,{children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:M.onClose,isDisabled:d.length===0,children:"Done"})})]})]})]})},Ne=r.memo(({name:o,onInputChange:n})=>e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(Z,{children:"Module Name"}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. ACL RTP Test Battery",value:o,onChange:n,isRequired:!0})]})),Le=r.memo(({availableCategories:o,value:n,onChange:l})=>{const d=r.useMemo(()=>[...o,{id:"other",name:"Other"}],[o]),m=r.useMemo(()=>d.map(c=>({value:c.id,label:c.name})),[d]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(Z,{children:"Module Category"}),e.jsxRuntimeExports.jsx(X.st,{isDisabled:o.length===0,options:m,value:n.length===0?{value:"other",label:"Other"}:d.filter(c=>n.includes(c.id)).map(c=>({value:c.id,label:c.name}))[0],onChange:c=>l(c?[c.value]:[]),placeholder:"Select category"})]})}),ke=r.memo(({description:o,onInputChange:n})=>e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(Z,{children:e.jsxRuntimeExports.jsxs("span",{children:["Description",e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",children:"Briefly describe the objective of this module. Max 40 words."})]})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. Assess readiness to return to play post-ACL reconstruction",value:o,onChange:n})]})),Ie=r.memo(({value:o,onChange:n,onAdjustActivities:l})=>{const d=r.useMemo(()=>o.map(m=>({id:m.id,name:m.name})),[o]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(t.HStack,{justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(Z,{children:e.jsxRuntimeExports.jsxs("span",{children:["Activities",e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",children:"Drag and drop to reorder the activities in this module."})]})}),e.jsxRuntimeExports.jsx(t.Button,{size:"sm",variant:"solid",colorScheme:"blue",onClick:l,children:"Add / Remove Activities"})]}),d.length===0?e.jsxRuntimeExports.jsx(t.VStack,{children:e.jsxRuntimeExports.jsxs(t.Text,{color:"gray.500",fontSize:"lg",mb:"4rem",mt:"4rem",children:["No activities selected for this module.",e.jsxRuntimeExports.jsx(t.Button,{ml:"0.5em",size:"sm",variant:"link",colorScheme:"blue",onClick:l,children:"Add activities."})]})}):e.jsxRuntimeExports.jsx(fe,{value:d,onChange:m=>{const c=m(d);n(c.map(x=>x.id))}})]})}),pe=({value:o,onChange:n,forceKind:l,disableRemove:d,disableKind:m,isDisabled:c,lockRanges:x,...f})=>{const i=r.useMemo(()=>[...o].sort((p,C)=>{const a=oe.availablePlanes.indexOf(p.plane),u=oe.availablePlanes.indexOf(C.plane);return a-u}),[o]),N=r.useCallback(p=>"segment"in p.id?K.getSegmentNameWithPlane(p.id.segment,p.plane,!0)??"Unknown":K.getJointNameWithPlane(p.id.joint,p.plane,!0)??"Unknown",[]),E=r.useCallback((p,C)=>{const a=i.findIndex(j=>j.id===C.id&&j.plane===C.plane);let u=[...i];l&&(C={...C,kind:l}),u[a]=C,x&&(u=u.map(j=>({...j,min:C.min,max:C.max}))),n(u)},[n,i,l,x]),M=r.useCallback(p=>{const C=i.filter(a=>a.id!==p.id||a.plane!==p.plane);n(C)},[n,i]);return e.jsxRuntimeExports.jsx(t.VStack,{alignItems:"flex-start",overflowY:"auto",...f,children:i.map((p,C)=>e.jsxRuntimeExports.jsx(De,{label:N(p),parameter:p,onChange:a=>E(C,a),onRemove:d||c?void 0:()=>M(p),forceKind:l,disableKind:m||c,isDisabled:c},`${JSON.stringify(p.id)}-${p.plane}`))})},De=({label:o,parameter:n,onChange:l,onRemove:d,forceKind:m,disableKind:c,isDisabled:x})=>{const f=r.useCallback(E=>"joint"in n.id?K.getJointAngleDirectionName(n.id.joint,n.plane,E<0?-1:1):K.getSegmentAngleDirectionName(n.id.segment,n.plane,E<0?-1:1),[n]),{min:i,max:N}="joint"in n.id?K.getNormativeJointRange(n.id.joint,n.plane):{min:-180,max:180};return e.jsxRuntimeExports.jsxs(t.VStack,{borderRadius:"md",p:2,px:4,bg:"gray.100",w:"100%",overflow:"hidden",flexShrink:"0",children:[e.jsxRuntimeExports.jsxs(t.HStack,{w:"100%",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",flex:1,textTransform:"capitalize",fontWeight:"semibold",children:o}),d&&!x&&e.jsxRuntimeExports.jsx(t.IconButton,{size:"xs",variant:"ghost","aria-label":"delete",icon:e.jsxRuntimeExports.jsx(t.Icon,{as:de.FaTrash}),onClick:d}),!m&&e.jsxRuntimeExports.jsx(ve,{selectedItem:n?.kind??F.ThresholdKind.Limit,onChange:({value:E})=>l({...n,kind:E}),isDisabled:c||x,buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:F.ThresholdKind.Limit,label:"limit"},{value:F.ThresholdKind.Target,label:"target"}]})]}),e.jsxRuntimeExports.jsx(ye,{w:"100%",size:"xs",min:i,max:N,zeroMarker:!0,value:[n.min,n.max],onChange:E=>l({...n,min:E[0],max:E[1]}),formatValue:E=>`${Math.abs(E)}°`,valueLabel:E=>f(E)??"",positiveNegativeLabels:f(0)?[f(-1)??"",f(1)??""]:void 0,isDisabled:x})]})},ae=(o,n)=>"segment"in o&&"segment"in n&&o.segment===n.segment||"joint"in o&&"joint"in n&&o.joint===n.joint,he=({options:o,value:n,onChange:l,forceKind:d,singleValue:m,singleValueSideless:c,editOnly:x,disableKind:f,maxParameters:i,...N})=>{const E=c?2:i,M=r.useMemo(()=>o.map(u=>({label:"segment"in u.id?K.getSegmentNameWithPlane(u.id.segment,u.plane,!0)??"Unknown":K.getJointNameWithPlane(u.id.joint,u.plane,!0)??"Unknown",value:u.id,plane:u.plane})),[o]),p=r.useMemo(()=>{if(!c||n.length===0)return M;const u=n[0];return M.filter(j=>oe.getAnalysisPartIdNoSide(j.value)===oe.getAnalysisPartIdNoSide(u.id)&&j.plane===u.plane)},[M,n,c]),C=r.useMemo(()=>M.filter(u=>n.some(j=>ae(j.id,u.value)&&j.plane===u.plane)),[M,n]),a=r.useCallback(u=>{const j=u.map(g=>{const b=n.find(L=>ae(L.id,g.value)&&L.plane===g.plane),T=o.find(L=>ae(L.id,g.value)&&L.plane===g.plane),z=c?n.find(L=>oe.getAnalysisPartIdNoSide(L.id)===oe.getAnalysisPartIdNoSide(g.value)&&L.plane===g.plane):void 0,D=z&&!b?z.min:T&&T.min?T.min:0,A=z&&!b?z.max:T&&T.max?T.max:0;return b??{id:g.value,plane:g.plane,min:D,max:A,kind:d??F.ThresholdKind.Limit}});l(j)},[l,n,o,d,c]);return r.useEffect(()=>{const u=n.filter(j=>o.some(g=>ae(g.id,j.id)&&g.plane===j.plane));u.length!==n.length&&l(u)},[o,l]),e.jsxRuntimeExports.jsxs(t.Box,{...N,children:[e.jsxRuntimeExports.jsx(X.st,{isMulti:!m,placeholder:n.length?`${n.length} selected`:"Search...",value:C,isDisabled:x||C.length>=(E??1/0),onChange:u=>Array.isArray(u)?a([...u]):a(u!==null?[u]:[]),options:p,controlShouldRenderValue:!1}),e.jsxRuntimeExports.jsx(pe,{marginTop:2,maxH:"28rem",value:n,onChange:l,forceKind:d,disableKind:f,isDisabled:x,lockRanges:c})]})},je=o=>{switch(o){case F.SensorLocation.Thorax:return"Thorax";case F.SensorLocation.CenterBack:return"Center Back";case F.SensorLocation.Pelvis:return"Pelvis";case F.SensorLocation.LeftThigh:return"Left Thigh";case F.SensorLocation.RightThigh:return"Right Thigh";case F.SensorLocation.LeftShank:return"Left Shank";case F.SensorLocation.RightShank:return"Right Shank";case F.SensorLocation.LeftFoot:return"Left Foot";case F.SensorLocation.RightFoot:return"Right Foot";case F.SensorLocation.LeftUpperArm:return"Left Upper Arm";case F.SensorLocation.RightUpperArm:return"Right Upper Arm";case F.SensorLocation.LeftForearm:return"Left Forearm";case F.SensorLocation.RightForearm:return"Right Forearm";case F.SensorLocation.Head:return"Head"}return console.warn(`Unknown sensor location: ${o}`),"Unknown"},_e=6,Ge=[F.SensorLocation.LeftFoot,F.SensorLocation.LeftShank,F.SensorLocation.LeftThigh,F.SensorLocation.Pelvis,F.SensorLocation.RightFoot,F.SensorLocation.RightShank,F.SensorLocation.RightThigh,F.SensorLocation.Thorax,F.SensorLocation.CenterBack,F.SensorLocation.Head],Be=Ge.map(o=>({label:je(o),value:o})),ue=(o,n)=>o.map(l=>({label:n?n(l):l,value:l})),Pe=({id:o,onError:n,onCancel:l,onSave:d,hideButtons:m,setButtonOnClick:c,setButtonDisabled:x,quantumOwned:f,isView:i})=>{const[{fetching:N},E]=q.useMutation(y.CREATE_ACTION),[{fetching:M},p]=q.useMutation(y.UPDATE_ACTION),[{data:C}]=q.useQuery({query:y.GET_ACTION_BY_ID,variables:{id:o??""},pause:!o}),a=$.getFragmentData(y.ACTION_FRAGMENT,C?.getActionById),u=N||M,j=!!a&&!!o,[g,b]=r.useState(""),[T,z]=r.useState(""),[D,A]=r.useState(""),[L,_]=r.useState(""),[P,R]=r.useState(),[w,k]=r.useState([]),[H,v]=r.useState([]),[G,J]=r.useState([]),s=r.useMemo(()=>H.map(O=>O.value),[H]),h=Ee.usePartOptionsForSensorLocations(s),[{data:S}]=q.useQuery({query:y.GET_ALL_MODULE_CATEGORIES}),I=r.useMemo(()=>$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,S?.moduleCategories)?.map(W=>({label:W.name,value:W.id})),[S?.moduleCategories]),B=r.useMemo(()=>ue(Object.values(F.SessionType),K.mapSessionTypeEnumToLabel),[]),[U,Y]=r.useState([]),Q=g.length>0,[te,ce]=r.useState({});r.useEffect(()=>{if(a){const O=$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,a.categories),W={name:a.name,activityType:a.activityType??void 0,description:a.description||"",cameraPlacement:a.cameraPlacement||"",videoLink:a.videoLink||"",sessionType:a.sessionType.map(V=>({label:K.mapSessionTypeEnumToLabel(V),value:V})),categories:O?.map(V=>V.id)||[],sensorLocations:a.sensorLocations.map(V=>({label:je(V),value:V})),thresholds:re.thresholdsToParameters(a.thresholds)};b(W.name),R(W.activityType??void 0),z(W.description),A(W.cameraPlacement),_(W.videoLink),k(W.sessionType),J(O?.map(V=>V.id)||[]),v(W.sensorLocations),Y(W.thresholds),ce(W)}},[a]);const ne=r.useMemo(()=>JSON.stringify(te)!==JSON.stringify({name:g,description:T,cameraPlacement:D,videoLink:L,activityType:P,sessionType:w.map(O=>O.value),categories:G,sensorLocations:s,thresholds:re.parametersToThresholds(U)}),[te,g,s,T,D,L,P,w,G,U]),se=r.useCallback(()=>{const O={name:g,description:T,cameraPlacement:D,videoLink:L,activityType:P,activityKind:K.getActivityKindFromActivityType(P),sessionType:w.map(V=>V.value),categories:G,sensorLocations:s,thresholds:re.parametersToThresholds(U),laterality:F.ActionLaterality.Either,quantumOwned:f};let W;j&&o?W=p({id:o,fields:O}):W=E({fields:O}),W.then(({error:V})=>{V?n(V):d()})},[f,E,p,o,g,s,T,D,L,P,w,G,j,U,d,n]);return r.useEffect(()=>{x&&x({cancelButton:u,saveButton:i?!0:u||!Q||!ne})},[u,x,Q,ne,i]),r.useEffect(()=>{c&&c({cancelButton:l,saveButton:i?()=>{}:se})},[c,l,se,i]),console.log(Q,ne,u,te),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-2 gap-4 w-full",children:[e.jsxRuntimeExports.jsxs("div",{className:"col-span-2 lg:col-span-1 flex flex-col gap-4",children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:g,onChange:O=>b(O.target.value),type:"text",placeholder:"i.e. Lunge & Return",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Activity Type"}),e.jsxRuntimeExports.jsx(X.st,{isClearable:!0,isMulti:!1,value:P?{label:K.mapActivityTypeEnumToLabel(P),value:P}:null,onChange:O=>R(O?.value),options:ue(Object.values(F.ActivityType),K.mapActivityTypeEnumToLabel),placeholder:"(optional) Select activity type",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Camera Placement"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:D,onChange:O=>A(O.target.value),rows:2,placeholder:"(optional) Describe camera setup, placement, angles",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Video Link"}),e.jsxRuntimeExports.jsx(t.Input,{value:L,onChange:O=>_(O.target.value),type:"url",placeholder:"(optional) https://...",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Description"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:T,onChange:O=>z(O.target.value),rows:2,placeholder:"(optional) Describe how to perform the test or exercise",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Link to Category"}),e.jsxRuntimeExports.jsx(X.st,{isMulti:!0,value:I?.filter(O=>G.includes(O.value)),onChange:O=>J((O??[]).map(W=>W.value)),options:I,placeholder:"Select one or more categories",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Session Types"}),e.jsxRuntimeExports.jsx(X.st,{isMulti:!0,value:w,onChange:O=>k(O??[]),options:B,placeholder:"Select one or more session types",isDisabled:i})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"col-span-2 lg:col-span-1 flex flex-col gap-4",children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Sensor Locations"}),e.jsxRuntimeExports.jsx(X.st,{isMulti:!0,value:H,onChange:O=>v([...O]),options:Be,isOptionDisabled:()=>H.length>=_e,isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(he,{options:h,value:U,onChange:Y,editOnly:i})]})]}),e.jsxRuntimeExports.jsx("div",{className:re.cn("col-span-2 flex justify-end",(m||i)&&"hidden"),children:e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mt:16,gap:4,children:[e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:u,onClick:l,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:u||!Q||!ne,isLoading:u,onClick:se,children:"Save changes"})]})})]})},ee=({children:o})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:o}),ze=({id:o,onCancel:n,onSave:l,onError:d,hideButtons:m,quantumOwned:c,setButtonOnClick:x,setButtonDisabled:f})=>{const[{data:i}]=q.useQuery({query:c?y.GET_QUANTUM_OWNED_ACTIONS:y.GET_ACTIONS}),[{data:N}]=q.useQuery({query:y.GET_MODULE_BY_ID,variables:{id:o},pause:!o}),[{data:E}]=q.useQuery({query:y.GET_ALL_MODULE_CATEGORIES}),M=$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,E?.moduleCategories),[{fetching:p},C]=q.useMutation(y.UPDATE_MODULE),[{fetching:a},u]=q.useMutation(y.CREATE_MODULE),j=$.getFragmentData(y.ACTION_FRAGMENT,c?i?.quantumOwnedActions:i?.actions)??[],g=$.getFragmentData(y.ACTION_MODULE_FRAGMENT,N?.module),b=$.getFragmentData(y.MODULE_ACTION_FRAGMENT,g?.moduleActions)??[],[T,z]=r.useState([...b.map(k=>k.actionId)??[]]),[D,A]=r.useState(g?.name??""),[L,_]=r.useState([]),[P,R]=r.useState(g?.description??"");r.useEffect(()=>{g&&(z(b.map(k=>k.actionId)),A(g.name),R(g.description??""),_(g.categories.map(k=>$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,k).id)??[]))},[g,b]);const w=r.useCallback(()=>{let k;const H={actions:T,name:D,categories:L.filter(v=>v!=="other"),description:P,quantumOwned:c};g?k=C({id:g.id,input:H}):k=u({input:H}),k.then(({error:v})=>{v?d(v):l()})},[u,C,T,D,P,L,g,l,d,c]);return r.useEffect(()=>{f&&f({cancelButton:p||a,saveButton:p||a||!D||P.trim().split(/\s+/).filter(Boolean).length>40})},[f,p,a,T,D,P]),r.useEffect(()=>{x&&x({cancelButton:n,saveButton:w})},[x,n,w]),e.jsxRuntimeExports.jsxs(t.Box,{width:"100%",children:[e.jsxRuntimeExports.jsx(me,{name:D,setName:A,actions:j,selectedActionIds:T,setSelectedActionIds:z,availableCategories:M??[],selectedCategoryIds:L,setSelectedCategoryIds:_,description:P,setDescription:R}),!m&&e.jsxRuntimeExports.jsx(t.HStack,{justifyContent:"flex-start",children:e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mt:16,gap:4,children:[e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:p||a,onClick:n,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:p||a||!D||P.trim().split(/\s+/).filter(Boolean).length>40,isLoading:p||a,onClick:w,children:"Save"})]})})]})};exports.ActivityList=xe;exports.CopyActivityForm=Oe;exports.CopyModuleForm=Fe;exports.ModuleForm=me;exports.ParameterEditList=pe;exports.ParameterEditSelect=he;exports.UpsertActivityForm=Pe;exports.UpsertModuleForm=ze;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./react-jsx-runtime-vendor-Dszzpdy0.cjs"),t=require("@chakra-ui/react"),n=require("react"),J=require("urql"),ge=require("./utils-cn-FIKrq5Mb.cjs");require("./moment-vendor-1cRqq0AH.cjs");const ne=require("./hooks.cjs"),ye=require("./ufuzzy-vendor-7qHa_k39.cjs"),me=require("./react-icons-vendor-BF_sZq07.cjs"),oe=require("./react-select-vendor-BeWvSe2q.cjs"),$=require("./generated.cjs"),T=require("./graphql-Ce2MNCsk.cjs"),pe=require("./react-dnd-vendor-PwwXhPmK.cjs"),k=require("./generated-graphql.cjs"),ae=require("./services-human-CnvSTmoF.cjs"),le=require("./types.cjs"),je=require("./utils-parameters-dwKmz1VU.cjs"),Se=({setSearch:o,actions:s,updateUseCases:i,hideUseCaseFilter:x=!1})=>{const h=n.useMemo(()=>s?.flatMap(u=>u.useCases).filter((u,m,g)=>g.findIndex(a=>a.id===u.id)===m).map(u=>({label:u.name,value:u.id}))||[],[s]);return e.jsxRuntimeExports.jsxs(t.Flex,{width:"100%",alignContent:"space-evenly",gap:4,children:[e.jsxRuntimeExports.jsxs(t.InputGroup,{size:"md",flex:1,children:[e.jsxRuntimeExports.jsx(t.InputLeftElement,{children:e.jsxRuntimeExports.jsx(t.Icon,{as:me.FaSearch,color:"gray.300"})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"Search by name...",width:"100%",maxW:x?void 0:"30rem",onChange:u=>o(u.target.value)})]}),!x&&e.jsxRuntimeExports.jsx(t.InputGroup,{size:"md",children:e.jsxRuntimeExports.jsx(oe.st,{size:"md",chakraStyles:{container:u=>({...u,width:"100%"})},menuPortalTarget:document.body,placeholder:"Filter use case",isMulti:!0,options:h,onChange:u=>i(u.map(m=>m.value))})})]})},se=({children:o})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:o}),ve=({value:o,onChange:s})=>{const i=n.useState(()=>Math.random().toString(36).substring(2,15))[0],x=n.useCallback((h,u)=>{s(m=>{const g=[...m],[a]=g.splice(h,1);return g.splice(u,0,a),g})},[s]);return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsx(pe.DndProvider,{backend:pe.HTML5Backend,children:e.jsxRuntimeExports.jsx(t.TableContainer,{children:e.jsxRuntimeExports.jsxs(t.Table,{variant:"simple",size:"md",children:[e.jsxRuntimeExports.jsx(t.Thead,{children:e.jsxRuntimeExports.jsxs(t.Tr,{children:[e.jsxRuntimeExports.jsx(t.Th,{children:"Order"}),e.jsxRuntimeExports.jsx(t.Th,{children:"Name"})]})}),e.jsxRuntimeExports.jsx(t.Tbody,{children:o.map((h,u)=>e.jsxRuntimeExports.jsx(Me,{listKey:i,index:u,id:h.id,name:h.name,move:x},h.id))})]})})})})},Me=({listKey:o,index:s,id:i,name:x,move:h})=>{const u=n.useRef(null),[{handlerId:m},g]=pe.useDrop({accept:o,collect:E=>({handlerId:E.getHandlerId()?.toString()??""}),hover:(E,M)=>{if(!u.current)return;const C=E.index,c=s;if(C===c)return;const R=u.current?.getBoundingClientRect(),p=(R.bottom-R.top)/2,y=M.getClientOffset().y-R.top;C<c&&y<p||C>c&&y>p||(h(C,c),E.index=c)}}),[{isDragging:a},d]=pe.useDrag({type:o,item:()=>({id:i,index:s}),collect:E=>({isDragging:E.isDragging()})}),j=a?.6:1,L=a?"grabbing":"grab";return d(g(u)),e.jsxRuntimeExports.jsxs(t.Tr,{ref:u,style:{opacity:j,cursor:L},"data-handler-id":m,children:[e.jsxRuntimeExports.jsx(t.Td,{children:s+1}),e.jsxRuntimeExports.jsx(t.Td,{children:x})]})},Le=({items:o,onChange:s,selectedItem:i,isDisabled:x,selectedProps:h,buttonProps:u})=>{const m=a=>a===i||a.value===i,g=a=>m(a)?{...u,...h}:u;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:x,children:o.map((a,d)=>e.jsxRuntimeExports.jsx(t.Tooltip,{label:a.tooltip,openDelay:50,closeDelay:200,placement:"top",visibility:a.tooltip?"visible":"hidden",hasArrow:!0,children:e.jsxRuntimeExports.jsx(t.Button,{onClick:()=>m(a)?null:s(a,d),isDisabled:a.disabled,...g(a),children:a.label})},d))})},de=(o,s)=>s<0?-1*Math.abs(o):Math.abs(o),we=({isReversed:o,min:s,max:i,value:x,onChange:h,inputProps:u,size:m,zeroMarker:g,formatValue:a,valueLabel:d,positiveNegativeLabels:j,isDisabled:L,...E})=>{const[M,C]=n.useState([void 0,void 0]),c=M[0],R=M[1],p=g&&s<-5&&i>5,b=Number(x?.[0]??R??s)>0?1:-1,y=Number(x?.[1]??R??i)<0?-1:1,w=j?.[0]===j?.[1],N=x?.[0],z=x?.[1];n.useEffect(()=>{N!==void 0&&z!==void 0&&C([N.toFixed(0),z.toFixed(0)])},[N,z,C]);const O=n.useCallback(([S,G])=>{S<G&&C([S.toFixed(0),G.toFixed(0)])},[C]),D=n.useCallback(([S,G])=>{S<G&&h([S,G])},[h]),P=n.useCallback(()=>{C(([S,G])=>{const V=isNaN(Number(S))?s:Number(S),q=isNaN(Number(G))?i:Number(G),ee=de(Number(V),b),l=de(Number(q),y),r=b<0?Math.max(ee,s):Math.min(ee,i),v=y<0?Math.max(l,s):Math.min(l,i);return r>v?(h([v,r]),[v.toFixed(0),r.toFixed(0)]):(h([r,v]),[r.toFixed(0),v.toFixed(0)])})},[h,C,b,y,s,i]),K=n.useCallback(S=>{const G=S===""||isNaN(Number(S))?S:de(Number(S),b);C(([V,q])=>[G.toString(),q])},[C,b]),A=n.useCallback(S=>{const G=S===""||isNaN(Number(S))?S:de(Number(S),y);C(([V,q])=>[V,G.toString()])},[C,y]),f=n.useMemo(()=>m==="xs"?"0.75rem":void 0,[m]),I=n.useCallback((S,G)=>{const V=Number(G.target.value);if(!c||!R||![-1,1].includes(V))return;const q=r=>V<0?-1*Math.abs(r):Math.abs(r),ee=S?q(Number(c)):Number(c),l=S?Number(R):q(Number(R));ee>l?h([l,ee]):h([ee,l])},[c,R,h]);return e.jsxRuntimeExports.jsxs(t.Flex,{direction:"column",...E,children:[e.jsxRuntimeExports.jsx(t.Box,{pt:"1em",mb:"-0.5em",children:e.jsxRuntimeExports.jsxs(t.RangeSlider,{"aria-label":["min","max"],isReversed:o,value:[Number(c??s),Number(R??i)],max:i,min:s,minStepsBetweenThumbs:3,step:1,onChange:O,onChangeEnd:D,isDisabled:L,children:[e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:s,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:m??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:a?a?.(s):s})}),e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:i,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:m??"sm",fontWeight:"semibold",style:{transform:"translateX(-100%)"},whiteSpace:"nowrap",children:a?a(i):i})}),p&&e.jsxRuntimeExports.jsxs(t.RangeSliderMark,{value:0,top:"-1em",pos:"relative",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:m,fontWeight:"semibold",children:a?.(0)??"0"}),e.jsxRuntimeExports.jsx(t.Box,{position:"absolute",width:"2px",height:"1em",top:"90%",left:"20%",backgroundColor:"var(--chakra-colors-gray-300)"})]}),e.jsxRuntimeExports.jsx(t.RangeSliderTrack,{children:e.jsxRuntimeExports.jsx(t.RangeSliderFilledTrack,{})}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:0,w:f,h:f}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:1,w:f,h:f})]})}),d&&e.jsxRuntimeExports.jsxs(t.Flex,{direction:o?"row-reverse":"row",justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:m??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:d(s)}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:m??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:d(i)})]}),e.jsxRuntimeExports.jsxs(t.Flex,{direction:o?"row-reverse":"row",justifyContent:"center",alignItems:"center",gap:"0.125em",children:[j&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:m,fontWeight:"bold",value:b,onChange:S=>I(!0,S),isDisabled:w||L,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:j[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:j[1]})]}),e.jsxRuntimeExports.jsx(t.NumberInput,{precision:0,size:m??"sm",min:0,max:b<0?Math.abs(s):z??i,value:c===""?"":Math.abs(Number(c??s)),onChange:K,onBlur:P,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:L,...u,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),e.jsxRuntimeExports.jsx(t.NumberInput,{size:m??"sm",min:0,max:y<0?Math.abs(N??s):i,precision:0,value:R===""?"":Math.abs(Number(R??i)),onChange:A,onBlur:P,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:L,...u,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),j&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:m,fontWeight:"bold",value:y,onChange:S=>I(!1,S),isDisabled:w||L,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:j[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:j[1]})]})]})]})},Ae=({tags:o,containerProps:s,...i})=>e.jsxRuntimeExports.jsx(t.HStack,{...s,children:o.map((x,h)=>e.jsxRuntimeExports.jsx(t.Tag,{...i,children:x},h))}),Fe=new ye.uFuzzy({}),Ie=({action:o,quantumIconSrc:s})=>{const{getLabel:i}=ne.useUiLabelContext(),x=n.useMemo(()=>({actionLowerCase:i("action").toLocaleLowerCase()}),[i]);return o.quantumOwned?e.jsxRuntimeExports.jsx(t.Tooltip,{label:`This ${x.actionLowerCase} is owned by Quantum`,"aria-label":"Quantum owned",children:e.jsxRuntimeExports.jsx(t.Box,{boxSize:"1.5em",borderRadius:"full",bg:"black",display:"flex",alignItems:"center",justifyContent:"center",children:e.jsxRuntimeExports.jsx(t.Image,{src:s,boxSize:"1em",alt:`Quantum-owned ${x.actionLowerCase}`})})}):null},Ne=(o,s)=>{if(!s||!s.trim().length)return o;const i=o.map(h=>h.name??"");return Fe.filter(i,s)?.map(h=>o[h])??[]},Oe=o=>!o||o.length===0?"None":o.map(s=>s.replace(/([A-Z])/g," $1").trim()).join(", "),ke=(o,s)=>!s||s.length==0?o:o.filter(i=>i.useCases?.some(x=>s.includes(x.id))??!1),Ee=({actions:o,totalActions:s,onCreate:i,onDelete:x,onEdit:h,onView:u,onSelected:m,onDuplicate:g,disableMultiSelect:a,disableDelete:d,disableEdit:j,disableCreate:L,hideUseCase:E=!0,tableProps:M,containerProps:C,quantumIconSrc:c="/favicon.ico"})=>{const[R,p]=n.useState(""),[b,y]=n.useState(),{getLabel:w}=ne.useUiLabelContext(),N=n.useMemo(()=>({action:w("action"),actionPlural:w("action_plural"),actionLowerCase:w("action").toLocaleLowerCase(),actionPluralLowerCase:w("action_plural").toLocaleLowerCase()}),[w]),z=n.useMemo(()=>{if(!o)return;const f=Ne(o,R);return E?f:ke(f,b)},[o,R,b,E]),O=n.useCallback(()=>{if(!x)return;const I=o.filter(S=>S.selected&&!S.quantumOwned).map(S=>S.id);x(I)},[o,x]),D=n.useCallback(()=>{if(!g)return;const f=o.filter(I=>I.selected);g(f.map(I=>I.id)),m&&f.forEach(I=>m(I,!1))},[o,g,m]),P=n.useMemo(()=>o.some(f=>f.selected&&!f.quantumOwned),[o]),K=n.useMemo(()=>o.some(f=>f.selected),[o]),A=n.useMemo(()=>o.some(f=>f.selected&&f.quantumOwned),[o]);return e.jsxRuntimeExports.jsxs(t.Box,{...C,children:[e.jsxRuntimeExports.jsxs(t.Flex,{alignContent:"space-between",gap:4,children:[(i||x||g)&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mb:"1rem",gap:4,children:[i&&e.jsxRuntimeExports.jsxs(t.Button,{isDisabled:!i||L,colorScheme:"blackAlpha",backgroundColor:"gray.700",onClick:i,children:["Create New ",N.action]}),x&&!a&&e.jsxRuntimeExports.jsx(t.Tooltip,{label:A?P?`Quantum-owned ${N.actionPluralLowerCase} are selected and will be skipped`:`Selected ${N.actionPluralLowerCase} are quantum-owned and cannot be deleted`:void 0,shouldWrapChildren:!0,children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!P||!x||d,onClick:O,children:"Delete Selected"})}),g&&!a&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!K,onClick:D,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx(Se,{setSearch:p,actions:o,updateUseCases:y,hideUseCaseFilter:E})]}),e.jsxRuntimeExports.jsx(t.TableContainer,{mr:"2rem",overflowX:"hidden",...M,children:e.jsxRuntimeExports.jsxs(t.Table,{size:"md",variant:"simple",children:[e.jsxRuntimeExports.jsx(t.Thead,{position:"sticky",top:0,bg:"white",zIndex:1,children:e.jsxRuntimeExports.jsxs(t.Tr,{children:[e.jsxRuntimeExports.jsxs(t.Th,{fontWeight:"normal",children:["(showing ",z?.length??0," of"," ",s??o.length,")"]}),e.jsxRuntimeExports.jsx(t.Th,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Th,{children:"Sensor Locations"}),!E&&e.jsxRuntimeExports.jsx(t.Th,{children:"Use Case"}),e.jsxRuntimeExports.jsx(t.Th,{})]})}),e.jsxRuntimeExports.jsx(t.Tbody,{children:z?.map(f=>e.jsxRuntimeExports.jsxs(t.Tr,{className:ge.cn("hover:bg-[#f7f7f7]",!a&&"cursor-pointer",f.selected&&"bg-gray-200"),onClick:()=>{a||m?.(f,!f.selected)},children:[e.jsxRuntimeExports.jsx(t.Td,{children:e.jsxRuntimeExports.jsxs(t.Flex,{children:[!a&&e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:f.selected?e.jsxRuntimeExports.jsx(me.FaCheckSquare,{className:"text-blue-500"}):e.jsxRuntimeExports.jsx(me.FaSquare,{className:"text-gray-400"})}),(f.quantumOwned||!h)&&u&&e.jsxRuntimeExports.jsx(t.Button,{ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:I=>{I.stopPropagation(),u(f.id)},children:"View"}),!f.quantumOwned&&h&&e.jsxRuntimeExports.jsx(t.Button,{isDisabled:j,ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:I=>{I.stopPropagation(),h(f.id)},children:"Edit"})]})}),e.jsxRuntimeExports.jsx(t.Td,{whiteSpace:"break-spaces",children:e.jsxRuntimeExports.jsxs(t.Flex,{align:"center",gap:2,children:[e.jsxRuntimeExports.jsx(Ie,{action:f,quantumIconSrc:c}),f.name]})}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",whiteSpace:"break-spaces",children:Oe(f.sensorLocations)}),!E&&e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:e.jsxRuntimeExports.jsx(Ae,{containerProps:{flexWrap:"wrap"},tags:f.useCases?.map(I=>I.name)??[]})})]},f.id))})]})})]})},De=({onSave:o,onCancel:s,onError:i,hideButtons:x=!1,setButtonDisabled:h,setButtonOnClick:u,quantumOwned:m})=>{const g=t.useToast(),{getLabel:a}=ne.useUiLabelContext(),d=n.useMemo(()=>({singular:a("action"),plural:a("action_plural"),pluralLowerCase:a("action_plural").toLowerCase(),singularLowerCase:a("action").toLowerCase()}),[a]),[j,L]=n.useState("copy"),[E,M]=n.useState(""),[C,c]=n.useState([]),[R,p]=n.useState(!1),[b]=J.useQuery({query:T.GET_GROUPS}),[y]=J.useQuery({query:T.GET_ACTIONS_BY_GROUP,variables:{groupId:E},pause:!E}),[,w]=J.useMutation(T.CREATE_ACTION),[,N]=J.useMutation(T.CONVERT_ACTION_TO_QUANTUM_OWNED),z=n.useMemo(()=>b.data?.groups?b.data.groups.map(l=>$.getFragmentData(T.GROUP_FRAGMENT,l)):[],[b.data]),O=n.useMemo(()=>y.data?y.data.actions.map(r=>$.getFragmentData(T.ACTION_FRAGMENT,r)):[],[y.data]),D=n.useMemo(()=>O.filter(l=>C.includes(l.id)),[O,C]),P=n.useCallback(l=>{const r=l?.value||"";M(r),c([])},[]),K=n.useCallback(l=>{const r=l.map(v=>v.value);c(r)},[]),A=n.useCallback(async l=>{const r=$.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,l.categories),_=$.getFragmentData(T.METADATA_GROUP_FRAGMENT,l.metadataGroups).flatMap(U=>U.data.map(X=>$.getFragmentData(T.METADATA_ITEM_FRAGMENT,X).id)),B={...l,name:`${l.name} (Copy)`,description:l.description||void 0,instructionsPointOfInterest:l.instructionsPointOfInterest||void 0,instructionsMovementReport:l.instructionsMovementReport||void 0,laterality:l.laterality,activityKind:l.activityKind,sensorLocations:l.sensorLocations,thresholds:l.thresholds.map(U=>({...U,id:void 0})),categories:r?.map(U=>U.id),quantumOwned:m,metadataItemIds:_,id:void 0},Q=await w({fields:B});if(Q.error)throw new Error(Q.error.message);if(Q.data?.createAction)return $.getFragmentData(T.ACTION_FRAGMENT,Q.data.createAction);throw new Error("No action data returned")},[w,m]),f=n.useCallback(async l=>{const r=await N({id:l.id});if(r.error)throw new Error(r.error.message);if(r.data?.convertActionToQuantumOwned)return $.getFragmentData(T.ACTION_FRAGMENT,r.data.convertActionToQuantumOwned);throw new Error("No action data returned")},[N]),I=n.useCallback(async()=>{if(p(!0),!D.length){const l=new Error(`No ${d.pluralLowerCase} selected for ${j==="copy"?"copying":"converting"}`);i?.(l),p(!1);return}try{const l=[];let r=0;const v=j==="copy"?A:f,_=j==="copy"?"copy":"convert";for(const B of D)try{const Q=await v(B);l.push(Q)}catch(Q){console.error(`Failed to ${_} ${d.singularLowerCase} "${B.name}":`,Q),r++}if(l.length>0){const B=l.length,Q=D.length,U=j==="copy"?"copied":"converted",X=j==="copy"?"copy":"convert";g({title:r>0?`Partial ${X} completed`:`${d.plural} ${U} successfully`,description:r>0?`${B} of ${Q} ${d.pluralLowerCase} ${U} successfully`:`${B} ${B>1?d.pluralLowerCase:d.singularLowerCase} ${U} successfully`,status:r>0?"warning":"success",duration:3e3,isClosable:!0}),o?.(),M(""),c([])}else throw new Error(`Failed to ${_} any ${d.pluralLowerCase}`)}catch(l){const r=j==="copy"?"copy":"convert",v=l instanceof Error?l.message:`Failed to ${r} ${d.pluralLowerCase}`;g({title:`${j==="copy"?"Copy":"Convert"} failed`,description:v,status:"error",duration:5e3,isClosable:!0}),i?.(l instanceof Error?l:new Error(v))}finally{p(!1)}},[D,j,A,f,g,o,i]),S=n.useCallback(()=>{M(""),c([]),L("copy"),s?.()},[s]);n.useEffect(()=>{h&&h({cancelButton:!1,saveButton:D.length===0||R})},[D.length,R,h]),n.useEffect(()=>{u&&u({cancelButton:S,saveButton:I})},[u,S,I]);const G=n.useMemo(()=>z.map(l=>({value:l.id,label:l.name})),[z]),V=n.useMemo(()=>O.filter(l=>j==="copy"?!0:!l.quantumOwned).map(l=>({value:l.id,label:l.name,isQuantumOwned:l.quantumOwned})),[O,j]),q=b.fetching,ee=y.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[m&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(se,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:j,onChange:l=>{L(l),c([])},children:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:6,children:[e.jsxRuntimeExports.jsx(t.Radio,{value:"copy",colorScheme:"blue",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"medium",children:["Copy ",d.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",d.plural.toLocaleLowerCase()," ","based on selected ones"]})]})}),e.jsxRuntimeExports.jsx(t.Radio,{value:"convert",colorScheme:"green",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"medium",children:["Convert to Quantum Owned ",d.singular]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Convert existing"," ",d.plural.toLocaleLowerCase()," to quantum-owned"]})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(se,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(oe.st,{placeholder:"Choose a group...",options:G,value:G.find(l=>l.value===E)||null,onChange:P,isLoading:q,isDisabled:q,isClearable:!0}),b.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",b.error.message]})]})]}),E&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsxs(se,{children:["Select ",d.plural," to"," ",j==="copy"?"Copy":"Convert"]}),ee?e.jsxRuntimeExports.jsxs(t.HStack,{children:[e.jsxRuntimeExports.jsx(t.Spinner,{size:"sm"}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Loading ",d.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(oe.st,{placeholder:`Choose ${d.pluralLowerCase} to ${j}...`,options:V,value:V.filter(l=>C.includes(l.value)),onChange:K,isDisabled:V.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(l,{context:r})=>e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",w:"100%",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(t.Text,{children:l.label}),r==="value"&&l.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),l.isQuantumOwned&&r==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),V.length===0&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:["No ",d.pluralLowerCase," found"]})]}),y.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load ",d.pluralLowerCase,":"," ",y.error.message]})]})]}),D.length>0&&e.jsxRuntimeExports.jsxs(t.Box,{p:4,bg:"gray.50",borderRadius:"md",children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"semibold",mb:3,children:D.length===1?`${d.singular} to ${j==="copy"?"Copy":"Convert"}:`:`${D.length} ${d.plural} to ${j==="copy"?"Copy":"Convert"}:`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[D.map((l,r)=>e.jsxRuntimeExports.jsxs(t.Box,{w:"100%",p:3,bg:"white",borderRadius:"md",border:"1px solid",borderColor:"gray.200",children:[e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",align:"start",mb:2,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"medium",fontSize:"sm",children:[r+1,". ",l.name]}),l.quantumOwned&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,fontSize:"sm",color:"gray.600",children:[l.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",l.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Type:"})," ",l.activityKind]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Laterality:"})," ",l.laterality]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Sensor Locations:"})," ",l.sensorLocations.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Thresholds:"})," ",l.thresholds.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Use Cases:"})," ",l.useCases.map(v=>v.name).join(", ")||"None"]})]})]},l.id)),D.length>1&&e.jsxRuntimeExports.jsx(t.Box,{w:"100%",p:2,bg:"blue.50",borderRadius:"md",border:"1px solid",borderColor:"blue.200",children:e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",fontWeight:"medium",color:"blue.800",children:["Total: ",D.length," ",d.pluralLowerCase," will be"," ",j==="copy"?"copied":"converted"]})})]})]}),!x&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:S,isDisabled:R,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:j==="copy"?"blue":"green",onClick:I,isDisabled:D.length===0||R,isLoading:R,loadingText:`${j==="copy"?"Copying":"Converting"}...`,children:[j==="copy"?"Copy":"Convert"," ",D.length===1?d.singular:`${D.length} ${d.plural}`]})]})]})})},_e=({onSave:o,onCancel:s,onError:i,hideButtons:x=!1,setButtonDisabled:h,setButtonOnClick:u,quantumOwned:m})=>{const g=t.useToast(),{getLabel:a}=ne.useUiLabelContext(),d=n.useMemo(()=>({singular:a("module"),plural:a("module_plural"),pluralLowerCase:a("module_plural").toLowerCase(),singularLowerCase:a("module").toLowerCase()}),[a]),j=n.useMemo(()=>({singular:a("action"),plural:a("action_plural"),pluralLowerCase:a("action_plural").toLowerCase(),singularLowerCase:a("action").toLowerCase()}),[a]),[L,E]=n.useState(""),[M,C]=n.useState([]),[c,R]=n.useState(!1),[p,b]=n.useState("copy"),[y]=J.useQuery({query:T.GET_GROUPS}),[w]=J.useQuery({query:T.GET_MODULES_BY_GROUP,variables:{groupId:L},pause:!L}),[,N]=J.useMutation(T.CREATE_MODULE),[,z]=J.useMutation(T.UPDATE_MODULE),[,O]=J.useMutation(T.CREATE_ACTION),[,D]=J.useMutation(T.CONVERT_ACTION_TO_QUANTUM_OWNED),P=n.useMemo(()=>y.data?.groups?y.data.groups.map(r=>$.getFragmentData(T.GROUP_FRAGMENT,r)):[],[y.data]),K=n.useMemo(()=>w.data?.modules?$.getFragmentData(T.ACTION_MODULE_FRAGMENT,w.data?.modules).map(v=>{const _=$.getFragmentData(T.MODULE_ACTION_FRAGMENT,v.moduleActions);return{...v,moduleActions:_.map(B=>({...B,action:$.getFragmentData(T.ACTION_FRAGMENT,B.action)})),categories:$.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,v.categories)}}):[],[w.data]),A=n.useMemo(()=>K.filter(r=>M.includes(r.id)),[K,M]),f=n.useCallback(r=>{const v=r?.value||"";E(v),C([])},[]),I=n.useCallback(r=>{const v=r.map(_=>_.value);C(v)},[]),S=n.useCallback(async()=>{if(R(!0),!A.length){R(!1);const r=new Error(`No modules selected for ${p==="convert"?"converting":"copying"}`);i?.(r);return}try{const r=[];let v=0;for(const _ of A)try{let B=_.moduleActions.map(Q=>Q.actionId);if(m){const Q=_.moduleActions.map(H=>H.action),U=async H=>{if(p==="copy"){if(H.quantumOwned)return H;const F=$.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,H.categories),Y={...H,quantumOwned:!0,thresholds:H.thresholds.map(Z=>({...Z,id:void 0})),categories:F?.map(Z=>Z.id),id:void 0},W=await O({fields:Y});return W.error||!W.data?.createAction?null:$.getFragmentData(T.ACTION_FRAGMENT,W.data.createAction)}if(H.quantumOwned)return H;const ce=await D({id:H.id});return ce.error||!ce.data?.convertActionToQuantumOwned?null:$.getFragmentData(T.ACTION_FRAGMENT,ce.data.convertActionToQuantumOwned)};B=(await Promise.all(Q.map(U))).filter(H=>!!H).map(H=>H.id)}if(p==="convert"){const Q={name:_.name,description:_.description||void 0,actions:B,categories:_.categories.map(X=>X.id),quantumOwned:!0},U=await z({id:_.id,input:Q});if(U.error)throw new Error(U.error.message);if(U.data?.updateModule){const X=$.getFragmentData(T.ACTION_MODULE_FRAGMENT,U.data.updateModule);r.push(X)}}else{const Q={name:`${_.name} (Copy)`,description:_.description||void 0,actions:B,categories:_.categories.map(X=>X.id),quantumOwned:m},U=await N({input:Q});if(U.error)throw new Error(U.error.message);if(U.data?.createModule){const X=$.getFragmentData(T.ACTION_MODULE_FRAGMENT,U.data.createModule);r.push(X)}}}catch(B){console.error(`Failed to ${p==="convert"?"convert":"copy"} module "${_.name}":`,B),v++}if(r.length>0){const _=r.length,B=A.length;g({title:v>0?`Partial ${p==="convert"?"convert":"copy"} completed`:`${d.plural} ${p==="convert"?"converted":"copied"} successfully`,description:v>0?`${_} of ${B} ${d.plural} ${p==="convert"?"converted":"copied"} successfully`:`${_} ${_>1?d.plural:d.singular} ${p==="convert"?"converted":"copied"} successfully`,status:v>0?"warning":"success",duration:3e3,isClosable:!0}),r.length>0&&o?.(),E(""),C([])}else throw new Error(`Failed to ${p==="convert"?"convert":"copy"} any modules`)}catch(r){const v=r instanceof Error?r.message:`Failed to ${p==="convert"?"convert":"copy"} modules`;g({title:p==="convert"?"Convert failed":"Copy failed",description:v,status:"error",duration:5e3,isClosable:!0}),i?.(r instanceof Error?r:new Error(v))}finally{R(!1)}},[A,N,z,g,o,i,m,O,D,p,d]),G=n.useCallback(()=>{E(""),C([]),b("copy"),s?.()},[s]);n.useEffect(()=>{h&&h({cancelButton:!1,saveButton:A.length===0||c})},[A.length,c,h]),n.useEffect(()=>{u&&u({cancelButton:G,saveButton:S})},[u,G,S]);const V=n.useMemo(()=>P.map(r=>({value:r.id,label:r.name})),[P]),q=n.useMemo(()=>K.filter(r=>p==="copy"?!0:!r.quantumOwned).map(r=>({value:r.id,label:r.name,isQuantumOwned:r.quantumOwned})),[K,p]),ee=y.fetching,l=w.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[m&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(se,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:p,onChange:r=>{b(r),C([])},children:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:6,children:[e.jsxRuntimeExports.jsx(t.Radio,{value:"copy",colorScheme:"blue",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"medium",children:["Copy ",d.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",d.pluralLowerCase," based on selected ones"]})]})}),e.jsxRuntimeExports.jsx(t.Radio,{value:"convert",colorScheme:"green",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"medium",children:"Convert to Quantum Owned"}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Convert existing ",d.pluralLowerCase," to quantum-owned"]})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(se,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(oe.st,{placeholder:"Choose a group...",options:V,value:V.find(r=>r.value===L)||null,onChange:f,isLoading:ee,isDisabled:ee,isClearable:!0}),y.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",y.error.message]})]})]}),L&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(se,{children:p==="convert"?`Select ${d.plural} to Convert`:`Select ${d.plural} to Copy`}),l?e.jsxRuntimeExports.jsxs(t.HStack,{children:[e.jsxRuntimeExports.jsx(t.Spinner,{size:"sm"}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Loading ",d.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(oe.st,{placeholder:p==="convert"?`Choose ${d.pluralLowerCase} to convert...`:`Choose ${d.pluralLowerCase} to copy...`,options:q,value:q.filter(r=>M.includes(r.value)),onChange:I,isDisabled:q.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(r,{context:v})=>e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",w:"100%",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(t.Text,{children:r.label}),v==="value"&&r.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),r.isQuantumOwned&&v==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),q.length===0&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:["No ",d.pluralLowerCase," found in this group"]})]}),w.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load ",d.pluralLowerCase,":"," ",w.error.message]})]})]}),A.length>0&&e.jsxRuntimeExports.jsxs(t.Box,{p:4,bg:"gray.50",borderRadius:"md",children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"semibold",mb:3,children:A.length===1?`${d.singular} to ${p==="copy"?"Copy":"Convert"}`:`${A.length} ${d.plural} to ${p==="copy"?"Copy":"Convert"}`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[A.map((r,v)=>e.jsxRuntimeExports.jsxs(t.Box,{w:"100%",p:3,bg:"white",borderRadius:"md",border:"1px solid",borderColor:"gray.200",children:[e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",align:"start",mb:2,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"medium",fontSize:"sm",children:[v+1,". ",r.name]}),r.quantumOwned&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,fontSize:"sm",color:"gray.600",children:[r.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",r.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Activities:"})," ",r.moduleActions.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Categories:"})," ",r.categories.map(_=>_.name).join(", ")||"None"]})]})]},r.id)),A.length>1&&e.jsxRuntimeExports.jsx(t.Box,{w:"100%",p:2,bg:"blue.50",borderRadius:"md",border:"1px solid",borderColor:"blue.200",children:e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",fontWeight:"medium",color:"blue.800",children:["Total: ",A.length," ",d.pluralLowerCase," will be"," ",p==="copy"?"copied":"converted"]})}),m&&A.filter(r=>r.moduleActions.some(v=>!v.action.quantumOwned)).length>0&&e.jsxRuntimeExports.jsx(t.Box,{p:2,bg:"yellow.50",borderRadius:"md",border:"1px solid",borderColor:"yellow.200",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",fontWeight:"medium",color:"yellow.800",children:p==="convert"?`Converting ${d.plural} will convert non QM-Owned ${j.plural} to QM-Owned ${j.plural}`:`Copying ${d.plural} with Non QM-Owned ${j.plural} will create corresponding QM-Owned ${j.plural}`})})]})]}),!x&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:G,isDisabled:c,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:p==="copy"?"blue":"green",onClick:S,isDisabled:A.length===0||c,isLoading:c,loadingText:`${p==="copy"?"Copying":"Converting"}...`,children:[p==="copy"?"Copy":"Convert"," ",A.length===1?d.singular:`${A.length} ${d.plural}`]})]})]})})},Re=({name:o,setName:s,actions:i,selectedActionIds:x,setSelectedActionIds:h,availableCategories:u,selectedCategoryIds:m,setSelectedCategoryIds:g,description:a,setDescription:d,...j})=>{const L=t.useDisclosure(),E=n.useMemo(()=>i.map(b=>({...b,selected:x.includes(b.id)})),[i,x]),M=n.useMemo(()=>i.reduce((b,y)=>(b[y.id]=y,b),{}),[i]),C=n.useMemo(()=>x.map(b=>M[b]),[x,M]),c=n.useCallback((b,y)=>{h(y?[...x,b.id]:x.filter(w=>w!==b.id))},[x,h]),R=n.useCallback(b=>{s(b.target.value)},[s]),p=n.useCallback(b=>{d?.(b.target.value)},[d]);return e.jsxRuntimeExports.jsxs(t.Box,{...j,children:[e.jsxRuntimeExports.jsxs(t.HStack,{gap:"2rem",children:[e.jsxRuntimeExports.jsx(Ge,{name:o??"",onInputChange:R}),e.jsxRuntimeExports.jsx($e,{availableCategories:u,value:m,onChange:g})]}),e.jsxRuntimeExports.jsx(Pe,{description:a??"",onInputChange:p}),e.jsxRuntimeExports.jsx(Be,{value:C,onChange:h,onAdjustActivities:()=>L.onOpen()}),e.jsxRuntimeExports.jsxs(t.Modal,{isOpen:L.isOpen,onClose:L.onClose,size:"6xl",children:[e.jsxRuntimeExports.jsx(t.ModalOverlay,{}),e.jsxRuntimeExports.jsxs(t.ModalContent,{children:[e.jsxRuntimeExports.jsx(t.ModalHeader,{children:"Select Activities"}),e.jsxRuntimeExports.jsx(t.ModalCloseButton,{}),e.jsxRuntimeExports.jsx(t.ModalBody,{children:e.jsxRuntimeExports.jsx(Ee,{actions:E,onSelected:c,disableCreate:!0,disableDelete:!0,tableProps:{height:"28rem",overflowY:"auto"}})}),e.jsxRuntimeExports.jsx(t.ModalFooter,{children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:L.onClose,isDisabled:x.length===0,children:"Done"})})]})]})]})},Ge=n.memo(({name:o,onInputChange:s})=>{const{getLabel:i}=ne.useUiLabelContext(),x=i("module");return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(se,{children:[x," Name"]}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. ACL RTP Test Battery",value:o,onChange:s,isRequired:!0})]})}),$e=n.memo(({availableCategories:o,value:s,onChange:i})=>{const{getLabel:x}=ne.useUiLabelContext(),h=x("module"),u=n.useMemo(()=>[...o,{id:"other",name:"Other"}],[o]),m=n.useMemo(()=>u.map(g=>({value:g.id,label:g.name})),[u]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(se,{children:[h," Category"]}),e.jsxRuntimeExports.jsx(oe.st,{isDisabled:o.length===0,options:m,value:s.length===0?{value:"other",label:"Other"}:u.filter(g=>s.includes(g.id)).map(g=>({value:g.id,label:g.name}))[0],onChange:g=>i(g?[g.value]:[]),placeholder:"Select category"})]})}),Pe=n.memo(({description:o,onInputChange:s})=>{const{getLabel:i}=ne.useUiLabelContext(),x=i("module");return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(se,{children:e.jsxRuntimeExports.jsxs("span",{children:["Description",e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",children:["Briefly describe the objective of this"," ",x.toLocaleLowerCase(),". Max 40 words."]})]})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. Assess readiness to return to play post-ACL reconstruction",value:o,onChange:s})]})}),Be=n.memo(({value:o,onChange:s,onAdjustActivities:i})=>{const{getLabel:x}=ne.useUiLabelContext(),h=n.useMemo(()=>({module:x("module"),moduleLowerCase:x("module").toLocaleLowerCase(),action:x("action"),actionPlural:x("action_plural"),actionPluralLowerCase:x("action_plural").toLocaleLowerCase()}),[x]),u=n.useMemo(()=>o.map(m=>({id:m.id,name:m.name})),[o]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(t.HStack,{justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(se,{children:e.jsxRuntimeExports.jsxs("span",{children:[h.actionPlural,e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",children:["Drag and drop to reorder the ",h.actionPluralLowerCase," in this ",h.moduleLowerCase,"."]})]})}),e.jsxRuntimeExports.jsxs(t.Button,{size:"sm",variant:"solid",colorScheme:"blue",onClick:i,children:["Add / Remove ",h.actionPlural]})]}),u.length===0?e.jsxRuntimeExports.jsx(t.VStack,{children:e.jsxRuntimeExports.jsxs(t.Text,{color:"gray.500",fontSize:"lg",mb:"4rem",mt:"4rem",children:["No ",h.actionPluralLowerCase," selected for this"," ",h.moduleLowerCase,".",e.jsxRuntimeExports.jsxs(t.Button,{ml:"0.5em",size:"sm",variant:"link",colorScheme:"blue",onClick:i,children:["Add ",h.actionPluralLowerCase,"."]})]})}):e.jsxRuntimeExports.jsx(ve,{value:u,onChange:m=>{const g=m(u);s(g.map(a=>a.id))}})]})}),fe=({value:o,onChange:s,forceKind:i,disableRemove:x,disableKind:h,isDisabled:u,lockRanges:m,...g})=>{const a=n.useMemo(()=>[...o].sort((E,M)=>{const C=le.availablePlanes.indexOf(E.plane),c=le.availablePlanes.indexOf(M.plane);return C-c}),[o]),d=n.useCallback(E=>"segment"in E.id?ae.getSegmentNameWithPlane(E.id.segment,E.plane,!0)??"Unknown":ae.getJointNameWithPlane(E.id.joint,E.plane,!0)??"Unknown",[]),j=n.useCallback((E,M)=>{const C=a.findIndex(R=>R.id===M.id&&R.plane===M.plane);let c=[...a];i&&(M={...M,kind:i}),c[C]=M,m&&(c=c.map(R=>({...R,min:M.min,max:M.max}))),s(c)},[s,a,i,m]),L=n.useCallback(E=>{const M=a.filter(C=>C.id!==E.id||C.plane!==E.plane);s(M)},[s,a]);return e.jsxRuntimeExports.jsx(t.VStack,{alignItems:"flex-start",overflowY:"auto",...g,children:a.map((E,M)=>e.jsxRuntimeExports.jsx(Ue,{label:d(E),parameter:E,onChange:C=>j(M,C),onRemove:x||u?void 0:()=>L(E),forceKind:i,disableKind:h||u,isDisabled:u},`${JSON.stringify(E.id)}-${E.plane}`))})},Ue=({label:o,parameter:s,onChange:i,onRemove:x,forceKind:h,disableKind:u,isDisabled:m})=>{const g=n.useCallback(j=>"joint"in s.id?ae.getJointAngleDirectionName(s.id.joint,s.plane,j<0?-1:1):ae.getSegmentAngleDirectionName(s.id.segment,s.plane,j<0?-1:1),[s]),{min:a,max:d}="joint"in s.id?ae.getNormativeJointRange(s.id.joint,s.plane):{min:-180,max:180};return e.jsxRuntimeExports.jsxs(t.VStack,{borderRadius:"md",p:2,px:4,bg:"gray.100",w:"100%",overflow:"hidden",flexShrink:"0",children:[e.jsxRuntimeExports.jsxs(t.HStack,{w:"100%",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",flex:1,textTransform:"capitalize",fontWeight:"semibold",children:o}),x&&!m&&e.jsxRuntimeExports.jsx(t.IconButton,{size:"xs",variant:"ghost","aria-label":"delete",icon:e.jsxRuntimeExports.jsx(t.Icon,{as:me.FaTrash}),onClick:x}),!h&&e.jsxRuntimeExports.jsx(Le,{selectedItem:s?.kind??k.ThresholdKind.Limit,onChange:({value:j})=>i({...s,kind:j}),isDisabled:u||m,buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:k.ThresholdKind.Limit,label:"limit"},{value:k.ThresholdKind.Target,label:"target"}]})]}),e.jsxRuntimeExports.jsx(we,{w:"100%",size:"xs",min:a,max:d,zeroMarker:!0,value:[s.min,s.max],onChange:j=>i({...s,min:j[0],max:j[1]}),formatValue:j=>`${Math.abs(j)}°`,valueLabel:j=>g(j)??"",positiveNegativeLabels:g(0)?[g(-1)??"",g(1)??""]:void 0,isDisabled:m})]})},xe=(o,s)=>"segment"in o&&"segment"in s&&o.segment===s.segment||"joint"in o&&"joint"in s&&o.joint===s.joint,Ce=({options:o,value:s,onChange:i,forceKind:x,singleValue:h,singleValueSideless:u,editOnly:m,disableKind:g,maxParameters:a,...d})=>{const j=u?2:a,L=n.useMemo(()=>o.map(c=>({label:"segment"in c.id?ae.getSegmentNameWithPlane(c.id.segment,c.plane,!0)??"Unknown":ae.getJointNameWithPlane(c.id.joint,c.plane,!0)??"Unknown",value:c.id,plane:c.plane})),[o]),E=n.useMemo(()=>{if(!u||s.length===0)return L;const c=s[0];return L.filter(R=>le.getAnalysisPartIdNoSide(R.value)===le.getAnalysisPartIdNoSide(c.id)&&R.plane===c.plane)},[L,s,u]),M=n.useMemo(()=>L.filter(c=>s.some(R=>xe(R.id,c.value)&&R.plane===c.plane)),[L,s]),C=n.useCallback(c=>{const R=c.map(p=>{const b=s.find(O=>xe(O.id,p.value)&&O.plane===p.plane),y=o.find(O=>xe(O.id,p.value)&&O.plane===p.plane),w=u?s.find(O=>le.getAnalysisPartIdNoSide(O.id)===le.getAnalysisPartIdNoSide(p.value)&&O.plane===p.plane):void 0,N=w&&!b?w.min:y&&y.min?y.min:0,z=w&&!b?w.max:y&&y.max?y.max:0;return b??{id:p.value,plane:p.plane,min:N,max:z,kind:x??k.ThresholdKind.Limit}});i(R)},[i,s,o,x,u]);return n.useEffect(()=>{const c=s.filter(R=>o.some(p=>xe(p.id,R.id)&&p.plane===R.plane));c.length!==s.length&&i(c)},[o,i]),e.jsxRuntimeExports.jsxs(t.Box,{...d,children:[e.jsxRuntimeExports.jsx(oe.st,{isMulti:!h,placeholder:s.length?`${s.length} selected`:"Search...",value:M,isDisabled:m||M.length>=(j??1/0),onChange:c=>Array.isArray(c)?C([...c]):C(c!==null?[c]:[]),options:E,controlShouldRenderValue:!1}),e.jsxRuntimeExports.jsx(fe,{marginTop:2,maxH:"28rem",value:s,onChange:i,forceKind:x,disableKind:g,isDisabled:m,lockRanges:u})]})},be=o=>{switch(o){case k.SensorLocation.Thorax:return"Thorax";case k.SensorLocation.CenterBack:return"Center Back";case k.SensorLocation.Pelvis:return"Pelvis";case k.SensorLocation.LeftThigh:return"Left Thigh";case k.SensorLocation.RightThigh:return"Right Thigh";case k.SensorLocation.LeftShank:return"Left Shank";case k.SensorLocation.RightShank:return"Right Shank";case k.SensorLocation.LeftFoot:return"Left Foot";case k.SensorLocation.RightFoot:return"Right Foot";case k.SensorLocation.LeftUpperArm:return"Left Upper Arm";case k.SensorLocation.RightUpperArm:return"Right Upper Arm";case k.SensorLocation.LeftForearm:return"Left Forearm";case k.SensorLocation.RightForearm:return"Right Forearm";case k.SensorLocation.Head:return"Head"}return console.warn(`Unknown sensor location: ${o}`),"Unknown"},ze=6,qe=[k.SensorLocation.LeftFoot,k.SensorLocation.LeftShank,k.SensorLocation.LeftThigh,k.SensorLocation.Pelvis,k.SensorLocation.RightFoot,k.SensorLocation.RightShank,k.SensorLocation.RightThigh,k.SensorLocation.Thorax,k.SensorLocation.CenterBack,k.SensorLocation.Head],Qe=qe.map(o=>({label:be(o),value:o})),We=({id:o,onError:s,onCancel:i,onSave:x,hideButtons:h,setButtonOnClick:u,setButtonDisabled:m,quantumOwned:g,isView:a})=>{const d=J.useClient(),[{fetching:j},L]=J.useMutation(T.CREATE_ACTION),[{fetching:E},M]=J.useMutation(T.UPDATE_ACTION),[{data:C}]=J.useQuery({query:T.GET_ACTION_BY_ID,variables:{id:o??""},pause:!o}),c=$.getFragmentData(T.ACTION_FRAGMENT,C?.getActionById),R=j||E,p=!!c&&!!o,{getLabel:b}=ne.useUiLabelContext(),y=n.useMemo(()=>({action:b("action")}),[b]),w=n.useMemo(()=>[{key:"module_category",label:"Link Category",multi:!0},{key:"activity_type",label:`${y.action} Type`,multi:!1},{key:"session_type",label:"Session Type",multi:!0},{key:"body_region",label:"Body Region",multi:!0},{key:"sport",label:"Sport",multi:!0}],[y.action]),[N,z]=n.useState(""),[O,D]=n.useState(""),[P,K]=n.useState(""),[A,f]=n.useState(""),[I,S]=n.useState([]),[G,V]=n.useState([]),[q,ee]=n.useState({}),l=n.useMemo(()=>I.map(F=>F.value),[I]),r=ne.usePartOptionsForSensorLocations(l),[v,_]=n.useState([]),B=N.length>0,[Q,U]=n.useState({});n.useEffect(()=>{const F=w.map(Y=>d.query(T.GET_METADATA_BY_KEY,{key:Y.key}));Promise.all(F).then(Y=>{const W={};Y.forEach(Z=>{if(Z.error||!Z.data)return;const te=$.getFragmentData(T.METADATA_GROUP_FRAGMENT,Z.data.getMetadataByKey),he=$.getFragmentData(T.METADATA_ITEM_FRAGMENT,te.data);W[te.key]=he.map(ie=>({label:ie.label||ie.value,value:ie.value,id:ie.id}))}),ee(W)})},[d,w]),n.useEffect(()=>{if(c){const Y=$.getFragmentData(T.METADATA_GROUP_FRAGMENT,c.metadataGroups).map(Z=>Z.data.map(te=>$.getFragmentData(T.METADATA_ITEM_FRAGMENT,te).id)),W={name:c.name,description:c.description||"",cameraPlacement:c.cameraPlacement||"",videoLink:c.videoLink||"",sensorLocations:c.sensorLocations.map(Z=>({label:be(Z),value:Z})),thresholds:je.thresholdsToParameters(c.thresholds),metadataIds:Y.flat()};z(W.name),D(W.description),K(W.cameraPlacement),f(W.videoLink),S(W.sensorLocations),_(W.thresholds),V(W.metadataIds),U(W)}},[c]);const X=n.useMemo(()=>JSON.stringify(Q)!==JSON.stringify({name:N,description:O,cameraPlacement:P,videoLink:A,sensorLocations:l,thresholds:je.parametersToThresholds(v),metadataIds:G}),[Q,N,l,O,P,A,G,v]),H=n.useCallback(()=>{const F={name:N,description:O,cameraPlacement:P,videoLink:A,sensorLocations:l,thresholds:je.parametersToThresholds(v),metadataItemIds:G,laterality:k.ActionLaterality.Either,quantumOwned:g,sessionType:[]};let Y;p&&o?Y=M({id:o,fields:F}):Y=L({fields:F}),Y.then(({error:W})=>{W?s(W):x()})},[g,L,M,o,N,l,O,P,A,G,p,v,x,s]);n.useEffect(()=>{m&&m({cancelButton:R,saveButton:a?!0:R||!B||!X})},[R,m,B,X,a]),n.useEffect(()=>{u&&u({cancelButton:i,saveButton:a?()=>{}:H})},[u,i,H,a]);const ce=(F,Y)=>{const W=w.find(te=>te.key===F);if(!W)return;const Z=W.multi?(Y??[]).map(te=>te.id):Y?[Y.id]:[];V(te=>[...te.filter(ie=>Object.values(q).flat().find(ue=>ue.id===ie)&&!Object.keys(q).find(ue=>q[ue]?.some(Te=>Te.id===ie&&ue===F))),...Z])};return e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-2 gap-4 w-full",children:[e.jsxRuntimeExports.jsxs("div",{className:"col-span-2 lg:col-span-1 flex flex-col gap-4",children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(re,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:N,onChange:F=>z(F.target.value),type:"text",placeholder:"i.e. Lunge & Return",isDisabled:a})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(re,{children:"Camera Placement"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:P,onChange:F=>K(F.target.value),rows:2,placeholder:"(optional) Describe camera setup, placement, angles",isDisabled:a})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(re,{children:"Video Link"}),e.jsxRuntimeExports.jsx(t.Input,{value:A,onChange:F=>f(F.target.value),type:"url",placeholder:"(optional) https://...",isDisabled:a})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(re,{children:"Description"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:O,onChange:F=>D(F.target.value),rows:2,placeholder:"(optional) Describe how to perform the test or exercise",isDisabled:a})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(re,{children:"Metadata Tags"}),w.map(F=>e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(re,{children:F.label}),e.jsxRuntimeExports.jsx(oe.st,{isMulti:F.multi,value:q[F.key]?.filter(Y=>G.includes(Y.id)),onChange:Y=>{ce(F.key,Y)},options:q[F.key],placeholder:`Select ${F.multi?"one or more":"one"} ${F.label.toLowerCase()}`,isDisabled:a,isClearable:F.multi})]},F.key))]})]}),e.jsxRuntimeExports.jsxs("div",{className:"col-span-2 lg:col-span-1 flex flex-col gap-4",children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(re,{children:"Sensor Locations"}),e.jsxRuntimeExports.jsx(oe.st,{isMulti:!0,value:I,onChange:F=>S([...F]),options:Qe,isOptionDisabled:()=>I.length>=ze,isDisabled:a})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(re,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(Ce,{options:r,value:v,onChange:_,editOnly:a})]})]}),e.jsxRuntimeExports.jsx("div",{className:ge.cn("col-span-2 flex justify-end",(h||a)&&"hidden"),children:e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mt:16,gap:4,children:[e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:R,onClick:i,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:R||!B||!X,isLoading:R,onClick:H,children:"Save changes"})]})})]})},re=({children:o})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:o}),He=({id:o,onCancel:s,onSave:i,onError:x,hideButtons:h,quantumOwned:u,setButtonOnClick:m,setButtonDisabled:g})=>{const[{data:a}]=J.useQuery({query:u?T.GET_QUANTUM_OWNED_ACTIONS:T.GET_ACTIONS}),[{data:d}]=J.useQuery({query:T.GET_MODULE_BY_ID,variables:{id:o},pause:!o}),[{data:j}]=J.useQuery({query:T.GET_ALL_MODULE_CATEGORIES}),L=$.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,j?.moduleCategories),[{fetching:E},M]=J.useMutation(T.UPDATE_MODULE),[{fetching:C},c]=J.useMutation(T.CREATE_MODULE),R=$.getFragmentData(T.ACTION_FRAGMENT,u?a?.quantumOwnedActions:a?.actions)??[],p=$.getFragmentData(T.ACTION_MODULE_FRAGMENT,d?.module),b=$.getFragmentData(T.MODULE_ACTION_FRAGMENT,p?.moduleActions)??[],[y,w]=n.useState([...b.map(f=>f.actionId)??[]]),[N,z]=n.useState(p?.name??""),[O,D]=n.useState([]),[P,K]=n.useState(p?.description??"");n.useEffect(()=>{p&&(w(b.map(f=>f.actionId)),z(p.name),K(p.description??""),D(p.categories.map(f=>$.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,f).id)??[]))},[p,b]);const A=n.useCallback(()=>{let f;const I={actions:y,name:N,categories:O.filter(S=>S!=="other"),description:P,quantumOwned:u};p?f=M({id:p.id,input:I}):f=c({input:I}),f.then(({error:S})=>{S?x(S):i()})},[c,M,y,N,P,O,p,i,x,u]);return n.useEffect(()=>{g&&g({cancelButton:E||C,saveButton:E||C||!N||P.trim().split(/\s+/).filter(Boolean).length>40})},[g,E,C,y,N,P]),n.useEffect(()=>{m&&m({cancelButton:s,saveButton:A})},[m,s,A]),e.jsxRuntimeExports.jsxs(t.Box,{width:"100%",children:[e.jsxRuntimeExports.jsx(Re,{name:N,setName:z,actions:R,selectedActionIds:y,setSelectedActionIds:w,availableCategories:L??[],selectedCategoryIds:O,setSelectedCategoryIds:D,description:P,setDescription:K}),!h&&e.jsxRuntimeExports.jsx(t.HStack,{justifyContent:"flex-start",children:e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mt:16,gap:4,children:[e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:E||C,onClick:s,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:E||C||!N||P.trim().split(/\s+/).filter(Boolean).length>40,isLoading:E||C,onClick:A,children:"Save"})]})})]})};exports.ActivityList=Ee;exports.CopyActivityForm=De;exports.CopyModuleForm=_e;exports.ModuleForm=Re;exports.ParameterEditList=fe;exports.ParameterEditSelect=Ce;exports.UpsertActivityForm=We;exports.UpsertModuleForm=He;