quantum-component-library 1.4.69 → 1.4.71
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/parameter-edit-list/index.d.ts +2 -1
- package/dist/components.cjs +1 -1
- package/dist/components.js +1428 -1398
- package/dist/{dnd-core-vendor-Dpm8Ha_h.cjs → dnd-core-vendor-BQo1WiA6.cjs} +1 -1
- package/dist/{dnd-core-vendor-BvkN08kD.js → dnd-core-vendor-NmXYCL5j.js} +2 -2
- package/dist/generated/graphql.d.ts +601 -6
- package/dist/generated-graphql.cjs +1 -1
- package/dist/generated-graphql.js +83 -76
- package/dist/{graphql-vendor-ipMKtdBu.js → graphql-vendor-BOwWQmc4.js} +1 -1
- package/dist/{graphql-vendor-CSrUjvOC.cjs → graphql-vendor-CMjSICJP.cjs} +1 -1
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.js +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.js +47 -46
- package/dist/lib/types/sensor-info.test.d.ts +1 -0
- package/dist/lib/utils/parameters.d.ts +14 -1
- package/dist/lib/utils/parameters.test.d.ts +1 -0
- package/dist/{lodash-vendor-CfNg9qwP.cjs → lodash-vendor-CGEP7jch.cjs} +1 -1
- package/dist/{lodash-vendor-CY4G3-79.js → lodash-vendor-Deq42ySR.js} +1 -1
- package/dist/{other-CPHWCRXi.js → other-Bp68Uzz1.js} +3 -3
- package/dist/{other-B_xypnnb.cjs → other-Bsl3n3tj.cjs} +1 -1
- package/dist/{react-dnd-vendor-DvbjNa5U.cjs → react-dnd-vendor-CPQdLxxA.cjs} +1 -1
- package/dist/{react-dnd-vendor-DYesaYGm.js → react-dnd-vendor-D7ujbWN2.js} +2 -2
- package/dist/react-icons-vendor-D3in8HbI.cjs +1 -0
- package/dist/{react-icons-vendor-DqOJrTLA.js → react-icons-vendor-bPI9-m-x.js} +26 -22
- package/dist/{react-select-vendor-B0QF8gkj.js → react-select-vendor-B-vWCyYj.js} +1 -1
- package/dist/{react-select-vendor-BLLqfZvd.cjs → react-select-vendor-Dletsq31.cjs} +1 -1
- package/dist/services-human-Cl36G8mV.cjs +1 -0
- package/dist/{services-human-D5IllQkM.js → services-human-mjbBM3xQ.js} +2 -2
- package/dist/services.cjs +1 -1
- package/dist/services.js +1 -1
- package/dist/types.cjs +1 -1
- package/dist/types.js +13 -13
- package/dist/{utils-conversion-DFO1UVSN.cjs → utils-conversion-CBAxJ_Vx.cjs} +1 -1
- package/dist/{utils-conversion-BQfLNP0g.js → utils-conversion-Dmt0JwSC.js} +1 -1
- package/dist/{utils-parameters-DkefNhWo.js → utils-parameters-BiyUnm5t.js} +17 -7
- package/dist/utils-parameters-Bx16_6xw.cjs +1 -0
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +19 -18
- package/dist/{vendor-DeYnrakH.cjs → vendor-CNEuzHxC.cjs} +1 -1
- package/dist/{vendor-BSFJsa1P.js → vendor-D_9BWGCW.js} +1 -1
- package/package.json +1 -1
- package/dist/react-icons-vendor-c4NUuwCE.cjs +0 -1
- package/dist/services-human-DFPelsei.cjs +0 -1
- package/dist/utils-parameters-dwKmz1VU.cjs +0 -1
|
@@ -8,7 +8,8 @@ type Props = Omit<BoxProps, "value" | "onChange"> & {
|
|
|
8
8
|
disableRemove?: boolean;
|
|
9
9
|
isDisabled?: boolean;
|
|
10
10
|
lockRanges?: boolean;
|
|
11
|
+
canAddCopy?: boolean;
|
|
11
12
|
onChange: (v: PartParameter[]) => void;
|
|
12
13
|
};
|
|
13
|
-
export declare const ParameterEditList: ({ value, onChange, forceKind, disableRemove, disableKind, isDisabled, lockRanges, ...container }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare const ParameterEditList: ({ value, onChange, forceKind, disableRemove, disableKind, isDisabled, lockRanges, canAddCopy, ...container }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
14
15
|
export {};
|
package/dist/components.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./react-jsx-runtime-vendor-Dszzpdy0.cjs");require("./moment-vendor-1cRqq0AH.cjs");const t=require("@chakra-ui/react"),s=require("react"),F=require("./generated.cjs"),E=require("./graphql-BEhru2G1.cjs"),ve=require("./utils-cn-FIKrq5Mb.cjs");require("./lodash-vendor-CfNg9qwP.cjs");const Z=require("urql"),ae=require("./hooks.cjs"),Pe=require("./ufuzzy-vendor-7qHa_k39.cjs"),ie=require("./react-select-vendor-BLLqfZvd.cjs"),he=require("./react-icons-vendor-c4NUuwCE.cjs"),je=require("./services.cjs"),Me=require("./react-dnd-vendor-DvbjNa5U.cjs"),ce=require("./services-human-DFPelsei.cjs"),$=require("./generated-graphql.cjs"),ge=require("./types.cjs"),Be=({setSearch:r,actions:n,updateUseCases:i,hideUseCaseFilter:h=!1})=>{const p=s.useMemo(()=>n?.flatMap(j=>j.useCases).filter((j,x,g)=>g.findIndex(o=>o.id===j.id)===x).map(j=>({label:j.name,value:j.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:he.FaSearch,color:"gray.300"})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"Search by name...",width:"100%",maxW:h?void 0:"30rem",onChange:j=>r(j.target.value)})]}),!h&&e.jsxRuntimeExports.jsx(t.InputGroup,{size:"md",children:e.jsxRuntimeExports.jsx(ie.st,{size:"md",chakraStyles:{container:j=>({...j,width:"100%"})},menuPortalTarget:document.body,placeholder:"Filter use case",isMulti:!0,options:p,onChange:j=>i(j.map(x=>x.value))})})]})},ue=({children:r})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:r}),$e=({items:r,onChange:n,selectedItem:i,isDisabled:h,selectedProps:p,buttonProps:j})=>{const x=o=>o===i||o.value===i,g=o=>x(o)?{...j,...p}:j;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:h,children:r.map((o,a)=>e.jsxRuntimeExports.jsx(t.Tooltip,{label:o.tooltip,openDelay:50,closeDelay:200,placement:"top",visibility:o.tooltip?"visible":"hidden",hasArrow:!0,children:e.jsxRuntimeExports.jsx(t.Button,{onClick:()=>x(o)?null:n(o,a),isDisabled:o.disabled,...g(o),children:o.label})},a))})},Te=(r,n)=>n<0?-1*Math.abs(r):Math.abs(r),Ue=({isReversed:r,min:n,max:i,value:h,onChange:p,inputProps:j,size:x,zeroMarker:g,formatValue:o,valueLabel:a,positiveNegativeLabels:m,isDisabled:y,...C})=>{const[v,M]=s.useState([void 0,void 0]),I=v[0],f=v[1],d=g&&n<-5&&i>5,k=Number(h?.[0]??f??n)>0?1:-1,R=Number(h?.[1]??f??i)<0?-1:1,N=m?.[0]===m?.[1],T=h?.[0],B=h?.[1];s.useEffect(()=>{T!==void 0&&B!==void 0&&M([T.toFixed(0),B.toFixed(0)])},[T,B,M]);const D=s.useCallback(([L,z])=>{L<z&&M([L.toFixed(0),z.toFixed(0)])},[M]),w=s.useCallback(([L,z])=>{L<z&&p([L,z])},[p]),K=s.useCallback(()=>{M(([L,z])=>{const J=isNaN(Number(L))?n:Number(L),q=isNaN(Number(z))?i:Number(z),Y=Te(Number(J),k),c=Te(Number(q),R),l=k<0?Math.max(Y,n):Math.min(Y,i),S=R<0?Math.max(c,n):Math.min(c,i);return l>S?(p([S,l]),[S.toFixed(0),l.toFixed(0)]):(p([l,S]),[l.toFixed(0),S.toFixed(0)])})},[p,M,k,R,n,i]),te=s.useCallback(L=>{const z=L===""||isNaN(Number(L))?L:Te(Number(L),k);M(([J,q])=>[z.toString(),q])},[M,k]),O=s.useCallback(L=>{const z=L===""||isNaN(Number(L))?L:Te(Number(L),R);M(([J,q])=>[J,z.toString()])},[M,R]),ne=s.useMemo(()=>x==="xs"?"0.75rem":void 0,[x]),V=s.useCallback((L,z)=>{const J=Number(z.target.value);if(!I||!f||![-1,1].includes(J))return;const q=l=>J<0?-1*Math.abs(l):Math.abs(l),Y=L?q(Number(I)):Number(I),c=L?Number(f):q(Number(f));Y>c?p([c,Y]):p([Y,c])},[I,f,p]);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:r,value:[Number(I??n),Number(f??i)],max:i,min:n,minStepsBetweenThumbs:3,step:1,onChange:D,onChangeEnd:w,isDisabled:y,children:[e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:n,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:x??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:o?o?.(n):n})}),e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:i,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:x??"sm",fontWeight:"semibold",style:{transform:"translateX(-100%)"},whiteSpace:"nowrap",children:o?o(i):i})}),d&&e.jsxRuntimeExports.jsxs(t.RangeSliderMark,{value:0,top:"-1em",pos:"relative",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:x,fontWeight:"semibold",children:o?.(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:ne,h:ne}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:1,w:ne,h:ne})]})}),a&&e.jsxRuntimeExports.jsxs(t.Flex,{direction:r?"row-reverse":"row",justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:x??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:a(n)}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:x??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:a(i)})]}),e.jsxRuntimeExports.jsxs(t.Flex,{direction:r?"row-reverse":"row",justifyContent:"center",alignItems:"center",gap:"0.125em",children:[m&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:x,fontWeight:"bold",value:k,onChange:L=>V(!0,L),isDisabled:N||y,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:m[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:m[1]})]}),e.jsxRuntimeExports.jsx(t.NumberInput,{precision:0,size:x??"sm",min:0,max:k<0?Math.abs(n):B??i,value:I===""?"":Math.abs(Number(I??n)),onChange:te,onBlur:K,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:y,...j,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),e.jsxRuntimeExports.jsx(t.NumberInput,{size:x??"sm",min:0,max:R<0?Math.abs(T??n):i,precision:0,value:f===""?"":Math.abs(Number(f??i)),onChange:O,onBlur:K,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:y,...j,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),m&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:x,fontWeight:"bold",value:R,onChange:L=>V(!1,L),isDisabled:N||y,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:m[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:m[1]})]})]})]})},ze=({tags:r,containerProps:n,...i})=>e.jsxRuntimeExports.jsx(t.HStack,{...n,children:r.map((h,p)=>e.jsxRuntimeExports.jsx(t.Tag,{...i,children:h},p))}),qe=new Pe.uFuzzy({}),We=({action:r,quantumIconSrc:n})=>{const{getLabel:i}=ae.useUiLabelContext(),h=s.useMemo(()=>({actionLowerCase:i("action").toLocaleLowerCase()}),[i]);return r.quantumOwned?e.jsxRuntimeExports.jsx(t.Tooltip,{label:`This ${h.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:n,boxSize:"1em",alt:`Quantum-owned ${h.actionLowerCase}`})})}):null},He=(r,n)=>{if(!n||!n.trim().length)return r;const i=r.map(p=>p.name??"");return qe.filter(i,n)?.map(p=>r[p])??[]},Ke=r=>!r||r.length===0?"None":r.map(n=>n.replace(/([A-Z])/g," $1").trim()).join(", "),Qe=(r,n)=>!n||n.length==0?r:r.filter(i=>i.useCases?.some(h=>n.includes(h.id))??!1),Ye=(r,n,i)=>!n||n.length===0?r:r.filter(h=>{const p={};return n.forEach(j=>{for(const[x,g]of Object.entries(i||{}))if(g.some(o=>o.id===j)){p[x]||(p[x]=[]),p[x].push(j);break}}),Object.entries(p).every(([j,x])=>{const g=h.metadataGroups?.find(y=>F.getFragmentData(E.METADATA_GROUP_FRAGMENT,y).key===j);if(!g)return!1;const o=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,g),m=F.getFragmentData(E.METADATA_ITEM_FRAGMENT,o.data).map(y=>y.id);return x.some(y=>m.includes(y))})}),we=({actions:r,totalActions:n,onCreate:i,onDelete:h,onEdit:p,onView:j,onSelected:x,onDuplicate:g,disableMultiSelect:o,disableDelete:a,disableEdit:m,disableCreate:y,hideUseCase:C=!0,showMetadataFilters:v=!0,tableProps:M,containerProps:I,quantumIconSrc:f="/favicon.ico",allowDuplicateSelection:d=!1,getSelectedCount:k})=>{const[R,N]=s.useState(""),[T,B]=s.useState(),[D,w]=s.useState([]),[K,te]=s.useState({}),{getLabel:O}=ae.useUiLabelContext(),ne=Z.useClient(),V=s.useMemo(()=>({action:O("action"),actionPlural:O("action_plural"),actionLowerCase:O("action").toLocaleLowerCase(),actionPluralLowerCase:O("action_plural").toLocaleLowerCase()}),[O]),L=s.useMemo(()=>[{key:"module_category",label:"Link Category",multi:!0},{key:"activity_type",label:`${V.action} Type`,multi:!0},{key:"session_type",label:"Session Type",multi:!0},{key:"body_region",label:"Body Region",multi:!0},{key:"sport",label:"Sport",multi:!0}],[V.action]);s.useEffect(()=>{if(!v)return;const u=L.map(A=>ne.query(E.GET_METADATA_BY_KEY,{key:A.key}));Promise.all(u).then(A=>{const W={};A.forEach(_=>{if(_.error||!_.data)return;const H=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,_.data.getMetadataByKey),Q=F.getFragmentData(E.METADATA_ITEM_FRAGMENT,H.data);W[H.key]=Q.map(se=>({label:se.label||se.value,value:se.value,id:se.id}))}),te(W)})},[ne,L,v]);const z=s.useMemo(()=>{if(!r)return;const u=He(r,R),A=C?u:Qe(u,T);return v?Ye(A,D,K):A},[r,R,T,C,v,D,K]),J=s.useCallback(()=>{if(!h)return;const A=r.filter(W=>W.selected&&!W.quantumOwned).map(W=>W.id);h(A)},[r,h]),q=s.useCallback(()=>{if(!g)return;const u=r.filter(A=>A.selected);g(u.map(A=>A.id)),x&&u.forEach(A=>x(A,!1))},[r,g,x]),Y=s.useMemo(()=>r.some(u=>u.selected&&!u.quantumOwned),[r]),c=s.useMemo(()=>r.some(u=>u.selected),[r]),l=s.useMemo(()=>r.some(u=>u.selected&&u.quantumOwned),[r]),S=s.useCallback((u,A)=>{const W=L.find(H=>H.key===u);if(!W)return;const _=W.multi?(A??[]).map(H=>H.id):A?[A.id]:[];w(H=>[...H.filter(se=>Object.values(K).flat().find(xe=>xe.id===se)&&!Object.keys(K).find(xe=>K[xe]?.some(me=>me.id===se&&xe===u))),..._])},[L,K]);return e.jsxRuntimeExports.jsxs(t.Box,{...I,children:[e.jsxRuntimeExports.jsxs(t.Flex,{alignContent:"space-between",gap:4,children:[(i||h||g)&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mb:"1rem",gap:4,children:[i&&e.jsxRuntimeExports.jsxs(t.Button,{isDisabled:!i||y,colorScheme:"blackAlpha",backgroundColor:"gray.700",onClick:i,children:["Create New ",V.action]}),h&&!o&&e.jsxRuntimeExports.jsx(t.Tooltip,{label:l?Y?`Quantum-owned ${V.actionPluralLowerCase} are selected and will be skipped`:`Selected ${V.actionPluralLowerCase} are quantum-owned and cannot be deleted`:void 0,shouldWrapChildren:!0,children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!Y||!h||a,onClick:J,children:"Delete Selected"})}),g&&!o&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!c,onClick:q,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx(Be,{setSearch:N,actions:r,updateUseCases:B,hideUseCaseFilter:C})]}),v&&K&&e.jsxRuntimeExports.jsx(t.Box,{my:4,children:e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4",children:L.map(u=>e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(t.FormLabel,{fontSize:"sm",children:u.label}),e.jsxRuntimeExports.jsx(ie.st,{chakraStyles:{menu:A=>({...A,zIndex:2})},isMulti:u.multi,value:K[u.key]?.filter(A=>D.includes(A.id)),onChange:A=>{S(u.key,A)},options:K[u.key],placeholder:`Select ${u.multi?"one or more":"one"} ${u.label.toLowerCase()}`,isClearable:u.multi})]},u.key))})}),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"," ",n??r.length,")"]}),e.jsxRuntimeExports.jsx(t.Th,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Th,{children:"Sensor Locations"}),!C&&e.jsxRuntimeExports.jsx(t.Th,{children:"Use Case"}),e.jsxRuntimeExports.jsx(t.Th,{})]})}),e.jsxRuntimeExports.jsx(t.Tbody,{children:z?.map(u=>{const A=d?k?.(u.id)??0:0,W=d?A>0:!!u.selected;return e.jsxRuntimeExports.jsxs(t.Tr,{className:ve.cn("hover:bg-[#f7f7f7]",!o&&!d&&"cursor-pointer",W&&"bg-gray-200"),onClick:()=>{o||d||x?.(u,!u.selected)},children:[e.jsxRuntimeExports.jsx(t.Td,{children:e.jsxRuntimeExports.jsxs(t.Flex,{alignItems:"center",children:[!o&&d?e.jsxRuntimeExports.jsxs(t.HStack,{spacing:1,onClick:_=>_.stopPropagation(),children:[e.jsxRuntimeExports.jsx(t.IconButton,{"aria-label":"Remove one instance",icon:e.jsxRuntimeExports.jsx(he.FaMinus,{}),size:"xs",variant:"outline",isDisabled:A===0,onClick:()=>x?.(u,!1)}),e.jsxRuntimeExports.jsx(t.Text,{minW:"1.5rem",textAlign:"center",fontWeight:A>0?"semibold":"normal",color:A>0?"blue.600":"gray.500",children:A}),e.jsxRuntimeExports.jsx(t.IconButton,{"aria-label":"Add one instance",icon:e.jsxRuntimeExports.jsx(he.FaPlus,{}),size:"xs",variant:"outline",colorScheme:"blue",onClick:()=>x?.(u,!0)})]}):o?null:e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:u.selected?e.jsxRuntimeExports.jsx(he.FaCheckSquare,{className:"text-blue-500"}):e.jsxRuntimeExports.jsx(he.FaSquare,{className:"text-gray-400"})}),(u.quantumOwned||!p)&&j&&e.jsxRuntimeExports.jsx(t.Button,{ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:_=>{_.stopPropagation(),j(u.id)},children:"View"}),!u.quantumOwned&&p&&e.jsxRuntimeExports.jsx(t.Button,{isDisabled:m,ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:_=>{_.stopPropagation(),p(u.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(We,{action:u,quantumIconSrc:f}),u.name]})}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",whiteSpace:"break-spaces",children:Ke(u.sensorLocations)}),!C&&e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:e.jsxRuntimeExports.jsx(ze,{containerProps:{flexWrap:"wrap"},tags:u.useCases?.map(_=>_.name)??[]})})]},u.id)})})]})})]})},Je=({onSave:r,onCancel:n,onError:i,hideButtons:h=!1,setButtonDisabled:p,setButtonOnClick:j,quantumOwned:x})=>{const g=t.useToast(),{getLabel:o}=ae.useUiLabelContext(),a=s.useMemo(()=>({singular:o("action"),plural:o("action_plural"),pluralLowerCase:o("action_plural").toLowerCase(),singularLowerCase:o("action").toLowerCase()}),[o]),[m,y]=s.useState("copy"),[C,v]=s.useState(""),[M,I]=s.useState([]),[f,d]=s.useState(!1),[k]=Z.useQuery({query:E.GET_GROUPS}),[R]=Z.useQuery({query:E.GET_ACTIONS_BY_GROUP,variables:{groupId:C},pause:!C}),[,N]=Z.useMutation(E.CREATE_ACTION),[,T]=Z.useMutation(E.CONVERT_ACTION_TO_QUANTUM_OWNED),B=s.useMemo(()=>k.data?.groups?k.data.groups.map(c=>F.getFragmentData(E.GROUP_FRAGMENT,c)):[],[k.data]),D=s.useMemo(()=>R.data?R.data.actions.map(l=>{const S=F.getFragmentData(E.ACTION_FRAGMENT,l),u=F.getFragmentData(E.REPORT_FRAGMENT,S.reports),A=F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,S.categories),_=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,S.metadataGroups).map(H=>({...H,data:H.data.map(Q=>F.getFragmentData(E.METADATA_ITEM_FRAGMENT,Q))}));return{...S,thresholds:F.getFragmentData(E.THRESHOLD_FRAGMENT,S.thresholds),reports:u.map(H=>({...H,thresholds:F.getFragmentData(E.THRESHOLD_FRAGMENT,H.thresholds)})),categories:A,metadataGroups:_}}):[],[R.data]),w=s.useMemo(()=>D.filter(c=>M.includes(c.id)),[D,M]),K=s.useCallback(c=>{const l=c?.value||"";v(l),I([])},[]),te=s.useCallback(c=>{const l=c.map(S=>S.value);I(l)},[]),O=s.useCallback(async c=>{const l={...c,name:`${c.name} (Copy)`,description:c.description||void 0,instructionsPointOfInterest:c.instructionsPointOfInterest||void 0,instructionsMovementReport:c.instructionsMovementReport||void 0,laterality:c.laterality,activityKind:c.activityKind,sensorLocations:c.sensorLocations,thresholds:c.thresholds.map(u=>({...u,id:void 0})),categories:c.categories.map(u=>u.id),quantumOwned:x,metadataItemIds:c.metadataGroups.flatMap(u=>u.data.map(A=>A.id)).filter(u=>u!==void 0),reports:c.reports.map(u=>({...u,id:void 0,thresholds:u.thresholds.map(A=>({...A,id:void 0}))})),id:void 0},S=await N({fields:l});if(S.error)throw new Error(S.error.message);if(S.data?.createAction)return F.getFragmentData(E.ACTION_FRAGMENT,S.data.createAction);throw new Error("No action data returned")},[N,x]),ne=s.useCallback(async c=>{const l=await T({id:c.id});if(l.error)throw new Error(l.error.message);if(l.data?.convertActionToQuantumOwned)return F.getFragmentData(E.ACTION_FRAGMENT,l.data.convertActionToQuantumOwned);throw new Error("No action data returned")},[T]),V=s.useCallback(async()=>{if(d(!0),!w.length){const c=new Error(`No ${a.pluralLowerCase} selected for ${m==="copy"?"copying":"converting"}`);i?.(c),d(!1);return}try{const c=[];let l=0;const S=m==="copy"?O:ne,u=m==="copy"?"copy":"convert";for(const A of w)try{const W=await S(A);c.push(W)}catch(W){console.error(`Failed to ${u} ${a.singularLowerCase} "${A.name}":`,W),l++}if(c.length>0){const A=c.length,W=w.length,_=m==="copy"?"copied":"converted",H=m==="copy"?"copy":"convert";g({title:l>0?`Partial ${H} completed`:`${a.plural} ${_} successfully`,description:l>0?`${A} of ${W} ${a.pluralLowerCase} ${_} successfully`:`${A} ${A>1?a.pluralLowerCase:a.singularLowerCase} ${_} successfully`,status:l>0?"warning":"success",duration:3e3,isClosable:!0}),r?.(),v(""),I([])}else throw new Error(`Failed to ${u} any ${a.pluralLowerCase}`)}catch(c){const l=m==="copy"?"copy":"convert",S=c instanceof Error?c.message:`Failed to ${l} ${a.pluralLowerCase}`;g({title:`${m==="copy"?"Copy":"Convert"} failed`,description:S,status:"error",duration:5e3,isClosable:!0}),i?.(c instanceof Error?c:new Error(S))}finally{d(!1)}},[w,m,O,ne,g,r,i,a]),L=s.useCallback(()=>{v(""),I([]),y("copy"),n?.()},[n]);s.useEffect(()=>{p&&p({cancelButton:!1,saveButton:w.length===0||f})},[w.length,f,p]),s.useEffect(()=>{j&&j({cancelButton:L,saveButton:V})},[j,L,V]);const z=s.useMemo(()=>B.map(c=>({value:c.id,label:c.name})),[B]),J=s.useMemo(()=>D.filter(c=>m==="copy"?!0:!c.quantumOwned).map(c=>({value:c.id,label:c.name,isQuantumOwned:c.quantumOwned})),[D,m]),q=k.fetching,Y=R.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(ue,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:m,onChange:c=>{y(c),I([])},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 ",a.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",a.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 ",a.singular]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Convert existing"," ",a.plural.toLocaleLowerCase()," to quantum-owned"]})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(ie.st,{placeholder:"Choose a group...",options:z,value:z.find(c=>c.value===C)||null,onChange:K,isLoading:q,isDisabled:q,isClearable:!0}),k.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: ",k.error.message]})]})]}),C&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsxs(ue,{children:["Select ",a.plural," to"," ",m==="copy"?"Copy":"Convert"]}),Y?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 ",a.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(ie.st,{placeholder:`Choose ${a.pluralLowerCase} to ${m}...`,options:J,value:J.filter(c=>M.includes(c.value)),onChange:te,isDisabled:J.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(c,{context:l})=>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:c.label}),l==="value"&&c.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),c.isQuantumOwned&&l==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),J.length===0&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:["No ",a.pluralLowerCase," 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 ",a.pluralLowerCase,":"," ",R.error.message]})]})]}),w.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:w.length===1?`${a.singular} to ${m==="copy"?"Copy":"Convert"}:`:`${w.length} ${a.plural} to ${m==="copy"?"Copy":"Convert"}:`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[w.map((c,l)=>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:[l+1,". ",c.name]}),c.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:[c.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",c.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Type:"})," ",c.activityKind]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Laterality:"})," ",c.laterality]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Sensor Locations:"})," ",c.sensorLocations.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Thresholds:"})," ",c.thresholds.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Use Cases:"})," ",c.useCases.map(S=>S.name).join(", ")||"None"]})]})]},c.id)),w.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: ",w.length," ",a.pluralLowerCase," will be"," ",m==="copy"?"copied":"converted"]})})]})]}),!h&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:L,isDisabled:f,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:m==="copy"?"blue":"green",onClick:V,isDisabled:w.length===0||f,isLoading:f,loadingText:`${m==="copy"?"Copying":"Converting"}...`,children:[m==="copy"?"Copy":"Convert"," ",w.length===1?a.singular:`${w.length} ${a.plural}`]})]})]})})},Ve=({onSave:r,onCancel:n,onError:i,hideButtons:h=!1,setButtonDisabled:p,setButtonOnClick:j,quantumOwned:x})=>{const g=t.useToast(),{getLabel:o}=ae.useUiLabelContext(),a=s.useMemo(()=>({singular:o("module"),plural:o("module_plural"),pluralLowerCase:o("module_plural").toLowerCase(),singularLowerCase:o("module").toLowerCase()}),[o]),m=s.useMemo(()=>({singular:o("action"),plural:o("action_plural"),pluralLowerCase:o("action_plural").toLowerCase(),singularLowerCase:o("action").toLowerCase()}),[o]),[y,C]=s.useState(""),[v,M]=s.useState([]),[I,f]=s.useState(!1),[d,k]=s.useState("copy"),[R]=Z.useQuery({query:E.GET_GROUPS}),[N]=Z.useQuery({query:E.GET_MODULES_BY_GROUP,variables:{groupId:y},pause:!y}),[,T]=Z.useMutation(E.CREATE_MODULE),[,B]=Z.useMutation(E.UPDATE_MODULE),[,D]=Z.useMutation(E.CREATE_ACTION),[,w]=Z.useMutation(E.CONVERT_ACTION_TO_QUANTUM_OWNED),K=s.useMemo(()=>R.data?.groups?R.data.groups.map(l=>F.getFragmentData(E.GROUP_FRAGMENT,l)):[],[R.data]),te=s.useMemo(()=>N.data?.modules?F.getFragmentData(E.ACTION_MODULE_FRAGMENT,N.data?.modules).map(S=>{const u=F.getFragmentData(E.MODULE_ACTION_FRAGMENT,S.moduleActions),W=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,S.metadataGroups).map(_=>F.getFragmentData(E.METADATA_ITEM_FRAGMENT,_.data)).flat();return{...S,moduleActions:u.map(_=>({..._,action:F.getFragmentData(E.ACTION_FRAGMENT,_.action)})),categories:F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,S.categories),metadataItems:W}}):[],[N.data]),O=s.useMemo(()=>te.filter(l=>v.includes(l.id)),[te,v]),ne=s.useCallback(l=>{const S=l?.value||"";C(S),M([])},[]),V=s.useCallback(l=>{const S=l.map(u=>u.value);M(S)},[]),L=s.useCallback(async()=>{if(f(!0),!O.length){f(!1);const l=new Error(`No modules selected for ${d==="convert"?"converting":"copying"}`);i?.(l);return}try{const l=[];let S=0;for(const u of O)try{let A=u.moduleActions.map(W=>W.actionId);if(x){const W=u.moduleActions.map(Q=>Q.action),_=async Q=>{if(d==="copy"){if(Q.quantumOwned)return Q;const de=F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,Q.categories),me=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,Q.metadataGroups).map(le=>F.getFragmentData(E.METADATA_ITEM_FRAGMENT,le.data).map(Ee=>Ee.id)).flat(),Ce=F.getFragmentData(E.REPORT_FRAGMENT,Q.reports).map(le=>({...le,id:void 0,thresholds:F.getFragmentData(E.THRESHOLD_FRAGMENT,le.thresholds).map(Ee=>({...Ee,id:void 0}))})),Ae=F.getFragmentData(E.THRESHOLD_FRAGMENT,Q.thresholds).map(le=>({...le,id:void 0})),Re={...Q,quantumOwned:!0,thresholds:Ae,categories:de?.map(le=>le.id),reports:Ce,metadataIds:me,id:void 0},pe=await D({fields:Re});return pe.error||!pe.data?.createAction?null:F.getFragmentData(E.ACTION_FRAGMENT,pe.data.createAction)}if(Q.quantumOwned)return Q;const se=await w({id:Q.id});return se.error||!se.data?.convertActionToQuantumOwned?null:F.getFragmentData(E.ACTION_FRAGMENT,se.data.convertActionToQuantumOwned)};A=(await Promise.all(W.map(_))).filter(Q=>!!Q?.id).map(Q=>Q.id)}if(d==="convert"){const W={name:u.name,description:u.description||void 0,actions:A,categories:u.categories.map(H=>H.id),quantumOwned:!0},_=await B({id:u.id,input:W});if(_.error)throw new Error(_.error.message);if(_.data?.updateModule){const H=F.getFragmentData(E.ACTION_MODULE_FRAGMENT,_.data.updateModule);l.push(H)}}else{const W={name:`${u.name} (Copy)`,description:u.description||void 0,moduleActions:u.moduleActions.map(H=>({actionId:H.actionId,reportId:H.reportId??void 0})),categories:u.categories.map(H=>H.id),quantumOwned:x,metadataItemIds:u.metadataItems.map(H=>H.id)},_=await T({input:W});if(_.error)throw new Error(_.error.message);if(_.data?.createModule){const H=F.getFragmentData(E.ACTION_MODULE_FRAGMENT,_.data.createModule);l.push(H)}}}catch(A){console.error(`Failed to ${d==="convert"?"convert":"copy"} module "${u.name}":`,A),S++}if(l.length>0){const u=l.length,A=O.length;g({title:S>0?`Partial ${d==="convert"?"convert":"copy"} completed`:`${a.plural} ${d==="convert"?"converted":"copied"} successfully`,description:S>0?`${u} of ${A} ${a.plural} ${d==="convert"?"converted":"copied"} successfully`:`${u} ${u>1?a.plural:a.singular} ${d==="convert"?"converted":"copied"} successfully`,status:S>0?"warning":"success",duration:3e3,isClosable:!0}),l.length>0&&r?.(),C(""),M([])}else throw new Error(`Failed to ${d==="convert"?"convert":"copy"} any modules`)}catch(l){const S=l instanceof Error?l.message:`Failed to ${d==="convert"?"convert":"copy"} modules`;g({title:d==="convert"?"Convert failed":"Copy failed",description:S,status:"error",duration:5e3,isClosable:!0}),i?.(l instanceof Error?l:new Error(S))}finally{f(!1)}},[O,T,B,g,r,i,x,D,w,d,a]),z=s.useCallback(()=>{C(""),M([]),k("copy"),n?.()},[n]);s.useEffect(()=>{p&&p({cancelButton:!1,saveButton:O.length===0||I})},[O.length,I,p]),s.useEffect(()=>{j&&j({cancelButton:z,saveButton:L})},[j,z,L]);const J=s.useMemo(()=>K.map(l=>({value:l.id,label:l.name})),[K]),q=s.useMemo(()=>te.filter(l=>d==="copy"?!0:!l.quantumOwned).map(l=>({value:l.id,label:l.name,isQuantumOwned:l.quantumOwned})),[te,d]),Y=R.fetching,c=N.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(ue,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:d,onChange:l=>{k(l),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.jsxs(t.Text,{fontWeight:"medium",children:["Copy ",a.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",a.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 ",a.pluralLowerCase," to quantum-owned"]})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(ie.st,{placeholder:"Choose a group...",options:J,value:J.find(l=>l.value===y)||null,onChange:ne,isLoading:Y,isDisabled:Y,isClearable:!0}),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 groups: ",R.error.message]})]})]}),y&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:d==="convert"?`Select ${a.plural} to Convert`:`Select ${a.plural} to Copy`}),c?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 ",a.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(ie.st,{placeholder:d==="convert"?`Choose ${a.pluralLowerCase} to convert...`:`Choose ${a.pluralLowerCase} to copy...`,options:q,value:q.filter(l=>v.includes(l.value)),onChange:V,isDisabled:q.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(l,{context:S})=>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}),S==="value"&&l.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),l.isQuantumOwned&&S==="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 ",a.pluralLowerCase," found in this group"]})]}),N.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 ",a.pluralLowerCase,":"," ",N.error.message]})]})]}),O.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:O.length===1?`${a.singular} to ${d==="copy"?"Copy":"Convert"}`:`${O.length} ${a.plural} to ${d==="copy"?"Copy":"Convert"}`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[O.map((l,S)=>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:[S+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:"Activities:"})," ",l.moduleActions.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Categories:"})," ",l.categories.map(u=>u.name).join(", ")||"None"]})]})]},l.id)),O.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: ",O.length," ",a.pluralLowerCase," will be"," ",d==="copy"?"copied":"converted"]})}),x&&O.filter(l=>l.moduleActions.some(S=>!S.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:d==="convert"?`Converting ${a.plural} will convert non QM-Owned ${m.plural} to QM-Owned ${m.plural}`:`Copying ${a.plural} with Non QM-Owned ${m.plural} will create corresponding QM-Owned ${m.plural}`})})]})]}),!h&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:z,isDisabled:I,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:d==="copy"?"blue":"green",onClick:L,isDisabled:O.length===0||I,isLoading:I,loadingText:`${d==="copy"?"Copying":"Converting"}...`,children:[d==="copy"?"Copy":"Convert"," ",O.length===1?a.singular:`${O.length} ${a.plural}`]})]})]})})},Le=s.createContext(void 0),fe=()=>{const r=s.useContext(Le);if(!r)throw new Error("useUpsertModuleFormContext must be used within a UpsertModuleFormProvider");return r},Ne=({name:r,setName:n,actions:i,moduleActionEntries:h,setModuleActionEntries:p,availableCategories:j,selectedCategoryIds:x,setSelectedCategoryIds:g,description:o,setDescription:a,selectedMetadataIds:m,setSelectedMetadataIds:y,...C})=>{const v=t.useDisclosure(),M=s.useMemo(()=>{const T={};return h.forEach(B=>{T[B.actionId]=(T[B.actionId]??0)+1}),T},[h]),I=s.useCallback(T=>M[T]??0,[M]),f=s.useMemo(()=>i.map(T=>({...T,selected:(M[T.id]??0)>0})),[i,M]),d=s.useMemo(()=>i.reduce((T,B)=>(T[B.id]=B,T),{}),[i]),k=s.useCallback((T,B)=>{if(B){const D={key:crypto.randomUUID(),actionId:T.id,reportId:null};p(w=>[...w,D])}else p(D=>{for(let w=D.length-1;w>=0;w--)if(D[w].actionId===T.id){const K=[...D];return K.splice(w,1),K}return D})},[p]),R=s.useCallback(T=>{n(T.target.value)},[n]),N=s.useCallback(T=>{a?.(T.target.value)},[a]);return e.jsxRuntimeExports.jsxs(t.Box,{...C,children:[e.jsxRuntimeExports.jsxs(t.HStack,{gap:"2rem",children:[e.jsxRuntimeExports.jsx(Xe,{name:r??"",onInputChange:R}),e.jsxRuntimeExports.jsx(Ze,{availableCategories:j,value:x,onChange:g})]}),e.jsxRuntimeExports.jsx(et,{description:o??"",onInputChange:N}),e.jsxRuntimeExports.jsx(ot,{selectedMetadataIds:m,setSelectedMetadataIds:y}),e.jsxRuntimeExports.jsx(tt,{moduleActionEntries:h,setModuleActionEntries:p,actionsById:d,onAdjustActivities:()=>v.onOpen()}),e.jsxRuntimeExports.jsxs(t.Modal,{isOpen:v.isOpen,onClose:v.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(we,{actions:f,onSelected:k,allowDuplicateSelection:!0,getSelectedCount:I,disableCreate:!0,disableDelete:!0,tableProps:{height:"28rem",overflowY:"auto"}})}),e.jsxRuntimeExports.jsx(t.ModalFooter,{children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:v.onClose,isDisabled:h.length===0,children:"Done"})})]})]})]})},Xe=s.memo(({name:r,onInputChange:n})=>{const{getLabel:i}=ae.useUiLabelContext(),h=i("module"),{isView:p}=fe();return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(ue,{children:[h," Name"]}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. ACL RTP Test Battery",value:r,onChange:n,isRequired:!0,isDisabled:p})]})}),Ze=s.memo(({availableCategories:r,value:n,onChange:i})=>{const{getLabel:h}=ae.useUiLabelContext(),p=h("module"),{isView:j}=fe(),x=s.useMemo(()=>r.map(g=>({value:g.id,label:g.name})),[r]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(ue,{children:[p," Category"]}),e.jsxRuntimeExports.jsx(ie.st,{isDisabled:r.length===0||j,options:x,value:r.filter(g=>n.includes(g.id)).map(g=>({value:g.id,label:g.name}))[0]??null,onChange:g=>i(g?[g.value]:[]),placeholder:"Select category"})]})}),et=s.memo(({description:r,onInputChange:n})=>{const{getLabel:i}=ae.useUiLabelContext(),h=i("module"),{isView:p}=fe();return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(ue,{children:e.jsxRuntimeExports.jsxs("span",{children:["Description",e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",children:["Briefly describe the objective of this"," ",h.toLocaleLowerCase(),". Max 40 words."]})]})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. Assess readiness to return to play post-ACL reconstruction",value:r,onChange:n,isDisabled:p})]})}),tt=s.memo(({moduleActionEntries:r,setModuleActionEntries:n,actionsById:i,onAdjustActivities:h})=>{const{getLabel:p}=ae.useUiLabelContext(),{isView:j}=fe(),x=s.useMemo(()=>({module:p("module"),moduleLowerCase:p("module").toLocaleLowerCase(),action:p("action"),actionPlural:p("action_plural"),actionPluralLowerCase:p("action_plural").toLocaleLowerCase()}),[p]),g=s.useMemo(()=>r.map(o=>{const a=i[o.actionId];return a?{key:o.key,actionId:o.actionId,name:a.name,reports:F.getFragmentData(E.REPORT_FRAGMENT,a.reports)||[],selectedReportId:o.reportId}:null}).filter(Boolean),[r,i]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(t.HStack,{justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(ue,{children:e.jsxRuntimeExports.jsxs("span",{children:[x.actionPlural,!j&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",children:["Drag and drop to reorder the ",x.actionPluralLowerCase," ","in this ",x.moduleLowerCase,"."]})]})}),!j&&e.jsxRuntimeExports.jsxs(t.Button,{size:"sm",variant:"solid",colorScheme:"blue",onClick:h,children:["Add / Remove ",x.actionPlural]})]}),g.length===0?e.jsxRuntimeExports.jsx(t.VStack,{children:e.jsxRuntimeExports.jsxs(t.Text,{color:"gray.500",fontSize:"lg",mb:"4rem",mt:"4rem",children:["No ",x.actionPluralLowerCase," selected for this"," ",x.moduleLowerCase,".",!j&&e.jsxRuntimeExports.jsxs(t.Button,{ml:"0.5em",size:"sm",variant:"link",colorScheme:"blue",onClick:h,children:["Add ",x.actionPluralLowerCase,"."]})]})}):e.jsxRuntimeExports.jsx(st,{value:g,onChange:o=>{n(a=>{const m=a.map(C=>{const v=i[C.actionId];return v?{key:C.key,actionId:C.actionId,name:v.name,reports:F.getFragmentData(E.REPORT_FRAGMENT,v.reports)||[],selectedReportId:C.reportId}:null}).filter(Boolean);return o(m).map(C=>({key:C.key,actionId:C.actionId,reportId:C.selectedReportId}))})},disabled:j,setModuleActionEntries:n})]})}),st=s.memo(({value:r,onChange:n,disabled:i,setModuleActionEntries:h})=>{const[p]=s.useState(()=>Math.random().toString(36).substring(2,15)),j=s.useCallback((o,a)=>{i||n(m=>{const y=[...m],[C]=y.splice(o,1);return y.splice(a,0,C),y})},[n,i]),x=s.useCallback(o=>{h(a=>{const m=a.findIndex(M=>M.key===o);if(m===-1)return a;const y=a[m],C={key:crypto.randomUUID(),actionId:y.actionId,reportId:null},v=[...a];return v.splice(m+1,0,C),v})},[h]),g=s.useCallback(o=>{h(a=>a.filter(m=>m.key!==o))},[h]);return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsx(Me.DndProvider,{backend:Me.HTML5Backend,children:e.jsxRuntimeExports.jsx(t.VStack,{spacing:3,align:"stretch",children:r.map((o,a)=>e.jsxRuntimeExports.jsx(nt,{listKey:p,item:o,index:a,disabled:!!i,move:j,onReportChange:m=>{h(y=>y.map(C=>C.key===o.key?{...C,reportId:m}:C))},onDuplicate:()=>x(o.key),onRemove:()=>g(o.key)},o.key))})})})}),nt=s.memo(({listKey:r,item:n,index:i,disabled:h,move:p,onReportChange:j,onDuplicate:x,onRemove:g})=>{const o=s.useRef(null),{getLabel:a}=ae.useUiLabelContext(),m=a("action"),[{handlerId:y},C]=Me.useDrop({accept:r,collect:R=>({handlerId:R.getHandlerId()?.toString()??""}),hover:(R,N)=>{if(!o.current)return;const T=R.index,B=i;if(T===B)return;const D=o.current?.getBoundingClientRect(),w=(D.bottom-D.top)/2,te=N.getClientOffset().y-D.top;T<B&&te<w||T>B&&te>w||(p(T,B),R.index=B)}}),[{isDragging:v},M]=Me.useDrag({type:r,item:()=>({id:n.key,index:i}),collect:R=>({isDragging:R.isDragging()}),canDrag:!h}),I=s.useMemo(()=>`action-report-label-${n.key}`,[n.key]),f=s.useMemo(()=>[{value:null,label:"No Report"},...n.reports.map(R=>{const N=R.name&&R.name.length>0?R.name:"No Name",T=je.reportKindName(R.reportKind);return{value:R.id,label:`${N} (${T})`}})],[n.reports]),d=v?.6:1,k=h?"default":v?"grabbing":"grab";return M(C(o)),e.jsxRuntimeExports.jsx(t.Box,{ref:o,p:3,border:"1px solid",borderColor:"gray.200",borderRadius:"md",bg:"gray.50",style:{opacity:d,cursor:k},"data-handler-id":y,children:e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",align:"center",children:[e.jsxRuntimeExports.jsxs(t.HStack,{spacing:3,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"semibold",minW:"2rem",children:[i+1,"."]}),e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"medium",children:n.name})]}),e.jsxRuntimeExports.jsxs(t.HStack,{spacing:3,align:"center",children:[e.jsxRuntimeExports.jsxs(t.Text,{id:I,fontSize:"sm",color:"gray.600",children:[m," Report:"]}),e.jsxRuntimeExports.jsx(t.Box,{width:{base:"100%",md:"350px"},children:e.jsxRuntimeExports.jsx(ie.st,{"aria-labelledby":I,value:f.find(R=>R.value===n.selectedReportId),onChange:R=>{j(R?.value||null)},options:f,placeholder:"Select report...",isDisabled:h})}),!h&&e.jsxRuntimeExports.jsxs(t.HStack,{spacing:1,children:[e.jsxRuntimeExports.jsx(t.Button,{size:"xs",variant:"ghost",colorScheme:"blue",onClick:x,title:"Add another instance with a different report",children:"+ Duplicate"}),e.jsxRuntimeExports.jsx(t.Button,{size:"xs",variant:"ghost",colorScheme:"red",onClick:g,title:"Remove this entry",children:"Remove"})]})]})]})})}),ot=s.memo(({selectedMetadataIds:r,setSelectedMetadataIds:n})=>{const{getLabel:i}=ae.useUiLabelContext(),{isView:h,metadataOptions:p}=fe(),j=s.useMemo(()=>[{key:"activity_type",label:`${i("action")} Type`,multi:!0},{key:"session_type",label:"Session Type",multi:!0},{key:"body_region",label:"Body Region",multi:!0},{key:"sport",label:"Sport",multi:!0}],[i]),x=s.useCallback((g,o)=>{const a=j.find(y=>y.key===g);if(!a)return;const m=a.multi?(o??[]).map(y=>y.id):o?[o.id]:[];n(y=>[...y.filter(v=>Object.values(p||{}).flat().find(I=>I.id===v)&&!Object.keys(p||{}).find(I=>p?.[I]?.some(f=>f.id===v&&I===g))),...m])},[j,p,n]);return p?e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(ue,{children:"Metadata Tags"}),e.jsxRuntimeExports.jsx(t.HStack,{gap:"1rem",align:"start",children:j.map(g=>e.jsxRuntimeExports.jsxs(t.FormControl,{flex:"1",children:[e.jsxRuntimeExports.jsx(t.FormLabel,{fontSize:"sm",children:g.label}),e.jsxRuntimeExports.jsx(ie.st,{isMulti:g.multi,value:p[g.key]?.filter(o=>r.includes(o.id)),onChange:o=>{x(g.key,o)},options:p[g.key],placeholder:`Select ${g.multi?"one or more":"one"} ${g.label.toLowerCase()}`,isDisabled:h,isClearable:g.multi})]},g.key))})]}):null}),De=({value:r,onChange:n,forceKind:i,disableRemove:h,disableKind:p,isDisabled:j,lockRanges:x,...g})=>{const o=s.useMemo(()=>[...r].sort((C,v)=>{const M=ge.availablePlanes.indexOf(C.plane),I=ge.availablePlanes.indexOf(v.plane);return M-I}),[r]),a=s.useCallback(C=>"segment"in C.id?ce.getSegmentNameWithPlane(C.id.segment,C.plane,!0)??"Unknown":ce.getJointNameWithPlane(C.id.joint,C.plane,!0)??"Unknown",[]),m=s.useCallback((C,v)=>{const M=o.findIndex(f=>f.id===v.id&&f.plane===v.plane);let I=[...o];i&&(v={...v,kind:i}),I[M]=v,x&&(I=I.map(f=>({...f,min:v.min,max:v.max}))),n(I)},[n,o,i,x]),y=s.useCallback(C=>{const v=o.filter(M=>M.id!==C.id||M.plane!==C.plane);n(v)},[n,o]);return e.jsxRuntimeExports.jsx(t.VStack,{alignItems:"flex-start",overflowY:"auto",...g,children:o.map((C,v)=>e.jsxRuntimeExports.jsx(rt,{label:a(C),parameter:C,onChange:M=>m(v,M),onRemove:h||j?void 0:()=>y(C),forceKind:i,disableKind:p||j,isDisabled:j},`${JSON.stringify(C.id)}-${C.plane}`))})},rt=({label:r,parameter:n,onChange:i,onRemove:h,forceKind:p,disableKind:j,isDisabled:x})=>{const g=s.useCallback(m=>"joint"in n.id?ce.getJointAngleDirectionName(n.id.joint,n.plane,m<0?-1:1):ce.getSegmentAngleDirectionName(n.id.segment,n.plane,m<0?-1:1),[n]),{min:o,max:a}="joint"in n.id?ce.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%",alignItems:"center",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",flex:1,textTransform:"capitalize",fontWeight:"semibold",children:r}),n.sensorOnly?e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor"}):e.jsxRuntimeExports.jsxs(t.HStack,{spacing:1,children:[e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"blue",variant:"subtle",children:"Pose"}),e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor"})]}),h&&!x&&e.jsxRuntimeExports.jsx(t.IconButton,{size:"xs",variant:"ghost","aria-label":"delete",icon:e.jsxRuntimeExports.jsx(t.Icon,{as:he.FaTrash}),onClick:h}),!p&&e.jsxRuntimeExports.jsx($e,{selectedItem:n?.kind??$.ThresholdKind.Limit,onChange:({value:m})=>i({...n,kind:m}),isDisabled:j||x,buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:$.ThresholdKind.Limit,label:"limit"},{value:$.ThresholdKind.Target,label:"target"}]})]}),e.jsxRuntimeExports.jsx(Ue,{w:"100%",size:"xs",min:o,max:a,zeroMarker:!0,value:[n.min,n.max],onChange:m=>i({...n,min:m[0],max:m[1]}),formatValue:m=>`${Math.abs(m)}°`,valueLabel:m=>g(m)??"",positiveNegativeLabels:g(0)?[g(-1)??"",g(1)??""]:void 0,isDisabled:x})]})},Se=(r,n)=>"segment"in r&&"segment"in n&&r.segment===n.segment||"joint"in r&&"joint"in n&&r.joint===n.joint,ke=({options:r,value:n,onChange:i,forceKind:h,singleValue:p,singleValueSideless:j,editOnly:x,disableKind:g,maxParameters:o,...a})=>{const m=j?2:o,y=s.useMemo(()=>{const f=new Map;return r.forEach(d=>{const k="joint"in d.id;let R,N;if(k?(R=ce.getJointNameWithPlane(d.id.joint,d.plane,!0)??"Unknown",N=`joint:${d.id.joint}`):(R=ce.getSegmentNameWithPlane(d.id.segment,d.plane,!0)??"Unknown",N=`segment:${d.id.segment}`),!f.has(N)){const D=k?ce.getPartName(d.id.joint)??"Unknown Joint":ce.getPartName(d.id.segment)??"Unknown Segment";f.set(N,{label:D,options:[]})}const T=f.get(N),B=[R,k?d.id.joint:d.id.segment,d.plane].filter(Boolean).map(D=>String(D).toLowerCase().replace(/\s+|_/g,""));T.options.push({label:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:2,justify:"space-between",alignItems:"center",w:"100%",pl:3,children:[e.jsxRuntimeExports.jsx(t.Text,{children:R}),d.sensorOnly?e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor"}):e.jsxRuntimeExports.jsxs(t.HStack,{spacing:1,children:[e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"blue",variant:"subtle",children:"Pose"}),e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor"})]})]}),value:d.id,plane:d.plane,sensorOnly:d.sensorOnly,searchTokens:B})}),Array.from(f.values())},[r]),C=s.useMemo(()=>{if(!j||n.length===0)return y;const f=n[0];return y.map(d=>({...d,options:d.options.filter(k=>ge.getAnalysisPartIdNoSide(k.value)===ge.getAnalysisPartIdNoSide(f.id)&&k.plane===f.plane)})).filter(d=>d.options.length>0)},[y,n,j]),v=s.useMemo(()=>y.flatMap(d=>d.options).filter(d=>n.some(k=>Se(k.id,d.value)&&k.plane===d.plane)),[y,n]),M=s.useCallback((f,d)=>{if(!d)return!0;const k=d.toLowerCase().replace(/\s+|_/g,""),R=f.data;return!R||!R.searchTokens?!1:R.searchTokens.some(N=>N.includes(k))},[]),I=s.useCallback(f=>{const d=f.map(k=>{const R=n.find(w=>Se(w.id,k.value)&&w.plane===k.plane),N=r.find(w=>Se(w.id,k.value)&&w.plane===k.plane),T=j?n.find(w=>ge.getAnalysisPartIdNoSide(w.id)===ge.getAnalysisPartIdNoSide(k.value)&&w.plane===k.plane):void 0,B=T&&!R?T.min:N&&N.min?N.min:0,D=T&&!R?T.max:N&&N.max?N.max:0;return R??{id:k.value,plane:k.plane,min:B,max:D,sensorOnly:k.sensorOnly,kind:h??$.ThresholdKind.Limit}});i(d)},[i,n,r,h,j]);return s.useEffect(()=>{const f=n.filter(d=>r.some(k=>Se(k.id,d.id)&&k.plane===d.plane));f.length!==n.length&&i(f)},[r,i,n]),e.jsxRuntimeExports.jsxs(t.Box,{...a,children:[e.jsxRuntimeExports.jsx(ie.st,{isMulti:!p,placeholder:n.length?`${n.length} selected`:"Search...",value:v,isDisabled:x||v.length>=(m??1/0),onChange:f=>Array.isArray(f)?I([...f]):I(f!==null?[f]:[]),options:C,controlShouldRenderValue:!1,formatOptionLabel:f=>f.label,filterOption:M,isSearchable:!0}),e.jsxRuntimeExports.jsx(De,{marginTop:2,maxH:"28rem",value:n,onChange:i,forceKind:h,disableKind:g,isDisabled:x,lockRanges:j})]})},Fe=r=>{switch(r){case $.SensorLocation.Thorax:return"Thorax";case $.SensorLocation.CenterBack:return"Center Back";case $.SensorLocation.Pelvis:return"Pelvis";case $.SensorLocation.LeftThigh:return"Left Thigh";case $.SensorLocation.RightThigh:return"Right Thigh";case $.SensorLocation.LeftShank:return"Left Shank";case $.SensorLocation.RightShank:return"Right Shank";case $.SensorLocation.LeftFoot:return"Left Foot";case $.SensorLocation.RightFoot:return"Right Foot";case $.SensorLocation.LeftUpperArm:return"Left Upper Arm";case $.SensorLocation.RightUpperArm:return"Right Upper Arm";case $.SensorLocation.LeftForearm:return"Left Forearm";case $.SensorLocation.RightForearm:return"Right Forearm";case $.SensorLocation.Head:return"Head"}},at=({id:r,onError:n,onCancel:i,onSave:h,hideButtons:p,setButtonOnClick:j,setButtonDisabled:x,quantumOwned:g,isView:o})=>{const a=Z.useClient(),[{fetching:m},y]=Z.useMutation(E.CREATE_ACTION),[{fetching:C},v]=Z.useMutation(E.UPDATE_ACTION),[{data:M}]=Z.useQuery({query:E.GET_ACTION_BY_ID,variables:{id:r??""},pause:!r}),I=s.useMemo(()=>{const b=F.getFragmentData(E.ACTION_FRAGMENT,M?.getActionById);if(!b)return null;const P=(F.getFragmentData(E.REPORT_FRAGMENT,b.reports)||[]).map(G=>({...G,thresholds:F.getFragmentData(E.THRESHOLD_FRAGMENT,G.thresholds)}));return{...b,thresholds:F.getFragmentData(E.THRESHOLD_FRAGMENT,b.thresholds),reports:P}},[M]),f=m||C,d=!!I&&!!r,{getLabel:k}=ae.useUiLabelContext(),R=s.useMemo(()=>({action:k("action")}),[k]),N=s.useMemo(()=>[{key:"module_category",label:"Link Category",multi:!0},{key:"activity_type",label:`${R.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},{key:"activity_motion_direction",label:"Activity Motion Direction",multi:!0}],[R.action]),[T,B]=s.useState(""),[D,w]=s.useState(""),[K,te]=s.useState(""),[O,ne]=s.useState(""),[V,L]=s.useState([]),[z,J]=s.useState({}),[q,Y]=s.useState(null),[c,l]=s.useState(""),[S,u]=s.useState([]),[A,W]=s.useState([]),[_,H]=s.useState(""),[Q,se]=s.useState([]),de=ae.useAllPartParameters(),xe=s.useMemo(()=>de.filter(b=>b.sensorOnly),[de]),me=[{label:je.reportKindName($.ReportKind.GeneralActivity),value:$.ReportKind.GeneralActivity},{label:je.reportKindName($.ReportKind.MovementCoordination),value:$.ReportKind.MovementCoordination},{label:je.reportKindName($.ReportKind.Range),value:$.ReportKind.Range},{label:je.reportKindName($.ReportKind.StabilityBalance),value:$.ReportKind.StabilityBalance},{label:je.reportKindName($.ReportKind.PointOfInterest),value:$.ReportKind.PointOfInterest}],be=s.useMemo(()=>T.trim().length>0,[T]),[Ce,Ae]=s.useState({});s.useEffect(()=>{const b=N.map(U=>a.query(E.GET_METADATA_BY_KEY,{key:U.key}));Promise.all(b).then(U=>{const P={};U.forEach(G=>{if(G.error||!G.data)return;const ee=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,G.data.getMetadataByKey),X=F.getFragmentData(E.METADATA_ITEM_FRAGMENT,ee.data);P[ee.key]=X.map(re=>({label:re.label||re.value,value:re.value,id:re.id}))}),J(P)})},[a,N]),s.useEffect(()=>{if(I){const U=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,I.metadataGroups).map(ee=>ee.data.map(X=>F.getFragmentData(E.METADATA_ITEM_FRAGMENT,X).id)),P=I.reports.map(ee=>({id:ee.id,name:ee.name??"",instructions:ee.instructions??"",kind:ee.reportKind,autoGenerate:ee.autoGenerate??!1,parameters:ee.thresholds.map(X=>({id:{[X.partKind]:X.partId},kind:X.kind,min:X.min,max:X.max,plane:X.partDimension,oldId:X.id,sensorOnly:xe.some(re=>{const Ie=re.id[X.partKind];return Ie?Ie===X.partId&&re.plane===X.partDimension:!1})})),sensorLocations:ee.sensorLocations})),G={name:I.name,description:I.description||"",cameraPlacement:I.cameraPlacement||"",videoLink:I.videoLink||"",metadataIds:U.flat(),reports:P};B(G.name),w(G.description),te(G.cameraPlacement),ne(G.videoLink),L(G.metadataIds),se(P),Ae(G)}},[I]);const Re=s.useMemo(()=>JSON.stringify(Ce)!==JSON.stringify({name:T,description:D,cameraPlacement:K,videoLink:O,metadataIds:V,reports:Q}),[Ce,T,D,K,O,V,Q]),pe=s.useCallback(()=>{const b={name:T,description:D,cameraPlacement:K,videoLink:O,metadataItemIds:V,laterality:$.ActionLaterality.Either,quantumOwned:g,sessionType:[],thresholds:[],reports:Q.map(P=>({id:P.isNew?void 0:P.id,name:P.name,reportKind:P.kind,sensorLocations:P.sensorLocations,instructions:P.instructions,autoGenerate:P.autoGenerate??!1,thresholds:P.parameters.map(G=>({id:G.oldId,kind:G.kind,min:G.min,max:G.max,partKind:"joint"in G.id?"joint":"segment",partId:"joint"in G.id?G.id.joint:G.id.segment,partDimension:G.plane}))}))};let U;d&&r?U=v({id:r,fields:b}):U=y({fields:b}),U.then(({error:P})=>{P?n(P):h()})},[g,y,v,r,T,D,K,O,V,Q,d,h,n]);s.useEffect(()=>{x&&x({cancelButton:f,saveButton:o?!0:f||!be||!Re})},[f,x,be,Re,o]),s.useEffect(()=>{j&&j({cancelButton:i,saveButton:o?()=>{}:pe})},[j,i,pe,o]);const le=s.useCallback(b=>{const U=ce.getSuggestedSensorLocations(b.map(P=>"joint"in P.id?P.id.joint:P.id.segment));W(U)},[]);s.useEffect(()=>{le(S)},[S,le]);const Ee=s.useCallback(()=>{if(!q||!c.trim())return;const b=q===$.ReportKind.PointOfInterest,U={id:Date.now().toString(),name:c.trim(),kind:q,parameters:b?[]:S,sensorLocations:b?[]:A,instructions:b?_:"",autoGenerate:!1,isNew:!0};se(P=>[...P,U]),Y(null),l(""),u([]),W([]),H("")},[q,c,S,A,_]),Oe=s.useCallback(b=>{se(U=>U.filter(P=>P.id!==b))},[]),_e=(b,U)=>{const P=N.find(ee=>ee.key===b);if(!P)return;const G=P.multi?(U??[]).map(ee=>ee.id):U?[U.id]:[];L(ee=>[...ee.filter(re=>Object.values(z).flat().find(ye=>ye.id===re)&&!Object.keys(z).find(ye=>z[ye]?.some(Ge=>Ge.id===re&&ye===b))),...G])};return e.jsxRuntimeExports.jsxs(t.VStack,{spacing:4,w:"full",align:"stretch",children:[e.jsxRuntimeExports.jsxs(t.Tabs,{children:[e.jsxRuntimeExports.jsxs(t.TabList,{children:[e.jsxRuntimeExports.jsx(t.Tab,{children:"Activity Configuration"}),e.jsxRuntimeExports.jsx(t.Tab,{children:"Reports Configuration"})]}),e.jsxRuntimeExports.jsxs(t.TabPanels,{children:[e.jsxRuntimeExports.jsx(t.TabPanel,{px:0,children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:T,onChange:b=>B(b.target.value),type:"text",placeholder:"i.e. Lunge & Return",isDisabled:o})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Camera Placement"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:K,onChange:b=>te(b.target.value),rows:2,placeholder:"(optional) Describe camera setup, placement, angles",isDisabled:o})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Video Link"}),e.jsxRuntimeExports.jsx(t.Input,{value:O,onChange:b=>ne(b.target.value),type:"url",placeholder:"(optional) https://...",isDisabled:o})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Description"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:D,onChange:b=>w(b.target.value),rows:2,placeholder:"(optional) Describe how to perform the test or exercise",isDisabled:o})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(oe,{children:"Metadata Tags"}),N.map(b=>e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:b.label}),e.jsxRuntimeExports.jsx(ie.st,{isMulti:b.multi,value:z[b.key]?.filter(U=>V.includes(U.id)),onChange:U=>{_e(b.key,U)},options:z[b.key],placeholder:`Select ${b.multi?"one or more":"one"} ${b.label.toLowerCase()}`,isDisabled:o,isClearable:b.multi})]},b.key))]})]})}),e.jsxRuntimeExports.jsx(t.TabPanel,{px:0,children:e.jsxRuntimeExports.jsxs("div",{className:ve.cn("grid grid-cols-1 gap-6",!o&&"md:grid-cols-2"),children:[e.jsxRuntimeExports.jsxs("div",{className:ve.cn("space-y-4",o&&"hidden"),children:[e.jsxRuntimeExports.jsx(oe,{children:"Add New Report"}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Report Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:c,onChange:b=>l(b.target.value),maxLength:120,type:"text",placeholder:"Enter report name...",isDisabled:o})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Report Type"}),e.jsxRuntimeExports.jsx(ie.st,{value:q?me.find(b=>b.value===q):null,onChange:b=>Y(b?.value||null),options:me,placeholder:"Select report type...",isDisabled:o,isClearable:!0})]}),q!==$.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(ke,{options:de,value:S,onChange:u,editOnly:o})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Sensor Locations"}),e.jsxRuntimeExports.jsx(t.Input,{value:A.map(b=>Fe(b)).join(", "),placeholder:"Auto-filled based on parameters...",isDisabled:!0})]})]}),q===$.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:_,onChange:b=>H(b.target.value),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:o})]}),e.jsxRuntimeExports.jsx("div",{className:"w-full flex justify-end",children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:Ee,isDisabled:!q||!c.trim()||o||me.length===0||q!==$.ReportKind.PointOfInterest&&S.length===0,children:"Add Report"})})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(oe,{children:"Configured Reports"}),Q.length===0?e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",children:"No reports created yet"}):e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:Q.map(b=>e.jsxRuntimeExports.jsxs("div",{className:"p-3 border border-gray-200 rounded-md bg-gray-50 flex flex-col gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.600",children:je.reportKindName(b.kind)}),!o&&e.jsxRuntimeExports.jsx(t.Button,{size:"xs",colorScheme:"red",variant:"ghost",onClick:()=>Oe(b.id),children:"Remove"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Report Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:b.name,onChange:U=>se(P=>P.map(G=>G.id===b.id?{...G,name:U.target.value}:G)),placeholder:"Enter report name...",isDisabled:o})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{display:"flex",alignItems:"center",children:[e.jsxRuntimeExports.jsx(t.FormLabel,{htmlFor:`auto-generate-${b.id}`,mb:"0",children:"Auto Generate"}),e.jsxRuntimeExports.jsx(t.Switch,{id:`auto-generate-${b.id}`,isChecked:b.autoGenerate??!1,onChange:U=>se(P=>P.map(G=>G.id===b.id?{...G,autoGenerate:U.target.checked}:G)),isDisabled:o})]}),b.kind===$.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:b.instructions,onChange:U=>se(P=>P.map(G=>G.id===b.id?{...G,instructions:U.target.value}:G)),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:o})]}),b.kind!==$.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs("div",{className:"flex flex-col",children:[e.jsxRuntimeExports.jsx(oe,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(ke,{options:de,value:b.parameters,onChange:U=>{const P=X=>"joint"in X.id?X.id.joint:X.id.segment,G=U.map(P),ee=ce.getSuggestedSensorLocations(G);se(X=>X.map(re=>re.id===b.id?{...re,parameters:U,sensorLocations:ee}:re))},editOnly:o})]}),b.kind!==$.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Sensors:"," ",b.sensorLocations.map(U=>Fe(U)).join(", ")]})]},b.id))})]})]})})]})]}),e.jsxRuntimeExports.jsx(t.HStack,{justify:"end",className:ve.cn((p||o)&&"!hidden"),children:e.jsxRuntimeExports.jsxs(t.ButtonGroup,{gap:4,children:[e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:f,onClick:i,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:f||!be||!Re,isLoading:f,onClick:pe,children:"Save changes"})]})})]})},oe=({children:r})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:r}),it=({children:r,isView:n,metadataKeys:i})=>{const[h,p]=s.useState({}),j=Z.useClient();return s.useEffect(()=>{let x=!1;return(async()=>{const o=(i??[]).map(y=>j.query(E.GET_METADATA_BY_KEY,{key:y}).toPromise()),a=await Promise.all(o),m={};for(const y of a){if(y.error||!y.data?.getMetadataByKey)continue;const C=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,y.data.getMetadataByKey);if(!C)continue;const v=F.getFragmentData(E.METADATA_ITEM_FRAGMENT,C.data)??[];m[C.key]=v.map(M=>({label:M.label||M.value,value:M.value,id:M.id}))}x||p(m)})(),()=>{x=!0}},[j,i]),e.jsxRuntimeExports.jsx(Le.Provider,{value:{isView:n,metadataOptions:h},children:r})},lt=({id:r,onCancel:n,onSave:i,onError:h,hideButtons:p,quantumOwned:j,setButtonOnClick:x,setButtonDisabled:g,isView:o})=>{const[{data:a,fetching:m}]=Z.useQuery({query:j?E.GET_QUANTUM_OWNED_ACTIONS:E.GET_ACTIONS}),[{data:y}]=Z.useQuery({query:E.GET_MODULE_BY_ID,variables:{id:r},pause:!r}),[{data:C}]=Z.useQuery({query:E.GET_ALL_MODULE_CATEGORIES}),v=F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,C?.moduleCategories),[{fetching:M},I]=Z.useMutation(E.UPDATE_MODULE),[{fetching:f},d]=Z.useMutation(E.CREATE_MODULE),k=s.useMemo(()=>!a||m?[]:F.getFragmentData(E.ACTION_FRAGMENT,j?a?.quantumOwnedActions??[]:a?.actions??[]).filter(q=>!!q?.id),[a,j,m]),R=F.getFragmentData(E.ACTION_MODULE_FRAGMENT,y?.module),N=s.useMemo(()=>F.getFragmentData(E.MODULE_ACTION_FRAGMENT,R?.moduleActions)??[],[R?.moduleActions]),[T,B]=s.useState([]),[D,w]=s.useState(R?.name??""),[K,te]=s.useState([]),[O,ne]=s.useState(R?.description??""),[V,L]=s.useState([]);s.useEffect(()=>{if(R){const J=N.map((c,l)=>({key:c.id??`${c.actionId}-${l}`,actionId:c.actionId,reportId:c.reportId||null}));B(J),w(R.name),ne(R.description??""),te(R.categories.map(c=>F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,c).id)??[]);const Y=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,R.metadataGroups).map(c=>c.data.map(l=>F.getFragmentData(E.METADATA_ITEM_FRAGMENT,l).id));L(Y.flat())}},[R,N]);const z=s.useCallback(()=>{let J;const q={moduleActions:T.map(Y=>({actionId:Y.actionId,reportId:Y.reportId??void 0})),name:D,categories:K,description:O,quantumOwned:j,metadataItemIds:V};R?J=I({id:R.id,input:q}):J=d({input:q}),J.then(({error:Y})=>{Y?h(Y instanceof Error?Y:new Error(String(Y))):i()})},[d,I,T,D,O,K,V,R,i,h,j]);return s.useEffect(()=>{g&&g({cancelButton:M||f,saveButton:M||f||!D||O.trim().split(/\s+/).filter(Boolean).length>40})},[g,M,f,T,D,O]),s.useEffect(()=>{x&&x({cancelButton:n,saveButton:z})},[x,n,z]),e.jsxRuntimeExports.jsx(t.Box,{width:"100%",children:e.jsxRuntimeExports.jsxs(it,{isView:o,metadataKeys:["activity_type","session_type","body_region","sport"],children:[e.jsxRuntimeExports.jsx(Ne,{name:D,setName:w,actions:k,moduleActionEntries:T,setModuleActionEntries:B,availableCategories:v??[],selectedCategoryIds:K,setSelectedCategoryIds:te,description:O,setDescription:ne,selectedMetadataIds:V,setSelectedMetadataIds:L}),!p&&!o&&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:M||f,onClick:n,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:M||f||!D||O.trim().split(/\s+/).filter(Boolean).length>40,isLoading:M||f,onClick:z,children:"Save"})]})})]})})};exports.ActivityList=we;exports.CopyActivityForm=Je;exports.CopyModuleForm=Ve;exports.ModuleForm=Ne;exports.ParameterEditList=De;exports.ParameterEditSelect=ke;exports.UpsertActivityForm=at;exports.UpsertModuleForm=lt;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./react-jsx-runtime-vendor-Dszzpdy0.cjs");require("./moment-vendor-1cRqq0AH.cjs");const t=require("@chakra-ui/react"),s=require("react"),I=require("./generated.cjs"),f=require("./graphql-BEhru2G1.cjs"),Me=require("./utils-cn-FIKrq5Mb.cjs"),he=require("./types.cjs");require("./lodash-vendor-CGEP7jch.cjs");const ee=require("urql"),ae=require("./hooks.cjs"),Be=require("./ufuzzy-vendor-7qHa_k39.cjs"),ie=require("./react-select-vendor-Dletsq31.cjs"),ge=require("./react-icons-vendor-D3in8HbI.cjs"),je=require("./services.cjs"),ve=require("./react-dnd-vendor-CPQdLxxA.cjs"),ce=require("./services-human-Cl36G8mV.cjs"),z=require("./generated-graphql.cjs"),ke=require("./utils-parameters-Bx16_6xw.cjs"),$e=({setSearch:o,actions:n,updateUseCases:i,hideUseCaseFilter:g=!1})=>{const m=s.useMemo(()=>n?.flatMap(p=>p.useCases).filter((p,j,R)=>R.findIndex(r=>r.id===p.id)===j).map(p=>({label:p.name,value:p.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:ge.FaSearch,color:"gray.300"})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"Search by name...",width:"100%",maxW:g?void 0:"30rem",onChange:p=>o(p.target.value)})]}),!g&&e.jsxRuntimeExports.jsx(t.InputGroup,{size:"md",children:e.jsxRuntimeExports.jsx(ie.st,{size:"md",chakraStyles:{container:p=>({...p,width:"100%"})},menuPortalTarget:document.body,placeholder:"Filter use case",isMulti:!0,options:m,onChange:p=>i(p.map(j=>j.value))})})]})},ue=({children:o})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:o}),Ue=({items:o,onChange:n,selectedItem:i,isDisabled:g,selectedProps:m,buttonProps:p})=>{const j=r=>r===i||r.value===i,R=r=>j(r)?{...p,...m}:p;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:g,children:o.map((r,a)=>e.jsxRuntimeExports.jsx(t.Tooltip,{label:r.tooltip,openDelay:50,closeDelay:200,placement:"top",visibility:r.tooltip?"visible":"hidden",hasArrow:!0,children:e.jsxRuntimeExports.jsx(t.Button,{onClick:()=>j(r)?null:n(r,a),isDisabled:r.disabled,...R(r),children:r.label})},a))})},Se=(o,n)=>n<0?-1*Math.abs(o):Math.abs(o),ze=({isReversed:o,min:n,max:i,value:g,onChange:m,inputProps:p,size:j,zeroMarker:R,formatValue:r,valueLabel:a,positiveNegativeLabels:C,isDisabled:b,...A})=>{const[k,E]=s.useState([void 0,void 0]),T=k[0],h=k[1],d=R&&n<-5&&i>5,F=Number(g?.[0]??h??n)>0?1:-1,x=Number(g?.[1]??h??i)<0?-1:1,O=C?.[0]===C?.[1],S=g?.[0],$=g?.[1];s.useEffect(()=>{S!==void 0&&$!==void 0&&E([S.toFixed(0),$.toFixed(0)])},[S,$,E]);const L=s.useCallback(([w,K])=>{w<K&&E([w.toFixed(0),K.toFixed(0)])},[E]),_=s.useCallback(([w,K])=>{w<K&&m([w,K])},[m]),G=s.useCallback(()=>{E(([w,K])=>{const J=isNaN(Number(w))?n:Number(w),q=isNaN(Number(K))?i:Number(K),Y=Se(Number(J),F),c=Se(Number(q),x),l=F<0?Math.max(Y,n):Math.min(Y,i),M=x<0?Math.max(c,n):Math.min(c,i);return l>M?(m([M,l]),[M.toFixed(0),l.toFixed(0)]):(m([l,M]),[l.toFixed(0),M.toFixed(0)])})},[m,E,F,x,n,i]),te=s.useCallback(w=>{const K=w===""||isNaN(Number(w))?w:Se(Number(w),F);E(([J,q])=>[K.toString(),q])},[E,F]),P=s.useCallback(w=>{const K=w===""||isNaN(Number(w))?w:Se(Number(w),x);E(([J,q])=>[J,K.toString()])},[E,x]),ne=s.useMemo(()=>j==="xs"?"0.75rem":void 0,[j]),X=s.useCallback((w,K)=>{const J=Number(K.target.value);if(!T||!h||![-1,1].includes(J))return;const q=l=>J<0?-1*Math.abs(l):Math.abs(l),Y=w?q(Number(T)):Number(T),c=w?Number(h):q(Number(h));Y>c?m([c,Y]):m([Y,c])},[T,h,m]);return e.jsxRuntimeExports.jsxs(t.Flex,{direction:"column",...A,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(T??n),Number(h??i)],max:i,min:n,minStepsBetweenThumbs:3,step:1,onChange:L,onChangeEnd:_,isDisabled:b,children:[e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:n,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:j??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:r?r?.(n):n})}),e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:i,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:j??"sm",fontWeight:"semibold",style:{transform:"translateX(-100%)"},whiteSpace:"nowrap",children:r?r(i):i})}),d&&e.jsxRuntimeExports.jsxs(t.RangeSliderMark,{value:0,top:"-1em",pos:"relative",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:j,fontWeight:"semibold",children:r?.(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:ne,h:ne}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:1,w:ne,h:ne})]})}),a&&e.jsxRuntimeExports.jsxs(t.Flex,{direction:o?"row-reverse":"row",justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:j??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:a(n)}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:j??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:a(i)})]}),e.jsxRuntimeExports.jsxs(t.Flex,{direction:o?"row-reverse":"row",justifyContent:"center",alignItems:"center",gap:"0.125em",children:[C&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:j,fontWeight:"bold",value:F,onChange:w=>X(!0,w),isDisabled:O||b,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:C[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:C[1]})]}),e.jsxRuntimeExports.jsx(t.NumberInput,{precision:0,size:j??"sm",min:0,max:F<0?Math.abs(n):$??i,value:T===""?"":Math.abs(Number(T??n)),onChange:te,onBlur:G,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:b,...p,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),e.jsxRuntimeExports.jsx(t.NumberInput,{size:j??"sm",min:0,max:x<0?Math.abs(S??n):i,precision:0,value:h===""?"":Math.abs(Number(h??i)),onChange:P,onBlur:G,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:b,...p,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),C&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:j,fontWeight:"bold",value:x,onChange:w=>X(!1,w),isDisabled:O||b,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:C[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:C[1]})]})]})]})},qe=({tags:o,containerProps:n,...i})=>e.jsxRuntimeExports.jsx(t.HStack,{...n,children:o.map((g,m)=>e.jsxRuntimeExports.jsx(t.Tag,{...i,children:g},m))}),Ke=new Be.uFuzzy({}),We=({action:o,quantumIconSrc:n})=>{const{getLabel:i}=ae.useUiLabelContext(),g=s.useMemo(()=>({actionLowerCase:i("action").toLocaleLowerCase()}),[i]);return o.quantumOwned?e.jsxRuntimeExports.jsx(t.Tooltip,{label:`This ${g.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:n,boxSize:"1em",alt:`Quantum-owned ${g.actionLowerCase}`})})}):null},He=(o,n)=>{if(!n||!n.trim().length)return o;const i=o.map(m=>m.name??"");return Ke.filter(i,n)?.map(m=>o[m])??[]},Qe=o=>!o||o.length===0?"None":o.map(n=>he.sensorLocationName(n)).join(", "),Ye=(o,n)=>!n||n.length==0?o:o.filter(i=>i.useCases?.some(g=>n.includes(g.id))??!1),Je=(o,n,i)=>!n||n.length===0?o:o.filter(g=>{const m={};return n.forEach(p=>{for(const[j,R]of Object.entries(i||{}))if(R.some(r=>r.id===p)){m[j]||(m[j]=[]),m[j].push(p);break}}),Object.entries(m).every(([p,j])=>{const R=g.metadataGroups?.find(b=>I.getFragmentData(f.METADATA_GROUP_FRAGMENT,b).key===p);if(!R)return!1;const r=I.getFragmentData(f.METADATA_GROUP_FRAGMENT,R),C=I.getFragmentData(f.METADATA_ITEM_FRAGMENT,r.data).map(b=>b.id);return j.some(b=>C.includes(b))})}),Le=({actions:o,totalActions:n,onCreate:i,onDelete:g,onEdit:m,onView:p,onSelected:j,onDuplicate:R,disableMultiSelect:r,disableDelete:a,disableEdit:C,disableCreate:b,hideUseCase:A=!0,showMetadataFilters:k=!0,tableProps:E,containerProps:T,quantumIconSrc:h="/favicon.ico",allowDuplicateSelection:d=!1,getSelectedCount:F})=>{const[x,O]=s.useState(""),[S,$]=s.useState(),[L,_]=s.useState([]),[G,te]=s.useState({}),{getLabel:P}=ae.useUiLabelContext(),ne=ee.useClient(),X=s.useMemo(()=>({action:P("action"),actionPlural:P("action_plural"),actionLowerCase:P("action").toLocaleLowerCase(),actionPluralLowerCase:P("action_plural").toLocaleLowerCase()}),[P]),w=s.useMemo(()=>[{key:"module_category",label:"Link Category",multi:!0},{key:"activity_type",label:`${X.action} Type`,multi:!0},{key:"session_type",label:"Session Type",multi:!0},{key:"body_region",label:"Body Region",multi:!0},{key:"sport",label:"Sport",multi:!0}],[X.action]);s.useEffect(()=>{if(!k)return;const u=w.map(v=>ne.query(f.GET_METADATA_BY_KEY,{key:v.key}));Promise.all(u).then(v=>{const W={};v.forEach(B=>{if(B.error||!B.data)return;const H=I.getFragmentData(f.METADATA_GROUP_FRAGMENT,B.data.getMetadataByKey),Q=I.getFragmentData(f.METADATA_ITEM_FRAGMENT,H.data);W[H.key]=Q.map(se=>({label:se.label||se.value,value:se.value,id:se.id}))}),te(W)})},[ne,w,k]);const K=s.useMemo(()=>{if(!o)return;const u=He(o,x),v=A?u:Ye(u,S);return k?Je(v,L,G):v},[o,x,S,A,k,L,G]),J=s.useCallback(()=>{if(!g)return;const v=o.filter(W=>W.selected&&!W.quantumOwned).map(W=>W.id);g(v)},[o,g]),q=s.useCallback(()=>{if(!R)return;const u=o.filter(v=>v.selected);R(u.map(v=>v.id)),j&&u.forEach(v=>j(v,!1))},[o,R,j]),Y=s.useMemo(()=>o.some(u=>u.selected&&!u.quantumOwned),[o]),c=s.useMemo(()=>o.some(u=>u.selected),[o]),l=s.useMemo(()=>o.some(u=>u.selected&&u.quantumOwned),[o]),M=s.useCallback((u,v)=>{const W=w.find(H=>H.key===u);if(!W)return;const B=W.multi?(v??[]).map(H=>H.id):v?[v.id]:[];_(H=>[...H.filter(se=>Object.values(G).flat().find(xe=>xe.id===se)&&!Object.keys(G).find(xe=>G[xe]?.some(me=>me.id===se&&xe===u))),...B])},[w,G]);return e.jsxRuntimeExports.jsxs(t.Box,{...T,children:[e.jsxRuntimeExports.jsxs(t.Flex,{alignContent:"space-between",gap:4,children:[(i||g||R)&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mb:"1rem",gap:4,children:[i&&e.jsxRuntimeExports.jsxs(t.Button,{isDisabled:!i||b,colorScheme:"blackAlpha",backgroundColor:"gray.700",onClick:i,children:["Create New ",X.action]}),g&&!r&&e.jsxRuntimeExports.jsx(t.Tooltip,{label:l?Y?`Quantum-owned ${X.actionPluralLowerCase} are selected and will be skipped`:`Selected ${X.actionPluralLowerCase} are quantum-owned and cannot be deleted`:void 0,shouldWrapChildren:!0,children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!Y||!g||a,onClick:J,children:"Delete Selected"})}),R&&!r&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!c,onClick:q,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx($e,{setSearch:O,actions:o,updateUseCases:$,hideUseCaseFilter:A})]}),k&&G&&e.jsxRuntimeExports.jsx(t.Box,{my:4,children:e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4",children:w.map(u=>e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(t.FormLabel,{fontSize:"sm",children:u.label}),e.jsxRuntimeExports.jsx(ie.st,{chakraStyles:{menu:v=>({...v,zIndex:2})},isMulti:u.multi,value:G[u.key]?.filter(v=>L.includes(v.id)),onChange:v=>{M(u.key,v)},options:G[u.key],placeholder:`Select ${u.multi?"one or more":"one"} ${u.label.toLowerCase()}`,isClearable:u.multi})]},u.key))})}),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 ",K?.length??0," of"," ",n??o.length,")"]}),e.jsxRuntimeExports.jsx(t.Th,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Th,{children:"Sensor Locations"}),!A&&e.jsxRuntimeExports.jsx(t.Th,{children:"Use Case"}),e.jsxRuntimeExports.jsx(t.Th,{})]})}),e.jsxRuntimeExports.jsx(t.Tbody,{children:K?.map(u=>{const v=d?F?.(u.id)??0:0,W=d?v>0:!!u.selected;return e.jsxRuntimeExports.jsxs(t.Tr,{className:Me.cn("hover:bg-[#f7f7f7]",!r&&!d&&"cursor-pointer",W&&"bg-gray-200"),onClick:()=>{r||d||j?.(u,!u.selected)},children:[e.jsxRuntimeExports.jsx(t.Td,{children:e.jsxRuntimeExports.jsxs(t.Flex,{alignItems:"center",children:[!r&&d?e.jsxRuntimeExports.jsxs(t.HStack,{spacing:1,onClick:B=>B.stopPropagation(),children:[e.jsxRuntimeExports.jsx(t.IconButton,{"aria-label":"Remove one instance",icon:e.jsxRuntimeExports.jsx(ge.FaMinus,{}),size:"xs",variant:"outline",isDisabled:v===0,onClick:()=>j?.(u,!1)}),e.jsxRuntimeExports.jsx(t.Text,{minW:"1.5rem",textAlign:"center",fontWeight:v>0?"semibold":"normal",color:v>0?"blue.600":"gray.500",children:v}),e.jsxRuntimeExports.jsx(t.IconButton,{"aria-label":"Add one instance",icon:e.jsxRuntimeExports.jsx(ge.FaPlus,{}),size:"xs",variant:"outline",colorScheme:"blue",onClick:()=>j?.(u,!0)})]}):r?null:e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:u.selected?e.jsxRuntimeExports.jsx(ge.FaCheckSquare,{className:"text-blue-500"}):e.jsxRuntimeExports.jsx(ge.FaSquare,{className:"text-gray-400"})}),(u.quantumOwned||!m)&&p&&e.jsxRuntimeExports.jsx(t.Button,{ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:B=>{B.stopPropagation(),p(u.id)},children:"View"}),!u.quantumOwned&&m&&e.jsxRuntimeExports.jsx(t.Button,{isDisabled:C,ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:B=>{B.stopPropagation(),m(u.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(We,{action:u,quantumIconSrc:h}),u.name]})}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",whiteSpace:"break-spaces",children:Qe(u.sensorLocations)}),!A&&e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:e.jsxRuntimeExports.jsx(qe,{containerProps:{flexWrap:"wrap"},tags:u.useCases?.map(B=>B.name)??[]})})]},u.id)})})]})})]})},Xe=({onSave:o,onCancel:n,onError:i,hideButtons:g=!1,setButtonDisabled:m,setButtonOnClick:p,quantumOwned:j})=>{const R=t.useToast(),{getLabel:r}=ae.useUiLabelContext(),a=s.useMemo(()=>({singular:r("action"),plural:r("action_plural"),pluralLowerCase:r("action_plural").toLowerCase(),singularLowerCase:r("action").toLowerCase()}),[r]),[C,b]=s.useState("copy"),[A,k]=s.useState(""),[E,T]=s.useState([]),[h,d]=s.useState(!1),[F]=ee.useQuery({query:f.GET_GROUPS}),[x]=ee.useQuery({query:f.GET_ACTIONS_BY_GROUP,variables:{groupId:A},pause:!A}),[,O]=ee.useMutation(f.CREATE_ACTION),[,S]=ee.useMutation(f.CONVERT_ACTION_TO_QUANTUM_OWNED),$=s.useMemo(()=>F.data?.groups?F.data.groups.map(c=>I.getFragmentData(f.GROUP_FRAGMENT,c)):[],[F.data]),L=s.useMemo(()=>x.data?x.data.actions.map(l=>{const M=I.getFragmentData(f.ACTION_FRAGMENT,l),u=I.getFragmentData(f.REPORT_FRAGMENT,M.reports),v=I.getFragmentData(f.MODULE_CATEGORY_FRAGMENT,M.categories),B=I.getFragmentData(f.METADATA_GROUP_FRAGMENT,M.metadataGroups).map(H=>({...H,data:H.data.map(Q=>I.getFragmentData(f.METADATA_ITEM_FRAGMENT,Q))}));return{...M,thresholds:I.getFragmentData(f.THRESHOLD_FRAGMENT,M.thresholds),reports:u.map(H=>({...H,thresholds:I.getFragmentData(f.THRESHOLD_FRAGMENT,H.thresholds)})),categories:v,metadataGroups:B}}):[],[x.data]),_=s.useMemo(()=>L.filter(c=>E.includes(c.id)),[L,E]),G=s.useCallback(c=>{const l=c?.value||"";k(l),T([])},[]),te=s.useCallback(c=>{const l=c.map(M=>M.value);T(l)},[]),P=s.useCallback(async c=>{const l={...c,name:`${c.name} (Copy)`,description:c.description||void 0,instructionsPointOfInterest:c.instructionsPointOfInterest||void 0,instructionsMovementReport:c.instructionsMovementReport||void 0,laterality:c.laterality,activityKind:c.activityKind,sensorLocations:c.sensorLocations,thresholds:c.thresholds.map(u=>({...u,id:void 0})),categories:c.categories.map(u=>u.id),quantumOwned:j,metadataItemIds:c.metadataGroups.flatMap(u=>u.data.map(v=>v.id)).filter(u=>u!==void 0),reports:c.reports.map(u=>({...u,id:void 0,thresholds:u.thresholds.map(v=>({...v,id:void 0}))})),id:void 0},M=await O({fields:l});if(M.error)throw new Error(M.error.message);if(M.data?.createAction)return I.getFragmentData(f.ACTION_FRAGMENT,M.data.createAction);throw new Error("No action data returned")},[O,j]),ne=s.useCallback(async c=>{const l=await S({id:c.id});if(l.error)throw new Error(l.error.message);if(l.data?.convertActionToQuantumOwned)return I.getFragmentData(f.ACTION_FRAGMENT,l.data.convertActionToQuantumOwned);throw new Error("No action data returned")},[S]),X=s.useCallback(async()=>{if(d(!0),!_.length){const c=new Error(`No ${a.pluralLowerCase} selected for ${C==="copy"?"copying":"converting"}`);i?.(c),d(!1);return}try{const c=[];let l=0;const M=C==="copy"?P:ne,u=C==="copy"?"copy":"convert";for(const v of _)try{const W=await M(v);c.push(W)}catch(W){console.error(`Failed to ${u} ${a.singularLowerCase} "${v.name}":`,W),l++}if(c.length>0){const v=c.length,W=_.length,B=C==="copy"?"copied":"converted",H=C==="copy"?"copy":"convert";R({title:l>0?`Partial ${H} completed`:`${a.plural} ${B} successfully`,description:l>0?`${v} of ${W} ${a.pluralLowerCase} ${B} successfully`:`${v} ${v>1?a.pluralLowerCase:a.singularLowerCase} ${B} successfully`,status:l>0?"warning":"success",duration:3e3,isClosable:!0}),o?.(),k(""),T([])}else throw new Error(`Failed to ${u} any ${a.pluralLowerCase}`)}catch(c){const l=C==="copy"?"copy":"convert",M=c instanceof Error?c.message:`Failed to ${l} ${a.pluralLowerCase}`;R({title:`${C==="copy"?"Copy":"Convert"} failed`,description:M,status:"error",duration:5e3,isClosable:!0}),i?.(c instanceof Error?c:new Error(M))}finally{d(!1)}},[_,C,P,ne,R,o,i,a]),w=s.useCallback(()=>{k(""),T([]),b("copy"),n?.()},[n]);s.useEffect(()=>{m&&m({cancelButton:!1,saveButton:_.length===0||h})},[_.length,h,m]),s.useEffect(()=>{p&&p({cancelButton:w,saveButton:X})},[p,w,X]);const K=s.useMemo(()=>$.map(c=>({value:c.id,label:c.name})),[$]),J=s.useMemo(()=>L.filter(c=>C==="copy"?!0:!c.quantumOwned).map(c=>({value:c.id,label:c.name,isQuantumOwned:c.quantumOwned})),[L,C]),q=F.fetching,Y=x.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[j&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:C,onChange:c=>{b(c),T([])},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 ",a.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",a.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 ",a.singular]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Convert existing"," ",a.plural.toLocaleLowerCase()," to quantum-owned"]})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(ie.st,{placeholder:"Choose a group...",options:K,value:K.find(c=>c.value===A)||null,onChange:G,isLoading:q,isDisabled:q,isClearable:!0}),F.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: ",F.error.message]})]})]}),A&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsxs(ue,{children:["Select ",a.plural," to"," ",C==="copy"?"Copy":"Convert"]}),Y?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 ",a.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(ie.st,{placeholder:`Choose ${a.pluralLowerCase} to ${C}...`,options:J,value:J.filter(c=>E.includes(c.value)),onChange:te,isDisabled:J.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(c,{context:l})=>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:c.label}),l==="value"&&c.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),c.isQuantumOwned&&l==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),J.length===0&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:["No ",a.pluralLowerCase," found"]})]}),x.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 ",a.pluralLowerCase,":"," ",x.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?`${a.singular} to ${C==="copy"?"Copy":"Convert"}:`:`${_.length} ${a.plural} to ${C==="copy"?"Copy":"Convert"}:`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[_.map((c,l)=>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:[l+1,". ",c.name]}),c.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:[c.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",c.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Type:"})," ",c.activityKind]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Laterality:"})," ",c.laterality]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Sensor Locations:"})," ",c.sensorLocations.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Thresholds:"})," ",c.thresholds.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Use Cases:"})," ",c.useCases.map(M=>M.name).join(", ")||"None"]})]})]},c.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," ",a.pluralLowerCase," will be"," ",C==="copy"?"copied":"converted"]})})]})]}),!g&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:w,isDisabled:h,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:C==="copy"?"blue":"green",onClick:X,isDisabled:_.length===0||h,isLoading:h,loadingText:`${C==="copy"?"Copying":"Converting"}...`,children:[C==="copy"?"Copy":"Convert"," ",_.length===1?a.singular:`${_.length} ${a.plural}`]})]})]})})},Ze=({onSave:o,onCancel:n,onError:i,hideButtons:g=!1,setButtonDisabled:m,setButtonOnClick:p,quantumOwned:j})=>{const R=t.useToast(),{getLabel:r}=ae.useUiLabelContext(),a=s.useMemo(()=>({singular:r("module"),plural:r("module_plural"),pluralLowerCase:r("module_plural").toLowerCase(),singularLowerCase:r("module").toLowerCase()}),[r]),C=s.useMemo(()=>({singular:r("action"),plural:r("action_plural"),pluralLowerCase:r("action_plural").toLowerCase(),singularLowerCase:r("action").toLowerCase()}),[r]),[b,A]=s.useState(""),[k,E]=s.useState([]),[T,h]=s.useState(!1),[d,F]=s.useState("copy"),[x]=ee.useQuery({query:f.GET_GROUPS}),[O]=ee.useQuery({query:f.GET_MODULES_BY_GROUP,variables:{groupId:b},pause:!b}),[,S]=ee.useMutation(f.CREATE_MODULE),[,$]=ee.useMutation(f.UPDATE_MODULE),[,L]=ee.useMutation(f.CREATE_ACTION),[,_]=ee.useMutation(f.CONVERT_ACTION_TO_QUANTUM_OWNED),G=s.useMemo(()=>x.data?.groups?x.data.groups.map(l=>I.getFragmentData(f.GROUP_FRAGMENT,l)):[],[x.data]),te=s.useMemo(()=>O.data?.modules?I.getFragmentData(f.ACTION_MODULE_FRAGMENT,O.data?.modules).map(M=>{const u=I.getFragmentData(f.MODULE_ACTION_FRAGMENT,M.moduleActions),W=I.getFragmentData(f.METADATA_GROUP_FRAGMENT,M.metadataGroups).map(B=>I.getFragmentData(f.METADATA_ITEM_FRAGMENT,B.data)).flat();return{...M,moduleActions:u.map(B=>({...B,action:I.getFragmentData(f.ACTION_FRAGMENT,B.action)})),categories:I.getFragmentData(f.MODULE_CATEGORY_FRAGMENT,M.categories),metadataItems:W}}):[],[O.data]),P=s.useMemo(()=>te.filter(l=>k.includes(l.id)),[te,k]),ne=s.useCallback(l=>{const M=l?.value||"";A(M),E([])},[]),X=s.useCallback(l=>{const M=l.map(u=>u.value);E(M)},[]),w=s.useCallback(async()=>{if(h(!0),!P.length){h(!1);const l=new Error(`No modules selected for ${d==="convert"?"converting":"copying"}`);i?.(l);return}try{const l=[];let M=0;for(const u of P)try{let v=u.moduleActions.map(W=>W.actionId);if(j){const W=u.moduleActions.map(Q=>Q.action),B=async Q=>{if(d==="copy"){if(Q.quantumOwned)return Q;const de=I.getFragmentData(f.MODULE_CATEGORY_FRAGMENT,Q.categories),me=I.getFragmentData(f.METADATA_GROUP_FRAGMENT,Q.metadataGroups).map(le=>I.getFragmentData(f.METADATA_ITEM_FRAGMENT,le.data).map(Ee=>Ee.id)).flat(),ye=I.getFragmentData(f.REPORT_FRAGMENT,Q.reports).map(le=>({...le,id:void 0,thresholds:I.getFragmentData(f.THRESHOLD_FRAGMENT,le.thresholds).map(Ee=>({...Ee,id:void 0}))})),Ae=I.getFragmentData(f.THRESHOLD_FRAGMENT,Q.thresholds).map(le=>({...le,id:void 0})),Re={...Q,quantumOwned:!0,thresholds:Ae,categories:de?.map(le=>le.id),reports:ye,metadataIds:me,id:void 0},pe=await L({fields:Re});return pe.error||!pe.data?.createAction?null:I.getFragmentData(f.ACTION_FRAGMENT,pe.data.createAction)}if(Q.quantumOwned)return Q;const se=await _({id:Q.id});return se.error||!se.data?.convertActionToQuantumOwned?null:I.getFragmentData(f.ACTION_FRAGMENT,se.data.convertActionToQuantumOwned)};v=(await Promise.all(W.map(B))).filter(Q=>!!Q?.id).map(Q=>Q.id)}if(d==="convert"){const W={name:u.name,description:u.description||void 0,actions:v,categories:u.categories.map(H=>H.id),quantumOwned:!0},B=await $({id:u.id,input:W});if(B.error)throw new Error(B.error.message);if(B.data?.updateModule){const H=I.getFragmentData(f.ACTION_MODULE_FRAGMENT,B.data.updateModule);l.push(H)}}else{const W={name:`${u.name} (Copy)`,description:u.description||void 0,moduleActions:u.moduleActions.map(H=>({actionId:H.actionId,reportId:H.reportId??void 0})),categories:u.categories.map(H=>H.id),quantumOwned:j,metadataItemIds:u.metadataItems.map(H=>H.id)},B=await S({input:W});if(B.error)throw new Error(B.error.message);if(B.data?.createModule){const H=I.getFragmentData(f.ACTION_MODULE_FRAGMENT,B.data.createModule);l.push(H)}}}catch(v){console.error(`Failed to ${d==="convert"?"convert":"copy"} module "${u.name}":`,v),M++}if(l.length>0){const u=l.length,v=P.length;R({title:M>0?`Partial ${d==="convert"?"convert":"copy"} completed`:`${a.plural} ${d==="convert"?"converted":"copied"} successfully`,description:M>0?`${u} of ${v} ${a.plural} ${d==="convert"?"converted":"copied"} successfully`:`${u} ${u>1?a.plural:a.singular} ${d==="convert"?"converted":"copied"} successfully`,status:M>0?"warning":"success",duration:3e3,isClosable:!0}),l.length>0&&o?.(),A(""),E([])}else throw new Error(`Failed to ${d==="convert"?"convert":"copy"} any modules`)}catch(l){const M=l instanceof Error?l.message:`Failed to ${d==="convert"?"convert":"copy"} modules`;R({title:d==="convert"?"Convert failed":"Copy failed",description:M,status:"error",duration:5e3,isClosable:!0}),i?.(l instanceof Error?l:new Error(M))}finally{h(!1)}},[P,S,$,R,o,i,j,L,_,d,a]),K=s.useCallback(()=>{A(""),E([]),F("copy"),n?.()},[n]);s.useEffect(()=>{m&&m({cancelButton:!1,saveButton:P.length===0||T})},[P.length,T,m]),s.useEffect(()=>{p&&p({cancelButton:K,saveButton:w})},[p,K,w]);const J=s.useMemo(()=>G.map(l=>({value:l.id,label:l.name})),[G]),q=s.useMemo(()=>te.filter(l=>d==="copy"?!0:!l.quantumOwned).map(l=>({value:l.id,label:l.name,isQuantumOwned:l.quantumOwned})),[te,d]),Y=x.fetching,c=O.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[j&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:d,onChange:l=>{F(l),E([])},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 ",a.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",a.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 ",a.pluralLowerCase," to quantum-owned"]})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(ie.st,{placeholder:"Choose a group...",options:J,value:J.find(l=>l.value===b)||null,onChange:ne,isLoading:Y,isDisabled:Y,isClearable:!0}),x.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: ",x.error.message]})]})]}),b&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:d==="convert"?`Select ${a.plural} to Convert`:`Select ${a.plural} to Copy`}),c?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 ",a.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(ie.st,{placeholder:d==="convert"?`Choose ${a.pluralLowerCase} to convert...`:`Choose ${a.pluralLowerCase} to copy...`,options:q,value:q.filter(l=>k.includes(l.value)),onChange:X,isDisabled:q.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(l,{context:M})=>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}),M==="value"&&l.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),l.isQuantumOwned&&M==="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 ",a.pluralLowerCase," found in this group"]})]}),O.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 ",a.pluralLowerCase,":"," ",O.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?`${a.singular} to ${d==="copy"?"Copy":"Convert"}`:`${P.length} ${a.plural} to ${d==="copy"?"Copy":"Convert"}`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[P.map((l,M)=>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:[M+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:"Activities:"})," ",l.moduleActions.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Categories:"})," ",l.categories.map(u=>u.name).join(", ")||"None"]})]})]},l.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," ",a.pluralLowerCase," will be"," ",d==="copy"?"copied":"converted"]})}),j&&P.filter(l=>l.moduleActions.some(M=>!M.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:d==="convert"?`Converting ${a.plural} will convert non QM-Owned ${C.plural} to QM-Owned ${C.plural}`:`Copying ${a.plural} with Non QM-Owned ${C.plural} will create corresponding QM-Owned ${C.plural}`})})]})]}),!g&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:K,isDisabled:T,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:d==="copy"?"blue":"green",onClick:w,isDisabled:P.length===0||T,isLoading:T,loadingText:`${d==="copy"?"Copying":"Converting"}...`,children:[d==="copy"?"Copy":"Convert"," ",P.length===1?a.singular:`${P.length} ${a.plural}`]})]})]})})},Ne=s.createContext(void 0),be=()=>{const o=s.useContext(Ne);if(!o)throw new Error("useUpsertModuleFormContext must be used within a UpsertModuleFormProvider");return o},De=({name:o,setName:n,actions:i,moduleActionEntries:g,setModuleActionEntries:m,availableCategories:p,selectedCategoryIds:j,setSelectedCategoryIds:R,description:r,setDescription:a,selectedMetadataIds:C,setSelectedMetadataIds:b,...A})=>{const k=t.useDisclosure(),E=s.useMemo(()=>{const S={};return g.forEach($=>{S[$.actionId]=(S[$.actionId]??0)+1}),S},[g]),T=s.useCallback(S=>E[S]??0,[E]),h=s.useMemo(()=>i.map(S=>({...S,selected:(E[S.id]??0)>0})),[i,E]),d=s.useMemo(()=>i.reduce((S,$)=>(S[$.id]=$,S),{}),[i]),F=s.useCallback((S,$)=>{if($){const L={key:crypto.randomUUID(),actionId:S.id,reportId:null};m(_=>[..._,L])}else m(L=>{for(let _=L.length-1;_>=0;_--)if(L[_].actionId===S.id){const G=[...L];return G.splice(_,1),G}return L})},[m]),x=s.useCallback(S=>{n(S.target.value)},[n]),O=s.useCallback(S=>{a?.(S.target.value)},[a]);return e.jsxRuntimeExports.jsxs(t.Box,{...A,children:[e.jsxRuntimeExports.jsxs(t.HStack,{gap:"2rem",children:[e.jsxRuntimeExports.jsx(Ve,{name:o??"",onInputChange:x}),e.jsxRuntimeExports.jsx(et,{availableCategories:p,value:j,onChange:R})]}),e.jsxRuntimeExports.jsx(tt,{description:r??"",onInputChange:O}),e.jsxRuntimeExports.jsx(rt,{selectedMetadataIds:C,setSelectedMetadataIds:b}),e.jsxRuntimeExports.jsx(st,{moduleActionEntries:g,setModuleActionEntries:m,actionsById:d,onAdjustActivities:()=>k.onOpen()}),e.jsxRuntimeExports.jsxs(t.Modal,{isOpen:k.isOpen,onClose:k.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(Le,{actions:h,onSelected:F,allowDuplicateSelection:!0,getSelectedCount:T,disableCreate:!0,disableDelete:!0,tableProps:{height:"28rem",overflowY:"auto"}})}),e.jsxRuntimeExports.jsx(t.ModalFooter,{children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:k.onClose,isDisabled:g.length===0,children:"Done"})})]})]})]})},Ve=s.memo(({name:o,onInputChange:n})=>{const{getLabel:i}=ae.useUiLabelContext(),g=i("module"),{isView:m}=be();return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(ue,{children:[g," Name"]}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. ACL RTP Test Battery",value:o,onChange:n,isRequired:!0,isDisabled:m})]})}),et=s.memo(({availableCategories:o,value:n,onChange:i})=>{const{getLabel:g}=ae.useUiLabelContext(),m=g("module"),{isView:p}=be(),j=s.useMemo(()=>o.map(R=>({value:R.id,label:R.name})),[o]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(ue,{children:[m," Category"]}),e.jsxRuntimeExports.jsx(ie.st,{isDisabled:o.length===0||p,options:j,value:o.filter(R=>n.includes(R.id)).map(R=>({value:R.id,label:R.name}))[0]??null,onChange:R=>i(R?[R.value]:[]),placeholder:"Select category"})]})}),tt=s.memo(({description:o,onInputChange:n})=>{const{getLabel:i}=ae.useUiLabelContext(),g=i("module"),{isView:m}=be();return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(ue,{children:e.jsxRuntimeExports.jsxs("span",{children:["Description",e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",children:["Briefly describe the objective of this"," ",g.toLocaleLowerCase(),". Max 40 words."]})]})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. Assess readiness to return to play post-ACL reconstruction",value:o,onChange:n,isDisabled:m})]})}),st=s.memo(({moduleActionEntries:o,setModuleActionEntries:n,actionsById:i,onAdjustActivities:g})=>{const{getLabel:m}=ae.useUiLabelContext(),{isView:p}=be(),j=s.useMemo(()=>({module:m("module"),moduleLowerCase:m("module").toLocaleLowerCase(),action:m("action"),actionPlural:m("action_plural"),actionPluralLowerCase:m("action_plural").toLocaleLowerCase()}),[m]),R=s.useMemo(()=>o.map(r=>{const a=i[r.actionId];return a?{key:r.key,actionId:r.actionId,name:a.name,reports:I.getFragmentData(f.REPORT_FRAGMENT,a.reports)||[],selectedReportId:r.reportId}:null}).filter(Boolean),[o,i]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(t.HStack,{justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(ue,{children:e.jsxRuntimeExports.jsxs("span",{children:[j.actionPlural,!p&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",children:["Drag and drop to reorder the ",j.actionPluralLowerCase," ","in this ",j.moduleLowerCase,"."]})]})}),!p&&e.jsxRuntimeExports.jsxs(t.Button,{size:"sm",variant:"solid",colorScheme:"blue",onClick:g,children:["Add / Remove ",j.actionPlural]})]}),R.length===0?e.jsxRuntimeExports.jsx(t.VStack,{children:e.jsxRuntimeExports.jsxs(t.Text,{color:"gray.500",fontSize:"lg",mb:"4rem",mt:"4rem",children:["No ",j.actionPluralLowerCase," selected for this"," ",j.moduleLowerCase,".",!p&&e.jsxRuntimeExports.jsxs(t.Button,{ml:"0.5em",size:"sm",variant:"link",colorScheme:"blue",onClick:g,children:["Add ",j.actionPluralLowerCase,"."]})]})}):e.jsxRuntimeExports.jsx(nt,{value:R,onChange:r=>{n(a=>{const C=a.map(A=>{const k=i[A.actionId];return k?{key:A.key,actionId:A.actionId,name:k.name,reports:I.getFragmentData(f.REPORT_FRAGMENT,k.reports)||[],selectedReportId:A.reportId}:null}).filter(Boolean);return r(C).map(A=>({key:A.key,actionId:A.actionId,reportId:A.selectedReportId}))})},disabled:p,setModuleActionEntries:n})]})}),nt=s.memo(({value:o,onChange:n,disabled:i,setModuleActionEntries:g})=>{const[m]=s.useState(()=>Math.random().toString(36).substring(2,15)),p=s.useCallback((r,a)=>{i||n(C=>{const b=[...C],[A]=b.splice(r,1);return b.splice(a,0,A),b})},[n,i]),j=s.useCallback(r=>{g(a=>{const C=a.findIndex(E=>E.key===r);if(C===-1)return a;const b=a[C],A={key:crypto.randomUUID(),actionId:b.actionId,reportId:null},k=[...a];return k.splice(C+1,0,A),k})},[g]),R=s.useCallback(r=>{g(a=>a.filter(C=>C.key!==r))},[g]);return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsx(ve.DndProvider,{backend:ve.HTML5Backend,children:e.jsxRuntimeExports.jsx(t.VStack,{spacing:3,align:"stretch",children:o.map((r,a)=>e.jsxRuntimeExports.jsx(ot,{listKey:m,item:r,index:a,disabled:!!i,move:p,onReportChange:C=>{g(b=>b.map(A=>A.key===r.key?{...A,reportId:C}:A))},onDuplicate:()=>j(r.key),onRemove:()=>R(r.key)},r.key))})})})}),ot=s.memo(({listKey:o,item:n,index:i,disabled:g,move:m,onReportChange:p,onDuplicate:j,onRemove:R})=>{const r=s.useRef(null),{getLabel:a}=ae.useUiLabelContext(),C=a("action"),[{handlerId:b},A]=ve.useDrop({accept:o,collect:x=>({handlerId:x.getHandlerId()?.toString()??""}),hover:(x,O)=>{if(!r.current)return;const S=x.index,$=i;if(S===$)return;const L=r.current?.getBoundingClientRect(),_=(L.bottom-L.top)/2,te=O.getClientOffset().y-L.top;S<$&&te<_||S>$&&te>_||(m(S,$),x.index=$)}}),[{isDragging:k},E]=ve.useDrag({type:o,item:()=>({id:n.key,index:i}),collect:x=>({isDragging:x.isDragging()}),canDrag:!g}),T=s.useMemo(()=>`action-report-label-${n.key}`,[n.key]),h=s.useMemo(()=>[{value:null,label:"No Report"},...n.reports.map(x=>{const O=x.name&&x.name.length>0?x.name:"No Name",S=je.reportKindName(x.reportKind);return{value:x.id,label:`${O} (${S})`}})],[n.reports]),d=k?.6:1,F=g?"default":k?"grabbing":"grab";return E(A(r)),e.jsxRuntimeExports.jsx(t.Box,{ref:r,p:3,border:"1px solid",borderColor:"gray.200",borderRadius:"md",bg:"gray.50",style:{opacity:d,cursor:F},"data-handler-id":b,children:e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",align:"center",children:[e.jsxRuntimeExports.jsxs(t.HStack,{spacing:3,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"semibold",minW:"2rem",children:[i+1,"."]}),e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"medium",children:n.name})]}),e.jsxRuntimeExports.jsxs(t.HStack,{spacing:3,align:"center",children:[e.jsxRuntimeExports.jsxs(t.Text,{id:T,fontSize:"sm",color:"gray.600",children:[C," Report:"]}),e.jsxRuntimeExports.jsx(t.Box,{width:{base:"100%",md:"350px"},children:e.jsxRuntimeExports.jsx(ie.st,{"aria-labelledby":T,value:h.find(x=>x.value===n.selectedReportId),onChange:x=>{p(x?.value||null)},options:h,placeholder:"Select report...",isDisabled:g})}),!g&&e.jsxRuntimeExports.jsxs(t.HStack,{spacing:1,children:[e.jsxRuntimeExports.jsx(t.Button,{size:"xs",variant:"ghost",colorScheme:"blue",onClick:j,title:"Add another instance with a different report",children:"+ Duplicate"}),e.jsxRuntimeExports.jsx(t.Button,{size:"xs",variant:"ghost",colorScheme:"red",onClick:R,title:"Remove this entry",children:"Remove"})]})]})]})})}),rt=s.memo(({selectedMetadataIds:o,setSelectedMetadataIds:n})=>{const{getLabel:i}=ae.useUiLabelContext(),{isView:g,metadataOptions:m}=be(),p=s.useMemo(()=>[{key:"activity_type",label:`${i("action")} Type`,multi:!0},{key:"session_type",label:"Session Type",multi:!0},{key:"body_region",label:"Body Region",multi:!0},{key:"sport",label:"Sport",multi:!0}],[i]),j=s.useCallback((R,r)=>{const a=p.find(b=>b.key===R);if(!a)return;const C=a.multi?(r??[]).map(b=>b.id):r?[r.id]:[];n(b=>[...b.filter(k=>Object.values(m||{}).flat().find(T=>T.id===k)&&!Object.keys(m||{}).find(T=>m?.[T]?.some(h=>h.id===k&&T===R))),...C])},[p,m,n]);return m?e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(ue,{children:"Metadata Tags"}),e.jsxRuntimeExports.jsx(t.HStack,{gap:"1rem",align:"start",children:p.map(R=>e.jsxRuntimeExports.jsxs(t.FormControl,{flex:"1",children:[e.jsxRuntimeExports.jsx(t.FormLabel,{fontSize:"sm",children:R.label}),e.jsxRuntimeExports.jsx(ie.st,{isMulti:R.multi,value:m[R.key]?.filter(r=>o.includes(r.id)),onChange:r=>{j(R.key,r)},options:m[R.key],placeholder:`Select ${R.multi?"one or more":"one"} ${R.label.toLowerCase()}`,isDisabled:g,isClearable:R.multi})]},R.key))})]}):null}),Oe=({value:o,onChange:n,forceKind:i,disableRemove:g,disableKind:m,isDisabled:p,lockRanges:j,canAddCopy:R,...r})=>{const a=s.useMemo(()=>o.map((E,T)=>T).sort((E,T)=>{const h=he.availablePlanes.indexOf(o[E].plane),d=he.availablePlanes.indexOf(o[T].plane);return h-d}),[o]),C=s.useCallback(E=>"segment"in E.id?ce.getSegmentNameWithPlane(E.id.segment,E.plane,!0)??"Unknown":ce.getJointNameWithPlane(E.id.joint,E.plane,!0)??"Unknown",[]),b=s.useCallback((E,T)=>{let h=[...o];i&&(T={...T,kind:i}),h[E]=T,j&&(h=h.map(d=>({...d,min:T.min,max:T.max}))),n(h)},[n,o,i,j]),A=s.useCallback(E=>{n(o.filter((T,h)=>h!==E))},[n,o]),k=s.useCallback(E=>{const T=[...o];T.splice(E+1,0,{...o[E],oldId:void 0}),n(T)},[n,o]);return e.jsxRuntimeExports.jsx(t.VStack,{alignItems:"flex-start",overflowY:"auto",...r,children:a.map(E=>e.jsxRuntimeExports.jsx(at,{label:C(o[E]),parameter:o[E],onChange:T=>b(E,T),onRemove:g||p?void 0:()=>A(E),onAddCopy:R&&!p?()=>k(E):void 0,forceKind:i,disableKind:m||p,isDisabled:p},o[E].oldId??`new-${E}`))})},at=({label:o,parameter:n,onChange:i,onRemove:g,onAddCopy:m,forceKind:p,disableKind:j,isDisabled:R})=>{const r=s.useCallback(b=>"joint"in n.id?ce.getJointAngleDirectionName(n.id.joint,n.plane,b<0?-1:1):ce.getSegmentAngleDirectionName(n.id.segment,n.plane,b<0?-1:1),[n]),{min:a,max:C}="joint"in n.id?ce.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%",alignItems:"center",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",flex:1,textTransform:"capitalize",fontWeight:"semibold",children:o}),n.sensorOnly?e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor"}):e.jsxRuntimeExports.jsxs(t.HStack,{spacing:1,children:[e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"blue",variant:"subtle",children:"Pose"}),e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor"})]}),m&&e.jsxRuntimeExports.jsx(t.IconButton,{size:"xs",variant:"ghost","aria-label":"Add another",title:"Add this parameter again with its own range",icon:e.jsxRuntimeExports.jsx(t.Icon,{as:ge.FaCopy}),onClick:m}),g&&!R&&e.jsxRuntimeExports.jsx(t.IconButton,{size:"xs",variant:"ghost","aria-label":"delete",icon:e.jsxRuntimeExports.jsx(t.Icon,{as:ge.FaTrash}),onClick:g}),!p&&e.jsxRuntimeExports.jsx(Ue,{selectedItem:n?.kind??z.ThresholdKind.Limit,onChange:({value:b})=>i({...n,kind:b}),isDisabled:j||R,buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:z.ThresholdKind.Limit,label:"limit"},{value:z.ThresholdKind.Target,label:"target"}]})]}),e.jsxRuntimeExports.jsx(ze,{w:"100%",size:"xs",min:a,max:C,zeroMarker:!0,value:[n.min,n.max],onChange:b=>i({...n,min:b[0],max:b[1]}),formatValue:b=>`${Math.abs(b)}°`,valueLabel:b=>r(b)??"",positiveNegativeLabels:r(0)?[r(-1)??"",r(1)??""]:void 0,isDisabled:R})]})},fe=(o,n)=>"segment"in o&&"segment"in n&&o.segment===n.segment||"joint"in o&&"joint"in n&&o.joint===n.joint,Fe=({options:o,value:n,onChange:i,forceKind:g,singleValue:m,singleValueSideless:p,editOnly:j,disableKind:R,maxParameters:r,...a})=>{const C=p?2:r,b=s.useMemo(()=>{const h=new Map;return o.forEach(d=>{const F="joint"in d.id;let x,O;if(F?(x=ce.getJointNameWithPlane(d.id.joint,d.plane,!0)??"Unknown",O=`joint:${d.id.joint}`):(x=ce.getSegmentNameWithPlane(d.id.segment,d.plane,!0)??"Unknown",O=`segment:${d.id.segment}`),!h.has(O)){const L=F?ce.getPartName(d.id.joint)??"Unknown Joint":ce.getPartName(d.id.segment)??"Unknown Segment";h.set(O,{label:L,options:[]})}const S=h.get(O),$=[x,F?d.id.joint:d.id.segment,d.plane].filter(Boolean).map(L=>String(L).toLowerCase().replace(/\s+|_/g,""));S.options.push({label:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:2,justify:"space-between",alignItems:"center",w:"100%",pl:3,children:[e.jsxRuntimeExports.jsx(t.Text,{children:x}),d.sensorOnly?e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor"}):e.jsxRuntimeExports.jsxs(t.HStack,{spacing:1,children:[e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"blue",variant:"subtle",children:"Pose"}),e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor"})]})]}),value:d.id,plane:d.plane,sensorOnly:d.sensorOnly,searchTokens:$})}),Array.from(h.values())},[o]),A=s.useMemo(()=>{if(!p||n.length===0)return b;const h=n[0];return b.map(d=>({...d,options:d.options.filter(F=>he.getAnalysisPartIdNoSide(F.value)===he.getAnalysisPartIdNoSide(h.id)&&F.plane===h.plane)})).filter(d=>d.options.length>0)},[b,n,p]),k=s.useMemo(()=>b.flatMap(d=>d.options).filter(d=>n.some(F=>fe(F.id,d.value)&&F.plane===d.plane)),[b,n]),E=s.useCallback((h,d)=>{if(!d)return!0;const F=d.toLowerCase().replace(/\s+|_/g,""),x=h.data;return!x||!x.searchTokens?!1:x.searchTokens.some(O=>O.includes(F))},[]),T=s.useCallback(h=>{const d=n.filter(x=>h.some(O=>fe(x.id,O.value)&&x.plane===O.plane)),F=h.flatMap(x=>{if(n.find(G=>fe(G.id,x.value)&&G.plane===x.plane))return[];const S=o.find(G=>fe(G.id,x.value)&&G.plane===x.plane),$=p?n.find(G=>he.getAnalysisPartIdNoSide(G.id)===he.getAnalysisPartIdNoSide(x.value)&&G.plane===x.plane):void 0,L=$?$.min:S&&S.min?S.min:0,_=$?$.max:S&&S.max?S.max:0;return[{id:x.value,plane:x.plane,min:L,max:_,sensorOnly:x.sensorOnly,kind:g??z.ThresholdKind.Limit}]});i([...d,...F])},[i,n,o,g,p]);return s.useEffect(()=>{const h=n.filter(d=>o.some(F=>fe(F.id,d.id)&&F.plane===d.plane));h.length!==n.length&&i(h)},[o,i,n]),e.jsxRuntimeExports.jsxs(t.Box,{...a,children:[e.jsxRuntimeExports.jsx(ie.st,{isMulti:!m,placeholder:n.length?`${n.length} selected`:"Search...",value:k,isDisabled:j||n.length>=(C??1/0),onChange:h=>Array.isArray(h)?T([...h]):T(h!==null?[h]:[]),options:A,controlShouldRenderValue:!1,formatOptionLabel:h=>h.label,filterOption:E,isSearchable:!0}),e.jsxRuntimeExports.jsx(Oe,{marginTop:2,maxH:"28rem",value:n,onChange:i,forceKind:g,disableKind:R,isDisabled:j,lockRanges:p,canAddCopy:!j&&!m&&!p&&n.length<(C??1/0)})]})},we=o=>{switch(o){case z.SensorLocation.Thorax:return"Thorax";case z.SensorLocation.CenterBack:return"Center Back";case z.SensorLocation.Pelvis:return"Pelvis";case z.SensorLocation.LeftThigh:return"Left Thigh";case z.SensorLocation.RightThigh:return"Right Thigh";case z.SensorLocation.LeftShank:return"Left Lower Leg";case z.SensorLocation.RightShank:return"Right Lower Leg";case z.SensorLocation.LeftFoot:return"Left Foot";case z.SensorLocation.RightFoot:return"Right Foot";case z.SensorLocation.LeftUpperArm:return"Left Upper Arm";case z.SensorLocation.RightUpperArm:return"Right Upper Arm";case z.SensorLocation.LeftForearm:return"Left Forearm";case z.SensorLocation.RightForearm:return"Right Forearm";case z.SensorLocation.Head:return"Head"}},it=({id:o,onError:n,onCancel:i,onSave:g,hideButtons:m,setButtonOnClick:p,setButtonDisabled:j,quantumOwned:R,isView:r})=>{const a=ee.useClient(),[{fetching:C},b]=ee.useMutation(f.CREATE_ACTION),[{fetching:A},k]=ee.useMutation(f.UPDATE_ACTION),[{data:E}]=ee.useQuery({query:f.GET_ACTION_BY_ID,variables:{id:o??""},pause:!o}),T=s.useMemo(()=>{const y=I.getFragmentData(f.ACTION_FRAGMENT,E?.getActionById);if(!y)return null;const N=(I.getFragmentData(f.REPORT_FRAGMENT,y.reports)||[]).map(D=>({...D,thresholds:I.getFragmentData(f.THRESHOLD_FRAGMENT,D.thresholds)}));return{...y,thresholds:I.getFragmentData(f.THRESHOLD_FRAGMENT,y.thresholds),reports:N}},[E]),h=C||A,d=!!T&&!!o,{getLabel:F}=ae.useUiLabelContext(),x=s.useMemo(()=>({action:F("action")}),[F]),O=s.useMemo(()=>[{key:"module_category",label:"Link Category",multi:!0},{key:"activity_type",label:`${x.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},{key:"activity_motion_direction",label:"Activity Motion Direction",multi:!0}],[x.action]),[S,$]=s.useState(""),[L,_]=s.useState(""),[G,te]=s.useState(""),[P,ne]=s.useState(""),[X,w]=s.useState([]),[K,J]=s.useState({}),[q,Y]=s.useState(null),[c,l]=s.useState(""),[M,u]=s.useState([]),[v,W]=s.useState([]),[B,H]=s.useState(""),[Q,se]=s.useState([]),de=ae.useAllPartParameters(),xe=s.useMemo(()=>de.filter(y=>y.sensorOnly),[de]),me=[{label:je.reportKindName(z.ReportKind.GeneralActivity),value:z.ReportKind.GeneralActivity},{label:je.reportKindName(z.ReportKind.MovementCoordination),value:z.ReportKind.MovementCoordination},{label:je.reportKindName(z.ReportKind.Range),value:z.ReportKind.Range},{label:je.reportKindName(z.ReportKind.StabilityBalance),value:z.ReportKind.StabilityBalance},{label:je.reportKindName(z.ReportKind.PointOfInterest),value:z.ReportKind.PointOfInterest}],Ce=s.useMemo(()=>S.trim().length>0,[S]),[ye,Ae]=s.useState({});s.useEffect(()=>{const y=O.map(U=>a.query(f.GET_METADATA_BY_KEY,{key:U.key}));Promise.all(y).then(U=>{const N={};U.forEach(D=>{if(D.error||!D.data)return;const Z=I.getFragmentData(f.METADATA_GROUP_FRAGMENT,D.data.getMetadataByKey),V=I.getFragmentData(f.METADATA_ITEM_FRAGMENT,Z.data);N[Z.key]=V.map(re=>({label:re.label||re.value,value:re.value,id:re.id}))}),J(N)})},[a,O]),s.useEffect(()=>{if(T){const U=I.getFragmentData(f.METADATA_GROUP_FRAGMENT,T.metadataGroups).map(Z=>Z.data.map(V=>I.getFragmentData(f.METADATA_ITEM_FRAGMENT,V).id)),N=T.reports.map(Z=>({id:Z.id,name:Z.name??"",instructions:Z.instructions??"",kind:Z.reportKind,autoGenerate:Z.autoGenerate??!1,parameters:Z.thresholds.map(V=>({id:{[V.partKind]:V.partId},kind:V.kind,min:V.min,max:V.max,plane:V.partDimension,oldId:V.id,sensorOnly:xe.some(re=>{const Ie=re.id[V.partKind];return Ie?Ie===V.partId&&re.plane===V.partDimension:!1})})),sensorLocations:Z.sensorLocations})),D={name:T.name,description:T.description||"",cameraPlacement:T.cameraPlacement||"",videoLink:T.videoLink||"",metadataIds:U.flat(),reports:N};$(D.name),_(D.description),te(D.cameraPlacement),ne(D.videoLink),w(D.metadataIds),se(N),Ae(D)}},[T]);const Re=s.useMemo(()=>JSON.stringify(ye)!==JSON.stringify({name:S,description:L,cameraPlacement:G,videoLink:P,metadataIds:X,reports:Q}),[ye,S,L,G,P,X,Q]),pe=s.useCallback(()=>{const y={name:S,description:L,cameraPlacement:G,videoLink:P,metadataItemIds:X,laterality:z.ActionLaterality.Either,quantumOwned:R,sessionType:[],thresholds:[],reports:Q.map(N=>({id:N.isNew?void 0:N.id,name:N.name,reportKind:N.kind,sensorLocations:N.sensorLocations,instructions:N.instructions,autoGenerate:N.autoGenerate??!1,thresholds:N.parameters.map(D=>({id:D.oldId,kind:D.kind,min:D.min,max:D.max,partKind:"joint"in D.id?"joint":"segment",partId:"joint"in D.id?D.id.joint:D.id.segment,partDimension:D.plane}))}))};let U;d&&o?U=k({id:o,fields:y}):U=b({fields:y}),U.then(({error:N})=>{N?n(N):g()})},[R,b,k,o,S,L,G,P,X,Q,d,g,n]);s.useEffect(()=>{j&&j({cancelButton:h,saveButton:r?!0:h||!Ce||!Re})},[h,j,Ce,Re,r]),s.useEffect(()=>{p&&p({cancelButton:i,saveButton:r?()=>{}:pe})},[p,i,pe,r]);const le=s.useCallback(y=>{const U=ce.getSuggestedSensorLocations(y.map(N=>"joint"in N.id?N.id.joint:N.id.segment));W(U)},[]);s.useEffect(()=>{le(M)},[M,le]);const Ee=s.useCallback(()=>{if(!q||!c.trim())return;const y=q===z.ReportKind.PointOfInterest,U={id:Date.now().toString(),name:c.trim(),kind:q,parameters:y?[]:M,sensorLocations:y?[]:v,instructions:y?B:"",autoGenerate:!1,isNew:!0};se(N=>[...N,U]),Y(null),l(""),u([]),W([]),H("")},[q,c,M,v,B]),_e=s.useCallback(y=>{se(U=>U.filter(N=>N.id!==y))},[]),Ge=(y,U)=>{const N=O.find(Z=>Z.key===y);if(!N)return;const D=N.multi?(U??[]).map(Z=>Z.id):U?[U.id]:[];w(Z=>[...Z.filter(re=>Object.values(K).flat().find(Te=>Te.id===re)&&!Object.keys(K).find(Te=>K[Te]?.some(Pe=>Pe.id===re&&Te===y))),...D])};return e.jsxRuntimeExports.jsxs(t.VStack,{spacing:4,w:"full",align:"stretch",children:[e.jsxRuntimeExports.jsxs(t.Tabs,{children:[e.jsxRuntimeExports.jsxs(t.TabList,{children:[e.jsxRuntimeExports.jsx(t.Tab,{children:"Activity Configuration"}),e.jsxRuntimeExports.jsx(t.Tab,{children:"Reports Configuration"})]}),e.jsxRuntimeExports.jsxs(t.TabPanels,{children:[e.jsxRuntimeExports.jsx(t.TabPanel,{px:0,children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:S,onChange:y=>$(y.target.value),type:"text",placeholder:"i.e. Lunge & Return",isDisabled:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Camera Placement"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:G,onChange:y=>te(y.target.value),rows:2,placeholder:"(optional) Describe camera setup, placement, angles",isDisabled:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Video Link"}),e.jsxRuntimeExports.jsx(t.Input,{value:P,onChange:y=>ne(y.target.value),type:"url",placeholder:"(optional) https://...",isDisabled:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Description"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:L,onChange:y=>_(y.target.value),rows:2,placeholder:"(optional) Describe how to perform the test or exercise",isDisabled:r})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(oe,{children:"Metadata Tags"}),O.map(y=>e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:y.label}),e.jsxRuntimeExports.jsx(ie.st,{isMulti:y.multi,value:K[y.key]?.filter(U=>X.includes(U.id)),onChange:U=>{Ge(y.key,U)},options:K[y.key],placeholder:`Select ${y.multi?"one or more":"one"} ${y.label.toLowerCase()}`,isDisabled:r,isClearable:y.multi})]},y.key))]})]})}),e.jsxRuntimeExports.jsx(t.TabPanel,{px:0,children:e.jsxRuntimeExports.jsxs("div",{className:Me.cn("grid grid-cols-1 gap-6",!r&&"md:grid-cols-2"),children:[e.jsxRuntimeExports.jsxs("div",{className:Me.cn("space-y-4",r&&"hidden"),children:[e.jsxRuntimeExports.jsx(oe,{children:"Add New Report"}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Report Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:c,onChange:y=>l(y.target.value),maxLength:120,type:"text",placeholder:"Enter report name...",isDisabled:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Report Type"}),e.jsxRuntimeExports.jsx(ie.st,{value:q?me.find(y=>y.value===q):null,onChange:y=>{const U=y?.value||null;Y(U);const N=ke.forcedThresholdKindForReport(U);N&&u(D=>D.map(Z=>({...Z,kind:N})))},options:me,placeholder:"Select report type...",isDisabled:r,isClearable:!0})]}),q!==z.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(Fe,{options:de,value:M,onChange:u,forceKind:ke.forcedThresholdKindForReport(q),editOnly:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Sensor Locations"}),e.jsxRuntimeExports.jsx(t.Input,{value:v.map(y=>we(y)).join(", "),placeholder:"Auto-filled based on parameters...",isDisabled:!0})]})]}),q===z.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:B,onChange:y=>H(y.target.value),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:r})]}),e.jsxRuntimeExports.jsx("div",{className:"w-full flex justify-end",children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:Ee,isDisabled:!q||!c.trim()||r||me.length===0||q!==z.ReportKind.PointOfInterest&&M.length===0,children:"Add Report"})})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(oe,{children:"Configured Reports"}),Q.length===0?e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",children:"No reports created yet"}):e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:Q.map(y=>e.jsxRuntimeExports.jsxs("div",{className:"p-3 border border-gray-200 rounded-md bg-gray-50 flex flex-col gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.600",children:je.reportKindName(y.kind)}),!r&&e.jsxRuntimeExports.jsx(t.Button,{size:"xs",colorScheme:"red",variant:"ghost",onClick:()=>_e(y.id),children:"Remove"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Report Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:y.name,onChange:U=>se(N=>N.map(D=>D.id===y.id?{...D,name:U.target.value}:D)),placeholder:"Enter report name...",isDisabled:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{display:"flex",alignItems:"center",children:[e.jsxRuntimeExports.jsx(t.FormLabel,{htmlFor:`auto-generate-${y.id}`,mb:"0",children:"Auto Generate"}),e.jsxRuntimeExports.jsx(t.Switch,{id:`auto-generate-${y.id}`,isChecked:y.autoGenerate??!1,onChange:U=>se(N=>N.map(D=>D.id===y.id?{...D,autoGenerate:U.target.checked}:D)),isDisabled:r})]}),y.kind===z.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:y.instructions,onChange:U=>se(N=>N.map(D=>D.id===y.id?{...D,instructions:U.target.value}:D)),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:r})]}),y.kind!==z.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs("div",{className:"flex flex-col",children:[e.jsxRuntimeExports.jsx(oe,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(Fe,{options:de,forceKind:ke.forcedThresholdKindForReport(y.kind),value:y.parameters,onChange:U=>{const N=V=>"joint"in V.id?V.id.joint:V.id.segment,D=U.map(N),Z=ce.getSuggestedSensorLocations(D);se(V=>V.map(re=>re.id===y.id?{...re,parameters:U,sensorLocations:Z}:re))},editOnly:r})]}),y.kind!==z.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Sensors:"," ",y.sensorLocations.map(U=>we(U)).join(", ")]})]},y.id))})]})]})})]})]}),e.jsxRuntimeExports.jsx(t.HStack,{justify:"end",className:Me.cn((m||r)&&"!hidden"),children:e.jsxRuntimeExports.jsxs(t.ButtonGroup,{gap:4,children:[e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:h,onClick:i,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:h||!Ce||!Re,isLoading:h,onClick:pe,children:"Save changes"})]})})]})},oe=({children:o})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:o}),lt=({children:o,isView:n,metadataKeys:i})=>{const[g,m]=s.useState({}),p=ee.useClient();return s.useEffect(()=>{let j=!1;return(async()=>{const r=(i??[]).map(b=>p.query(f.GET_METADATA_BY_KEY,{key:b}).toPromise()),a=await Promise.all(r),C={};for(const b of a){if(b.error||!b.data?.getMetadataByKey)continue;const A=I.getFragmentData(f.METADATA_GROUP_FRAGMENT,b.data.getMetadataByKey);if(!A)continue;const k=I.getFragmentData(f.METADATA_ITEM_FRAGMENT,A.data)??[];C[A.key]=k.map(E=>({label:E.label||E.value,value:E.value,id:E.id}))}j||m(C)})(),()=>{j=!0}},[p,i]),e.jsxRuntimeExports.jsx(Ne.Provider,{value:{isView:n,metadataOptions:g},children:o})},ct=({id:o,onCancel:n,onSave:i,onError:g,hideButtons:m,quantumOwned:p,setButtonOnClick:j,setButtonDisabled:R,isView:r})=>{const[{data:a,fetching:C}]=ee.useQuery({query:p?f.GET_QUANTUM_OWNED_ACTIONS:f.GET_ACTIONS}),[{data:b}]=ee.useQuery({query:f.GET_MODULE_BY_ID,variables:{id:o},pause:!o}),[{data:A}]=ee.useQuery({query:f.GET_ALL_MODULE_CATEGORIES}),k=I.getFragmentData(f.MODULE_CATEGORY_FRAGMENT,A?.moduleCategories),[{fetching:E},T]=ee.useMutation(f.UPDATE_MODULE),[{fetching:h},d]=ee.useMutation(f.CREATE_MODULE),F=s.useMemo(()=>!a||C?[]:I.getFragmentData(f.ACTION_FRAGMENT,p?a?.quantumOwnedActions??[]:a?.actions??[]).filter(q=>!!q?.id),[a,p,C]),x=I.getFragmentData(f.ACTION_MODULE_FRAGMENT,b?.module),O=s.useMemo(()=>I.getFragmentData(f.MODULE_ACTION_FRAGMENT,x?.moduleActions)??[],[x?.moduleActions]),[S,$]=s.useState([]),[L,_]=s.useState(x?.name??""),[G,te]=s.useState([]),[P,ne]=s.useState(x?.description??""),[X,w]=s.useState([]);s.useEffect(()=>{if(x){const J=O.map((c,l)=>({key:c.id??`${c.actionId}-${l}`,actionId:c.actionId,reportId:c.reportId||null}));$(J),_(x.name),ne(x.description??""),te(x.categories.map(c=>I.getFragmentData(f.MODULE_CATEGORY_FRAGMENT,c).id)??[]);const Y=I.getFragmentData(f.METADATA_GROUP_FRAGMENT,x.metadataGroups).map(c=>c.data.map(l=>I.getFragmentData(f.METADATA_ITEM_FRAGMENT,l).id));w(Y.flat())}},[x,O]);const K=s.useCallback(()=>{let J;const q={moduleActions:S.map(Y=>({actionId:Y.actionId,reportId:Y.reportId??void 0})),name:L,categories:G,description:P,quantumOwned:p,metadataItemIds:X};x?J=T({id:x.id,input:q}):J=d({input:q}),J.then(({error:Y})=>{Y?g(Y instanceof Error?Y:new Error(String(Y))):i()})},[d,T,S,L,P,G,X,x,i,g,p]);return s.useEffect(()=>{R&&R({cancelButton:E||h,saveButton:E||h||!L||P.trim().split(/\s+/).filter(Boolean).length>40})},[R,E,h,S,L,P]),s.useEffect(()=>{j&&j({cancelButton:n,saveButton:K})},[j,n,K]),e.jsxRuntimeExports.jsx(t.Box,{width:"100%",children:e.jsxRuntimeExports.jsxs(lt,{isView:r,metadataKeys:["activity_type","session_type","body_region","sport"],children:[e.jsxRuntimeExports.jsx(De,{name:L,setName:_,actions:F,moduleActionEntries:S,setModuleActionEntries:$,availableCategories:k??[],selectedCategoryIds:G,setSelectedCategoryIds:te,description:P,setDescription:ne,selectedMetadataIds:X,setSelectedMetadataIds:w}),!m&&!r&&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||h,onClick:n,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:E||h||!L||P.trim().split(/\s+/).filter(Boolean).length>40,isLoading:E||h,onClick:K,children:"Save"})]})})]})})};exports.ActivityList=Le;exports.CopyActivityForm=Xe;exports.CopyModuleForm=Ze;exports.ModuleForm=De;exports.ParameterEditList=Oe;exports.ParameterEditSelect=Fe;exports.UpsertActivityForm=it;exports.UpsertModuleForm=ct;
|