quantum-component-library 1.4.69 → 1.4.70
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.cjs +1 -1
- package/dist/components.js +450 -443
- 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 +584 -6
- package/dist/generated-graphql.cjs +1 -1
- package/dist/generated-graphql.js +82 -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-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/services-human-DFPelsei.cjs +0 -1
- package/dist/utils-parameters-dwKmz1VU.cjs +0 -1
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"),k=require("./generated.cjs"),E=require("./graphql-BEhru2G1.cjs"),ve=require("./utils-cn-FIKrq5Mb.cjs"),he=require("./types.cjs");require("./lodash-vendor-CGEP7jch.cjs");const ee=require("urql"),ie=require("./hooks.cjs"),Be=require("./ufuzzy-vendor-7qHa_k39.cjs"),ae=require("./react-select-vendor-Dletsq31.cjs"),ge=require("./react-icons-vendor-c4NUuwCE.cjs"),je=require("./services.cjs"),Me=require("./react-dnd-vendor-CPQdLxxA.cjs"),ce=require("./services-human-Cl36G8mV.cjs"),U=require("./generated-graphql.cjs"),Fe=require("./utils-parameters-Bx16_6xw.cjs"),$e=({setSearch:r,actions:n,updateUseCases:a,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:ge.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(ae.st,{size:"md",chakraStyles:{container:j=>({...j,width:"100%"})},menuPortalTarget:document.body,placeholder:"Filter use case",isMulti:!0,options:p,onChange:j=>a(j.map(x=>x.value))})})]})},ue=({children:r})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:r}),Ue=({items:r,onChange:n,selectedItem:a,isDisabled:h,selectedProps:p,buttonProps:j})=>{const x=o=>o===a||o.value===a,g=o=>x(o)?{...j,...p}:j;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:h,children:r.map((o,i)=>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,i),isDisabled:o.disabled,...g(o),children:o.label})},i))})},Te=(r,n)=>n<0?-1*Math.abs(r):Math.abs(r),ze=({isReversed:r,min:n,max:a,value:h,onChange:p,inputProps:j,size:x,zeroMarker:g,formatValue:o,valueLabel:i,positiveNegativeLabels:m,isDisabled:y,...C})=>{const[v,M]=s.useState([void 0,void 0]),I=v[0],f=v[1],d=g&&n<-5&&a>5,F=Number(h?.[0]??f??n)>0?1:-1,R=Number(h?.[1]??f??a)<0?-1:1,N=m?.[0]===m?.[1],T=h?.[0],$=h?.[1];s.useEffect(()=>{T!==void 0&&$!==void 0&&M([T.toFixed(0),$.toFixed(0)])},[T,$,M]);const D=s.useCallback(([L,q])=>{L<q&&M([L.toFixed(0),q.toFixed(0)])},[M]),w=s.useCallback(([L,q])=>{L<q&&p([L,q])},[p]),H=s.useCallback(()=>{M(([L,q])=>{const J=isNaN(Number(L))?n:Number(L),z=isNaN(Number(q))?a:Number(q),Y=Te(Number(J),F),c=Te(Number(z),R),l=F<0?Math.max(Y,n):Math.min(Y,a),S=R<0?Math.max(c,n):Math.min(c,a);return l>S?(p([S,l]),[S.toFixed(0),l.toFixed(0)]):(p([l,S]),[l.toFixed(0),S.toFixed(0)])})},[p,M,F,R,n,a]),te=s.useCallback(L=>{const q=L===""||isNaN(Number(L))?L:Te(Number(L),F);M(([J,z])=>[q.toString(),z])},[M,F]),G=s.useCallback(L=>{const q=L===""||isNaN(Number(L))?L:Te(Number(L),R);M(([J,z])=>[J,q.toString()])},[M,R]),ne=s.useMemo(()=>x==="xs"?"0.75rem":void 0,[x]),V=s.useCallback((L,q)=>{const J=Number(q.target.value);if(!I||!f||![-1,1].includes(J))return;const z=l=>J<0?-1*Math.abs(l):Math.abs(l),Y=L?z(Number(I)):Number(I),c=L?Number(f):z(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??a)],max:a,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:a,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:x??"sm",fontWeight:"semibold",style:{transform:"translateX(-100%)"},whiteSpace:"nowrap",children:o?o(a):a})}),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})]})}),i&&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:i(n)}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:x??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:i(a)})]}),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:F,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:F<0?Math.abs(n):$??a,value:I===""?"":Math.abs(Number(I??n)),onChange:te,onBlur:H,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):a,precision:0,value:f===""?"":Math.abs(Number(f??a)),onChange:G,onBlur:H,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]})]})]})]})},qe=({tags:r,containerProps:n,...a})=>e.jsxRuntimeExports.jsx(t.HStack,{...n,children:r.map((h,p)=>e.jsxRuntimeExports.jsx(t.Tag,{...a,children:h},p))}),Ke=new Be.uFuzzy({}),We=({action:r,quantumIconSrc:n})=>{const{getLabel:a}=ie.useUiLabelContext(),h=s.useMemo(()=>({actionLowerCase:a("action").toLocaleLowerCase()}),[a]);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 a=r.map(p=>p.name??"");return Ke.filter(a,n)?.map(p=>r[p])??[]},Qe=r=>!r||r.length===0?"None":r.map(n=>he.sensorLocationName(n)).join(", "),Ye=(r,n)=>!n||n.length==0?r:r.filter(a=>a.useCases?.some(h=>n.includes(h.id))??!1),Je=(r,n,a)=>!n||n.length===0?r:r.filter(h=>{const p={};return n.forEach(j=>{for(const[x,g]of Object.entries(a||{}))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=>k.getFragmentData(E.METADATA_GROUP_FRAGMENT,y).key===j);if(!g)return!1;const o=k.getFragmentData(E.METADATA_GROUP_FRAGMENT,g),m=k.getFragmentData(E.METADATA_ITEM_FRAGMENT,o.data).map(y=>y.id);return x.some(y=>m.includes(y))})}),Le=({actions:r,totalActions:n,onCreate:a,onDelete:h,onEdit:p,onView:j,onSelected:x,onDuplicate:g,disableMultiSelect:o,disableDelete:i,disableEdit:m,disableCreate:y,hideUseCase:C=!0,showMetadataFilters:v=!0,tableProps:M,containerProps:I,quantumIconSrc:f="/favicon.ico",allowDuplicateSelection:d=!1,getSelectedCount:F})=>{const[R,N]=s.useState(""),[T,$]=s.useState(),[D,w]=s.useState([]),[H,te]=s.useState({}),{getLabel:G}=ie.useUiLabelContext(),ne=ee.useClient(),V=s.useMemo(()=>({action:G("action"),actionPlural:G("action_plural"),actionLowerCase:G("action").toLocaleLowerCase(),actionPluralLowerCase:G("action_plural").toLocaleLowerCase()}),[G]),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 K={};A.forEach(P=>{if(P.error||!P.data)return;const W=k.getFragmentData(E.METADATA_GROUP_FRAGMENT,P.data.getMetadataByKey),Q=k.getFragmentData(E.METADATA_ITEM_FRAGMENT,W.data);K[W.key]=Q.map(se=>({label:se.label||se.value,value:se.value,id:se.id}))}),te(K)})},[ne,L,v]);const q=s.useMemo(()=>{if(!r)return;const u=He(r,R),A=C?u:Ye(u,T);return v?Je(A,D,H):A},[r,R,T,C,v,D,H]),J=s.useCallback(()=>{if(!h)return;const A=r.filter(K=>K.selected&&!K.quantumOwned).map(K=>K.id);h(A)},[r,h]),z=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 K=L.find(W=>W.key===u);if(!K)return;const P=K.multi?(A??[]).map(W=>W.id):A?[A.id]:[];w(W=>[...W.filter(se=>Object.values(H).flat().find(xe=>xe.id===se)&&!Object.keys(H).find(xe=>H[xe]?.some(me=>me.id===se&&xe===u))),...P])},[L,H]);return e.jsxRuntimeExports.jsxs(t.Box,{...I,children:[e.jsxRuntimeExports.jsxs(t.Flex,{alignContent:"space-between",gap:4,children:[(a||h||g)&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mb:"1rem",gap:4,children:[a&&e.jsxRuntimeExports.jsxs(t.Button,{isDisabled:!a||y,colorScheme:"blackAlpha",backgroundColor:"gray.700",onClick:a,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||i,onClick:J,children:"Delete Selected"})}),g&&!o&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!c,onClick:z,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx($e,{setSearch:N,actions:r,updateUseCases:$,hideUseCaseFilter:C})]}),v&&H&&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(ae.st,{chakraStyles:{menu:A=>({...A,zIndex:2})},isMulti:u.multi,value:H[u.key]?.filter(A=>D.includes(A.id)),onChange:A=>{S(u.key,A)},options:H[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 ",q?.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:q?.map(u=>{const A=d?F?.(u.id)??0:0,K=d?A>0:!!u.selected;return e.jsxRuntimeExports.jsxs(t.Tr,{className:ve.cn("hover:bg-[#f7f7f7]",!o&&!d&&"cursor-pointer",K&&"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:P=>P.stopPropagation(),children:[e.jsxRuntimeExports.jsx(t.IconButton,{"aria-label":"Remove one instance",icon:e.jsxRuntimeExports.jsx(ge.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(ge.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(ge.FaCheckSquare,{className:"text-blue-500"}):e.jsxRuntimeExports.jsx(ge.FaSquare,{className:"text-gray-400"})}),(u.quantumOwned||!p)&&j&&e.jsxRuntimeExports.jsx(t.Button,{ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:P=>{P.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:P=>{P.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:Qe(u.sensorLocations)}),!C&&e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:e.jsxRuntimeExports.jsx(qe,{containerProps:{flexWrap:"wrap"},tags:u.useCases?.map(P=>P.name)??[]})})]},u.id)})})]})})]})},Ve=({onSave:r,onCancel:n,onError:a,hideButtons:h=!1,setButtonDisabled:p,setButtonOnClick:j,quantumOwned:x})=>{const g=t.useToast(),{getLabel:o}=ie.useUiLabelContext(),i=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),[F]=ee.useQuery({query:E.GET_GROUPS}),[R]=ee.useQuery({query:E.GET_ACTIONS_BY_GROUP,variables:{groupId:C},pause:!C}),[,N]=ee.useMutation(E.CREATE_ACTION),[,T]=ee.useMutation(E.CONVERT_ACTION_TO_QUANTUM_OWNED),$=s.useMemo(()=>F.data?.groups?F.data.groups.map(c=>k.getFragmentData(E.GROUP_FRAGMENT,c)):[],[F.data]),D=s.useMemo(()=>R.data?R.data.actions.map(l=>{const S=k.getFragmentData(E.ACTION_FRAGMENT,l),u=k.getFragmentData(E.REPORT_FRAGMENT,S.reports),A=k.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,S.categories),P=k.getFragmentData(E.METADATA_GROUP_FRAGMENT,S.metadataGroups).map(W=>({...W,data:W.data.map(Q=>k.getFragmentData(E.METADATA_ITEM_FRAGMENT,Q))}));return{...S,thresholds:k.getFragmentData(E.THRESHOLD_FRAGMENT,S.thresholds),reports:u.map(W=>({...W,thresholds:k.getFragmentData(E.THRESHOLD_FRAGMENT,W.thresholds)})),categories:A,metadataGroups:P}}):[],[R.data]),w=s.useMemo(()=>D.filter(c=>M.includes(c.id)),[D,M]),H=s.useCallback(c=>{const l=c?.value||"";v(l),I([])},[]),te=s.useCallback(c=>{const l=c.map(S=>S.value);I(l)},[]),G=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 k.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 k.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 ${i.pluralLowerCase} selected for ${m==="copy"?"copying":"converting"}`);a?.(c),d(!1);return}try{const c=[];let l=0;const S=m==="copy"?G:ne,u=m==="copy"?"copy":"convert";for(const A of w)try{const K=await S(A);c.push(K)}catch(K){console.error(`Failed to ${u} ${i.singularLowerCase} "${A.name}":`,K),l++}if(c.length>0){const A=c.length,K=w.length,P=m==="copy"?"copied":"converted",W=m==="copy"?"copy":"convert";g({title:l>0?`Partial ${W} completed`:`${i.plural} ${P} successfully`,description:l>0?`${A} of ${K} ${i.pluralLowerCase} ${P} successfully`:`${A} ${A>1?i.pluralLowerCase:i.singularLowerCase} ${P} successfully`,status:l>0?"warning":"success",duration:3e3,isClosable:!0}),r?.(),v(""),I([])}else throw new Error(`Failed to ${u} any ${i.pluralLowerCase}`)}catch(c){const l=m==="copy"?"copy":"convert",S=c instanceof Error?c.message:`Failed to ${l} ${i.pluralLowerCase}`;g({title:`${m==="copy"?"Copy":"Convert"} failed`,description:S,status:"error",duration:5e3,isClosable:!0}),a?.(c instanceof Error?c:new Error(S))}finally{d(!1)}},[w,m,G,ne,g,r,a,i]),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 q=s.useMemo(()=>$.map(c=>({value:c.id,label:c.name})),[$]),J=s.useMemo(()=>D.filter(c=>m==="copy"?!0:!c.quantumOwned).map(c=>({value:c.id,label:c.name,isQuantumOwned:c.quantumOwned})),[D,m]),z=F.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 ",i.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",i.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 ",i.singular]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Convert existing"," ",i.plural.toLocaleLowerCase()," to quantum-owned"]})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(ae.st,{placeholder:"Choose a group...",options:q,value:q.find(c=>c.value===C)||null,onChange:H,isLoading:z,isDisabled:z,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]})]})]}),C&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsxs(ue,{children:["Select ",i.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 ",i.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(ae.st,{placeholder:`Choose ${i.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 ",i.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 ",i.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?`${i.singular} to ${m==="copy"?"Copy":"Convert"}:`:`${w.length} ${i.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," ",i.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?i.singular:`${w.length} ${i.plural}`]})]})]})})},Xe=({onSave:r,onCancel:n,onError:a,hideButtons:h=!1,setButtonDisabled:p,setButtonOnClick:j,quantumOwned:x})=>{const g=t.useToast(),{getLabel:o}=ie.useUiLabelContext(),i=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,F]=s.useState("copy"),[R]=ee.useQuery({query:E.GET_GROUPS}),[N]=ee.useQuery({query:E.GET_MODULES_BY_GROUP,variables:{groupId:y},pause:!y}),[,T]=ee.useMutation(E.CREATE_MODULE),[,$]=ee.useMutation(E.UPDATE_MODULE),[,D]=ee.useMutation(E.CREATE_ACTION),[,w]=ee.useMutation(E.CONVERT_ACTION_TO_QUANTUM_OWNED),H=s.useMemo(()=>R.data?.groups?R.data.groups.map(l=>k.getFragmentData(E.GROUP_FRAGMENT,l)):[],[R.data]),te=s.useMemo(()=>N.data?.modules?k.getFragmentData(E.ACTION_MODULE_FRAGMENT,N.data?.modules).map(S=>{const u=k.getFragmentData(E.MODULE_ACTION_FRAGMENT,S.moduleActions),K=k.getFragmentData(E.METADATA_GROUP_FRAGMENT,S.metadataGroups).map(P=>k.getFragmentData(E.METADATA_ITEM_FRAGMENT,P.data)).flat();return{...S,moduleActions:u.map(P=>({...P,action:k.getFragmentData(E.ACTION_FRAGMENT,P.action)})),categories:k.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,S.categories),metadataItems:K}}):[],[N.data]),G=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),!G.length){f(!1);const l=new Error(`No modules selected for ${d==="convert"?"converting":"copying"}`);a?.(l);return}try{const l=[];let S=0;for(const u of G)try{let A=u.moduleActions.map(K=>K.actionId);if(x){const K=u.moduleActions.map(Q=>Q.action),P=async Q=>{if(d==="copy"){if(Q.quantumOwned)return Q;const de=k.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,Q.categories),me=k.getFragmentData(E.METADATA_GROUP_FRAGMENT,Q.metadataGroups).map(le=>k.getFragmentData(E.METADATA_ITEM_FRAGMENT,le.data).map(Ee=>Ee.id)).flat(),Ce=k.getFragmentData(E.REPORT_FRAGMENT,Q.reports).map(le=>({...le,id:void 0,thresholds:k.getFragmentData(E.THRESHOLD_FRAGMENT,le.thresholds).map(Ee=>({...Ee,id:void 0}))})),Ae=k.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:k.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:k.getFragmentData(E.ACTION_FRAGMENT,se.data.convertActionToQuantumOwned)};A=(await Promise.all(K.map(P))).filter(Q=>!!Q?.id).map(Q=>Q.id)}if(d==="convert"){const K={name:u.name,description:u.description||void 0,actions:A,categories:u.categories.map(W=>W.id),quantumOwned:!0},P=await $({id:u.id,input:K});if(P.error)throw new Error(P.error.message);if(P.data?.updateModule){const W=k.getFragmentData(E.ACTION_MODULE_FRAGMENT,P.data.updateModule);l.push(W)}}else{const K={name:`${u.name} (Copy)`,description:u.description||void 0,moduleActions:u.moduleActions.map(W=>({actionId:W.actionId,reportId:W.reportId??void 0})),categories:u.categories.map(W=>W.id),quantumOwned:x,metadataItemIds:u.metadataItems.map(W=>W.id)},P=await T({input:K});if(P.error)throw new Error(P.error.message);if(P.data?.createModule){const W=k.getFragmentData(E.ACTION_MODULE_FRAGMENT,P.data.createModule);l.push(W)}}}catch(A){console.error(`Failed to ${d==="convert"?"convert":"copy"} module "${u.name}":`,A),S++}if(l.length>0){const u=l.length,A=G.length;g({title:S>0?`Partial ${d==="convert"?"convert":"copy"} completed`:`${i.plural} ${d==="convert"?"converted":"copied"} successfully`,description:S>0?`${u} of ${A} ${i.plural} ${d==="convert"?"converted":"copied"} successfully`:`${u} ${u>1?i.plural:i.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}),a?.(l instanceof Error?l:new Error(S))}finally{f(!1)}},[G,T,$,g,r,a,x,D,w,d,i]),q=s.useCallback(()=>{C(""),M([]),F("copy"),n?.()},[n]);s.useEffect(()=>{p&&p({cancelButton:!1,saveButton:G.length===0||I})},[G.length,I,p]),s.useEffect(()=>{j&&j({cancelButton:q,saveButton:L})},[j,q,L]);const J=s.useMemo(()=>H.map(l=>({value:l.id,label:l.name})),[H]),z=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=>{F(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 ",i.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",i.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 ",i.pluralLowerCase," to quantum-owned"]})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(ae.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 ${i.plural} to Convert`:`Select ${i.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 ",i.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(ae.st,{placeholder:d==="convert"?`Choose ${i.pluralLowerCase} to convert...`:`Choose ${i.pluralLowerCase} to copy...`,options:z,value:z.filter(l=>v.includes(l.value)),onChange:V,isDisabled:z.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"})]})}),z.length===0&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:["No ",i.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 ",i.pluralLowerCase,":"," ",N.error.message]})]})]}),G.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:G.length===1?`${i.singular} to ${d==="copy"?"Copy":"Convert"}`:`${G.length} ${i.plural} to ${d==="copy"?"Copy":"Convert"}`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[G.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)),G.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: ",G.length," ",i.pluralLowerCase," will be"," ",d==="copy"?"copied":"converted"]})}),x&&G.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 ${i.plural} will convert non QM-Owned ${m.plural} to QM-Owned ${m.plural}`:`Copying ${i.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:q,isDisabled:I,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:d==="copy"?"blue":"green",onClick:L,isDisabled:G.length===0||I,isLoading:I,loadingText:`${d==="copy"?"Copying":"Converting"}...`,children:[d==="copy"?"Copy":"Convert"," ",G.length===1?i.singular:`${G.length} ${i.plural}`]})]})]})})},Ne=s.createContext(void 0),fe=()=>{const r=s.useContext(Ne);if(!r)throw new Error("useUpsertModuleFormContext must be used within a UpsertModuleFormProvider");return r},De=({name:r,setName:n,actions:a,moduleActionEntries:h,setModuleActionEntries:p,availableCategories:j,selectedCategoryIds:x,setSelectedCategoryIds:g,description:o,setDescription:i,selectedMetadataIds:m,setSelectedMetadataIds:y,...C})=>{const v=t.useDisclosure(),M=s.useMemo(()=>{const T={};return h.forEach($=>{T[$.actionId]=(T[$.actionId]??0)+1}),T},[h]),I=s.useCallback(T=>M[T]??0,[M]),f=s.useMemo(()=>a.map(T=>({...T,selected:(M[T.id]??0)>0})),[a,M]),d=s.useMemo(()=>a.reduce((T,$)=>(T[$.id]=$,T),{}),[a]),F=s.useCallback((T,$)=>{if($){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 H=[...D];return H.splice(w,1),H}return D})},[p]),R=s.useCallback(T=>{n(T.target.value)},[n]),N=s.useCallback(T=>{i?.(T.target.value)},[i]);return e.jsxRuntimeExports.jsxs(t.Box,{...C,children:[e.jsxRuntimeExports.jsxs(t.HStack,{gap:"2rem",children:[e.jsxRuntimeExports.jsx(Ze,{name:r??"",onInputChange:R}),e.jsxRuntimeExports.jsx(et,{availableCategories:j,value:x,onChange:g})]}),e.jsxRuntimeExports.jsx(tt,{description:o??"",onInputChange:N}),e.jsxRuntimeExports.jsx(rt,{selectedMetadataIds:m,setSelectedMetadataIds:y}),e.jsxRuntimeExports.jsx(st,{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(Le,{actions:f,onSelected:F,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"})})]})]})]})},Ze=s.memo(({name:r,onInputChange:n})=>{const{getLabel:a}=ie.useUiLabelContext(),h=a("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})]})}),et=s.memo(({availableCategories:r,value:n,onChange:a})=>{const{getLabel:h}=ie.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(ae.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=>a(g?[g.value]:[]),placeholder:"Select category"})]})}),tt=s.memo(({description:r,onInputChange:n})=>{const{getLabel:a}=ie.useUiLabelContext(),h=a("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})]})}),st=s.memo(({moduleActionEntries:r,setModuleActionEntries:n,actionsById:a,onAdjustActivities:h})=>{const{getLabel:p}=ie.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 i=a[o.actionId];return i?{key:o.key,actionId:o.actionId,name:i.name,reports:k.getFragmentData(E.REPORT_FRAGMENT,i.reports)||[],selectedReportId:o.reportId}:null}).filter(Boolean),[r,a]);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(nt,{value:g,onChange:o=>{n(i=>{const m=i.map(C=>{const v=a[C.actionId];return v?{key:C.key,actionId:C.actionId,name:v.name,reports:k.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})]})}),nt=s.memo(({value:r,onChange:n,disabled:a,setModuleActionEntries:h})=>{const[p]=s.useState(()=>Math.random().toString(36).substring(2,15)),j=s.useCallback((o,i)=>{a||n(m=>{const y=[...m],[C]=y.splice(o,1);return y.splice(i,0,C),y})},[n,a]),x=s.useCallback(o=>{h(i=>{const m=i.findIndex(M=>M.key===o);if(m===-1)return i;const y=i[m],C={key:crypto.randomUUID(),actionId:y.actionId,reportId:null},v=[...i];return v.splice(m+1,0,C),v})},[h]),g=s.useCallback(o=>{h(i=>i.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,i)=>e.jsxRuntimeExports.jsx(ot,{listKey:p,item:o,index:i,disabled:!!a,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))})})})}),ot=s.memo(({listKey:r,item:n,index:a,disabled:h,move:p,onReportChange:j,onDuplicate:x,onRemove:g})=>{const o=s.useRef(null),{getLabel:i}=ie.useUiLabelContext(),m=i("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,$=a;if(T===$)return;const D=o.current?.getBoundingClientRect(),w=(D.bottom-D.top)/2,te=N.getClientOffset().y-D.top;T<$&&te<w||T>$&&te>w||(p(T,$),R.index=$)}}),[{isDragging:v},M]=Me.useDrag({type:r,item:()=>({id:n.key,index:a}),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,F=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:F},"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:[a+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(ae.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"})]})]})]})})}),rt=s.memo(({selectedMetadataIds:r,setSelectedMetadataIds:n})=>{const{getLabel:a}=ie.useUiLabelContext(),{isView:h,metadataOptions:p}=fe(),j=s.useMemo(()=>[{key:"activity_type",label:`${a("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}],[a]),x=s.useCallback((g,o)=>{const i=j.find(y=>y.key===g);if(!i)return;const m=i.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(ae.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}),Oe=({value:r,onChange:n,forceKind:a,disableRemove:h,disableKind:p,isDisabled:j,lockRanges:x,...g})=>{const o=s.useMemo(()=>[...r].sort((C,v)=>{const M=he.availablePlanes.indexOf(C.plane),I=he.availablePlanes.indexOf(v.plane);return M-I}),[r]),i=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];a&&(v={...v,kind:a}),I[M]=v,x&&(I=I.map(f=>({...f,min:v.min,max:v.max}))),n(I)},[n,o,a,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(it,{label:i(C),parameter:C,onChange:M=>m(v,M),onRemove:h||j?void 0:()=>y(C),forceKind:a,disableKind:p||j,isDisabled:j},`${JSON.stringify(C.id)}-${C.plane}`))})},it=({label:r,parameter:n,onChange:a,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:i}="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:ge.FaTrash}),onClick:h}),!p&&e.jsxRuntimeExports.jsx(Ue,{selectedItem:n?.kind??U.ThresholdKind.Limit,onChange:({value:m})=>a({...n,kind:m}),isDisabled:j||x,buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:U.ThresholdKind.Limit,label:"limit"},{value:U.ThresholdKind.Target,label:"target"}]})]}),e.jsxRuntimeExports.jsx(ze,{w:"100%",size:"xs",min:o,max:i,zeroMarker:!0,value:[n.min,n.max],onChange:m=>a({...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:a,forceKind:h,singleValue:p,singleValueSideless:j,editOnly:x,disableKind:g,maxParameters:o,...i})=>{const m=j?2:o,y=s.useMemo(()=>{const f=new Map;return r.forEach(d=>{const F="joint"in d.id;let R,N;if(F?(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=F?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),$=[R,F?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:$})}),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(F=>he.getAnalysisPartIdNoSide(F.value)===he.getAnalysisPartIdNoSide(f.id)&&F.plane===f.plane)})).filter(d=>d.options.length>0)},[y,n,j]),v=s.useMemo(()=>y.flatMap(d=>d.options).filter(d=>n.some(F=>Se(F.id,d.value)&&F.plane===d.plane)),[y,n]),M=s.useCallback((f,d)=>{if(!d)return!0;const F=d.toLowerCase().replace(/\s+|_/g,""),R=f.data;return!R||!R.searchTokens?!1:R.searchTokens.some(N=>N.includes(F))},[]),I=s.useCallback(f=>{const d=f.map(F=>{const R=n.find(w=>Se(w.id,F.value)&&w.plane===F.plane),N=r.find(w=>Se(w.id,F.value)&&w.plane===F.plane),T=j?n.find(w=>he.getAnalysisPartIdNoSide(w.id)===he.getAnalysisPartIdNoSide(F.value)&&w.plane===F.plane):void 0,$=T&&!R?T.min:N&&N.min?N.min:0,D=T&&!R?T.max:N&&N.max?N.max:0;return R??{id:F.value,plane:F.plane,min:$,max:D,sensorOnly:F.sensorOnly,kind:h??U.ThresholdKind.Limit}});a(d)},[a,n,r,h,j]);return s.useEffect(()=>{const f=n.filter(d=>r.some(F=>Se(F.id,d.id)&&F.plane===d.plane));f.length!==n.length&&a(f)},[r,a,n]),e.jsxRuntimeExports.jsxs(t.Box,{...i,children:[e.jsxRuntimeExports.jsx(ae.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(Oe,{marginTop:2,maxH:"28rem",value:n,onChange:a,forceKind:h,disableKind:g,isDisabled:x,lockRanges:j})]})},we=r=>{switch(r){case U.SensorLocation.Thorax:return"Thorax";case U.SensorLocation.CenterBack:return"Center Back";case U.SensorLocation.Pelvis:return"Pelvis";case U.SensorLocation.LeftThigh:return"Left Thigh";case U.SensorLocation.RightThigh:return"Right Thigh";case U.SensorLocation.LeftShank:return"Left Lower Leg";case U.SensorLocation.RightShank:return"Right Lower Leg";case U.SensorLocation.LeftFoot:return"Left Foot";case U.SensorLocation.RightFoot:return"Right Foot";case U.SensorLocation.LeftUpperArm:return"Left Upper Arm";case U.SensorLocation.RightUpperArm:return"Right Upper Arm";case U.SensorLocation.LeftForearm:return"Left Forearm";case U.SensorLocation.RightForearm:return"Right Forearm";case U.SensorLocation.Head:return"Head"}},at=({id:r,onError:n,onCancel:a,onSave:h,hideButtons:p,setButtonOnClick:j,setButtonDisabled:x,quantumOwned:g,isView:o})=>{const i=ee.useClient(),[{fetching:m},y]=ee.useMutation(E.CREATE_ACTION),[{fetching:C},v]=ee.useMutation(E.UPDATE_ACTION),[{data:M}]=ee.useQuery({query:E.GET_ACTION_BY_ID,variables:{id:r??""},pause:!r}),I=s.useMemo(()=>{const b=k.getFragmentData(E.ACTION_FRAGMENT,M?.getActionById);if(!b)return null;const O=(k.getFragmentData(E.REPORT_FRAGMENT,b.reports)||[]).map(_=>({..._,thresholds:k.getFragmentData(E.THRESHOLD_FRAGMENT,_.thresholds)}));return{...b,thresholds:k.getFragmentData(E.THRESHOLD_FRAGMENT,b.thresholds),reports:O}},[M]),f=m||C,d=!!I&&!!r,{getLabel:F}=ie.useUiLabelContext(),R=s.useMemo(()=>({action:F("action")}),[F]),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,$]=s.useState(""),[D,w]=s.useState(""),[H,te]=s.useState(""),[G,ne]=s.useState(""),[V,L]=s.useState([]),[q,J]=s.useState({}),[z,Y]=s.useState(null),[c,l]=s.useState(""),[S,u]=s.useState([]),[A,K]=s.useState([]),[P,W]=s.useState(""),[Q,se]=s.useState([]),de=ie.useAllPartParameters(),xe=s.useMemo(()=>de.filter(b=>b.sensorOnly),[de]),me=[{label:je.reportKindName(U.ReportKind.GeneralActivity),value:U.ReportKind.GeneralActivity},{label:je.reportKindName(U.ReportKind.MovementCoordination),value:U.ReportKind.MovementCoordination},{label:je.reportKindName(U.ReportKind.Range),value:U.ReportKind.Range},{label:je.reportKindName(U.ReportKind.StabilityBalance),value:U.ReportKind.StabilityBalance},{label:je.reportKindName(U.ReportKind.PointOfInterest),value:U.ReportKind.PointOfInterest}],be=s.useMemo(()=>T.trim().length>0,[T]),[Ce,Ae]=s.useState({});s.useEffect(()=>{const b=N.map(B=>i.query(E.GET_METADATA_BY_KEY,{key:B.key}));Promise.all(b).then(B=>{const O={};B.forEach(_=>{if(_.error||!_.data)return;const X=k.getFragmentData(E.METADATA_GROUP_FRAGMENT,_.data.getMetadataByKey),Z=k.getFragmentData(E.METADATA_ITEM_FRAGMENT,X.data);O[X.key]=Z.map(re=>({label:re.label||re.value,value:re.value,id:re.id}))}),J(O)})},[i,N]),s.useEffect(()=>{if(I){const B=k.getFragmentData(E.METADATA_GROUP_FRAGMENT,I.metadataGroups).map(X=>X.data.map(Z=>k.getFragmentData(E.METADATA_ITEM_FRAGMENT,Z).id)),O=I.reports.map(X=>({id:X.id,name:X.name??"",instructions:X.instructions??"",kind:X.reportKind,autoGenerate:X.autoGenerate??!1,parameters:X.thresholds.map(Z=>({id:{[Z.partKind]:Z.partId},kind:Z.kind,min:Z.min,max:Z.max,plane:Z.partDimension,oldId:Z.id,sensorOnly:xe.some(re=>{const Ie=re.id[Z.partKind];return Ie?Ie===Z.partId&&re.plane===Z.partDimension:!1})})),sensorLocations:X.sensorLocations})),_={name:I.name,description:I.description||"",cameraPlacement:I.cameraPlacement||"",videoLink:I.videoLink||"",metadataIds:B.flat(),reports:O};$(_.name),w(_.description),te(_.cameraPlacement),ne(_.videoLink),L(_.metadataIds),se(O),Ae(_)}},[I]);const Re=s.useMemo(()=>JSON.stringify(Ce)!==JSON.stringify({name:T,description:D,cameraPlacement:H,videoLink:G,metadataIds:V,reports:Q}),[Ce,T,D,H,G,V,Q]),pe=s.useCallback(()=>{const b={name:T,description:D,cameraPlacement:H,videoLink:G,metadataItemIds:V,laterality:U.ActionLaterality.Either,quantumOwned:g,sessionType:[],thresholds:[],reports:Q.map(O=>({id:O.isNew?void 0:O.id,name:O.name,reportKind:O.kind,sensorLocations:O.sensorLocations,instructions:O.instructions,autoGenerate:O.autoGenerate??!1,thresholds:O.parameters.map(_=>({id:_.oldId,kind:_.kind,min:_.min,max:_.max,partKind:"joint"in _.id?"joint":"segment",partId:"joint"in _.id?_.id.joint:_.id.segment,partDimension:_.plane}))}))};let B;d&&r?B=v({id:r,fields:b}):B=y({fields:b}),B.then(({error:O})=>{O?n(O):h()})},[g,y,v,r,T,D,H,G,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:a,saveButton:o?()=>{}:pe})},[j,a,pe,o]);const le=s.useCallback(b=>{const B=ce.getSuggestedSensorLocations(b.map(O=>"joint"in O.id?O.id.joint:O.id.segment));K(B)},[]);s.useEffect(()=>{le(S)},[S,le]);const Ee=s.useCallback(()=>{if(!z||!c.trim())return;const b=z===U.ReportKind.PointOfInterest,B={id:Date.now().toString(),name:c.trim(),kind:z,parameters:b?[]:S,sensorLocations:b?[]:A,instructions:b?P:"",autoGenerate:!1,isNew:!0};se(O=>[...O,B]),Y(null),l(""),u([]),K([]),W("")},[z,c,S,A,P]),_e=s.useCallback(b=>{se(B=>B.filter(O=>O.id!==b))},[]),Ge=(b,B)=>{const O=N.find(X=>X.key===b);if(!O)return;const _=O.multi?(B??[]).map(X=>X.id):B?[B.id]:[];L(X=>[...X.filter(re=>Object.values(q).flat().find(ye=>ye.id===re)&&!Object.keys(q).find(ye=>q[ye]?.some(Pe=>Pe.id===re&&ye===b))),..._])};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.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:H,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:G,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(ae.st,{isMulti:b.multi,value:q[b.key]?.filter(B=>V.includes(B.id)),onChange:B=>{Ge(b.key,B)},options:q[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(ae.st,{value:z?me.find(b=>b.value===z):null,onChange:b=>{const B=b?.value||null;Y(B);const O=Fe.forcedThresholdKindForReport(B);O&&u(_=>_.map(X=>({...X,kind:O})))},options:me,placeholder:"Select report type...",isDisabled:o,isClearable:!0})]}),z!==U.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,forceKind:Fe.forcedThresholdKindForReport(z),editOnly:o})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Sensor Locations"}),e.jsxRuntimeExports.jsx(t.Input,{value:A.map(b=>we(b)).join(", "),placeholder:"Auto-filled based on parameters...",isDisabled:!0})]})]}),z===U.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:P,onChange:b=>W(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:!z||!c.trim()||o||me.length===0||z!==U.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:()=>_e(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:B=>se(O=>O.map(_=>_.id===b.id?{..._,name:B.target.value}:_)),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:B=>se(O=>O.map(_=>_.id===b.id?{..._,autoGenerate:B.target.checked}:_)),isDisabled:o})]}),b.kind===U.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:b.instructions,onChange:B=>se(O=>O.map(_=>_.id===b.id?{..._,instructions:B.target.value}:_)),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:o})]}),b.kind!==U.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs("div",{className:"flex flex-col",children:[e.jsxRuntimeExports.jsx(oe,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(ke,{options:de,forceKind:Fe.forcedThresholdKindForReport(b.kind),value:b.parameters,onChange:B=>{const O=Z=>"joint"in Z.id?Z.id.joint:Z.id.segment,_=B.map(O),X=ce.getSuggestedSensorLocations(_);se(Z=>Z.map(re=>re.id===b.id?{...re,parameters:B,sensorLocations:X}:re))},editOnly:o})]}),b.kind!==U.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Sensors:"," ",b.sensorLocations.map(B=>we(B)).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:a,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}),lt=({children:r,isView:n,metadataKeys:a})=>{const[h,p]=s.useState({}),j=ee.useClient();return s.useEffect(()=>{let x=!1;return(async()=>{const o=(a??[]).map(y=>j.query(E.GET_METADATA_BY_KEY,{key:y}).toPromise()),i=await Promise.all(o),m={};for(const y of i){if(y.error||!y.data?.getMetadataByKey)continue;const C=k.getFragmentData(E.METADATA_GROUP_FRAGMENT,y.data.getMetadataByKey);if(!C)continue;const v=k.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,a]),e.jsxRuntimeExports.jsx(Ne.Provider,{value:{isView:n,metadataOptions:h},children:r})},ct=({id:r,onCancel:n,onSave:a,onError:h,hideButtons:p,quantumOwned:j,setButtonOnClick:x,setButtonDisabled:g,isView:o})=>{const[{data:i,fetching:m}]=ee.useQuery({query:j?E.GET_QUANTUM_OWNED_ACTIONS:E.GET_ACTIONS}),[{data:y}]=ee.useQuery({query:E.GET_MODULE_BY_ID,variables:{id:r},pause:!r}),[{data:C}]=ee.useQuery({query:E.GET_ALL_MODULE_CATEGORIES}),v=k.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,C?.moduleCategories),[{fetching:M},I]=ee.useMutation(E.UPDATE_MODULE),[{fetching:f},d]=ee.useMutation(E.CREATE_MODULE),F=s.useMemo(()=>!i||m?[]:k.getFragmentData(E.ACTION_FRAGMENT,j?i?.quantumOwnedActions??[]:i?.actions??[]).filter(z=>!!z?.id),[i,j,m]),R=k.getFragmentData(E.ACTION_MODULE_FRAGMENT,y?.module),N=s.useMemo(()=>k.getFragmentData(E.MODULE_ACTION_FRAGMENT,R?.moduleActions)??[],[R?.moduleActions]),[T,$]=s.useState([]),[D,w]=s.useState(R?.name??""),[H,te]=s.useState([]),[G,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}));$(J),w(R.name),ne(R.description??""),te(R.categories.map(c=>k.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,c).id)??[]);const Y=k.getFragmentData(E.METADATA_GROUP_FRAGMENT,R.metadataGroups).map(c=>c.data.map(l=>k.getFragmentData(E.METADATA_ITEM_FRAGMENT,l).id));L(Y.flat())}},[R,N]);const q=s.useCallback(()=>{let J;const z={moduleActions:T.map(Y=>({actionId:Y.actionId,reportId:Y.reportId??void 0})),name:D,categories:H,description:G,quantumOwned:j,metadataItemIds:V};R?J=I({id:R.id,input:z}):J=d({input:z}),J.then(({error:Y})=>{Y?h(Y instanceof Error?Y:new Error(String(Y))):a()})},[d,I,T,D,G,H,V,R,a,h,j]);return s.useEffect(()=>{g&&g({cancelButton:M||f,saveButton:M||f||!D||G.trim().split(/\s+/).filter(Boolean).length>40})},[g,M,f,T,D,G]),s.useEffect(()=>{x&&x({cancelButton:n,saveButton:q})},[x,n,q]),e.jsxRuntimeExports.jsx(t.Box,{width:"100%",children:e.jsxRuntimeExports.jsxs(lt,{isView:o,metadataKeys:["activity_type","session_type","body_region","sport"],children:[e.jsxRuntimeExports.jsx(De,{name:D,setName:w,actions:F,moduleActionEntries:T,setModuleActionEntries:$,availableCategories:v??[],selectedCategoryIds:H,setSelectedCategoryIds:te,description:G,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||G.trim().split(/\s+/).filter(Boolean).length>40,isLoading:M||f,onClick:q,children:"Save"})]})})]})})};exports.ActivityList=Le;exports.CopyActivityForm=Ve;exports.CopyModuleForm=Xe;exports.ModuleForm=De;exports.ParameterEditList=Oe;exports.ParameterEditSelect=ke;exports.UpsertActivityForm=at;exports.UpsertModuleForm=ct;
|