quantum-component-library 1.0.0-qa → 1.4.45-dev.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/copy-activity-form/index.d.ts +6 -4
- package/dist/components.cjs +1 -13
- package/dist/components.js +1060 -1006
- package/dist/{dnd-core-vendor-bgjKfDi6.cjs → dnd-core-vendor-2Ve0kqUN.cjs} +1 -1
- package/dist/{dnd-core-vendor-q7mfiuVu.js → dnd-core-vendor-CErAmYu_.js} +2 -2
- package/dist/emotion-react-vendor-CHdBBD18.cjs +1 -0
- package/dist/emotion-react-vendor-CSrsXjBq.js +81 -0
- package/dist/emotion-vendor-D6PQH2K8.cjs +1 -0
- package/dist/emotion-vendor-DNnoMT20.js +546 -0
- package/dist/floating-ui-vendor-BcB50aec.js +246 -0
- package/dist/floating-ui-vendor-Dsd5TAjM.cjs +1 -0
- package/dist/generated/gql.d.ts +5 -0
- package/dist/generated/graphql.d.ts +19 -0
- package/dist/{generated-ChsGaiYd.cjs → generated-B5QGMyhw.cjs} +1 -1
- package/dist/{generated-GfcSQz21.js → generated-esGwfMXj.js} +21 -20
- package/dist/graphql/mutations/actions.d.ts +3 -0
- package/dist/{graphql-DiUes2Np.js → graphql-DpdZo65w.js} +35 -28
- package/dist/{graphql-CqPvuCvr.cjs → graphql-KvyVlavd.cjs} +18 -12
- package/dist/graphql-vendor-BWnD0b-j.js +1285 -0
- package/dist/graphql-vendor-CL0XsjHb.cjs +19 -0
- package/dist/hoist-non-react-statics-vendor-C5vG1oEE.cjs +1 -0
- package/dist/hoist-non-react-statics-vendor-DJU3S3cV.js +68 -0
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.js +45 -46
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +115 -115
- package/dist/{lodash-vendor-D5A6v3mw.cjs → lodash-vendor-CR237hSU.cjs} +1 -1
- package/dist/{lodash-vendor-Dz4vW7Gd.js → lodash-vendor-D4ZPCr77.js} +1 -1
- package/dist/moment-vendor-1cRqq0AH.cjs +10 -0
- package/dist/moment-vendor-DMLRxgRE.js +2589 -0
- package/dist/{other-TR0ap-t4.cjs → other-Dp3RPYfF.cjs} +1 -1
- package/dist/providers.cjs +1 -1
- package/dist/providers.js +8 -8
- package/dist/quantum-component-library.css +1 -1
- package/dist/react-dnd-vendor-BPzSDojS.cjs +2 -0
- package/dist/{react-dnd-vendor-BZs2igAJ.js → react-dnd-vendor-D4nn9Mqx.js} +22 -21
- package/dist/react-is-vendor-CosIbvzW.cjs +15 -0
- package/dist/react-is-vendor-DpFLFzFZ.js +174 -0
- package/dist/react-jsx-runtime-vendor-Dszzpdy0.cjs +22 -0
- package/dist/react-jsx-runtime-vendor-OVHDjVDe.js +284 -0
- package/dist/react-select-vendor-BPaBUHFp.cjs +4 -0
- package/dist/{react-select-vendor-eBH7yy3O.js → react-select-vendor-C_DuqfB7.js} +13 -10
- package/dist/services.cjs +1 -1
- package/dist/services.js +1 -1
- package/dist/stylis-vendor-CdCMw5Aa.js +334 -0
- package/dist/stylis-vendor-DzcTLVj9.cjs +1 -0
- package/dist/tailwind-vendor-B4y94WzT.js +2740 -0
- package/dist/tailwind-vendor-C0M23-WD.cjs +1 -0
- package/dist/types.cjs +1 -1
- package/dist/types.js +2 -2
- package/dist/ufuzzy-vendor-7qHa_k39.cjs +1 -0
- package/dist/ufuzzy-vendor-Dl0ZI6Av.js +456 -0
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +31 -30
- package/dist/vendor-BjLvygDR.cjs +1 -0
- package/dist/vendor-VALJ9W3p.js +526 -0
- package/package.json +14 -10
- package/dist/graphql-vendor-JsvuUrRs.cjs +0 -14
- package/dist/graphql-vendor-YnA_qhJA.js +0 -669
- package/dist/react-dnd-vendor-BWqlt2EC.cjs +0 -2
- package/dist/react-select-vendor-By3h6JjH.cjs +0 -4
- package/dist/styled-components-vendor-Bvwhddj9.js +0 -1154
- package/dist/styled-components-vendor-D09ATioU.cjs +0 -60
- package/dist/vendor-BeqUcSbw.cjs +0 -45
- package/dist/vendor-DvX9OX-j.js +0 -7876
- package/dist/{providers → lib/providers}/index.d.ts +0 -0
- package/dist/{providers → lib/providers}/quantum-library-provider.d.ts +0 -0
- package/dist/{other-CmpBz5tg.js → other-C4VnLmM6.js} +1 -1
|
@@ -20,11 +20,13 @@ export interface CopyActivityFormProps {
|
|
|
20
20
|
quantumOwned?: boolean;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
* Form component for copying activities (actions) from one group.
|
|
23
|
+
* Form component for copying or converting activities (actions) from one group.
|
|
24
24
|
*
|
|
25
25
|
* The workflow is:
|
|
26
|
-
* 1. Select
|
|
27
|
-
* 2. Select
|
|
28
|
-
* 3.
|
|
26
|
+
* 1. Select operation mode (copy/convert) when quantumOwned is enabled
|
|
27
|
+
* 2. Select a source group
|
|
28
|
+
* 3. Select activities from available actions to copy/convert
|
|
29
|
+
* 4. Copy creates new activities with same fields but no ID
|
|
30
|
+
* 5. Convert changes existing activities to quantum-owned
|
|
29
31
|
*/
|
|
30
32
|
export declare const CopyActivityForm: React.FC<CopyActivityFormProps>;
|
package/dist/components.cjs
CHANGED
|
@@ -1,13 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./vendor-BeqUcSbw.cjs"),t=require("@chakra-ui/react"),o=require("react"),xe=require("./styled-components-vendor-D09ATioU.cjs"),H=require("./react-select-vendor-By3h6JjH.cjs"),de=require("./react-icons-vendor-D2s8zw9h.cjs"),G=require("urql"),R=require("./generated-ChsGaiYd.cjs"),w=require("./graphql-CqPvuCvr.cjs"),oe=require("./react-dnd-vendor-BWqlt2EC.cjs"),V=require("./services.cjs"),J=require("./types.cjs"),X=require("./utils.cjs"),Re=require("./hooks.cjs"),fe=({setSearch:n,actions:s,updateUseCases:a})=>{const m=o.useMemo(()=>s?.flatMap(c=>c.useCases).filter((c,u,h)=>h.findIndex(f=>f.id===c.id)===u).map(c=>({label:c.name,value:c.id}))||[],[s]);return e.jsxRuntimeExports.jsxs(t.Flex,{width:"100%",alignContent:"space-evenly",gap:4,children:[e.jsxRuntimeExports.jsxs(t.InputGroup,{size:"md",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...",maxW:"30rem",onChange:c=>n(c.target.value)})]}),e.jsxRuntimeExports.jsx(t.InputGroup,{size:"md",children:e.jsxRuntimeExports.jsx(H.st,{size:"md",chakraStyles:{container:c=>({...c,width:"100%"})},menuPortalTarget:document.body,placeholder:"Filter use case",isMulti:!0,options:m,onChange:c=>a(c.map(u=>u.value))})})]})},Y=({children:n})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:n}),be=({value:n,onChange:s})=>{const a=o.useState(()=>Math.random().toString(36).substring(2,15))[0],m=o.useCallback((c,u)=>{s(h=>{const f=[...h],[b]=f.splice(c,1);return f.splice(u,0,b),f})},[s]);return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsx(oe.DndProvider,{backend:oe.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:n.map((c,u)=>e.jsxRuntimeExports.jsx(Ce,{listKey:a,index:u,id:c.id,name:c.name,move:m},c.id))})]})})})})},Ce=({listKey:n,index:s,id:a,name:m,move:c})=>{const u=o.useRef(null),[{handlerId:h},f]=oe.useDrop({accept:n,collect:E=>({handlerId:E.getHandlerId()?.toString()??""}),hover:(E,A)=>{if(!u.current)return;const d=E.index,l=s;if(d===l)return;const T=u.current?.getBoundingClientRect(),C=(T.bottom-T.top)/2,p=A.getClientOffset().y-T.top;d<l&&p<C||d>l&&p>C||(c(d,l),E.index=l)}}),[{isDragging:b},v]=oe.useDrag({type:n,item:()=>({id:a,index:s}),collect:E=>({isDragging:E.isDragging()})}),F=b?.6:1,g=b?"grabbing":"grab";return v(f(u)),e.jsxRuntimeExports.jsxs(t.Tr,{ref:u,style:{opacity:F,cursor:g},"data-handler-id":h,children:[e.jsxRuntimeExports.jsx(t.Td,{children:s+1}),e.jsxRuntimeExports.jsx(t.Td,{children:m})]})},le=({items:n,onChange:s,selectedItem:a,isDisabled:m,selectedProps:c,buttonProps:u})=>{const h=b=>b===a||b.value===a,f=b=>h(b)?{...u,...c}:u;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:m,children:n.map((b,v)=>e.jsxRuntimeExports.jsx(t.Tooltip,{label:b.tooltip,openDelay:50,closeDelay:200,placement:"top",visibility:b.tooltip?"visible":"hidden",hasArrow:!0,children:e.jsxRuntimeExports.jsx(t.Button,{onClick:()=>h(b)?null:s(b,v),isDisabled:b.disabled,...f(b),children:b.label})},v))})},se=(n,s)=>s<0?-1*Math.abs(n):Math.abs(n),Se=({isReversed:n,min:s,max:a,value:m,onChange:c,inputProps:u,size:h,zeroMarker:f,formatValue:b,valueLabel:v,positiveNegativeLabels:F,isDisabled:g,...E})=>{const[A,d]=o.useState([void 0,void 0]),l=A[0],T=A[1],C=f&&s<-5&&a>5,S=Number(m?.[0]??T??s)>0?1:-1,p=Number(m?.[1]??T??a)<0?-1:1,j=F?.[0]===F?.[1],M=m?.[0],D=m?.[1];o.useEffect(()=>{M!==void 0&&D!==void 0&&d([M.toFixed(0),D.toFixed(0)])},[M,D,d]);const I=o.useCallback(([i,y])=>{i<y&&d([i.toFixed(0),y.toFixed(0)])},[d]),z=o.useCallback(([i,y])=>{i<y&&c([i,y])},[c]),k=o.useCallback(()=>{d(([i,y])=>{const L=isNaN(Number(i))?s:Number(i),_=isNaN(Number(y))?a:Number(y),W=se(Number(L),S),O=se(Number(_),p),q=S<0?Math.max(W,s):Math.min(W,a),B=p<0?Math.max(O,s):Math.min(O,a);return q>B?(c([B,q]),[B.toFixed(0),q.toFixed(0)]):(c([q,B]),[q.toFixed(0),B.toFixed(0)])})},[c,d,S,p,s,a]),U=o.useCallback(i=>{const y=i===""||isNaN(Number(i))?i:se(Number(i),S);d(([L,_])=>[y.toString(),_])},[d,S]),P=o.useCallback(i=>{const y=i===""||isNaN(Number(i))?i:se(Number(i),p);d(([L,_])=>[L,y.toString()])},[d,p]),x=o.useMemo(()=>h==="xs"?"0.75rem":void 0,[h]),r=o.useCallback((i,y)=>{const L=Number(y.target.value);if(!l||!T||![-1,1].includes(L))return;const _=q=>L<0?-1*Math.abs(q):Math.abs(q),W=i?_(Number(l)):Number(l),O=i?Number(T):_(Number(T));W>O?c([O,W]):c([W,O])},[l,T,c]);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:n,value:[Number(l??s),Number(T??a)],max:a,min:s,minStepsBetweenThumbs:3,step:1,onChange:I,onChangeEnd:z,isDisabled:g,children:[e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:s,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:h??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:b?b?.(s):s})}),e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:a,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:h??"sm",fontWeight:"semibold",style:{transform:"translateX(-100%)"},whiteSpace:"nowrap",children:b?b(a):a})}),C&&e.jsxRuntimeExports.jsxs(t.RangeSliderMark,{value:0,top:"-1em",pos:"relative",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:h,fontWeight:"semibold",children:b?.(0)??"0"}),e.jsxRuntimeExports.jsx(ye,{})]}),e.jsxRuntimeExports.jsx(t.RangeSliderTrack,{children:e.jsxRuntimeExports.jsx(t.RangeSliderFilledTrack,{})}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:0,w:x,h:x}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:1,w:x,h:x})]})}),v&&e.jsxRuntimeExports.jsxs(t.Flex,{direction:n?"row-reverse":"row",justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:h??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:v(s)}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:h??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:v(a)})]}),e.jsxRuntimeExports.jsxs(t.Flex,{direction:n?"row-reverse":"row",justifyContent:"center",alignItems:"center",gap:"0.125em",children:[F&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:h,fontWeight:"bold",value:S,onChange:i=>r(!0,i),isDisabled:j||g,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:F[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:F[1]})]}),e.jsxRuntimeExports.jsx(t.NumberInput,{precision:0,size:h??"sm",min:0,max:S<0?Math.abs(s):D??a,value:l===""?"":Math.abs(Number(l??s)),onChange:U,onBlur:k,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:g,...u,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),e.jsxRuntimeExports.jsx(t.NumberInput,{size:h??"sm",min:0,max:p<0?Math.abs(M??s):a,precision:0,value:T===""?"":Math.abs(Number(T??a)),onChange:P,onBlur:k,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:g,...u,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),F&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:h,fontWeight:"bold",value:p,onChange:i=>r(!1,i),isDisabled:j||g,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:F[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:F[1]})]})]})]})},ye=xe.dt(t.Box)`
|
|
2
|
-
position: absolute;
|
|
3
|
-
width: 2px;
|
|
4
|
-
height: 1em;
|
|
5
|
-
top: 90%;
|
|
6
|
-
left: 20%;
|
|
7
|
-
background-color: var(--chakra-colors-gray-300);
|
|
8
|
-
`,ve=({tags:n,containerProps:s,...a})=>e.jsxRuntimeExports.jsx(t.HStack,{...s,children:n.map((m,c)=>e.jsxRuntimeExports.jsx(t.Tag,{...a,children:m},c))}),Te=new e.uFuzzy({}),Me=(n,s)=>{if(!s||!s.trim().length)return n;const a=n.map(c=>c.name??"");return Te.filter(a,s)?.map(c=>n[c])??[]},Ae=(n,s)=>!s||s.length==0?n:n.filter(a=>a.useCases.some(m=>s.includes(m.id))),me=({actions:n,totalActions:s,onCreate:a,onDelete:m,onEdit:c,onSelected:u,onDuplicate:h,disableMultiSelect:f,disableDelete:b,disableEdit:v,disableCreate:F,tableProps:g,...E})=>{const[A,d]=o.useState(""),[l,T]=o.useState(),C=o.useMemo(()=>{if(!n)return;const j=Me(n,A);return Ae(j,l).sort((D,I)=>D.name.localeCompare(I.name))},[n,A,l]),S=o.useCallback(()=>{if(!m)return;const j=n.filter(M=>M.selected).map(M=>M.id);m(j)},[n,m]),p=o.useCallback(()=>{if(!h)return;const j=n.filter(M=>M.selected);h(j.map(M=>M.id)),u&&j.forEach(M=>u(M,!1))},[n,h,u]);return e.jsxRuntimeExports.jsxs(t.Box,{...E,children:[e.jsxRuntimeExports.jsxs(t.Flex,{alignContent:"space-between",gap:4,children:[(a||m||h)&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mb:"1rem",gap:4,children:[a&&e.jsxRuntimeExports.jsx(t.Button,{isDisabled:!a||F,colorScheme:"blackAlpha",backgroundColor:"gray.700",onClick:a,children:"Create New Activity"}),m&&!f&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:n.length<=0||!m||b,onClick:S,children:"Delete Selected"}),h&&!f&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:n.length<=0,onClick:p,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx(fe,{setSearch:d,actions:n,updateUseCases:T})]}),e.jsxRuntimeExports.jsx(t.TableContainer,{mr:"2rem",overflowX:"hidden",...g,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 ",C?.length??0," of"," ",s??n.length,")"]}),e.jsxRuntimeExports.jsx(t.Th,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Th,{children:"Sensor Count"}),e.jsxRuntimeExports.jsx(t.Th,{children:"Use Case"}),e.jsxRuntimeExports.jsx(t.Th,{})]})}),e.jsxRuntimeExports.jsx(t.Tbody,{children:C?.map(j=>e.jsxRuntimeExports.jsxs(we,{disableMultiSelect:f,selected:j.selected,title:f&&j.selected?"This activity is selected. Click it again to deselect.":void 0,bg:f&&j.selected?"gray.200":void 0,onClick:()=>f?u?.(j,!j.selected):void 0,children:[e.jsxRuntimeExports.jsx(t.Td,{children:e.jsxRuntimeExports.jsxs(t.Flex,{children:[u&&!f&&e.jsxRuntimeExports.jsx(t.Checkbox,{isChecked:j.selected,onChange:M=>u(j,M.target.checked)}),c&&e.jsxRuntimeExports.jsx(t.Button,{disabled:v,ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:()=>c(j.id),children:"edit"})]})}),e.jsxRuntimeExports.jsx(t.Td,{whiteSpace:"break-spaces",children:j.name}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:j.sensorLocations.length}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:e.jsxRuntimeExports.jsx(ve,{containerProps:{flexWrap:"wrap"},tags:j.useCases?.map(M=>M.name)??[]})})]},j.id))})]})})]})},we=xe.dt(t.Tr)`
|
|
9
|
-
&:hover {
|
|
10
|
-
background-color: ${n=>n.disableMultiSelect&&!n.selected?"#f7f7f7":void 0};
|
|
11
|
-
}
|
|
12
|
-
cursor: ${n=>n.disableMultiSelect?"pointer":"default"};
|
|
13
|
-
`,Fe=({onSave:n,onCancel:s,onError:a,hideButtons:m=!1,setButtonDisabled:c,setButtonOnClick:u,quantumOwned:h})=>{const f=t.useToast(),[b,v]=o.useState(""),[F,g]=o.useState([]),[E,A]=o.useState(!1),[d]=G.useQuery({query:w.GET_GROUPS}),[l]=G.useQuery({query:w.GET_ACTIONS_BY_GROUP,variables:{groupId:b},pause:!b}),[,T]=G.useMutation(w.CREATE_ACTION),C=o.useMemo(()=>d.data?.groups?d.data.groups.map(x=>R.getFragmentData(w.GROUP_FRAGMENT,x)):[],[d.data]),S=o.useMemo(()=>l.data?l.data.actions.map(r=>R.getFragmentData(w.ACTION_FRAGMENT,r)):[],[l.data]),p=o.useMemo(()=>S.filter(x=>F.includes(x.id)),[S,F]),j=o.useCallback(x=>{const r=x?.value||"";v(r),g([])},[]),M=o.useCallback(x=>{const r=x.map(i=>i.value);g(r)},[]),D=o.useCallback(async()=>{if(A(!0),!p.length){const x=new Error("No activities selected for copying");a?.(x),A(!1);return}try{const x=[];let r=0;for(const i of p)try{const y={...i,name:`${i.name} (Copy)`,description:i.description||void 0,instructionsPointOfInterest:i.instructionsPointOfInterest||void 0,instructionsMovementReport:i.instructionsMovementReport||void 0,laterality:i.laterality,activityKind:i.activityKind,sensorLocations:i.sensorLocations,thresholds:i.thresholds.map(_=>({..._,id:void 0})),quantumOwned:h,id:void 0},L=await T({fields:y});if(L.error)throw new Error(L.error.message);if(L.data?.createAction){const _=R.getFragmentData(w.ACTION_FRAGMENT,L.data.createAction);x.push(_)}}catch(y){console.error(`Failed to copy activity "${i.name}":`,y),r++}if(x.length>0){const i=x.length,y=p.length;f({title:r>0?"Partial copy completed":"Activities copied successfully",description:r>0?`${i} of ${y} activities copied successfully`:`${i} activit${i>1?"ies":"y"} copied successfully`,status:r>0?"warning":"success",duration:3e3,isClosable:!0}),n?.(),v(""),g([])}else throw new Error("Failed to copy any activities")}catch(x){const r=x instanceof Error?x.message:"Failed to copy activities";f({title:"Copy failed",description:r,status:"error",duration:5e3,isClosable:!0}),a?.(x instanceof Error?x:new Error(r))}finally{A(!1)}},[p,T,f,n,a,h]),I=o.useCallback(()=>{v(""),g([]),s?.()},[s]);o.useEffect(()=>{c&&c({cancelButton:!1,saveButton:p.length===0||E})},[p.length,E,c]),o.useEffect(()=>{u&&u({cancelButton:I,saveButton:D})},[u,I,D]);const z=o.useMemo(()=>C.map(x=>({value:x.id,label:x.name})),[C]),k=o.useMemo(()=>S.map(x=>({value:x.id,label:x.name,isQuantumOwned:x.quantumOwned})),[S]),U=d.fetching,P=l.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Y,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(H.st,{placeholder:"Choose a group...",options:z,value:z.find(x=>x.value===b)||null,onChange:j,isLoading:U,isDisabled:U,isClearable:!0}),d.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: ",d.error.message]})]})]}),b&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Y,{children:"Select Activities to Copy"}),P?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(H.st,{placeholder:"Choose activities to copy...",options:k,value:k.filter(x=>F.includes(x.value)),onChange:M,isDisabled:k.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(x,{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:x.label}),r==="value"&&x.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),x.isQuantumOwned&&r==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),k.length===0&&e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:"No activities found"})]}),l.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: ",l.error.message]})]})]}),p.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:p.length===1?"Activity to Copy:":`${p.length} Activities to Copy:`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[p.map((x,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,". ",x.name]}),x.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:[x.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",x.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Type:"})," ",x.activityKind]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Laterality:"})," ",x.laterality]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Sensor Locations:"})," ",x.sensorLocations.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Thresholds:"})," ",x.thresholds.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Use Cases:"})," ",x.useCases.map(i=>i.name).join(", ")||"None"]})]})]},x.id)),p.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: ",p.length," activities will be copied"]})})]})]}),!m&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:I,isDisabled:E,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:"blue",onClick:D,isDisabled:p.length===0||E,isLoading:E,loadingText:"Copying...",children:["Copy"," ",p.length===1?"Activity":`${p.length} Activities`]})]})]})})},Ie=({onSave:n,onCancel:s,onError:a,hideButtons:m=!1,setButtonDisabled:c,setButtonOnClick:u,quantumOwned:h})=>{const f=t.useToast(),[b,v]=o.useState(""),[F,g]=o.useState([]),[E,A]=o.useState(!1),[d]=G.useQuery({query:w.GET_GROUPS}),[l]=G.useQuery({query:w.GET_MODULES_BY_GROUP,variables:{groupId:b},pause:!b}),[,T]=G.useMutation(w.CREATE_MODULE),[,C]=G.useMutation(w.CREATE_ACTION),S=o.useMemo(()=>d.data?.groups?d.data.groups.map(r=>R.getFragmentData(w.GROUP_FRAGMENT,r)):[],[d.data]),p=o.useMemo(()=>l.data?.modules?R.getFragmentData(w.ACTION_MODULE_FRAGMENT,l.data?.modules).map(i=>{const y=R.getFragmentData(w.MODULE_ACTION_FRAGMENT,i.moduleActions);return{...i,moduleActions:y.map(L=>({...L,action:R.getFragmentData(w.ACTION_FRAGMENT,L.action)})),categories:R.getFragmentData(w.MODULE_CATEGORY_FRAGMENT,i.categories)}}):[],[l.data]),j=o.useMemo(()=>p.filter(r=>F.includes(r.id)),[p,F]),M=o.useCallback(r=>{const i=r?.value||"";v(i),g([])},[]),D=o.useCallback(r=>{const i=r.map(y=>y.value);g(i)},[]),I=o.useCallback(async()=>{if(A(!0),!j.length){A(!1);const r=new Error("No modules selected for copying");a?.(r);return}try{const r=[];let i=0;for(const y of j)try{let L=y.moduleActions.map(O=>O.actionId);if(h){const O=y.moduleActions.map(B=>B.action);L=(await Promise.all(O.map(async B=>{if(B.quantumOwned)return Promise.resolve(B);const Z={...B,quantumOwned:h,thresholds:B.thresholds.map(Q=>({...Q,id:void 0})),id:void 0};return await C({fields:Z}).then(Q=>Q.error||!Q.data?.createAction?null:R.getFragmentData(w.ACTION_FRAGMENT,Q.data.createAction))}))).filter(B=>!!B).map(B=>B.id)}const _={name:`${y.name} (Copy)`,description:y.description||void 0,actions:L,categories:y.categories.map(O=>O.id),quantumOwned:h},W=await T({input:_});if(W.error)throw new Error(W.error.message);if(W.data?.createModule){const O=R.getFragmentData(w.ACTION_MODULE_FRAGMENT,W.data.createModule);r.push(O)}}catch(L){console.error(`Failed to copy module "${y.name}":`,L),i++}if(r.length>0){const y=r.length,L=j.length;f({title:i>0?"Partial copy completed":"Modules copied successfully",description:i>0?`${y} of ${L} modules copied successfully`:`${y} module${y>1?"s":""} copied successfully`,status:i>0?"warning":"success",duration:3e3,isClosable:!0}),r.length>0&&n?.(),v(""),g([])}else throw new Error("Failed to copy any modules")}catch(r){const i=r instanceof Error?r.message:"Failed to copy modules";f({title:"Copy failed",description:i,status:"error",duration:5e3,isClosable:!0}),a?.(r instanceof Error?r:new Error(i))}finally{A(!1)}},[j,T,f,n,a,h,C]),z=o.useCallback(()=>{v(""),g([]),s?.()},[s]);o.useEffect(()=>{c&&c({cancelButton:!1,saveButton:j.length===0||E})},[j.length,E,c]),o.useEffect(()=>{u&&u({cancelButton:z,saveButton:I})},[u,z,I]);const k=o.useMemo(()=>S.map(r=>({value:r.id,label:r.name})),[S]),U=o.useMemo(()=>p.map(r=>({value:r.id,label:r.name,isQuantumOwned:r.quantumOwned})),[p]),P=d.fetching,x=l.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Y,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(H.st,{placeholder:"Choose a group...",options:k,value:k.find(r=>r.value===b)||null,onChange:M,isLoading:P,isDisabled:P,isClearable:!0}),d.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: ",d.error.message]})]})]}),b&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Y,{children:"Select Module to Copy"}),x?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(H.st,{placeholder:"Choose modules to copy...",options:U,value:U.filter(r=>F.includes(r.value)),onChange:D,isDisabled:U.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(r,{context:i})=>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}),i==="value"&&r.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),r.isQuantumOwned&&i==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),U.length===0&&e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:"No modules found in this group"})]}),l.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: ",l.error.message]})]})]}),j.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:j.length===1?"Module to Copy:":`${j.length} Modules to Copy:`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[j.map((r,i)=>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:[i+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:"Actions:"})," ",r.moduleActions.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Categories:"})," ",r.categories.map(y=>y.name).join(", ")||"None"]})]})]},r.id)),j.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: ",j.length," modules will be copied"]})}),h&&j.filter(r=>r.moduleActions.some(i=>!i.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:"Copying Modules with Non QM-Owned Actions will create corresponding QM-Owned Actions"})})]})]}),!m&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:z,isDisabled:E,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:"blue",onClick:I,isDisabled:j.length===0||E,isLoading:E,loadingText:"Copying...",children:["Copy"," ",j.length===1?"Module":`${j.length} Modules`]})]})]})})},pe=({name:n,setName:s,actions:a,selectedActionIds:m,setSelectedActionIds:c,availableCategories:u,selectedCategoryIds:h,setSelectedCategoryIds:f,description:b,setDescription:v,...F})=>{const g=t.useDisclosure(),E=o.useMemo(()=>a.map(S=>({...S,selected:m.includes(S.id)})),[a,m]),A=o.useMemo(()=>a.reduce((S,p)=>(S[p.id]=p,S),{}),[a]),d=o.useMemo(()=>m.map(S=>A[S]),[E,m]),l=o.useCallback((S,p)=>{c(p?[...m,S.id]:m.filter(j=>j!==S.id))},[m,c]),T=o.useCallback(S=>{s(S.target.value)},[s]),C=o.useCallback(S=>{v?.(S.target.value)},[v]);return e.jsxRuntimeExports.jsxs(t.Box,{...F,children:[e.jsxRuntimeExports.jsxs(t.HStack,{gap:"2rem",children:[e.jsxRuntimeExports.jsx(Ne,{name:n??"",onInputChange:T}),e.jsxRuntimeExports.jsx(ke,{availableCategories:u,value:h,onChange:f})]}),e.jsxRuntimeExports.jsx(Le,{description:b??"",onInputChange:C}),e.jsxRuntimeExports.jsx(Oe,{value:d,onChange:c,onAdjustActivities:()=>g.onOpen()}),e.jsxRuntimeExports.jsxs(t.Modal,{isOpen:g.isOpen,onClose:g.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(me,{actions:E,onSelected:l,disableCreate:!0,disableDelete:!0,tableProps:{height:"28rem",overflowY:"auto"}})}),e.jsxRuntimeExports.jsx(t.ModalFooter,{children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:g.onClose,isDisabled:m.length===0,children:"Done"})})]})]})]})},Ne=o.memo(({name:n,onInputChange:s})=>e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(Y,{children:"Module Name"}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. ACL RTP Test Battery",value:n,onChange:s,isRequired:!0})]})),ke=o.memo(({availableCategories:n,value:s,onChange:a})=>{const m=o.useMemo(()=>[...n,{id:"other",name:"Other"}],[n]),c=o.useMemo(()=>m.map(u=>({value:u.id,label:u.name})),[m]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(Y,{children:"Module Category"}),e.jsxRuntimeExports.jsx(H.st,{isDisabled:n.length===0,isClearable:!0,options:c,value:m.filter(u=>s.includes(u.id)).map(u=>({value:u.id,label:u.name})),onChange:u=>a(u?[u.value]:[]),placeholder:"Select category"})]})}),Le=o.memo(({description:n,onInputChange:s})=>e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(Y,{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:n,onChange:s})]})),Oe=o.memo(({value:n,onChange:s,onAdjustActivities:a})=>{const m=o.useMemo(()=>n.map(c=>({id:c.id,name:c.name})),[n]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(t.HStack,{justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(Y,{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:a,children:"Add / Remove Activities"})]}),m.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:a,children:"Add activities."})]})}):e.jsxRuntimeExports.jsx(be,{value:m,onChange:c=>{const u=c(m);s(u.map(h=>h.id))}})]})}),he=({value:n,onChange:s,forceKind:a,disableRemove:m,disableKind:c,lockRanges:u,...h})=>{const f=o.useMemo(()=>[...n].sort((g,E)=>{const A=J.availablePlanes.indexOf(g.plane),d=J.availablePlanes.indexOf(E.plane);return A-d}),[n]),b=o.useCallback(g=>"segment"in g.id?V.getSegmentNameWithPlane(g.id.segment,g.plane,!0)??"Unknown":V.getJointNameWithPlane(g.id.joint,g.plane,!0)??"Unknown",[]),v=o.useCallback((g,E)=>{const A=f.findIndex(l=>l.id===E.id&&l.plane===E.plane);let d=[...f];a&&(E={...E,kind:a}),d[A]=E,u&&(d=d.map(l=>({...l,min:E.min,max:E.max}))),s(d)},[s,f,a,u]),F=o.useCallback(g=>{const E=f.filter(A=>A.id!==g.id||A.plane!==g.plane);s(E)},[s,f]);return e.jsxRuntimeExports.jsx(t.VStack,{alignItems:"flex-start",overflowY:"auto",...h,children:f.map((g,E)=>e.jsxRuntimeExports.jsx(De,{label:b(g),parameter:g,onChange:A=>v(E,A),onRemove:m?void 0:()=>F(g),forceKind:a,disableKind:c},`${JSON.stringify(g.id)}-${g.plane}`))})},De=({label:n,parameter:s,onChange:a,onRemove:m,forceKind:c,disableKind:u})=>{const h=o.useCallback(v=>"joint"in s.id?V.getJointAngleDirectionName(s.id.joint,s.plane,v<0?-1:1):V.getSegmentAngleDirectionName(s.id.segment,s.plane,v<0?-1:1),[s]),{min:f,max:b}="joint"in s.id?V.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:n}),m&&e.jsxRuntimeExports.jsx(t.IconButton,{size:"xs",variant:"ghost","aria-label":"delete",icon:e.jsxRuntimeExports.jsx(t.Icon,{as:de.FaTrash}),onClick:m}),!c&&e.jsxRuntimeExports.jsx(le,{selectedItem:s?.kind??R.ThresholdKind.Limit,onChange:({value:v})=>a({...s,kind:v}),isDisabled:u,buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:R.ThresholdKind.Limit,label:"limit"},{value:R.ThresholdKind.Target,label:"target"}]})]}),e.jsxRuntimeExports.jsx(Se,{w:"100%",size:"xs",min:f,max:b,zeroMarker:!0,value:[s.min,s.max],onChange:v=>a({...s,min:v[0],max:v[1]}),formatValue:v=>`${Math.abs(v)}°`,valueLabel:v=>h(v)??"",positiveNegativeLabels:h(0)?[h(-1)??"",h(1)??""]:void 0})]})},ne=(n,s)=>"segment"in n&&"segment"in s&&n.segment===s.segment||"joint"in n&&"joint"in s&&n.joint===s.joint,je=({options:n,value:s,onChange:a,forceKind:m,singleValue:c,singleValueSideless:u,editOnly:h,disableKind:f,maxParameters:b,...v})=>{const F=u?2:b,g=o.useMemo(()=>n.map(l=>({label:"segment"in l.id?V.getSegmentNameWithPlane(l.id.segment,l.plane,!0)??"Unknown":V.getJointNameWithPlane(l.id.joint,l.plane,!0)??"Unknown",value:l.id,plane:l.plane})),[n]),E=o.useMemo(()=>{if(!u||s.length===0)return g;const l=s[0];return g.filter(T=>J.getAnalysisPartIdNoSide(T.value)===J.getAnalysisPartIdNoSide(l.id)&&T.plane===l.plane)},[g,s,u]),A=o.useMemo(()=>g.filter(l=>s.some(T=>ne(T.id,l.value)&&T.plane===l.plane)),[g,s]),d=o.useCallback(l=>{const T=l.map(C=>{const S=s.find(I=>ne(I.id,C.value)&&I.plane===C.plane),p=n.find(I=>ne(I.id,C.value)&&I.plane===C.plane),j=u?s.find(I=>J.getAnalysisPartIdNoSide(I.id)===J.getAnalysisPartIdNoSide(C.value)&&I.plane===C.plane):void 0,M=j&&!S?j.min:p&&p.min?p.min:0,D=j&&!S?j.max:p&&p.max?p.max:0;return S??{id:C.value,plane:C.plane,min:M,max:D,kind:m??R.ThresholdKind.Limit}});a(T)},[a,s,n,m,u]);return o.useEffect(()=>{const l=s.filter(T=>n.some(C=>ne(C.id,T.id)&&C.plane===T.plane));l.length!==s.length&&a(l)},[n,a]),e.jsxRuntimeExports.jsxs(t.Box,{...v,children:[e.jsxRuntimeExports.jsx(H.st,{isMulti:!c,placeholder:s.length?`${s.length} selected`:"Search...",value:A,isDisabled:h||A.length>=(F??1/0),onChange:l=>Array.isArray(l)?d([...l]):d(l!==null?[l]:[]),options:E,controlShouldRenderValue:!1}),e.jsxRuntimeExports.jsx(he,{marginTop:2,maxH:"28rem",value:s,onChange:a,forceKind:m,disableKind:f,lockRanges:u})]})},ge=n=>{switch(n){case R.SensorLocation.Thorax:return"Thorax";case R.SensorLocation.CenterBack:return"Center Back";case R.SensorLocation.Pelvis:return"Pelvis";case R.SensorLocation.LeftThigh:return"Left Thigh";case R.SensorLocation.RightThigh:return"Right Thigh";case R.SensorLocation.LeftShank:return"Left Shank";case R.SensorLocation.RightShank:return"Right Shank";case R.SensorLocation.LeftFoot:return"Left Foot";case R.SensorLocation.RightFoot:return"Right Foot";case R.SensorLocation.LeftUpperArm:return"Left Upper Arm";case R.SensorLocation.RightUpperArm:return"Right Upper Arm";case R.SensorLocation.LeftForearm:return"Left Forearm";case R.SensorLocation.RightForearm:return"Right Forearm";case R.SensorLocation.Head:return"Head"}return console.warn(`Unknown sensor location: ${n}`),"Unknown"},_e=6,Be=[R.SensorLocation.LeftFoot,R.SensorLocation.LeftShank,R.SensorLocation.LeftThigh,R.SensorLocation.Pelvis,R.SensorLocation.RightFoot,R.SensorLocation.RightShank,R.SensorLocation.RightThigh,R.SensorLocation.Thorax,R.SensorLocation.CenterBack,R.SensorLocation.Head],Pe=Be.map(n=>({label:ge(n),value:n})),ae=n=>n.map(s=>s.__isNew__?{name:s.label}:{id:s.value,name:s.label}),Ge=({id:n,onError:s,onCancel:a,onSave:m,hideButtons:c,setButtonOnClick:u,setButtonDisabled:h,quantumOwned:f})=>{const b=G.useClient(),[{fetching:v},F]=G.useMutation(w.CREATE_ACTION),[{fetching:g},E]=G.useMutation(w.UPDATE_ACTION),[{data:A}]=G.useQuery({query:w.GET_ACTION_BY_ID,variables:{id:n??""},pause:!n}),d=R.getFragmentData(w.ACTION_FRAGMENT,A?.getActionById),l=v||g,T=!!d&&!!n,[C,S]=o.useState(""),[p,j]=o.useState(""),[M,D]=o.useState(""),[I,z]=o.useState(""),[k,U]=o.useState(R.ActionLaterality.Either),[P,x]=o.useState(R.ActionActivityKind.Action),[r,i]=o.useState([]),[y,L]=o.useState([]),_=o.useMemo(()=>r.map(N=>N.value),[r]),W=Re.usePartOptionsForSensorLocations(_),[O,q]=o.useState([]),[B,Z]=o.useState(!1),Q=C.length&&k;o.useEffect(()=>{d&&(S(d.name),x(d.activityKind),j(d.description||""),U(d.laterality),L(d.useCases.map(N=>({id:N.id,value:N.id,label:N.name,__isNew__:!1}))),D(d.instructionsPointOfInterest||""),z(d.instructionsMovementReport||""),i(d.sensorLocations.map(N=>({label:ge(N),value:N}))),q(X.thresholdsToParameters(d.thresholds)))},[d]);const Ee=o.useCallback(async N=>(await b.query(f?w.SEARCH_QUANTUM_OWNED_USE_CASES:w.SEARCH_USE_CASES,{query:N,limit:10}).then(K=>{const te=K.data;return te?te?.quantumOwnedUseCases?te.quantumOwnedUseCases:te.useCases:[]})??[]).map(K=>({label:K.name,value:K.id})),[b,f]),[ce,ue]=o.useState({});o.useEffect(()=>{ue({name:C,laterality:k,description:p,instructionsPointOfInterest:M,instructionsMovementReport:I,sensorLocations:_,thresholds:X.parametersToThresholds(O),useCases:ae(y),activityKind:P})},[ue,d]);const re=o.useMemo(()=>JSON.stringify(ce)!==JSON.stringify({name:C,laterality:k,description:p,instructionsPointOfInterest:M,instructionsMovementReport:I,sensorLocations:_,thresholds:X.parametersToThresholds(O),useCases:ae(y),activityKind:P}),[ce,C,k,_,p,I,M,O,y,P]),ie=o.useCallback(()=>{const N={name:C,laterality:k,description:p,instructionsPointOfInterest:M,instructionsMovementReport:I,sensorLocations:_,thresholds:X.parametersToThresholds(O),useCases:ae(y),activityKind:P,quantumOwned:f};let ee;T&&n?ee=E({id:n,fields:N}):ee=F({fields:N}),ee.then(({error:K})=>{K?s(K):m()})},[f,F,E,n,C,k,_,m,p,I,M,T,O,y,P,s]);return o.useEffect(()=>{h&&h({cancelButton:l,saveButton:l||!Q||!re})},[l,h,Q,re]),o.useEffect(()=>{u&&u({cancelButton:a,saveButton:ie})},[u,a,ie]),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-8",children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx($,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:C,onChange:N=>S(N.target.value),type:"text",placeholder:"i.e. Lunge & Return"})]}),e.jsxRuntimeExports.jsxs(t.HStack,{m:"0",p:"0",w:"100%",justifyItems:"space-between",children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx($,{children:"Activity Type"}),e.jsxRuntimeExports.jsx(le,{selectedItem:P,onChange:N=>x(N.value),buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:R.ActionActivityKind.Action,label:"Action"},{value:R.ActionActivityKind.Movement,label:"Movement"}]})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx($,{children:"Laterality"}),e.jsxRuntimeExports.jsx(le,{selectedItem:k,onChange:N=>U(N.value),buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:R.ActionLaterality.Unilateral,label:"unilateral"},{value:R.ActionLaterality.Bilateral,label:"bilateral"},{value:R.ActionLaterality.Either,label:"either / or"}]})]})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx($,{children:"Use Cases"}),e.jsxRuntimeExports.jsx(t.Tooltip,{isOpen:B,label:"Type to search for existing use cases",placement:"top-end",children:e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsx(H.yt,{value:y,onChange:N=>L([...N]),isMulti:!0,cacheOptions:!0,defaultOptions:!0,onFocus:()=>Z(!0),onBlur:()=>Z(!1),loadOptions:Ee,placeholder:"(optional) Search for & select use cases…"})})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx($,{children:"Description"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:p,onChange:N=>j(N.target.value),rows:2,placeholder:"(optional) Describe how to perform the test or exercise"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx($,{children:"Instructions for General Movement Report"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:I,onChange:N=>z(N.target.value),rows:2,placeholder:"(optional) Describe how to setup or generate the movement report"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx($,{children:"Instructions for Point of Interest Report"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:M,onChange:N=>D(N.target.value),rows:2,placeholder:"(optional) Describe how to setup or generate the point of interest report"})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"col-span-2 lg:col-span-1 flex flex-col gap-8",children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx($,{children:"Sensor Locations"}),e.jsxRuntimeExports.jsx(H.st,{isMulti:!0,value:r,onChange:N=>i([...N]),options:Pe,isOptionDisabled:()=>r.length>=_e})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx($,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(je,{options:W,value:O,onChange:q})]})]}),e.jsxRuntimeExports.jsx("div",{className:X.cn("col-span-2 flex justify-end",c&&"hidden"),children:e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mt:16,gap:4,children:[e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:l,onClick:a,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:l||!Q||!re,isLoading:l,onClick:ie,children:"Save changes"})]})})]})},$=({children:n})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:n}),Ue=({id:n,onCancel:s,onSave:a,onError:m,hideButtons:c,quantumOwned:u,setButtonOnClick:h,setButtonDisabled:f})=>{const[{data:b}]=G.useQuery({query:u?w.GET_QUANTUM_OWNED_ACTIONS:w.GET_ACTIONS}),[{data:v}]=G.useQuery({query:w.GET_MODULE_BY_ID,variables:{id:n},pause:!n}),[{data:F}]=G.useQuery({query:w.GET_ALL_MODULE_CATEGORIES}),g=R.getFragmentData(w.MODULE_CATEGORY_FRAGMENT,F?.moduleCategories),[{fetching:E},A]=G.useMutation(w.UPDATE_MODULE),[{fetching:d},l]=G.useMutation(w.CREATE_MODULE),T=R.getFragmentData(w.ACTION_FRAGMENT,u?b?.quantumOwnedActions:b?.actions)??[],C=R.getFragmentData(w.ACTION_MODULE_FRAGMENT,v?.module),S=R.getFragmentData(w.MODULE_ACTION_FRAGMENT,C?.moduleActions)??[],[p,j]=o.useState([...S.map(x=>x.actionId)??[]]),[M,D]=o.useState(C?.name??""),[I,z]=o.useState([]),[k,U]=o.useState(C?.description??"");o.useEffect(()=>{C&&(j(S.map(x=>x.actionId)),D(C.name),U(C.description??""),z(C.categories.map(x=>R.getFragmentData(w.MODULE_CATEGORY_FRAGMENT,x).id)??[]))},[C,S]);const P=o.useCallback(()=>{let x;const r={actions:p,name:M,categories:I.filter(i=>i!=="other"),description:k,quantumOwned:u};C?x=A({id:C.id,input:r}):x=l({input:r}),x.then(({error:i})=>{i?m(i):a()})},[l,A,p,M,k,I,C,a,m]);return o.useEffect(()=>{f&&f({cancelButton:E||d,saveButton:E||d||!M||k.trim().split(/\s+/).filter(Boolean).length>40})},[f,E,d,p,M,k]),o.useEffect(()=>{h&&h({cancelButton:s,saveButton:P})},[h,s,P]),e.jsxRuntimeExports.jsxs(t.Box,{width:"100%",children:[e.jsxRuntimeExports.jsx(pe,{name:M,setName:D,actions:T,selectedActionIds:p,setSelectedActionIds:j,availableCategories:g??[],selectedCategoryIds:I,setSelectedCategoryIds:z,description:k,setDescription:U}),!c&&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||d,onClick:s,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:E||d||!M||k.trim().split(/\s+/).filter(Boolean).length>40,isLoading:E||d,onClick:P,children:"Save"})]})})]})};exports.ActivityList=me;exports.CopyActivityForm=Fe;exports.CopyModuleForm=Ie;exports.ModuleForm=pe;exports.ParameterEditList=he;exports.ParameterEditSelect=je;exports.UpsertActivityForm=Ge;exports.UpsertModuleForm=Ue;
|
|
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"),Ee=require("./ufuzzy-vendor-7qHa_k39.cjs"),Y=require("./react-select-vendor-BPaBUHFp.cjs"),de=require("./react-icons-vendor-D2s8zw9h.cjs"),z=require("./graphql-vendor-CL0XsjHb.cjs"),g=require("./generated-B5QGMyhw.cjs"),w=require("./graphql-KvyVlavd.cjs"),oe=require("./react-dnd-vendor-BPzSDojS.cjs"),J=require("./services.cjs"),X=require("./types.cjs"),Z=require("./utils.cjs"),Re=require("./hooks.cjs"),fe=({setSearch:o,actions:s,updateUseCases:i})=>{const m=n.useMemo(()=>s?.flatMap(a=>a.useCases).filter((a,l,h)=>h.findIndex(f=>f.id===a.id)===l).map(a=>({label:a.name,value:a.id}))||[],[s]);return e.jsxRuntimeExports.jsxs(t.Flex,{width:"100%",alignContent:"space-evenly",gap:4,children:[e.jsxRuntimeExports.jsxs(t.InputGroup,{size:"md",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...",maxW:"30rem",onChange:a=>o(a.target.value)})]}),e.jsxRuntimeExports.jsx(t.InputGroup,{size:"md",children:e.jsxRuntimeExports.jsx(Y.st,{size:"md",chakraStyles:{container:a=>({...a,width:"100%"})},menuPortalTarget:document.body,placeholder:"Filter use case",isMulti:!0,options:m,onChange:a=>i(a.map(l=>l.value))})})]})},V=({children:o})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:o}),Ce=({value:o,onChange:s})=>{const i=n.useState(()=>Math.random().toString(36).substring(2,15))[0],m=n.useCallback((a,l)=>{s(h=>{const f=[...h],[x]=f.splice(a,1);return f.splice(l,0,x),f})},[s]);return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsx(oe.DndProvider,{backend:oe.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((a,l)=>e.jsxRuntimeExports.jsx(be,{listKey:i,index:l,id:a.id,name:a.name,move:m},a.id))})]})})})})},be=({listKey:o,index:s,id:i,name:m,move:a})=>{const l=n.useRef(null),[{handlerId:h},f]=oe.useDrop({accept:o,collect:C=>({handlerId:C.getHandlerId()?.toString()??""}),hover:(C,F)=>{if(!l.current)return;const u=C.index,c=s;if(u===c)return;const S=l.current?.getBoundingClientRect(),R=(S.bottom-S.top)/2,b=F.getClientOffset().y-S.top;u<c&&b<R||u>c&&b>R||(a(u,c),C.index=c)}}),[{isDragging:x},M]=oe.useDrag({type:o,item:()=>({id:i,index:s}),collect:C=>({isDragging:C.isDragging()})}),I=x?.6:1,E=x?"grabbing":"grab";return M(f(l)),e.jsxRuntimeExports.jsxs(t.Tr,{ref:l,style:{opacity:I,cursor:E},"data-handler-id":h,children:[e.jsxRuntimeExports.jsx(t.Td,{children:s+1}),e.jsxRuntimeExports.jsx(t.Td,{children:m})]})},ce=({items:o,onChange:s,selectedItem:i,isDisabled:m,selectedProps:a,buttonProps:l})=>{const h=x=>x===i||x.value===i,f=x=>h(x)?{...l,...a}:l;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:m,children:o.map((x,M)=>e.jsxRuntimeExports.jsx(t.Tooltip,{label:x.tooltip,openDelay:50,closeDelay:200,placement:"top",visibility:x.tooltip?"visible":"hidden",hasArrow:!0,children:e.jsxRuntimeExports.jsx(t.Button,{onClick:()=>h(x)?null:s(x,M),isDisabled:x.disabled,...f(x),children:x.label})},M))})},se=(o,s)=>s<0?-1*Math.abs(o):Math.abs(o),Se=({isReversed:o,min:s,max:i,value:m,onChange:a,inputProps:l,size:h,zeroMarker:f,formatValue:x,valueLabel:M,positiveNegativeLabels:I,isDisabled:E,...C})=>{const[F,u]=n.useState([void 0,void 0]),c=F[0],S=F[1],R=f&&s<-5&&i>5,y=Number(m?.[0]??S??s)>0?1:-1,b=Number(m?.[1]??S??i)<0?-1:1,j=I?.[0]===I?.[1],v=m?.[0],k=m?.[1];n.useEffect(()=>{v!==void 0&&k!==void 0&&u([v.toFixed(0),k.toFixed(0)])},[v,k,u]);const L=n.useCallback(([d,T])=>{d<T&&u([d.toFixed(0),T.toFixed(0)])},[u]),$=n.useCallback(([d,T])=>{d<T&&a([d,T])},[a]),_=n.useCallback(()=>{u(([d,T])=>{const P=isNaN(Number(d))?s:Number(d),r=isNaN(Number(T))?i:Number(T),A=se(Number(P),y),N=se(Number(r),b),U=y<0?Math.max(A,s):Math.min(A,i),D=b<0?Math.max(N,s):Math.min(N,i);return U>D?(a([D,U]),[D.toFixed(0),U.toFixed(0)]):(a([U,D]),[U.toFixed(0),D.toFixed(0)])})},[a,u,y,b,s,i]),W=n.useCallback(d=>{const T=d===""||isNaN(Number(d))?d:se(Number(d),y);u(([P,r])=>[T.toString(),r])},[u,y]),G=n.useCallback(d=>{const T=d===""||isNaN(Number(d))?d:se(Number(d),b);u(([P,r])=>[P,T.toString()])},[u,b]),B=n.useMemo(()=>h==="xs"?"0.75rem":void 0,[h]),p=n.useCallback((d,T)=>{const P=Number(T.target.value);if(!c||!S||![-1,1].includes(P))return;const r=U=>P<0?-1*Math.abs(U):Math.abs(U),A=d?r(Number(c)):Number(c),N=d?Number(S):r(Number(S));A>N?a([N,A]):a([A,N])},[c,S,a]);return e.jsxRuntimeExports.jsxs(t.Flex,{direction:"column",...C,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(S??i)],max:i,min:s,minStepsBetweenThumbs:3,step:1,onChange:L,onChangeEnd:$,isDisabled:E,children:[e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:s,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:h??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:x?x?.(s):s})}),e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:i,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:h??"sm",fontWeight:"semibold",style:{transform:"translateX(-100%)"},whiteSpace:"nowrap",children:x?x(i):i})}),R&&e.jsxRuntimeExports.jsxs(t.RangeSliderMark,{value:0,top:"-1em",pos:"relative",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:h,fontWeight:"semibold",children:x?.(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:B,h:B}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:1,w:B,h:B})]})}),M&&e.jsxRuntimeExports.jsxs(t.Flex,{direction:o?"row-reverse":"row",justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:h??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:M(s)}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:h??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:M(i)})]}),e.jsxRuntimeExports.jsxs(t.Flex,{direction:o?"row-reverse":"row",justifyContent:"center",alignItems:"center",gap:"0.125em",children:[I&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:h,fontWeight:"bold",value:y,onChange:d=>p(!0,d),isDisabled:j||E,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:I[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:I[1]})]}),e.jsxRuntimeExports.jsx(t.NumberInput,{precision:0,size:h??"sm",min:0,max:y<0?Math.abs(s):k??i,value:c===""?"":Math.abs(Number(c??s)),onChange:W,onBlur:_,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:E,...l,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),e.jsxRuntimeExports.jsx(t.NumberInput,{size:h??"sm",min:0,max:b<0?Math.abs(v??s):i,precision:0,value:S===""?"":Math.abs(Number(S??i)),onChange:G,onBlur:_,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:E,...l,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),I&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:h,fontWeight:"bold",value:b,onChange:d=>p(!1,d),isDisabled:j||E,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:I[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:I[1]})]})]})]})},ye=({tags:o,containerProps:s,...i})=>e.jsxRuntimeExports.jsx(t.HStack,{...s,children:o.map((m,a)=>e.jsxRuntimeExports.jsx(t.Tag,{...i,children:m},a))}),ve=new Ee.uFuzzy({}),Te=(o,s)=>{if(!s||!s.trim().length)return o;const i=o.map(a=>a.name??"");return ve.filter(i,s)?.map(a=>o[a])??[]},Me=(o,s)=>!s||s.length==0?o:o.filter(i=>i.useCases.some(m=>s.includes(m.id))),me=({actions:o,totalActions:s,onCreate:i,onDelete:m,onEdit:a,onSelected:l,onDuplicate:h,disableMultiSelect:f,disableDelete:x,disableEdit:M,disableCreate:I,tableProps:E,...C})=>{const[F,u]=n.useState(""),[c,S]=n.useState(),R=n.useMemo(()=>{if(!o)return;const j=Te(o,F);return Me(j,c).sort((k,L)=>k.name.localeCompare(L.name))},[o,F,c]),y=n.useCallback(()=>{if(!m)return;const j=o.filter(v=>v.selected).map(v=>v.id);m(j)},[o,m]),b=n.useCallback(()=>{if(!h)return;const j=o.filter(v=>v.selected);h(j.map(v=>v.id)),l&&j.forEach(v=>l(v,!1))},[o,h,l]);return e.jsxRuntimeExports.jsxs(t.Box,{...C,children:[e.jsxRuntimeExports.jsxs(t.Flex,{alignContent:"space-between",gap:4,children:[(i||m||h)&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mb:"1rem",gap:4,children:[i&&e.jsxRuntimeExports.jsx(t.Button,{isDisabled:!i||I,colorScheme:"blackAlpha",backgroundColor:"gray.700",onClick:i,children:"Create New Activity"}),m&&!f&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:o.length<=0||!m||x,onClick:y,children:"Delete Selected"}),h&&!f&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:o.length<=0,onClick:b,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx(fe,{setSearch:u,actions:o,updateUseCases:S})]}),e.jsxRuntimeExports.jsx(t.TableContainer,{mr:"2rem",overflowX:"hidden",...E,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 ",R?.length??0," of"," ",s??o.length,")"]}),e.jsxRuntimeExports.jsx(t.Th,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Th,{children:"Sensor Count"}),e.jsxRuntimeExports.jsx(t.Th,{children:"Use Case"}),e.jsxRuntimeExports.jsx(t.Th,{})]})}),e.jsxRuntimeExports.jsx(t.Tbody,{children:R?.map(j=>e.jsxRuntimeExports.jsxs(t.Tr,{title:f&&j.selected?"This activity is selected. Click it again to deselect.":void 0,bg:f&&j.selected?"gray.200":void 0,_hover:{bg:f&&!j.selected?"#f7f7f7":void 0},cursor:f?"pointer":"default",onClick:()=>f?l?.(j,!j.selected):void 0,children:[e.jsxRuntimeExports.jsx(t.Td,{children:e.jsxRuntimeExports.jsxs(t.Flex,{children:[l&&!f&&e.jsxRuntimeExports.jsx(t.Checkbox,{isChecked:j.selected,onChange:v=>l(j,v.target.checked)}),a&&e.jsxRuntimeExports.jsx(t.Button,{disabled:M,ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:()=>a(j.id),children:"edit"})]})}),e.jsxRuntimeExports.jsx(t.Td,{whiteSpace:"break-spaces",children:j.name}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:j.sensorLocations.length}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:e.jsxRuntimeExports.jsx(ye,{containerProps:{flexWrap:"wrap"},tags:j.useCases?.map(v=>v.name)??[]})})]},j.id))})]})})]})},Ae=({onSave:o,onCancel:s,onError:i,hideButtons:m=!1,setButtonDisabled:a,setButtonOnClick:l,quantumOwned:h})=>{const f=t.useToast(),[x,M]=n.useState("copy"),[I,E]=n.useState(""),[C,F]=n.useState([]),[u,c]=n.useState(!1),[S]=z.useQuery({query:w.GET_GROUPS}),[R]=z.useQuery({query:w.GET_ACTIONS_BY_GROUP,variables:{groupId:I},pause:!I}),[,y]=z.useMutation(w.CREATE_ACTION),[,b]=z.useMutation(w.CONVERT_ACTION_TO_QUANTUM_OWNED),j=n.useMemo(()=>S.data?.groups?S.data.groups.map(r=>g.getFragmentData(w.GROUP_FRAGMENT,r)):[],[S.data]),v=n.useMemo(()=>R.data?R.data.actions.map(A=>g.getFragmentData(w.ACTION_FRAGMENT,A)):[],[R.data]),k=n.useMemo(()=>v.filter(r=>C.includes(r.id)),[v,C]),L=n.useCallback(r=>{const A=r?.value||"";E(A),F([])},[]),$=n.useCallback(r=>{const A=r.map(N=>N.value);F(A)},[]),_=n.useCallback(async r=>{const A={...r,name:`${r.name} (Copy)`,description:r.description||void 0,instructionsPointOfInterest:r.instructionsPointOfInterest||void 0,instructionsMovementReport:r.instructionsMovementReport||void 0,laterality:r.laterality,activityKind:r.activityKind,sensorLocations:r.sensorLocations,thresholds:r.thresholds.map(U=>({...U,id:void 0})),quantumOwned:h,id:void 0},N=await y({fields:A});if(N.error)throw new Error(N.error.message);if(N.data?.createAction)return g.getFragmentData(w.ACTION_FRAGMENT,N.data.createAction);throw new Error("No action data returned")},[y,h]),W=n.useCallback(async r=>{const A=await b({id:r.id});if(A.error)throw new Error(A.error.message);if(A.data?.convertActionToQuantumOwned)return g.getFragmentData(w.ACTION_FRAGMENT,A.data.convertActionToQuantumOwned);throw new Error("No action data returned")},[b]),G=n.useCallback(async()=>{if(c(!0),!k.length){const r=new Error(`No activities selected for ${x==="copy"?"copying":"converting"}`);i?.(r),c(!1);return}try{const r=[];let A=0;const N=x==="copy"?_:W,U=x==="copy"?"copy":"convert";for(const D of k)try{const q=await N(D);r.push(q)}catch(q){console.error(`Failed to ${U} activity "${D.name}":`,q),A++}if(r.length>0){const D=r.length,q=k.length,Q=x==="copy"?"copied":"converted",re=x==="copy"?"copy":"convert";f({title:A>0?`Partial ${re} completed`:`Activities ${Q} successfully`,description:A>0?`${D} of ${q} activities ${Q} successfully`:`${D} activit${D>1?"ies":"y"} ${Q} successfully`,status:A>0?"warning":"success",duration:3e3,isClosable:!0}),o?.(),E(""),F([])}else throw new Error(`Failed to ${U} any activities`)}catch(r){const A=x==="copy"?"copy":"convert",N=r instanceof Error?r.message:`Failed to ${A} activities`;f({title:`${x==="copy"?"Copy":"Convert"} failed`,description:N,status:"error",duration:5e3,isClosable:!0}),i?.(r instanceof Error?r:new Error(N))}finally{c(!1)}},[k,x,_,W,f,o,i]),B=n.useCallback(()=>{E(""),F([]),M("copy"),s?.()},[s]);n.useEffect(()=>{a&&a({cancelButton:!1,saveButton:k.length===0||u})},[k.length,u,a]),n.useEffect(()=>{l&&l({cancelButton:B,saveButton:G})},[l,B,G]);const p=n.useMemo(()=>j.map(r=>({value:r.id,label:r.name})),[j]),d=n.useMemo(()=>v.map(r=>({value:r.id,label:r.name,isQuantumOwned:r.quantumOwned})),[v]),T=S.fetching,P=R.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[h&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(V,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:x,onChange:r=>M(r),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(V,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(Y.st,{placeholder:"Choose a group...",options:p,value:p.find(r=>r.value===I)||null,onChange:L,isLoading:T,isDisabled:T,isClearable:!0}),S.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: ",S.error.message]})]})]}),I&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsxs(V,{children:["Select Activities to"," ",x==="copy"?"Copy":"Convert"]}),P?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(Y.st,{placeholder:`Choose activities to ${x}...`,options:d,value:d.filter(r=>C.includes(r.value)),onChange:$,isDisabled:d.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(r,{context:A})=>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}),A==="value"&&r.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),r.isQuantumOwned&&A==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),d.length===0&&e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:"No activities found"})]}),R.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: ",R.error.message]})]})]}),k.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:k.length===1?`Activity to ${x==="copy"?"Copy":"Convert"}:`:`${k.length} Activities to ${x==="copy"?"Copy":"Convert"}:`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[k.map((r,A)=>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:[A+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:"Type:"})," ",r.activityKind]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Laterality:"})," ",r.laterality]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Sensor Locations:"})," ",r.sensorLocations.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Thresholds:"})," ",r.thresholds.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Use Cases:"})," ",r.useCases.map(N=>N.name).join(", ")||"None"]})]})]},r.id)),k.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: ",k.length," activities will be"," ",x==="copy"?"copied":"converted"]})})]})]}),!m&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:B,isDisabled:u,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:x==="copy"?"blue":"green",onClick:G,isDisabled:k.length===0||u,isLoading:u,loadingText:`${x==="copy"?"Copying":"Converting"}...`,children:[x==="copy"?"Copy":"Convert"," ",k.length===1?"Activity":`${k.length} Activities`]})]})]})})},we=({onSave:o,onCancel:s,onError:i,hideButtons:m=!1,setButtonDisabled:a,setButtonOnClick:l,quantumOwned:h})=>{const f=t.useToast(),[x,M]=n.useState(""),[I,E]=n.useState([]),[C,F]=n.useState(!1),[u]=z.useQuery({query:w.GET_GROUPS}),[c]=z.useQuery({query:w.GET_MODULES_BY_GROUP,variables:{groupId:x},pause:!x}),[,S]=z.useMutation(w.CREATE_MODULE),[,R]=z.useMutation(w.CREATE_ACTION),y=n.useMemo(()=>u.data?.groups?u.data.groups.map(p=>g.getFragmentData(w.GROUP_FRAGMENT,p)):[],[u.data]),b=n.useMemo(()=>c.data?.modules?g.getFragmentData(w.ACTION_MODULE_FRAGMENT,c.data?.modules).map(d=>{const T=g.getFragmentData(w.MODULE_ACTION_FRAGMENT,d.moduleActions);return{...d,moduleActions:T.map(P=>({...P,action:g.getFragmentData(w.ACTION_FRAGMENT,P.action)})),categories:g.getFragmentData(w.MODULE_CATEGORY_FRAGMENT,d.categories)}}):[],[c.data]),j=n.useMemo(()=>b.filter(p=>I.includes(p.id)),[b,I]),v=n.useCallback(p=>{const d=p?.value||"";M(d),E([])},[]),k=n.useCallback(p=>{const d=p.map(T=>T.value);E(d)},[]),L=n.useCallback(async()=>{if(F(!0),!j.length){F(!1);const p=new Error("No modules selected for copying");i?.(p);return}try{const p=[];let d=0;for(const T of j)try{let P=T.moduleActions.map(N=>N.actionId);if(h){const N=T.moduleActions.map(D=>D.action);P=(await Promise.all(N.map(async D=>{if(D.quantumOwned)return Promise.resolve(D);const q={...D,quantumOwned:h,thresholds:D.thresholds.map(Q=>({...Q,id:void 0})),id:void 0};return await R({fields:q}).then(Q=>Q.error||!Q.data?.createAction?null:g.getFragmentData(w.ACTION_FRAGMENT,Q.data.createAction))}))).filter(D=>!!D).map(D=>D.id)}const r={name:`${T.name} (Copy)`,description:T.description||void 0,actions:P,categories:T.categories.map(N=>N.id),quantumOwned:h},A=await S({input:r});if(A.error)throw new Error(A.error.message);if(A.data?.createModule){const N=g.getFragmentData(w.ACTION_MODULE_FRAGMENT,A.data.createModule);p.push(N)}}catch(P){console.error(`Failed to copy module "${T.name}":`,P),d++}if(p.length>0){const T=p.length,P=j.length;f({title:d>0?"Partial copy completed":"Modules copied successfully",description:d>0?`${T} of ${P} modules copied successfully`:`${T} module${T>1?"s":""} copied successfully`,status:d>0?"warning":"success",duration:3e3,isClosable:!0}),p.length>0&&o?.(),M(""),E([])}else throw new Error("Failed to copy any modules")}catch(p){const d=p instanceof Error?p.message:"Failed to copy modules";f({title:"Copy failed",description:d,status:"error",duration:5e3,isClosable:!0}),i?.(p instanceof Error?p:new Error(d))}finally{F(!1)}},[j,S,f,o,i,h,R]),$=n.useCallback(()=>{M(""),E([]),s?.()},[s]);n.useEffect(()=>{a&&a({cancelButton:!1,saveButton:j.length===0||C})},[j.length,C,a]),n.useEffect(()=>{l&&l({cancelButton:$,saveButton:L})},[l,$,L]);const _=n.useMemo(()=>y.map(p=>({value:p.id,label:p.name})),[y]),W=n.useMemo(()=>b.map(p=>({value:p.id,label:p.name,isQuantumOwned:p.quantumOwned})),[b]),G=u.fetching,B=c.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(V,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(Y.st,{placeholder:"Choose a group...",options:_,value:_.find(p=>p.value===x)||null,onChange:v,isLoading:G,isDisabled:G,isClearable:!0}),u.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: ",u.error.message]})]})]}),x&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(V,{children:"Select Module to Copy"}),B?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(Y.st,{placeholder:"Choose modules to copy...",options:W,value:W.filter(p=>I.includes(p.value)),onChange:k,isDisabled:W.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(p,{context:d})=>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:p.label}),d==="value"&&p.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),p.isQuantumOwned&&d==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),W.length===0&&e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:"No modules found in this group"})]}),c.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: ",c.error.message]})]})]}),j.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:j.length===1?"Module to Copy:":`${j.length} Modules to Copy:`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[j.map((p,d)=>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:[d+1,". ",p.name]}),p.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:[p.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",p.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Actions:"})," ",p.moduleActions.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Categories:"})," ",p.categories.map(T=>T.name).join(", ")||"None"]})]})]},p.id)),j.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: ",j.length," modules will be copied"]})}),h&&j.filter(p=>p.moduleActions.some(d=>!d.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:"Copying Modules with Non QM-Owned Actions will create corresponding QM-Owned Actions"})})]})]}),!m&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:$,isDisabled:C,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:"blue",onClick:L,isDisabled:j.length===0||C,isLoading:C,loadingText:"Copying...",children:["Copy"," ",j.length===1?"Module":`${j.length} Modules`]})]})]})})},pe=({name:o,setName:s,actions:i,selectedActionIds:m,setSelectedActionIds:a,availableCategories:l,selectedCategoryIds:h,setSelectedCategoryIds:f,description:x,setDescription:M,...I})=>{const E=t.useDisclosure(),C=n.useMemo(()=>i.map(y=>({...y,selected:m.includes(y.id)})),[i,m]),F=n.useMemo(()=>i.reduce((y,b)=>(y[b.id]=b,y),{}),[i]),u=n.useMemo(()=>m.map(y=>F[y]),[C,m]),c=n.useCallback((y,b)=>{a(b?[...m,y.id]:m.filter(j=>j!==y.id))},[m,a]),S=n.useCallback(y=>{s(y.target.value)},[s]),R=n.useCallback(y=>{M?.(y.target.value)},[M]);return e.jsxRuntimeExports.jsxs(t.Box,{...I,children:[e.jsxRuntimeExports.jsxs(t.HStack,{gap:"2rem",children:[e.jsxRuntimeExports.jsx(Fe,{name:o??"",onInputChange:S}),e.jsxRuntimeExports.jsx(Ne,{availableCategories:l,value:h,onChange:f})]}),e.jsxRuntimeExports.jsx(Ie,{description:x??"",onInputChange:R}),e.jsxRuntimeExports.jsx(ke,{value:u,onChange:a,onAdjustActivities:()=>E.onOpen()}),e.jsxRuntimeExports.jsxs(t.Modal,{isOpen:E.isOpen,onClose:E.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(me,{actions:C,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:E.onClose,isDisabled:m.length===0,children:"Done"})})]})]})]})},Fe=n.memo(({name:o,onInputChange:s})=>e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(V,{children:"Module Name"}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. ACL RTP Test Battery",value:o,onChange:s,isRequired:!0})]})),Ne=n.memo(({availableCategories:o,value:s,onChange:i})=>{const m=n.useMemo(()=>[...o,{id:"other",name:"Other"}],[o]),a=n.useMemo(()=>m.map(l=>({value:l.id,label:l.name})),[m]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(V,{children:"Module Category"}),e.jsxRuntimeExports.jsx(Y.st,{isDisabled:o.length===0,isClearable:!0,options:a,value:m.filter(l=>s.includes(l.id)).map(l=>({value:l.id,label:l.name})),onChange:l=>i(l?[l.value]:[]),placeholder:"Select category"})]})}),Ie=n.memo(({description:o,onInputChange:s})=>e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(V,{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:s})]})),ke=n.memo(({value:o,onChange:s,onAdjustActivities:i})=>{const m=n.useMemo(()=>o.map(a=>({id:a.id,name:a.name})),[o]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(t.HStack,{justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(V,{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:i,children:"Add / Remove Activities"})]}),m.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:i,children:"Add activities."})]})}):e.jsxRuntimeExports.jsx(Ce,{value:m,onChange:a=>{const l=a(m);s(l.map(h=>h.id))}})]})}),he=({value:o,onChange:s,forceKind:i,disableRemove:m,disableKind:a,lockRanges:l,...h})=>{const f=n.useMemo(()=>[...o].sort((E,C)=>{const F=X.availablePlanes.indexOf(E.plane),u=X.availablePlanes.indexOf(C.plane);return F-u}),[o]),x=n.useCallback(E=>"segment"in E.id?J.getSegmentNameWithPlane(E.id.segment,E.plane,!0)??"Unknown":J.getJointNameWithPlane(E.id.joint,E.plane,!0)??"Unknown",[]),M=n.useCallback((E,C)=>{const F=f.findIndex(c=>c.id===C.id&&c.plane===C.plane);let u=[...f];i&&(C={...C,kind:i}),u[F]=C,l&&(u=u.map(c=>({...c,min:C.min,max:C.max}))),s(u)},[s,f,i,l]),I=n.useCallback(E=>{const C=f.filter(F=>F.id!==E.id||F.plane!==E.plane);s(C)},[s,f]);return e.jsxRuntimeExports.jsx(t.VStack,{alignItems:"flex-start",overflowY:"auto",...h,children:f.map((E,C)=>e.jsxRuntimeExports.jsx(Le,{label:x(E),parameter:E,onChange:F=>M(C,F),onRemove:m?void 0:()=>I(E),forceKind:i,disableKind:a},`${JSON.stringify(E.id)}-${E.plane}`))})},Le=({label:o,parameter:s,onChange:i,onRemove:m,forceKind:a,disableKind:l})=>{const h=n.useCallback(M=>"joint"in s.id?J.getJointAngleDirectionName(s.id.joint,s.plane,M<0?-1:1):J.getSegmentAngleDirectionName(s.id.segment,s.plane,M<0?-1:1),[s]),{min:f,max:x}="joint"in s.id?J.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}),m&&e.jsxRuntimeExports.jsx(t.IconButton,{size:"xs",variant:"ghost","aria-label":"delete",icon:e.jsxRuntimeExports.jsx(t.Icon,{as:de.FaTrash}),onClick:m}),!a&&e.jsxRuntimeExports.jsx(ce,{selectedItem:s?.kind??g.ThresholdKind.Limit,onChange:({value:M})=>i({...s,kind:M}),isDisabled:l,buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:g.ThresholdKind.Limit,label:"limit"},{value:g.ThresholdKind.Target,label:"target"}]})]}),e.jsxRuntimeExports.jsx(Se,{w:"100%",size:"xs",min:f,max:x,zeroMarker:!0,value:[s.min,s.max],onChange:M=>i({...s,min:M[0],max:M[1]}),formatValue:M=>`${Math.abs(M)}°`,valueLabel:M=>h(M)??"",positiveNegativeLabels:h(0)?[h(-1)??"",h(1)??""]:void 0})]})},ne=(o,s)=>"segment"in o&&"segment"in s&&o.segment===s.segment||"joint"in o&&"joint"in s&&o.joint===s.joint,je=({options:o,value:s,onChange:i,forceKind:m,singleValue:a,singleValueSideless:l,editOnly:h,disableKind:f,maxParameters:x,...M})=>{const I=l?2:x,E=n.useMemo(()=>o.map(c=>({label:"segment"in c.id?J.getSegmentNameWithPlane(c.id.segment,c.plane,!0)??"Unknown":J.getJointNameWithPlane(c.id.joint,c.plane,!0)??"Unknown",value:c.id,plane:c.plane})),[o]),C=n.useMemo(()=>{if(!l||s.length===0)return E;const c=s[0];return E.filter(S=>X.getAnalysisPartIdNoSide(S.value)===X.getAnalysisPartIdNoSide(c.id)&&S.plane===c.plane)},[E,s,l]),F=n.useMemo(()=>E.filter(c=>s.some(S=>ne(S.id,c.value)&&S.plane===c.plane)),[E,s]),u=n.useCallback(c=>{const S=c.map(R=>{const y=s.find(L=>ne(L.id,R.value)&&L.plane===R.plane),b=o.find(L=>ne(L.id,R.value)&&L.plane===R.plane),j=l?s.find(L=>X.getAnalysisPartIdNoSide(L.id)===X.getAnalysisPartIdNoSide(R.value)&&L.plane===R.plane):void 0,v=j&&!y?j.min:b&&b.min?b.min:0,k=j&&!y?j.max:b&&b.max?b.max:0;return y??{id:R.value,plane:R.plane,min:v,max:k,kind:m??g.ThresholdKind.Limit}});i(S)},[i,s,o,m,l]);return n.useEffect(()=>{const c=s.filter(S=>o.some(R=>ne(R.id,S.id)&&R.plane===S.plane));c.length!==s.length&&i(c)},[o,i]),e.jsxRuntimeExports.jsxs(t.Box,{...M,children:[e.jsxRuntimeExports.jsx(Y.st,{isMulti:!a,placeholder:s.length?`${s.length} selected`:"Search...",value:F,isDisabled:h||F.length>=(I??1/0),onChange:c=>Array.isArray(c)?u([...c]):u(c!==null?[c]:[]),options:C,controlShouldRenderValue:!1}),e.jsxRuntimeExports.jsx(he,{marginTop:2,maxH:"28rem",value:s,onChange:i,forceKind:m,disableKind:f,lockRanges:l})]})},ge=o=>{switch(o){case g.SensorLocation.Thorax:return"Thorax";case g.SensorLocation.CenterBack:return"Center Back";case g.SensorLocation.Pelvis:return"Pelvis";case g.SensorLocation.LeftThigh:return"Left Thigh";case g.SensorLocation.RightThigh:return"Right Thigh";case g.SensorLocation.LeftShank:return"Left Shank";case g.SensorLocation.RightShank:return"Right Shank";case g.SensorLocation.LeftFoot:return"Left Foot";case g.SensorLocation.RightFoot:return"Right Foot";case g.SensorLocation.LeftUpperArm:return"Left Upper Arm";case g.SensorLocation.RightUpperArm:return"Right Upper Arm";case g.SensorLocation.LeftForearm:return"Left Forearm";case g.SensorLocation.RightForearm:return"Right Forearm";case g.SensorLocation.Head:return"Head"}return console.warn(`Unknown sensor location: ${o}`),"Unknown"},Oe=6,De=[g.SensorLocation.LeftFoot,g.SensorLocation.LeftShank,g.SensorLocation.LeftThigh,g.SensorLocation.Pelvis,g.SensorLocation.RightFoot,g.SensorLocation.RightShank,g.SensorLocation.RightThigh,g.SensorLocation.Thorax,g.SensorLocation.CenterBack,g.SensorLocation.Head],_e=De.map(o=>({label:ge(o),value:o})),le=o=>o.map(s=>s.__isNew__?{name:s.label}:{id:s.value,name:s.label}),Be=({id:o,onError:s,onCancel:i,onSave:m,hideButtons:a,setButtonOnClick:l,setButtonDisabled:h,quantumOwned:f})=>{const x=z.useClient(),[{fetching:M},I]=z.useMutation(w.CREATE_ACTION),[{fetching:E},C]=z.useMutation(w.UPDATE_ACTION),[{data:F}]=z.useQuery({query:w.GET_ACTION_BY_ID,variables:{id:o??""},pause:!o}),u=g.getFragmentData(w.ACTION_FRAGMENT,F?.getActionById),c=M||E,S=!!u&&!!o,[R,y]=n.useState(""),[b,j]=n.useState(""),[v,k]=n.useState(""),[L,$]=n.useState(""),[_,W]=n.useState(g.ActionLaterality.Either),[G,B]=n.useState(g.ActionActivityKind.Action),[p,d]=n.useState([]),[T,P]=n.useState([]),r=n.useMemo(()=>p.map(O=>O.value),[p]),A=Re.usePartOptionsForSensorLocations(r),[N,U]=n.useState([]),[D,q]=n.useState(!1),Q=R.length&&_;n.useEffect(()=>{u&&(y(u.name),B(u.activityKind),j(u.description||""),W(u.laterality),P(u.useCases.map(O=>({id:O.id,value:O.id,label:O.name,__isNew__:!1}))),k(u.instructionsPointOfInterest||""),$(u.instructionsMovementReport||""),d(u.sensorLocations.map(O=>({label:ge(O),value:O}))),U(Z.thresholdsToParameters(u.thresholds)))},[u]);const re=n.useCallback(async O=>(await x.query(f?w.SEARCH_QUANTUM_OWNED_USE_CASES:w.SEARCH_USE_CASES,{query:O,limit:10}).then(K=>{const te=K.data;return te?te?.quantumOwnedUseCases?te.quantumOwnedUseCases:te.useCases:[]})??[]).map(K=>({label:K.name,value:K.id})),[x,f]),[ue,xe]=n.useState({});n.useEffect(()=>{xe({name:R,laterality:_,description:b,instructionsPointOfInterest:v,instructionsMovementReport:L,sensorLocations:r,thresholds:Z.parametersToThresholds(N),useCases:le(T),activityKind:G})},[xe,u]);const ie=n.useMemo(()=>JSON.stringify(ue)!==JSON.stringify({name:R,laterality:_,description:b,instructionsPointOfInterest:v,instructionsMovementReport:L,sensorLocations:r,thresholds:Z.parametersToThresholds(N),useCases:le(T),activityKind:G}),[ue,R,_,r,b,L,v,N,T,G]),ae=n.useCallback(()=>{const O={name:R,laterality:_,description:b,instructionsPointOfInterest:v,instructionsMovementReport:L,sensorLocations:r,thresholds:Z.parametersToThresholds(N),useCases:le(T),activityKind:G,quantumOwned:f};let ee;S&&o?ee=C({id:o,fields:O}):ee=I({fields:O}),ee.then(({error:K})=>{K?s(K):m()})},[f,I,C,o,R,_,r,m,b,L,v,S,N,T,G,s]);return n.useEffect(()=>{h&&h({cancelButton:c,saveButton:c||!Q||!ie})},[c,h,Q,ie]),n.useEffect(()=>{l&&l({cancelButton:i,saveButton:ae})},[l,i,ae]),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-8",children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(H,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:R,onChange:O=>y(O.target.value),type:"text",placeholder:"i.e. Lunge & Return"})]}),e.jsxRuntimeExports.jsxs(t.HStack,{m:"0",p:"0",w:"100%",justifyItems:"space-between",children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(H,{children:"Activity Type"}),e.jsxRuntimeExports.jsx(ce,{selectedItem:G,onChange:O=>B(O.value),buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:g.ActionActivityKind.Action,label:"Action"},{value:g.ActionActivityKind.Movement,label:"Movement"}]})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(H,{children:"Laterality"}),e.jsxRuntimeExports.jsx(ce,{selectedItem:_,onChange:O=>W(O.value),buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:g.ActionLaterality.Unilateral,label:"unilateral"},{value:g.ActionLaterality.Bilateral,label:"bilateral"},{value:g.ActionLaterality.Either,label:"either / or"}]})]})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(H,{children:"Use Cases"}),e.jsxRuntimeExports.jsx(t.Tooltip,{isOpen:D,label:"Type to search for existing use cases",placement:"top-end",children:e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsx(Y.yt,{value:T,onChange:O=>P([...O]),isMulti:!0,cacheOptions:!0,defaultOptions:!0,onFocus:()=>q(!0),onBlur:()=>q(!1),loadOptions:re,placeholder:"(optional) Search for & select use cases…"})})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(H,{children:"Description"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:b,onChange:O=>j(O.target.value),rows:2,placeholder:"(optional) Describe how to perform the test or exercise"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(H,{children:"Instructions for General Movement Report"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:L,onChange:O=>$(O.target.value),rows:2,placeholder:"(optional) Describe how to setup or generate the movement report"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(H,{children:"Instructions for Point of Interest Report"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:v,onChange:O=>k(O.target.value),rows:2,placeholder:"(optional) Describe how to setup or generate the point of interest report"})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"col-span-2 lg:col-span-1 flex flex-col gap-8",children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(H,{children:"Sensor Locations"}),e.jsxRuntimeExports.jsx(Y.st,{isMulti:!0,value:p,onChange:O=>d([...O]),options:_e,isOptionDisabled:()=>p.length>=Oe})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(H,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(je,{options:A,value:N,onChange:U})]})]}),e.jsxRuntimeExports.jsx("div",{className:Z.cn("col-span-2 flex justify-end",a&&"hidden"),children:e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mt:16,gap:4,children:[e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:c,onClick:i,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:c||!Q||!ie,isLoading:c,onClick:ae,children:"Save changes"})]})})]})},H=({children:o})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:o}),Pe=({id:o,onCancel:s,onSave:i,onError:m,hideButtons:a,quantumOwned:l,setButtonOnClick:h,setButtonDisabled:f})=>{const[{data:x}]=z.useQuery({query:l?w.GET_QUANTUM_OWNED_ACTIONS:w.GET_ACTIONS}),[{data:M}]=z.useQuery({query:w.GET_MODULE_BY_ID,variables:{id:o},pause:!o}),[{data:I}]=z.useQuery({query:w.GET_ALL_MODULE_CATEGORIES}),E=g.getFragmentData(w.MODULE_CATEGORY_FRAGMENT,I?.moduleCategories),[{fetching:C},F]=z.useMutation(w.UPDATE_MODULE),[{fetching:u},c]=z.useMutation(w.CREATE_MODULE),S=g.getFragmentData(w.ACTION_FRAGMENT,l?x?.quantumOwnedActions:x?.actions)??[],R=g.getFragmentData(w.ACTION_MODULE_FRAGMENT,M?.module),y=g.getFragmentData(w.MODULE_ACTION_FRAGMENT,R?.moduleActions)??[],[b,j]=n.useState([...y.map(B=>B.actionId)??[]]),[v,k]=n.useState(R?.name??""),[L,$]=n.useState([]),[_,W]=n.useState(R?.description??"");n.useEffect(()=>{R&&(j(y.map(B=>B.actionId)),k(R.name),W(R.description??""),$(R.categories.map(B=>g.getFragmentData(w.MODULE_CATEGORY_FRAGMENT,B).id)??[]))},[R,y]);const G=n.useCallback(()=>{let B;const p={actions:b,name:v,categories:L.filter(d=>d!=="other"),description:_,quantumOwned:l};R?B=F({id:R.id,input:p}):B=c({input:p}),B.then(({error:d})=>{d?m(d):i()})},[c,F,b,v,_,L,R,i,m]);return n.useEffect(()=>{f&&f({cancelButton:C||u,saveButton:C||u||!v||_.trim().split(/\s+/).filter(Boolean).length>40})},[f,C,u,b,v,_]),n.useEffect(()=>{h&&h({cancelButton:s,saveButton:G})},[h,s,G]),e.jsxRuntimeExports.jsxs(t.Box,{width:"100%",children:[e.jsxRuntimeExports.jsx(pe,{name:v,setName:k,actions:S,selectedActionIds:b,setSelectedActionIds:j,availableCategories:E??[],selectedCategoryIds:L,setSelectedCategoryIds:$,description:_,setDescription:W}),!a&&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:C||u,onClick:s,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:C||u||!v||_.trim().split(/\s+/).filter(Boolean).length>40,isLoading:C||u,onClick:G,children:"Save"})]})})]})};exports.ActivityList=me;exports.CopyActivityForm=Ae;exports.CopyModuleForm=we;exports.ModuleForm=pe;exports.ParameterEditList=he;exports.ParameterEditSelect=je;exports.UpsertActivityForm=Be;exports.UpsertModuleForm=Pe;
|