quantum-component-library 1.4.52 → 1.4.53-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/components.cjs +1 -1
  2. package/dist/components.js +1009 -973
  3. package/dist/{dnd-core-vendor-CewhYmpg.cjs → dnd-core-vendor-BpIne3vw.cjs} +1 -1
  4. package/dist/{dnd-core-vendor-MevRgDB0.js → dnd-core-vendor-CxLn_KVZ.js} +2 -2
  5. package/dist/generated/gql.d.ts +2 -2
  6. package/dist/generated/graphql.d.ts +3 -0
  7. package/dist/generated-graphql.cjs +1 -1
  8. package/dist/generated-graphql.js +1 -1
  9. package/dist/generated.cjs +1 -1
  10. package/dist/generated.js +1 -1
  11. package/dist/{graphql-BOkP_KIq.js → graphql-CN-pqRpK.js} +5 -4
  12. package/dist/{graphql-DxJeiMzl.cjs → graphql-Dm6zPwG7.cjs} +1 -0
  13. package/dist/{graphql-vendor-uvLTmCiR.js → graphql-vendor-Cx8Mc6Yz.js} +1 -1
  14. package/dist/{graphql-vendor-BppBsUpc.cjs → graphql-vendor-D1Yd8wq_.cjs} +1 -1
  15. package/dist/hooks.cjs +1 -1
  16. package/dist/hooks.js +4 -4
  17. package/dist/index.cjs +1 -1
  18. package/dist/index.js +73 -71
  19. package/dist/lib/services/index.d.ts +1 -0
  20. package/dist/lib/services/reports.d.ts +2 -0
  21. package/dist/{lodash-vendor-B-xpwrnm.js → lodash-vendor-3vLqZYsK.js} +1 -1
  22. package/dist/{lodash-vendor-CWf2psR2.cjs → lodash-vendor-BXoJ3fY7.cjs} +1 -1
  23. package/dist/other-DNeraOC1.cjs +1 -0
  24. package/dist/{other-OzryMihZ.js → other-V9jzzJwZ.js} +7 -6
  25. package/dist/providers.cjs +1 -1
  26. package/dist/providers.js +1 -1
  27. package/dist/quantum-component-library.css +1 -1
  28. package/dist/{react-dnd-vendor-BYAS_HOo.js → react-dnd-vendor-DpRaxBS3.js} +2 -2
  29. package/dist/{react-dnd-vendor-BqsnzPKT.cjs → react-dnd-vendor-GZ764FSN.cjs} +1 -1
  30. package/dist/{react-select-vendor-sW1B_api.cjs → react-select-vendor-2_u9DhYj.cjs} +1 -1
  31. package/dist/{react-select-vendor-_26lPW2Z.js → react-select-vendor-DAt1SKof.js} +1 -1
  32. package/dist/{services-human-B4_65njx.cjs → services-human-BelpNNkM.cjs} +1 -1
  33. package/dist/{services-human-BIz3wOu_.js → services-human-CoaB5w4L.js} +8 -8
  34. package/dist/services.cjs +1 -1
  35. package/dist/services.js +69 -51
  36. package/dist/types.cjs +1 -1
  37. package/dist/types.js +3 -3
  38. package/dist/{utils-conversion-pcEG40AR.js → utils-conversion-C9aq8_At.js} +1 -1
  39. package/dist/{utils-conversion-BYVStK4S.cjs → utils-conversion-CuA6asju.cjs} +1 -1
  40. package/dist/utils.cjs +1 -1
  41. package/dist/utils.js +1 -1
  42. package/dist/{vendor-Dj-hzYUa.cjs → vendor-BUPEP1f9.cjs} +1 -1
  43. package/dist/{vendor-BHWxqW4x.js → vendor-Bap2-34A.js} +1 -1
  44. package/package.json +1 -1
  45. package/dist/other-Cad4iUZr.cjs +0 -1
@@ -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"),n=require("react"),A=require("./generated.cjs"),E=require("./graphql-DxJeiMzl.cjs"),Te=require("./utils-cn-FIKrq5Mb.cjs");require("./lodash-vendor-CWf2psR2.cjs");const ee=require("urql"),oe=require("./hooks.cjs"),De=require("./ufuzzy-vendor-7qHa_k39.cjs"),re=require("./react-select-vendor-sW1B_api.cjs"),Me=require("./react-icons-vendor-BF_sZq07.cjs"),Se=require("./react-dnd-vendor-BqsnzPKT.cjs"),ae=require("./services-human-B4_65njx.cjs"),P=require("./generated-graphql.cjs"),xe=require("./types.cjs"),_e=({setSearch:i,actions:o,updateUseCases:l,hideUseCaseFilter:j=!1})=>{const R=n.useMemo(()=>o?.flatMap(m=>m.useCases).filter((m,x,h)=>h.findIndex(r=>r.id===m.id)===x).map(m=>({label:m.name,value:m.id}))||[],[o]);return e.jsxRuntimeExports.jsxs(t.Flex,{width:"100%",alignContent:"space-evenly",gap:4,children:[e.jsxRuntimeExports.jsxs(t.InputGroup,{size:"md",flex:1,children:[e.jsxRuntimeExports.jsx(t.InputLeftElement,{children:e.jsxRuntimeExports.jsx(t.Icon,{as:Me.FaSearch,color:"gray.300"})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"Search by name...",width:"100%",maxW:j?void 0:"30rem",onChange:m=>i(m.target.value)})]}),!j&&e.jsxRuntimeExports.jsx(t.InputGroup,{size:"md",children:e.jsxRuntimeExports.jsx(re.st,{size:"md",chakraStyles:{container:m=>({...m,width:"100%"})},menuPortalTarget:document.body,placeholder:"Filter use case",isMulti:!0,options:R,onChange:m=>l(m.map(x=>x.value))})})]})},le=({children:i})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:i}),Ge=({items:i,onChange:o,selectedItem:l,isDisabled:j,selectedProps:R,buttonProps:m})=>{const x=r=>r===l||r.value===l,h=r=>x(r)?{...m,...R}:m;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:j,children:i.map((r,c)=>e.jsxRuntimeExports.jsx(t.Tooltip,{label:r.tooltip,openDelay:50,closeDelay:200,placement:"top",visibility:r.tooltip?"visible":"hidden",hasArrow:!0,children:e.jsxRuntimeExports.jsx(t.Button,{onClick:()=>x(r)?null:o(r,c),isDisabled:r.disabled,...h(r),children:r.label})},c))})},Ce=(i,o)=>o<0?-1*Math.abs(i):Math.abs(i),Pe=({isReversed:i,min:o,max:l,value:j,onChange:R,inputProps:m,size:x,zeroMarker:h,formatValue:r,valueLabel:c,positiveNegativeLabels:g,isDisabled:M,...v})=>{const[w,S]=n.useState([void 0,void 0]),y=w[0],d=w[1],p=h&&o<-5&&l>5,T=Number(j?.[0]??d??o)>0?1:-1,b=Number(j?.[1]??d??l)<0?-1:1,L=g?.[0]===g?.[1],N=j?.[0],D=j?.[1];n.useEffect(()=>{N!==void 0&&D!==void 0&&S([N.toFixed(0),D.toFixed(0)])},[N,D,S]);const F=n.useCallback(([I,$])=>{I<$&&S([I.toFixed(0),$.toFixed(0)])},[S]),O=n.useCallback(([I,$])=>{I<$&&R([I,$])},[R]),Y=n.useCallback(()=>{S(([I,$])=>{const J=isNaN(Number(I))?o:Number(I),z=isNaN(Number($))?l:Number($),H=Ce(Number(J),T),u=Ce(Number(z),b),s=T<0?Math.max(H,o):Math.min(H,l),a=b<0?Math.max(u,o):Math.min(u,l);return s>a?(R([a,s]),[a.toFixed(0),s.toFixed(0)]):(R([s,a]),[s.toFixed(0),a.toFixed(0)])})},[R,S,T,b,o,l]),se=n.useCallback(I=>{const $=I===""||isNaN(Number(I))?I:Ce(Number(I),T);S(([J,z])=>[$.toString(),z])},[S,T]),k=n.useCallback(I=>{const $=I===""||isNaN(Number(I))?I:Ce(Number(I),b);S(([J,z])=>[J,$.toString()])},[S,b]),V=n.useMemo(()=>x==="xs"?"0.75rem":void 0,[x]),X=n.useCallback((I,$)=>{const J=Number($.target.value);if(!y||!d||![-1,1].includes(J))return;const z=s=>J<0?-1*Math.abs(s):Math.abs(s),H=I?z(Number(y)):Number(y),u=I?Number(d):z(Number(d));H>u?R([u,H]):R([H,u])},[y,d,R]);return e.jsxRuntimeExports.jsxs(t.Flex,{direction:"column",...v,children:[e.jsxRuntimeExports.jsx(t.Box,{pt:"1em",mb:"-0.5em",children:e.jsxRuntimeExports.jsxs(t.RangeSlider,{"aria-label":["min","max"],isReversed:i,value:[Number(y??o),Number(d??l)],max:l,min:o,minStepsBetweenThumbs:3,step:1,onChange:F,onChangeEnd:O,isDisabled:M,children:[e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:o,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:x??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:r?r?.(o):o})}),e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:l,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:x??"sm",fontWeight:"semibold",style:{transform:"translateX(-100%)"},whiteSpace:"nowrap",children:r?r(l):l})}),p&&e.jsxRuntimeExports.jsxs(t.RangeSliderMark,{value:0,top:"-1em",pos:"relative",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:x,fontWeight:"semibold",children:r?.(0)??"0"}),e.jsxRuntimeExports.jsx(t.Box,{position:"absolute",width:"2px",height:"1em",top:"90%",left:"20%",backgroundColor:"var(--chakra-colors-gray-300)"})]}),e.jsxRuntimeExports.jsx(t.RangeSliderTrack,{children:e.jsxRuntimeExports.jsx(t.RangeSliderFilledTrack,{})}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:0,w:V,h:V}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:1,w:V,h:V})]})}),c&&e.jsxRuntimeExports.jsxs(t.Flex,{direction:i?"row-reverse":"row",justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:x??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:c(o)}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:x??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:c(l)})]}),e.jsxRuntimeExports.jsxs(t.Flex,{direction:i?"row-reverse":"row",justifyContent:"center",alignItems:"center",gap:"0.125em",children:[g&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:x,fontWeight:"bold",value:T,onChange:I=>X(!0,I),isDisabled:L||M,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:g[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:g[1]})]}),e.jsxRuntimeExports.jsx(t.NumberInput,{precision:0,size:x??"sm",min:0,max:T<0?Math.abs(o):D??l,value:y===""?"":Math.abs(Number(y??o)),onChange:se,onBlur:Y,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:M,...m,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),e.jsxRuntimeExports.jsx(t.NumberInput,{size:x??"sm",min:0,max:b<0?Math.abs(N??o):l,precision:0,value:d===""?"":Math.abs(Number(d??l)),onChange:k,onBlur:Y,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:M,...m,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),g&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:x,fontWeight:"bold",value:b,onChange:I=>X(!1,I),isDisabled:L||M,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:g[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:g[1]})]})]})]})},Be=({tags:i,containerProps:o,...l})=>e.jsxRuntimeExports.jsx(t.HStack,{...o,children:i.map((j,R)=>e.jsxRuntimeExports.jsx(t.Tag,{...l,children:j},R))}),$e=new De.uFuzzy({}),Ue=({action:i,quantumIconSrc:o})=>{const{getLabel:l}=oe.useUiLabelContext(),j=n.useMemo(()=>({actionLowerCase:l("action").toLocaleLowerCase()}),[l]);return i.quantumOwned?e.jsxRuntimeExports.jsx(t.Tooltip,{label:`This ${j.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:o,boxSize:"1em",alt:`Quantum-owned ${j.actionLowerCase}`})})}):null},ze=(i,o)=>{if(!o||!o.trim().length)return i;const l=i.map(R=>R.name??"");return $e.filter(l,o)?.map(R=>i[R])??[]},qe=i=>!i||i.length===0?"None":i.map(o=>o.replace(/([A-Z])/g," $1").trim()).join(", "),We=(i,o)=>!o||o.length==0?i:i.filter(l=>l.useCases?.some(j=>o.includes(j.id))??!1),Qe=(i,o,l)=>!o||o.length===0?i:i.filter(j=>{const R={};return o.forEach(m=>{for(const[x,h]of Object.entries(l||{}))if(h.some(r=>r.id===m)){R[x]||(R[x]=[]),R[x].push(m);break}}),Object.entries(R).every(([m,x])=>{const h=j.metadataGroups?.find(M=>A.getFragmentData(E.METADATA_GROUP_FRAGMENT,M).key===m);if(!h)return!1;const r=A.getFragmentData(E.METADATA_GROUP_FRAGMENT,h),g=A.getFragmentData(E.METADATA_ITEM_FRAGMENT,r.data).map(M=>M.id);return x.some(M=>g.includes(M))})}),Le=({actions:i,totalActions:o,onCreate:l,onDelete:j,onEdit:R,onView:m,onSelected:x,onDuplicate:h,disableMultiSelect:r,disableDelete:c,disableEdit:g,disableCreate:M,hideUseCase:v=!0,showMetadataFilters:w=!0,tableProps:S,containerProps:y,quantumIconSrc:d="/favicon.ico"})=>{const[p,T]=n.useState(""),[b,L]=n.useState(),[N,D]=n.useState([]),[F,O]=n.useState({}),{getLabel:Y}=oe.useUiLabelContext(),se=ee.useClient(),k=n.useMemo(()=>({action:Y("action"),actionPlural:Y("action_plural"),actionLowerCase:Y("action").toLocaleLowerCase(),actionPluralLowerCase:Y("action_plural").toLocaleLowerCase()}),[Y]),V=n.useMemo(()=>[{key:"module_category",label:"Link Category",multi:!0},{key:"activity_type",label:`${k.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}],[k.action]);n.useEffect(()=>{if(!w)return;const s=V.map(a=>se.query(E.GET_METADATA_BY_KEY,{key:a.key}));Promise.all(s).then(a=>{const C={};a.forEach(q=>{if(q.error||!q.data)return;const Q=A.getFragmentData(E.METADATA_GROUP_FRAGMENT,q.data.getMetadataByKey),B=A.getFragmentData(E.METADATA_ITEM_FRAGMENT,Q.data);C[Q.key]=B.map(_=>({label:_.label||_.value,value:_.value,id:_.id}))}),O(C)})},[se,V,w]);const X=n.useMemo(()=>{if(!i)return;const s=ze(i,p),a=v?s:We(s,b);return w?Qe(a,N,F):a},[i,p,b,v,w,N,F]),I=n.useCallback(()=>{if(!j)return;const a=i.filter(C=>C.selected&&!C.quantumOwned).map(C=>C.id);j(a)},[i,j]),$=n.useCallback(()=>{if(!h)return;const s=i.filter(a=>a.selected);h(s.map(a=>a.id)),x&&s.forEach(a=>x(a,!1))},[i,h,x]),J=n.useMemo(()=>i.some(s=>s.selected&&!s.quantumOwned),[i]),z=n.useMemo(()=>i.some(s=>s.selected),[i]),H=n.useMemo(()=>i.some(s=>s.selected&&s.quantumOwned),[i]),u=n.useCallback((s,a)=>{const C=V.find(Q=>Q.key===s);if(!C)return;const q=C.multi?(a??[]).map(Q=>Q.id):a?[a.id]:[];D(Q=>[...Q.filter(_=>Object.values(F).flat().find(ce=>ce.id===_)&&!Object.keys(F).find(ce=>F[ce]?.some(de=>de.id===_&&ce===s))),...q])},[V,F]);return e.jsxRuntimeExports.jsxs(t.Box,{...y,children:[e.jsxRuntimeExports.jsxs(t.Flex,{alignContent:"space-between",gap:4,children:[(l||j||h)&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mb:"1rem",gap:4,children:[l&&e.jsxRuntimeExports.jsxs(t.Button,{isDisabled:!l||M,colorScheme:"blackAlpha",backgroundColor:"gray.700",onClick:l,children:["Create New ",k.action]}),j&&!r&&e.jsxRuntimeExports.jsx(t.Tooltip,{label:H?J?`Quantum-owned ${k.actionPluralLowerCase} are selected and will be skipped`:`Selected ${k.actionPluralLowerCase} are quantum-owned and cannot be deleted`:void 0,shouldWrapChildren:!0,children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!J||!j||c,onClick:I,children:"Delete Selected"})}),h&&!r&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!z,onClick:$,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx(_e,{setSearch:T,actions:i,updateUseCases:L,hideUseCaseFilter:v})]}),w&&F&&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:V.map(s=>e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(t.FormLabel,{fontSize:"sm",children:s.label}),e.jsxRuntimeExports.jsx(re.st,{chakraStyles:{menu:a=>({...a,zIndex:2})},isMulti:s.multi,value:F[s.key]?.filter(a=>N.includes(a.id)),onChange:a=>{u(s.key,a)},options:F[s.key],placeholder:`Select ${s.multi?"one or more":"one"} ${s.label.toLowerCase()}`,isClearable:s.multi})]},s.key))})}),e.jsxRuntimeExports.jsx(t.TableContainer,{mr:"2rem",overflowX:"hidden",...S,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 ",X?.length??0," of"," ",o??i.length,")"]}),e.jsxRuntimeExports.jsx(t.Th,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Th,{children:"Sensor Locations"}),!v&&e.jsxRuntimeExports.jsx(t.Th,{children:"Use Case"}),e.jsxRuntimeExports.jsx(t.Th,{})]})}),e.jsxRuntimeExports.jsx(t.Tbody,{children:X?.map(s=>e.jsxRuntimeExports.jsxs(t.Tr,{className:Te.cn("hover:bg-[#f7f7f7]",!r&&"cursor-pointer",s.selected&&"bg-gray-200"),onClick:()=>{r||x?.(s,!s.selected)},children:[e.jsxRuntimeExports.jsx(t.Td,{children:e.jsxRuntimeExports.jsxs(t.Flex,{children:[!r&&e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:s.selected?e.jsxRuntimeExports.jsx(Me.FaCheckSquare,{className:"text-blue-500"}):e.jsxRuntimeExports.jsx(Me.FaSquare,{className:"text-gray-400"})}),(s.quantumOwned||!R)&&m&&e.jsxRuntimeExports.jsx(t.Button,{ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:a=>{a.stopPropagation(),m(s.id)},children:"View"}),!s.quantumOwned&&R&&e.jsxRuntimeExports.jsx(t.Button,{isDisabled:g,ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:a=>{a.stopPropagation(),R(s.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(Ue,{action:s,quantumIconSrc:d}),s.name]})}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",whiteSpace:"break-spaces",children:qe(s.sensorLocations)}),!v&&e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:e.jsxRuntimeExports.jsx(Be,{containerProps:{flexWrap:"wrap"},tags:s.useCases?.map(a=>a.name)??[]})})]},s.id))})]})})]})},He=({onSave:i,onCancel:o,onError:l,hideButtons:j=!1,setButtonDisabled:R,setButtonOnClick:m,quantumOwned:x})=>{const h=t.useToast(),{getLabel:r}=oe.useUiLabelContext(),c=n.useMemo(()=>({singular:r("action"),plural:r("action_plural"),pluralLowerCase:r("action_plural").toLowerCase(),singularLowerCase:r("action").toLowerCase()}),[r]),[g,M]=n.useState("copy"),[v,w]=n.useState(""),[S,y]=n.useState([]),[d,p]=n.useState(!1),[T]=ee.useQuery({query:E.GET_GROUPS}),[b]=ee.useQuery({query:E.GET_ACTIONS_BY_GROUP,variables:{groupId:v},pause:!v}),[,L]=ee.useMutation(E.CREATE_ACTION),[,N]=ee.useMutation(E.CONVERT_ACTION_TO_QUANTUM_OWNED),D=n.useMemo(()=>T.data?.groups?T.data.groups.map(u=>A.getFragmentData(E.GROUP_FRAGMENT,u)):[],[T.data]),F=n.useMemo(()=>b.data?b.data.actions.map(s=>{const a=A.getFragmentData(E.ACTION_FRAGMENT,s),C=A.getFragmentData(E.REPORT_FRAGMENT,a.reports),q=A.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,a.categories),B=A.getFragmentData(E.METADATA_GROUP_FRAGMENT,a.metadataGroups).map(_=>({..._,data:_.data.map(K=>A.getFragmentData(E.METADATA_ITEM_FRAGMENT,K))}));return{...a,thresholds:A.getFragmentData(E.THRESHOLD_FRAGMENT,a.thresholds),reports:C.map(_=>({..._,thresholds:A.getFragmentData(E.THRESHOLD_FRAGMENT,_.thresholds)})),categories:q,metadataGroups:B}}):[],[b.data]),O=n.useMemo(()=>F.filter(u=>S.includes(u.id)),[F,S]),Y=n.useCallback(u=>{const s=u?.value||"";w(s),y([])},[]),se=n.useCallback(u=>{const s=u.map(a=>a.value);y(s)},[]),k=n.useCallback(async u=>{const s={...u,name:`${u.name} (Copy)`,description:u.description||void 0,instructionsPointOfInterest:u.instructionsPointOfInterest||void 0,instructionsMovementReport:u.instructionsMovementReport||void 0,laterality:u.laterality,activityKind:u.activityKind,sensorLocations:u.sensorLocations,thresholds:u.thresholds.map(C=>({...C,id:void 0})),categories:u.categories.map(C=>C.id),quantumOwned:x,metadataItemIds:u.metadataGroups.flatMap(C=>C.data.map(q=>q.id)).filter(C=>C!==void 0),reports:u.reports.map(C=>({...C,id:void 0,thresholds:C.thresholds.map(q=>({...q,id:void 0}))})),id:void 0},a=await L({fields:s});if(a.error)throw new Error(a.error.message);if(a.data?.createAction)return A.getFragmentData(E.ACTION_FRAGMENT,a.data.createAction);throw new Error("No action data returned")},[L,x]),V=n.useCallback(async u=>{const s=await N({id:u.id});if(s.error)throw new Error(s.error.message);if(s.data?.convertActionToQuantumOwned)return A.getFragmentData(E.ACTION_FRAGMENT,s.data.convertActionToQuantumOwned);throw new Error("No action data returned")},[N]),X=n.useCallback(async()=>{if(p(!0),!O.length){const u=new Error(`No ${c.pluralLowerCase} selected for ${g==="copy"?"copying":"converting"}`);l?.(u),p(!1);return}try{const u=[];let s=0;const a=g==="copy"?k:V,C=g==="copy"?"copy":"convert";for(const q of O)try{const Q=await a(q);u.push(Q)}catch(Q){console.error(`Failed to ${C} ${c.singularLowerCase} "${q.name}":`,Q),s++}if(u.length>0){const q=u.length,Q=O.length,B=g==="copy"?"copied":"converted",_=g==="copy"?"copy":"convert";h({title:s>0?`Partial ${_} completed`:`${c.plural} ${B} successfully`,description:s>0?`${q} of ${Q} ${c.pluralLowerCase} ${B} successfully`:`${q} ${q>1?c.pluralLowerCase:c.singularLowerCase} ${B} successfully`,status:s>0?"warning":"success",duration:3e3,isClosable:!0}),i?.(),w(""),y([])}else throw new Error(`Failed to ${C} any ${c.pluralLowerCase}`)}catch(u){const s=g==="copy"?"copy":"convert",a=u instanceof Error?u.message:`Failed to ${s} ${c.pluralLowerCase}`;h({title:`${g==="copy"?"Copy":"Convert"} failed`,description:a,status:"error",duration:5e3,isClosable:!0}),l?.(u instanceof Error?u:new Error(a))}finally{p(!1)}},[O,g,k,V,h,i,l,c]),I=n.useCallback(()=>{w(""),y([]),M("copy"),o?.()},[o]);n.useEffect(()=>{R&&R({cancelButton:!1,saveButton:O.length===0||d})},[O.length,d,R]),n.useEffect(()=>{m&&m({cancelButton:I,saveButton:X})},[m,I,X]);const $=n.useMemo(()=>D.map(u=>({value:u.id,label:u.name})),[D]),J=n.useMemo(()=>F.filter(u=>g==="copy"?!0:!u.quantumOwned).map(u=>({value:u.id,label:u.name,isQuantumOwned:u.quantumOwned})),[F,g]),z=T.fetching,H=b.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(le,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:g,onChange:u=>{M(u),y([])},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 ",c.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",c.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 ",c.singular]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Convert existing"," ",c.plural.toLocaleLowerCase()," to quantum-owned"]})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(le,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(re.st,{placeholder:"Choose a group...",options:$,value:$.find(u=>u.value===v)||null,onChange:Y,isLoading:z,isDisabled:z,isClearable:!0}),T.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: ",T.error.message]})]})]}),v&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsxs(le,{children:["Select ",c.plural," to"," ",g==="copy"?"Copy":"Convert"]}),H?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 ",c.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(re.st,{placeholder:`Choose ${c.pluralLowerCase} to ${g}...`,options:J,value:J.filter(u=>S.includes(u.value)),onChange:se,isDisabled:J.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(u,{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:u.label}),s==="value"&&u.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),u.isQuantumOwned&&s==="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 ",c.pluralLowerCase," found"]})]}),b.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load ",c.pluralLowerCase,":"," ",b.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?`${c.singular} to ${g==="copy"?"Copy":"Convert"}:`:`${O.length} ${c.plural} to ${g==="copy"?"Copy":"Convert"}:`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[O.map((u,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,". ",u.name]}),u.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:[u.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",u.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Type:"})," ",u.activityKind]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Laterality:"})," ",u.laterality]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Sensor Locations:"})," ",u.sensorLocations.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Thresholds:"})," ",u.thresholds.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Use Cases:"})," ",u.useCases.map(a=>a.name).join(", ")||"None"]})]})]},u.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," ",c.pluralLowerCase," will be"," ",g==="copy"?"copied":"converted"]})})]})]}),!j&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:I,isDisabled:d,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:g==="copy"?"blue":"green",onClick:X,isDisabled:O.length===0||d,isLoading:d,loadingText:`${g==="copy"?"Copying":"Converting"}...`,children:[g==="copy"?"Copy":"Convert"," ",O.length===1?c.singular:`${O.length} ${c.plural}`]})]})]})})},Ke=({onSave:i,onCancel:o,onError:l,hideButtons:j=!1,setButtonDisabled:R,setButtonOnClick:m,quantumOwned:x})=>{const h=t.useToast(),{getLabel:r}=oe.useUiLabelContext(),c=n.useMemo(()=>({singular:r("module"),plural:r("module_plural"),pluralLowerCase:r("module_plural").toLowerCase(),singularLowerCase:r("module").toLowerCase()}),[r]),g=n.useMemo(()=>({singular:r("action"),plural:r("action_plural"),pluralLowerCase:r("action_plural").toLowerCase(),singularLowerCase:r("action").toLowerCase()}),[r]),[M,v]=n.useState(""),[w,S]=n.useState([]),[y,d]=n.useState(!1),[p,T]=n.useState("copy"),[b]=ee.useQuery({query:E.GET_GROUPS}),[L]=ee.useQuery({query:E.GET_MODULES_BY_GROUP,variables:{groupId:M},pause:!M}),[,N]=ee.useMutation(E.CREATE_MODULE),[,D]=ee.useMutation(E.UPDATE_MODULE),[,F]=ee.useMutation(E.CREATE_ACTION),[,O]=ee.useMutation(E.CONVERT_ACTION_TO_QUANTUM_OWNED),Y=n.useMemo(()=>b.data?.groups?b.data.groups.map(s=>A.getFragmentData(E.GROUP_FRAGMENT,s)):[],[b.data]),se=n.useMemo(()=>L.data?.modules?A.getFragmentData(E.ACTION_MODULE_FRAGMENT,L.data?.modules).map(a=>{const C=A.getFragmentData(E.MODULE_ACTION_FRAGMENT,a.moduleActions),Q=A.getFragmentData(E.METADATA_GROUP_FRAGMENT,a.metadataGroups).map(B=>A.getFragmentData(E.METADATA_ITEM_FRAGMENT,B.data)).flat();return{...a,moduleActions:C.map(B=>({...B,action:A.getFragmentData(E.ACTION_FRAGMENT,B.action)})),categories:A.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,a.categories),metadataItems:Q}}):[],[L.data]),k=n.useMemo(()=>se.filter(s=>w.includes(s.id)),[se,w]),V=n.useCallback(s=>{const a=s?.value||"";v(a),S([])},[]),X=n.useCallback(s=>{const a=s.map(C=>C.value);S(a)},[]),I=n.useCallback(async()=>{if(d(!0),!k.length){d(!1);const s=new Error(`No modules selected for ${p==="convert"?"converting":"copying"}`);l?.(s);return}try{const s=[];let a=0;for(const C of k)try{let q=C.moduleActions.map(Q=>Q.actionId);if(x){const Q=C.moduleActions.map(K=>K.action),B=async K=>{if(p==="copy"){if(K.quantumOwned)return K;const de=A.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,K.categories),Ee=A.getFragmentData(E.METADATA_GROUP_FRAGMENT,K.metadataGroups).map(ue=>A.getFragmentData(E.METADATA_ITEM_FRAGMENT,ue.data).map(he=>he.id)).flat(),me=A.getFragmentData(E.REPORT_FRAGMENT,K.reports).map(ue=>({...ue,id:void 0,thresholds:A.getFragmentData(E.THRESHOLD_FRAGMENT,ue.thresholds).map(he=>({...he,id:void 0}))})),pe=A.getFragmentData(E.THRESHOLD_FRAGMENT,K.thresholds).map(ue=>({...ue,id:void 0})),fe={...K,quantumOwned:!0,thresholds:pe,categories:de?.map(ue=>ue.id),reports:me,metadataIds:Ee,id:void 0},je=await F({fields:fe});return je.error||!je.data?.createAction?null:A.getFragmentData(E.ACTION_FRAGMENT,je.data.createAction)}if(K.quantumOwned)return K;const ce=await O({id:K.id});return ce.error||!ce.data?.convertActionToQuantumOwned?null:A.getFragmentData(E.ACTION_FRAGMENT,ce.data.convertActionToQuantumOwned)};q=(await Promise.all(Q.map(B))).filter(K=>!!K).map(K=>K.id)}if(p==="convert"){const Q={name:C.name,description:C.description||void 0,actions:q,categories:C.categories.map(_=>_.id),quantumOwned:!0},B=await D({id:C.id,input:Q});if(B.error)throw new Error(B.error.message);if(B.data?.updateModule){const _=A.getFragmentData(E.ACTION_MODULE_FRAGMENT,B.data.updateModule);s.push(_)}}else{const Q={name:`${C.name} (Copy)`,description:C.description||void 0,actions:q,categories:C.categories.map(_=>_.id),quantumOwned:x,metadataItemIds:C.metadataItems.map(_=>_.id),actionReports:C.moduleActions.filter(_=>!!_.reportId).map(_=>({actionId:_.actionId,reportId:_.reportId}))},B=await N({input:Q});if(B.error)throw new Error(B.error.message);if(B.data?.createModule){const _=A.getFragmentData(E.ACTION_MODULE_FRAGMENT,B.data.createModule);s.push(_)}}}catch(q){console.error(`Failed to ${p==="convert"?"convert":"copy"} module "${C.name}":`,q),a++}if(s.length>0){const C=s.length,q=k.length;h({title:a>0?`Partial ${p==="convert"?"convert":"copy"} completed`:`${c.plural} ${p==="convert"?"converted":"copied"} successfully`,description:a>0?`${C} of ${q} ${c.plural} ${p==="convert"?"converted":"copied"} successfully`:`${C} ${C>1?c.plural:c.singular} ${p==="convert"?"converted":"copied"} successfully`,status:a>0?"warning":"success",duration:3e3,isClosable:!0}),s.length>0&&i?.(),v(""),S([])}else throw new Error(`Failed to ${p==="convert"?"convert":"copy"} any modules`)}catch(s){const a=s instanceof Error?s.message:`Failed to ${p==="convert"?"convert":"copy"} modules`;h({title:p==="convert"?"Convert failed":"Copy failed",description:a,status:"error",duration:5e3,isClosable:!0}),l?.(s instanceof Error?s:new Error(a))}finally{d(!1)}},[k,N,D,h,i,l,x,F,O,p,c]),$=n.useCallback(()=>{v(""),S([]),T("copy"),o?.()},[o]);n.useEffect(()=>{R&&R({cancelButton:!1,saveButton:k.length===0||y})},[k.length,y,R]),n.useEffect(()=>{m&&m({cancelButton:$,saveButton:I})},[m,$,I]);const J=n.useMemo(()=>Y.map(s=>({value:s.id,label:s.name})),[Y]),z=n.useMemo(()=>se.filter(s=>p==="copy"?!0:!s.quantumOwned).map(s=>({value:s.id,label:s.name,isQuantumOwned:s.quantumOwned})),[se,p]),H=b.fetching,u=L.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(le,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:p,onChange:s=>{T(s),S([])},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 ",c.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",c.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 ",c.pluralLowerCase," to quantum-owned"]})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(le,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(re.st,{placeholder:"Choose a group...",options:J,value:J.find(s=>s.value===M)||null,onChange:V,isLoading:H,isDisabled:H,isClearable:!0}),b.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",b.error.message]})]})]}),M&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(le,{children:p==="convert"?`Select ${c.plural} to Convert`:`Select ${c.plural} to Copy`}),u?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 ",c.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(re.st,{placeholder:p==="convert"?`Choose ${c.pluralLowerCase} to convert...`:`Choose ${c.pluralLowerCase} to copy...`,options:z,value:z.filter(s=>w.includes(s.value)),onChange:X,isDisabled:z.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(s,{context:a})=>e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",w:"100%",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(t.Text,{children:s.label}),a==="value"&&s.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),s.isQuantumOwned&&a==="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 ",c.pluralLowerCase," found in this group"]})]}),L.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load ",c.pluralLowerCase,":"," ",L.error.message]})]})]}),k.length>0&&e.jsxRuntimeExports.jsxs(t.Box,{p:4,bg:"gray.50",borderRadius:"md",children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"semibold",mb:3,children:k.length===1?`${c.singular} to ${p==="copy"?"Copy":"Convert"}`:`${k.length} ${c.plural} to ${p==="copy"?"Copy":"Convert"}`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[k.map((s,a)=>e.jsxRuntimeExports.jsxs(t.Box,{w:"100%",p:3,bg:"white",borderRadius:"md",border:"1px solid",borderColor:"gray.200",children:[e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",align:"start",mb:2,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"medium",fontSize:"sm",children:[a+1,". ",s.name]}),s.quantumOwned&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,fontSize:"sm",color:"gray.600",children:[s.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",s.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Activities:"})," ",s.moduleActions.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Categories:"})," ",s.categories.map(C=>C.name).join(", ")||"None"]})]})]},s.id)),k.length>1&&e.jsxRuntimeExports.jsx(t.Box,{w:"100%",p:2,bg:"blue.50",borderRadius:"md",border:"1px solid",borderColor:"blue.200",children:e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",fontWeight:"medium",color:"blue.800",children:["Total: ",k.length," ",c.pluralLowerCase," will be"," ",p==="copy"?"copied":"converted"]})}),x&&k.filter(s=>s.moduleActions.some(a=>!a.action.quantumOwned)).length>0&&e.jsxRuntimeExports.jsx(t.Box,{p:2,bg:"yellow.50",borderRadius:"md",border:"1px solid",borderColor:"yellow.200",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",fontWeight:"medium",color:"yellow.800",children:p==="convert"?`Converting ${c.plural} will convert non QM-Owned ${g.plural} to QM-Owned ${g.plural}`:`Copying ${c.plural} with Non QM-Owned ${g.plural} will create corresponding QM-Owned ${g.plural}`})})]})]}),!j&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:$,isDisabled:y,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:p==="copy"?"blue":"green",onClick:I,isDisabled:k.length===0||y,isLoading:y,loadingText:`${p==="copy"?"Copying":"Converting"}...`,children:[p==="copy"?"Copy":"Convert"," ",k.length===1?c.singular:`${k.length} ${c.plural}`]})]})]})})},Ie=n.createContext(void 0),ge=()=>{const i=n.useContext(Ie);if(!i)throw new Error("useUpsertModuleFormContext must be used within a UpsertModuleFormProvider");return i},ke=({name:i,setName:o,actions:l,selectedActionIds:j,setSelectedActionIds:R,availableCategories:m,selectedCategoryIds:x,setSelectedCategoryIds:h,description:r,setDescription:c,selectedMetadataIds:g,setSelectedMetadataIds:M,actionReportIds:v,setActionReportIds:w,...S})=>{const y=t.useDisclosure(),d=n.useMemo(()=>l.map(D=>({...D,selected:j.includes(D.id)})),[l,j]),p=n.useMemo(()=>l.reduce((D,F)=>(D[F.id]=F,D),{}),[l]),T=n.useMemo(()=>j.map(D=>p[D]),[j,p]),b=n.useCallback((D,F)=>{R(F?[...j,D.id]:j.filter(O=>O!==D.id))},[j,R]),L=n.useCallback(D=>{o(D.target.value)},[o]),N=n.useCallback(D=>{c?.(D.target.value)},[c]);return e.jsxRuntimeExports.jsxs(t.Box,{...S,children:[e.jsxRuntimeExports.jsxs(t.HStack,{gap:"2rem",children:[e.jsxRuntimeExports.jsx(Ye,{name:i??"",onInputChange:L}),e.jsxRuntimeExports.jsx(Je,{availableCategories:m,value:x,onChange:h})]}),e.jsxRuntimeExports.jsx(Ve,{description:r??"",onInputChange:N}),e.jsxRuntimeExports.jsx(tt,{selectedMetadataIds:g,setSelectedMetadataIds:M}),e.jsxRuntimeExports.jsx(Xe,{value:T,onChange:R,onAdjustActivities:()=>y.onOpen(),actionReportIds:v,setActionReportIds:w}),e.jsxRuntimeExports.jsxs(t.Modal,{isOpen:y.isOpen,onClose:y.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:d,onSelected:b,disableCreate:!0,disableDelete:!0,tableProps:{height:"28rem",overflowY:"auto"}})}),e.jsxRuntimeExports.jsx(t.ModalFooter,{children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:y.onClose,isDisabled:j.length===0,children:"Done"})})]})]})]})},Ye=n.memo(({name:i,onInputChange:o})=>{const{getLabel:l}=oe.useUiLabelContext(),j=l("module"),{isView:R}=ge();return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(le,{children:[j," Name"]}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. ACL RTP Test Battery",value:i,onChange:o,isRequired:!0,isDisabled:R})]})}),Je=n.memo(({availableCategories:i,value:o,onChange:l})=>{const{getLabel:j}=oe.useUiLabelContext(),R=j("module"),{isView:m}=ge(),x=n.useMemo(()=>[...i,{id:"other",name:"Other"}],[i]),h=n.useMemo(()=>x.map(r=>({value:r.id,label:r.name})),[x]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(le,{children:[R," Category"]}),e.jsxRuntimeExports.jsx(re.st,{isDisabled:i.length===0||m,options:h,value:o.length===0?{value:"other",label:"Other"}:x.filter(r=>o.includes(r.id)).map(r=>({value:r.id,label:r.name}))[0],onChange:r=>l(r?[r.value]:[]),placeholder:"Select category"})]})}),Ve=n.memo(({description:i,onInputChange:o})=>{const{getLabel:l}=oe.useUiLabelContext(),j=l("module"),{isView:R}=ge();return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(le,{children:e.jsxRuntimeExports.jsxs("span",{children:["Description",e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",children:["Briefly describe the objective of this"," ",j.toLocaleLowerCase(),". Max 40 words."]})]})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. Assess readiness to return to play post-ACL reconstruction",value:i,onChange:o,isDisabled:R})]})}),Xe=n.memo(({value:i,onChange:o,onAdjustActivities:l,actionReportIds:j,setActionReportIds:R})=>{const{getLabel:m}=oe.useUiLabelContext(),{isView:x}=ge(),h=n.useMemo(()=>({module:m("module"),moduleLowerCase:m("module").toLocaleLowerCase(),action:m("action"),actionPlural:m("action_plural"),actionPluralLowerCase:m("action_plural").toLocaleLowerCase()}),[m]),r=n.useMemo(()=>i.map(c=>({id:c.id,name:c.name,reports:A.getFragmentData(E.REPORT_FRAGMENT,c.reports)||[],selectedReportId:j[c.id]||null})),[i,j]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(t.HStack,{justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(le,{children:e.jsxRuntimeExports.jsxs("span",{children:[h.actionPlural,!x&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",children:["Drag and drop to reorder the ",h.actionPluralLowerCase," ","in this ",h.moduleLowerCase,"."]})]})}),!x&&e.jsxRuntimeExports.jsxs(t.Button,{size:"sm",variant:"solid",colorScheme:"blue",onClick:l,children:["Add / Remove ",h.actionPlural]})]}),r.length===0?e.jsxRuntimeExports.jsx(t.VStack,{children:e.jsxRuntimeExports.jsxs(t.Text,{color:"gray.500",fontSize:"lg",mb:"4rem",mt:"4rem",children:["No ",h.actionPluralLowerCase," selected for this"," ",h.moduleLowerCase,".",!x&&e.jsxRuntimeExports.jsxs(t.Button,{ml:"0.5em",size:"sm",variant:"link",colorScheme:"blue",onClick:l,children:["Add ",h.actionPluralLowerCase,"."]})]})}):e.jsxRuntimeExports.jsx(Ze,{value:r,onChange:c=>{const g=c(r);o(g.map(M=>M.id))},disabled:x,actionReportIds:j,setActionReportIds:R})]})}),Ze=n.memo(({value:i,onChange:o,disabled:l,actionReportIds:j,setActionReportIds:R})=>{const[m]=n.useState(()=>Math.random().toString(36).substring(2,15)),x=n.useCallback((h,r)=>{l||o(c=>{const g=[...c],[M]=g.splice(h,1);return g.splice(r,0,M),g})},[o,l]);return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsx(Se.DndProvider,{backend:Se.HTML5Backend,children:e.jsxRuntimeExports.jsx(t.VStack,{spacing:3,align:"stretch",children:i.map((h,r)=>e.jsxRuntimeExports.jsx(et,{listKey:m,item:h,index:r,disabled:!!l,move:x,onReportChange:c=>{R({...j,[h.id]:c})}},h.id))})})})}),et=n.memo(({listKey:i,item:o,index:l,disabled:j,move:R,onReportChange:m})=>{const x=n.useRef(null),{getLabel:h}=oe.useUiLabelContext(),r=h("action"),[{handlerId:c},g]=Se.useDrop({accept:i,collect:d=>({handlerId:d.getHandlerId()?.toString()??""}),hover:(d,p)=>{if(!x.current)return;const T=d.index,b=l;if(T===b)return;const L=x.current?.getBoundingClientRect(),N=(L.bottom-L.top)/2,F=p.getClientOffset().y-L.top;T<b&&F<N||T>b&&F>N||(R(T,b),d.index=b)}}),[{isDragging:M},v]=Se.useDrag({type:i,item:()=>({id:o.id,index:l}),collect:d=>({isDragging:d.isDragging()}),canDrag:!j}),w=n.useMemo(()=>[{value:null,label:"No Report"},...o.reports.map(d=>({value:d.id,label:d.reportKind||"Report"}))],[o.reports]),S=M?.6:1,y=j?"default":M?"grabbing":"grab";return v(g(x)),e.jsxRuntimeExports.jsx(t.Box,{ref:x,p:3,border:"1px solid",borderColor:"gray.200",borderRadius:"md",bg:"gray.50",style:{opacity:S,cursor:y},"data-handler-id":c,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:[l+1,"."]}),e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"medium",children:o.name})]}),e.jsxRuntimeExports.jsxs(t.HStack,{spacing:3,align:"center",children:[e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:[r," Report:"]}),e.jsxRuntimeExports.jsx(t.Box,{width:"300px",children:e.jsxRuntimeExports.jsx(re.st,{value:w.find(d=>d.value===o.selectedReportId),onChange:d=>{m(d?.value||null)},options:w,placeholder:"Select report...",isDisabled:j})})]})]})})}),tt=n.memo(({selectedMetadataIds:i,setSelectedMetadataIds:o})=>{const{getLabel:l}=oe.useUiLabelContext(),{isView:j,metadataOptions:R}=ge(),m=n.useMemo(()=>[{key:"activity_type",label:`${l("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}],[l]),x=n.useCallback((h,r)=>{const c=m.find(M=>M.key===h);if(!c)return;const g=c.multi?(r??[]).map(M=>M.id):r?[r.id]:[];o(M=>[...M.filter(w=>Object.values(R||{}).flat().find(y=>y.id===w)&&!Object.keys(R||{}).find(y=>R?.[y]?.some(d=>d.id===w&&y===h))),...g])},[m,R,o]);return R?e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(le,{children:"Metadata Tags"}),e.jsxRuntimeExports.jsx(t.HStack,{gap:"1rem",align:"start",children:m.map(h=>e.jsxRuntimeExports.jsxs(t.FormControl,{flex:"1",children:[e.jsxRuntimeExports.jsx(t.FormLabel,{fontSize:"sm",children:h.label}),e.jsxRuntimeExports.jsx(re.st,{isMulti:h.multi,value:R[h.key]?.filter(r=>i.includes(r.id)),onChange:r=>{x(h.key,r)},options:R[h.key],placeholder:`Select ${h.multi?"one or more":"one"} ${h.label.toLowerCase()}`,isDisabled:j,isClearable:h.multi})]},h.key))})]}):null}),Oe=({value:i,onChange:o,forceKind:l,disableRemove:j,disableKind:R,isDisabled:m,lockRanges:x,...h})=>{const r=n.useMemo(()=>[...i].sort((v,w)=>{const S=xe.availablePlanes.indexOf(v.plane),y=xe.availablePlanes.indexOf(w.plane);return S-y}),[i]),c=n.useCallback(v=>"segment"in v.id?ae.getSegmentNameWithPlane(v.id.segment,v.plane,!0)??"Unknown":ae.getJointNameWithPlane(v.id.joint,v.plane,!0)??"Unknown",[]),g=n.useCallback((v,w)=>{const S=r.findIndex(d=>d.id===w.id&&d.plane===w.plane);let y=[...r];l&&(w={...w,kind:l}),y[S]=w,x&&(y=y.map(d=>({...d,min:w.min,max:w.max}))),o(y)},[o,r,l,x]),M=n.useCallback(v=>{const w=r.filter(S=>S.id!==v.id||S.plane!==v.plane);o(w)},[o,r]);return e.jsxRuntimeExports.jsx(t.VStack,{alignItems:"flex-start",overflowY:"auto",...h,children:r.map((v,w)=>e.jsxRuntimeExports.jsx(st,{label:c(v),parameter:v,onChange:S=>g(w,S),onRemove:j||m?void 0:()=>M(v),forceKind:l,disableKind:R||m,isDisabled:m},`${JSON.stringify(v.id)}-${v.plane}`))})},st=({label:i,parameter:o,onChange:l,onRemove:j,forceKind:R,disableKind:m,isDisabled:x})=>{const h=n.useCallback(g=>"joint"in o.id?ae.getJointAngleDirectionName(o.id.joint,o.plane,g<0?-1:1):ae.getSegmentAngleDirectionName(o.id.segment,o.plane,g<0?-1:1),[o]),{min:r,max:c}="joint"in o.id?ae.getNormativeJointRange(o.id.joint,o.plane):{min:-180,max:180};return e.jsxRuntimeExports.jsxs(t.VStack,{borderRadius:"md",p:2,px:4,bg:"gray.100",w:"100%",overflow:"hidden",flexShrink:"0",children:[e.jsxRuntimeExports.jsxs(t.HStack,{w:"100%",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",flex:1,textTransform:"capitalize",fontWeight:"semibold",children:i}),o.sensorOnly&&e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor Only"}),j&&!x&&e.jsxRuntimeExports.jsx(t.IconButton,{size:"xs",variant:"ghost","aria-label":"delete",icon:e.jsxRuntimeExports.jsx(t.Icon,{as:Me.FaTrash}),onClick:j}),!R&&e.jsxRuntimeExports.jsx(Ge,{selectedItem:o?.kind??P.ThresholdKind.Limit,onChange:({value:g})=>l({...o,kind:g}),isDisabled:m||x,buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:P.ThresholdKind.Limit,label:"limit"},{value:P.ThresholdKind.Target,label:"target"}]})]}),e.jsxRuntimeExports.jsx(Pe,{w:"100%",size:"xs",min:r,max:c,zeroMarker:!0,value:[o.min,o.max],onChange:g=>l({...o,min:g[0],max:g[1]}),formatValue:g=>`${Math.abs(g)}°`,valueLabel:g=>h(g)??"",positiveNegativeLabels:h(0)?[h(-1)??"",h(1)??""]:void 0,isDisabled:x})]})},ye=(i,o)=>"segment"in i&&"segment"in o&&i.segment===o.segment||"joint"in i&&"joint"in o&&i.joint===o.joint,Ae=({options:i,value:o,onChange:l,forceKind:j,singleValue:R,singleValueSideless:m,editOnly:x,disableKind:h,maxParameters:r,...c})=>{const g=m?2:r,M=n.useMemo(()=>{const d=new Map;return i.forEach(p=>{const T="joint"in p.id;let b,L;if(T?(b=ae.getJointNameWithPlane(p.id.joint,p.plane,!0)??"Unknown",L=`joint:${p.id.joint}`):(b=ae.getSegmentNameWithPlane(p.id.segment,p.plane,!0)??"Unknown",L=`segment:${p.id.segment}`),!d.has(L)){const F=T?ae.getPartName(p.id.joint)??"Unknown Joint":ae.getPartName(p.id.segment)??"Unknown Segment";d.set(L,{label:F,options:[]})}const N=d.get(L),D=[b,T?p.id.joint:p.id.segment,p.plane].filter(Boolean).map(F=>String(F).toLowerCase().replace(/\s+|_/g,""));N.options.push({label:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:2,justify:"space-between",w:"100%",pl:3,children:[e.jsxRuntimeExports.jsx(t.Text,{children:b}),p.sensorOnly&&e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor Only"})]}),value:p.id,plane:p.plane,sensorOnly:p.sensorOnly,searchTokens:D})}),Array.from(d.values())},[i]),v=n.useMemo(()=>{if(!m||o.length===0)return M;const d=o[0];return M.map(p=>({...p,options:p.options.filter(T=>xe.getAnalysisPartIdNoSide(T.value)===xe.getAnalysisPartIdNoSide(d.id)&&T.plane===d.plane)})).filter(p=>p.options.length>0)},[M,o,m]),w=n.useMemo(()=>M.flatMap(p=>p.options).filter(p=>o.some(T=>ye(T.id,p.value)&&T.plane===p.plane)),[M,o]),S=n.useCallback((d,p)=>{if(!p)return!0;const T=p.toLowerCase().replace(/\s+|_/g,""),b=d.data;return!b||!b.searchTokens?!1:b.searchTokens.some(L=>L.includes(T))},[]),y=n.useCallback(d=>{const p=d.map(T=>{const b=o.find(O=>ye(O.id,T.value)&&O.plane===T.plane),L=i.find(O=>ye(O.id,T.value)&&O.plane===T.plane),N=m?o.find(O=>xe.getAnalysisPartIdNoSide(O.id)===xe.getAnalysisPartIdNoSide(T.value)&&O.plane===T.plane):void 0,D=N&&!b?N.min:L&&L.min?L.min:0,F=N&&!b?N.max:L&&L.max?L.max:0;return b??{id:T.value,plane:T.plane,min:D,max:F,sensorOnly:T.sensorOnly,kind:j??P.ThresholdKind.Limit}});l(p)},[l,o,i,j,m]);return n.useEffect(()=>{const d=o.filter(p=>i.some(T=>ye(T.id,p.id)&&T.plane===p.plane));d.length!==o.length&&l(d)},[i,l,o]),e.jsxRuntimeExports.jsxs(t.Box,{...c,children:[e.jsxRuntimeExports.jsx(re.st,{isMulti:!R,placeholder:o.length?`${o.length} selected`:"Search...",value:w,isDisabled:x||w.length>=(g??1/0),onChange:d=>Array.isArray(d)?y([...d]):y(d!==null?[d]:[]),options:v,controlShouldRenderValue:!1,formatOptionLabel:d=>d.label,filterOption:S,isSearchable:!0}),e.jsxRuntimeExports.jsx(Oe,{marginTop:2,maxH:"28rem",value:o,onChange:l,forceKind:j,disableKind:h,isDisabled:x,lockRanges:m})]})},Fe=i=>{switch(i){case P.SensorLocation.Thorax:return"Thorax";case P.SensorLocation.CenterBack:return"Center Back";case P.SensorLocation.Pelvis:return"Pelvis";case P.SensorLocation.LeftThigh:return"Left Thigh";case P.SensorLocation.RightThigh:return"Right Thigh";case P.SensorLocation.LeftShank:return"Left Shank";case P.SensorLocation.RightShank:return"Right Shank";case P.SensorLocation.LeftFoot:return"Left Foot";case P.SensorLocation.RightFoot:return"Right Foot";case P.SensorLocation.LeftUpperArm:return"Left Upper Arm";case P.SensorLocation.RightUpperArm:return"Right Upper Arm";case P.SensorLocation.LeftForearm:return"Left Forearm";case P.SensorLocation.RightForearm:return"Right Forearm";case P.SensorLocation.Head:return"Head"}},nt=i=>{switch(i){case P.ReportKind.GeneralActivity:return"General Activity";case P.ReportKind.MovementCoordination:return"Movement Coordination";case P.ReportKind.PointOfInterest:return"Point of Interest";case P.ReportKind.Range:return"Range";case P.ReportKind.StabilityBalance:return"Stability Balance"}},ot=({id:i,onError:o,onCancel:l,onSave:j,hideButtons:R,setButtonOnClick:m,setButtonDisabled:x,quantumOwned:h,isView:r})=>{const c=ee.useClient(),[{fetching:g},M]=ee.useMutation(E.CREATE_ACTION),[{fetching:v},w]=ee.useMutation(E.UPDATE_ACTION),[{data:S}]=ee.useQuery({query:E.GET_ACTION_BY_ID,variables:{id:i??""},pause:!i}),y=n.useMemo(()=>{const f=A.getFragmentData(E.ACTION_FRAGMENT,S?.getActionById);if(!f)return null;const G=A.getFragmentData(E.REPORT_FRAGMENT,f.reports).map(W=>({...W,thresholds:A.getFragmentData(E.THRESHOLD_FRAGMENT,W.thresholds)}));return{...f,thresholds:A.getFragmentData(E.THRESHOLD_FRAGMENT,f.thresholds),reports:G}},[S]),d=g||v,p=!!y&&!!i,{getLabel:T}=oe.useUiLabelContext(),b=n.useMemo(()=>({action:T("action")}),[T]),L=n.useMemo(()=>[{key:"module_category",label:"Link Category",multi:!0},{key:"activity_type",label:`${b.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}],[b.action]),[N,D]=n.useState(""),[F,O]=n.useState(""),[Y,se]=n.useState(""),[k,V]=n.useState(""),[X,I]=n.useState([]),[$,J]=n.useState({}),[z,H]=n.useState(null),[u,s]=n.useState([]),[a,C]=n.useState([]),[q,Q]=n.useState(""),[B,_]=n.useState([]),K=oe.useAllPartParameters(),ce=n.useMemo(()=>K.filter(f=>f.sensorOnly),[K]),de=n.useMemo(()=>{const f=[{label:"General Activity",value:P.ReportKind.GeneralActivity},{label:"Movement Coordination",value:P.ReportKind.MovementCoordination},{label:"Point of Interest",value:P.ReportKind.PointOfInterest},{label:"Range",value:P.ReportKind.Range},{label:"Stability Balance",value:P.ReportKind.StabilityBalance}],U=B.map(G=>G.kind);return f.filter(G=>!U.includes(G.value))},[B]),Re=N.length>0,[Ee,we]=n.useState({});n.useEffect(()=>{const f=L.map(U=>c.query(E.GET_METADATA_BY_KEY,{key:U.key}));Promise.all(f).then(U=>{const G={};U.forEach(W=>{if(W.error||!W.data)return;const Z=A.getFragmentData(E.METADATA_GROUP_FRAGMENT,W.data.getMetadataByKey),te=A.getFragmentData(E.METADATA_ITEM_FRAGMENT,Z.data);G[Z.key]=te.map(ie=>({label:ie.label||ie.value,value:ie.value,id:ie.id}))}),J(G)})},[c,L]),n.useEffect(()=>{if(y){const U=A.getFragmentData(E.METADATA_GROUP_FRAGMENT,y.metadataGroups).map(Z=>Z.data.map(te=>A.getFragmentData(E.METADATA_ITEM_FRAGMENT,te).id)),G=y.reports.map(Z=>({id:Z.id,instructions:Z.instructions??"",kind:Z.reportKind,parameters:Z.thresholds.map(te=>({id:{[te.partKind]:te.partId},kind:te.kind,min:te.min,max:te.max,plane:te.partDimension,oldId:te.id,sensorOnly:ce.some(ie=>{const ve=ie.id[te.partKind];return ve?ve===te.partId&&ie.plane===te.partDimension:!1})})),sensorLocations:Z.sensorLocations})),W={name:y.name,description:y.description||"",cameraPlacement:y.cameraPlacement||"",videoLink:y.videoLink||"",metadataIds:U.flat(),reports:G};D(W.name),O(W.description),se(W.cameraPlacement),V(W.videoLink),I(W.metadataIds),_(G),we(W)}},[y]);const me=n.useMemo(()=>JSON.stringify(Ee)!==JSON.stringify({name:N,description:F,cameraPlacement:Y,videoLink:k,metadataIds:X,reports:B}),[Ee,N,F,Y,k,X,B]),pe=n.useCallback(()=>{const f={name:N,description:F,cameraPlacement:Y,videoLink:k,metadataItemIds:X,laterality:P.ActionLaterality.Either,quantumOwned:h,sessionType:[],thresholds:[],reports:B.map(G=>({id:G.isNew?void 0:G.id,reportKind:G.kind,sensorLocations:G.sensorLocations,instructions:G.instructions,thresholds:G.parameters.map(W=>({id:W.oldId,kind:W.kind,min:W.min,max:W.max,partKind:"joint"in W.id?"joint":"segment",partId:"joint"in W.id?W.id.joint:W.id.segment,partDimension:W.plane}))}))};let U;p&&i?U=w({id:i,fields:f}):U=M({fields:f}),U.then(({error:G})=>{G?o(G):j()})},[h,M,w,i,N,F,Y,k,X,B,p,j,o]);n.useEffect(()=>{x&&x({cancelButton:d,saveButton:r?!0:d||!Re||!me})},[d,x,Re,me,r]),n.useEffect(()=>{m&&m({cancelButton:l,saveButton:r?()=>{}:pe})},[m,l,pe,r]);const fe=n.useCallback(f=>{const U=ae.getSuggestedSensorLocations(f.map(G=>"joint"in G.id?G.id.joint:G.id.segment));C(U)},[]);n.useEffect(()=>{fe(u)},[u,fe]);const je=n.useCallback(()=>{if(!z)return;const f=z===P.ReportKind.PointOfInterest,U={id:Date.now().toString(),kind:z,parameters:f?[]:u,sensorLocations:f?[]:a,instructions:f?q:"",isNew:!0};_(G=>[...G,U]),H(null),s([]),C([]),Q("")},[z,u,a,q]),ue=n.useCallback(f=>{_(U=>U.filter(G=>G.id!==f))},[]),he=(f,U)=>{const G=L.find(Z=>Z.key===f);if(!G)return;const W=G.multi?(U??[]).map(Z=>Z.id):U?[U.id]:[];I(Z=>[...Z.filter(ie=>Object.values($).flat().find(be=>be.id===ie)&&!Object.keys($).find(be=>$[be]?.some(Ne=>Ne.id===ie&&be===f))),...W])};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:"Basic Information"}),e.jsxRuntimeExports.jsx(t.Tab,{children:"Reports"})]}),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(ne,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:N,onChange:f=>D(f.target.value),type:"text",placeholder:"i.e. Lunge & Return",isDisabled:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Camera Placement"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:Y,onChange:f=>se(f.target.value),rows:2,placeholder:"(optional) Describe camera setup, placement, angles",isDisabled:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Video Link"}),e.jsxRuntimeExports.jsx(t.Input,{value:k,onChange:f=>V(f.target.value),type:"url",placeholder:"(optional) https://...",isDisabled:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Description"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:F,onChange:f=>O(f.target.value),rows:2,placeholder:"(optional) Describe how to perform the test or exercise",isDisabled:r})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(ne,{children:"Metadata Tags"}),L.map(f=>e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:f.label}),e.jsxRuntimeExports.jsx(re.st,{isMulti:f.multi,value:$[f.key]?.filter(U=>X.includes(U.id)),onChange:U=>{he(f.key,U)},options:$[f.key],placeholder:`Select ${f.multi?"one or more":"one"} ${f.label.toLowerCase()}`,isDisabled:r,isClearable:f.multi})]},f.key))]})]})}),e.jsxRuntimeExports.jsx(t.TabPanel,{px:0,children:e.jsxRuntimeExports.jsxs("div",{className:Te.cn("grid grid-cols-1 gap-6",!r&&"md:grid-cols-2"),children:[e.jsxRuntimeExports.jsxs("div",{className:Te.cn("space-y-4",r&&"hidden"),children:[e.jsxRuntimeExports.jsx(ne,{children:"Add New Report"}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Report Kind"}),de.length===0?e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",p:2,children:"All report kinds have been used. Remove an existing report to add a new one."}):e.jsxRuntimeExports.jsx(re.st,{value:z?de.find(f=>f.value===z):null,onChange:f=>H(f?.value||null),options:de,placeholder:"Select report kind...",isDisabled:r,isClearable:!0})]}),z!==P.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(Ae,{options:K,value:u,onChange:s,editOnly:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Suggested Sensor Locations"}),e.jsxRuntimeExports.jsx(t.Input,{value:a.map(f=>Fe(f)).join(", "),placeholder:"Auto-filled based on parameters...",isDisabled:!0})]})]}),z===P.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:q,onChange:f=>Q(f.target.value),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:r})]}),e.jsxRuntimeExports.jsx("div",{className:"w-full flex justify-end",children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:je,isDisabled:!z||r||de.length===0||z!==P.ReportKind.PointOfInterest&&u.length===0,children:"Add Report"})})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(ne,{children:"Configured Reports"}),B.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:B.map(f=>e.jsxRuntimeExports.jsxs("div",{className:"p-3 border border-gray-200 rounded-md bg-gray-50",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex justify-between items-start mb-2",children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"semibold",children:nt(f.kind)}),!r&&e.jsxRuntimeExports.jsx(t.Button,{size:"xs",colorScheme:"red",variant:"ghost",onClick:()=>ue(f.id),children:"Remove"})]}),f.kind===P.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:f.instructions,onChange:U=>_(G=>G.map(W=>W.id===f.id?{...W,instructions:U.target.value}:W)),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:r})]}),f.kind!==P.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsx(Ae,{options:K,value:f.parameters,onChange:U=>{const G=U.map(Z=>Z.id.joint??Z.id.segment),W=ae.getSuggestedSensorLocations(G);_(Z=>Z.map(te=>te.id===f.id?{...te,parameters:U,sensorLocations:W}:te))},editOnly:r}),f.kind!==P.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",mt:2,children:["Sensors:"," ",f.sensorLocations.map(U=>Fe(U)).join(", ")]})]},f.id))})]})]})})]})]}),e.jsxRuntimeExports.jsx(t.HStack,{justify:"end",className:Te.cn((R||r)&&"!hidden"),children:e.jsxRuntimeExports.jsxs(t.ButtonGroup,{gap:4,children:[e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:d,onClick:l,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:d||!Re||!me,isLoading:d,onClick:pe,children:"Save changes"})]})})]})},ne=({children:i})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:i}),rt=({children:i,isView:o,metadataKeys:l})=>{const[j,R]=n.useState({}),m=ee.useClient();return n.useEffect(()=>{let x=!1;return(async()=>{const r=(l??[]).map(M=>m.query(E.GET_METADATA_BY_KEY,{key:M}).toPromise()),c=await Promise.all(r),g={};for(const M of c){if(M.error||!M.data?.getMetadataByKey)continue;const v=A.getFragmentData(E.METADATA_GROUP_FRAGMENT,M.data.getMetadataByKey);if(!v)continue;const w=A.getFragmentData(E.METADATA_ITEM_FRAGMENT,v.data)??[];g[v.key]=w.map(S=>({label:S.label||S.value,value:S.value,id:S.id}))}x||R(g)})(),()=>{x=!0}},[m,l]),e.jsxRuntimeExports.jsx(Ie.Provider,{value:{isView:o,metadataOptions:j},children:i})},it=({id:i,onCancel:o,onSave:l,onError:j,hideButtons:R,quantumOwned:m,setButtonOnClick:x,setButtonDisabled:h,isView:r})=>{const[{data:c,fetching:g}]=ee.useQuery({query:m?E.GET_QUANTUM_OWNED_ACTIONS:E.GET_ACTIONS}),[{data:M}]=ee.useQuery({query:E.GET_MODULE_BY_ID,variables:{id:i},pause:!i}),[{data:v}]=ee.useQuery({query:E.GET_ALL_MODULE_CATEGORIES}),w=A.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,v?.moduleCategories),[{fetching:S},y]=ee.useMutation(E.UPDATE_MODULE),[{fetching:d},p]=ee.useMutation(E.CREATE_MODULE),T=n.useMemo(()=>!c||g?[]:A.getFragmentData(E.ACTION_FRAGMENT,m?c?.quantumOwnedActions??[]:c?.actions??[]).filter(u=>!!u?.id),[c,m,g]),b=A.getFragmentData(E.ACTION_MODULE_FRAGMENT,M?.module),L=n.useMemo(()=>A.getFragmentData(E.MODULE_ACTION_FRAGMENT,b?.moduleActions)??[],[b?.moduleActions]),[N,D]=n.useState([...L.map(H=>H.actionId)??[]]),[F,O]=n.useState(b?.name??""),[Y,se]=n.useState([]),[k,V]=n.useState(b?.description??""),[X,I]=n.useState([]),[$,J]=n.useState({});n.useEffect(()=>{if(b){D(L.map(a=>a.actionId)),O(b.name),V(b.description??""),se(b.categories.map(a=>A.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,a).id)??[]);const u=A.getFragmentData(E.METADATA_GROUP_FRAGMENT,b.metadataGroups).map(a=>a.data.map(C=>A.getFragmentData(E.METADATA_ITEM_FRAGMENT,C).id));I(u.flat());const s={};L.forEach(a=>{s[a.actionId]=a.reportId||null}),J(s)}},[b,L]);const z=n.useCallback(()=>{let H;const u=Object.entries($).filter(([,a])=>a!==null).map(([a,C])=>({actionId:a,reportId:C})),s={actions:N,name:F,categories:Y.filter(a=>a!=="other"),description:k,quantumOwned:m,metadataItemIds:X,actionReports:u};b?H=y({id:b.id,input:s}):H=p({input:s}),H.then(({error:a})=>{a?j(a instanceof Error?a:new Error(String(a))):l()})},[p,y,N,F,k,Y,X,$,b,l,j,m]);return n.useEffect(()=>{h&&h({cancelButton:S||d,saveButton:S||d||!F||k.trim().split(/\s+/).filter(Boolean).length>40})},[h,S,d,N,F,k]),n.useEffect(()=>{x&&x({cancelButton:o,saveButton:z})},[x,o,z]),e.jsxRuntimeExports.jsx(t.Box,{width:"100%",children:e.jsxRuntimeExports.jsxs(rt,{isView:r,metadataKeys:["activity_type","session_type","body_region","sport"],children:[e.jsxRuntimeExports.jsx(ke,{name:F,setName:O,actions:T,selectedActionIds:N,setSelectedActionIds:D,availableCategories:w??[],selectedCategoryIds:Y,setSelectedCategoryIds:se,description:k,setDescription:V,selectedMetadataIds:X,setSelectedMetadataIds:I,actionReportIds:$,setActionReportIds:J}),!R&&!r&&e.jsxRuntimeExports.jsx(t.HStack,{justifyContent:"flex-start",children:e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mt:16,gap:4,children:[e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:S||d,onClick:o,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:S||d||!F||k.trim().split(/\s+/).filter(Boolean).length>40,isLoading:S||d,onClick:z,children:"Save"})]})})]})})};exports.ActivityList=Le;exports.CopyActivityForm=He;exports.CopyModuleForm=Ke;exports.ModuleForm=ke;exports.ParameterEditList=Oe;exports.ParameterEditSelect=Ae;exports.UpsertActivityForm=ot;exports.UpsertModuleForm=it;
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"),n=require("react"),A=require("./generated.cjs"),E=require("./graphql-Dm6zPwG7.cjs"),Te=require("./utils-cn-FIKrq5Mb.cjs");require("./lodash-vendor-BXoJ3fY7.cjs");const ee=require("urql"),re=require("./hooks.cjs"),Pe=require("./ufuzzy-vendor-7qHa_k39.cjs"),ie=require("./react-select-vendor-2_u9DhYj.cjs"),Se=require("./react-icons-vendor-BF_sZq07.cjs"),me=require("./services.cjs"),Me=require("./react-dnd-vendor-GZ764FSN.cjs"),ce=require("./services-human-BelpNNkM.cjs"),_=require("./generated-graphql.cjs"),pe=require("./types.cjs"),Be=({setSearch:i,actions:o,updateUseCases:l,hideUseCaseFilter:j=!1})=>{const R=n.useMemo(()=>o?.flatMap(p=>p.useCases).filter((p,m,h)=>h.findIndex(r=>r.id===p.id)===m).map(p=>({label:p.name,value:p.id}))||[],[o]);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:Se.FaSearch,color:"gray.300"})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"Search by name...",width:"100%",maxW:j?void 0:"30rem",onChange:p=>i(p.target.value)})]}),!j&&e.jsxRuntimeExports.jsx(t.InputGroup,{size:"md",children:e.jsxRuntimeExports.jsx(ie.st,{size:"md",chakraStyles:{container:p=>({...p,width:"100%"})},menuPortalTarget:document.body,placeholder:"Filter use case",isMulti:!0,options:R,onChange:p=>l(p.map(m=>m.value))})})]})},ue=({children:i})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:i}),$e=({items:i,onChange:o,selectedItem:l,isDisabled:j,selectedProps:R,buttonProps:p})=>{const m=r=>r===l||r.value===l,h=r=>m(r)?{...p,...R}:p;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:j,children:i.map((r,c)=>e.jsxRuntimeExports.jsx(t.Tooltip,{label:r.tooltip,openDelay:50,closeDelay:200,placement:"top",visibility:r.tooltip?"visible":"hidden",hasArrow:!0,children:e.jsxRuntimeExports.jsx(t.Button,{onClick:()=>m(r)?null:o(r,c),isDisabled:r.disabled,...h(r),children:r.label})},c))})},Ce=(i,o)=>o<0?-1*Math.abs(i):Math.abs(i),Ue=({isReversed:i,min:o,max:l,value:j,onChange:R,inputProps:p,size:m,zeroMarker:h,formatValue:r,valueLabel:c,positiveNegativeLabels:g,isDisabled:S,...v})=>{const[w,M]=n.useState([void 0,void 0]),T=w[0],d=w[1],x=h&&o<-5&&l>5,C=Number(j?.[0]??d??o)>0?1:-1,b=Number(j?.[1]??d??l)<0?-1:1,L=g?.[0]===g?.[1],O=j?.[0],D=j?.[1];n.useEffect(()=>{O!==void 0&&D!==void 0&&M([O.toFixed(0),D.toFixed(0)])},[O,D,M]);const F=n.useCallback(([I,$])=>{I<$&&M([I.toFixed(0),$.toFixed(0)])},[M]),N=n.useCallback(([I,$])=>{I<$&&R([I,$])},[R]),Y=n.useCallback(()=>{M(([I,$])=>{const J=isNaN(Number(I))?o:Number(I),z=isNaN(Number($))?l:Number($),H=Ce(Number(J),C),u=Ce(Number(z),b),s=C<0?Math.max(H,o):Math.min(H,l),a=b<0?Math.max(u,o):Math.min(u,l);return s>a?(R([a,s]),[a.toFixed(0),s.toFixed(0)]):(R([s,a]),[s.toFixed(0),a.toFixed(0)])})},[R,M,C,b,o,l]),se=n.useCallback(I=>{const $=I===""||isNaN(Number(I))?I:Ce(Number(I),C);M(([J,z])=>[$.toString(),z])},[M,C]),k=n.useCallback(I=>{const $=I===""||isNaN(Number(I))?I:Ce(Number(I),b);M(([J,z])=>[J,$.toString()])},[M,b]),X=n.useMemo(()=>m==="xs"?"0.75rem":void 0,[m]),Z=n.useCallback((I,$)=>{const J=Number($.target.value);if(!T||!d||![-1,1].includes(J))return;const z=s=>J<0?-1*Math.abs(s):Math.abs(s),H=I?z(Number(T)):Number(T),u=I?Number(d):z(Number(d));H>u?R([u,H]):R([H,u])},[T,d,R]);return e.jsxRuntimeExports.jsxs(t.Flex,{direction:"column",...v,children:[e.jsxRuntimeExports.jsx(t.Box,{pt:"1em",mb:"-0.5em",children:e.jsxRuntimeExports.jsxs(t.RangeSlider,{"aria-label":["min","max"],isReversed:i,value:[Number(T??o),Number(d??l)],max:l,min:o,minStepsBetweenThumbs:3,step:1,onChange:F,onChangeEnd:N,isDisabled:S,children:[e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:o,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:m??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:r?r?.(o):o})}),e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:l,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:m??"sm",fontWeight:"semibold",style:{transform:"translateX(-100%)"},whiteSpace:"nowrap",children:r?r(l):l})}),x&&e.jsxRuntimeExports.jsxs(t.RangeSliderMark,{value:0,top:"-1em",pos:"relative",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:m,fontWeight:"semibold",children:r?.(0)??"0"}),e.jsxRuntimeExports.jsx(t.Box,{position:"absolute",width:"2px",height:"1em",top:"90%",left:"20%",backgroundColor:"var(--chakra-colors-gray-300)"})]}),e.jsxRuntimeExports.jsx(t.RangeSliderTrack,{children:e.jsxRuntimeExports.jsx(t.RangeSliderFilledTrack,{})}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:0,w:X,h:X}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:1,w:X,h:X})]})}),c&&e.jsxRuntimeExports.jsxs(t.Flex,{direction:i?"row-reverse":"row",justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:m??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:c(o)}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:m??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:c(l)})]}),e.jsxRuntimeExports.jsxs(t.Flex,{direction:i?"row-reverse":"row",justifyContent:"center",alignItems:"center",gap:"0.125em",children:[g&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:m,fontWeight:"bold",value:C,onChange:I=>Z(!0,I),isDisabled:L||S,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:g[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:g[1]})]}),e.jsxRuntimeExports.jsx(t.NumberInput,{precision:0,size:m??"sm",min:0,max:C<0?Math.abs(o):D??l,value:T===""?"":Math.abs(Number(T??o)),onChange:se,onBlur:Y,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:S,...p,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),e.jsxRuntimeExports.jsx(t.NumberInput,{size:m??"sm",min:0,max:b<0?Math.abs(O??o):l,precision:0,value:d===""?"":Math.abs(Number(d??l)),onChange:k,onBlur:Y,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:S,...p,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),g&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:m,fontWeight:"bold",value:b,onChange:I=>Z(!1,I),isDisabled:L||S,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:g[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:g[1]})]})]})]})},ze=({tags:i,containerProps:o,...l})=>e.jsxRuntimeExports.jsx(t.HStack,{...o,children:i.map((j,R)=>e.jsxRuntimeExports.jsx(t.Tag,{...l,children:j},R))}),qe=new Pe.uFuzzy({}),We=({action:i,quantumIconSrc:o})=>{const{getLabel:l}=re.useUiLabelContext(),j=n.useMemo(()=>({actionLowerCase:l("action").toLocaleLowerCase()}),[l]);return i.quantumOwned?e.jsxRuntimeExports.jsx(t.Tooltip,{label:`This ${j.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:o,boxSize:"1em",alt:`Quantum-owned ${j.actionLowerCase}`})})}):null},Ke=(i,o)=>{if(!o||!o.trim().length)return i;const l=i.map(R=>R.name??"");return qe.filter(l,o)?.map(R=>i[R])??[]},Qe=i=>!i||i.length===0?"None":i.map(o=>o.replace(/([A-Z])/g," $1").trim()).join(", "),He=(i,o)=>!o||o.length==0?i:i.filter(l=>l.useCases?.some(j=>o.includes(j.id))??!1),Ye=(i,o,l)=>!o||o.length===0?i:i.filter(j=>{const R={};return o.forEach(p=>{for(const[m,h]of Object.entries(l||{}))if(h.some(r=>r.id===p)){R[m]||(R[m]=[]),R[m].push(p);break}}),Object.entries(R).every(([p,m])=>{const h=j.metadataGroups?.find(S=>A.getFragmentData(E.METADATA_GROUP_FRAGMENT,S).key===p);if(!h)return!1;const r=A.getFragmentData(E.METADATA_GROUP_FRAGMENT,h),g=A.getFragmentData(E.METADATA_ITEM_FRAGMENT,r.data).map(S=>S.id);return m.some(S=>g.includes(S))})}),Ie=({actions:i,totalActions:o,onCreate:l,onDelete:j,onEdit:R,onView:p,onSelected:m,onDuplicate:h,disableMultiSelect:r,disableDelete:c,disableEdit:g,disableCreate:S,hideUseCase:v=!0,showMetadataFilters:w=!0,tableProps:M,containerProps:T,quantumIconSrc:d="/favicon.ico"})=>{const[x,C]=n.useState(""),[b,L]=n.useState(),[O,D]=n.useState([]),[F,N]=n.useState({}),{getLabel:Y}=re.useUiLabelContext(),se=ee.useClient(),k=n.useMemo(()=>({action:Y("action"),actionPlural:Y("action_plural"),actionLowerCase:Y("action").toLocaleLowerCase(),actionPluralLowerCase:Y("action_plural").toLocaleLowerCase()}),[Y]),X=n.useMemo(()=>[{key:"module_category",label:"Link Category",multi:!0},{key:"activity_type",label:`${k.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}],[k.action]);n.useEffect(()=>{if(!w)return;const s=X.map(a=>se.query(E.GET_METADATA_BY_KEY,{key:a.key}));Promise.all(s).then(a=>{const y={};a.forEach(q=>{if(q.error||!q.data)return;const K=A.getFragmentData(E.METADATA_GROUP_FRAGMENT,q.data.getMetadataByKey),W=A.getFragmentData(E.METADATA_ITEM_FRAGMENT,K.data);y[K.key]=W.map(B=>({label:B.label||B.value,value:B.value,id:B.id}))}),N(y)})},[se,X,w]);const Z=n.useMemo(()=>{if(!i)return;const s=Ke(i,x),a=v?s:He(s,b);return w?Ye(a,O,F):a},[i,x,b,v,w,O,F]),I=n.useCallback(()=>{if(!j)return;const a=i.filter(y=>y.selected&&!y.quantumOwned).map(y=>y.id);j(a)},[i,j]),$=n.useCallback(()=>{if(!h)return;const s=i.filter(a=>a.selected);h(s.map(a=>a.id)),m&&s.forEach(a=>m(a,!1))},[i,h,m]),J=n.useMemo(()=>i.some(s=>s.selected&&!s.quantumOwned),[i]),z=n.useMemo(()=>i.some(s=>s.selected),[i]),H=n.useMemo(()=>i.some(s=>s.selected&&s.quantumOwned),[i]),u=n.useCallback((s,a)=>{const y=X.find(K=>K.key===s);if(!y)return;const q=y.multi?(a??[]).map(K=>K.id):a?[a.id]:[];D(K=>[...K.filter(B=>Object.values(F).flat().find(oe=>oe.id===B)&&!Object.keys(F).find(oe=>F[oe]?.some(de=>de.id===B&&oe===s))),...q])},[X,F]);return e.jsxRuntimeExports.jsxs(t.Box,{...T,children:[e.jsxRuntimeExports.jsxs(t.Flex,{alignContent:"space-between",gap:4,children:[(l||j||h)&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mb:"1rem",gap:4,children:[l&&e.jsxRuntimeExports.jsxs(t.Button,{isDisabled:!l||S,colorScheme:"blackAlpha",backgroundColor:"gray.700",onClick:l,children:["Create New ",k.action]}),j&&!r&&e.jsxRuntimeExports.jsx(t.Tooltip,{label:H?J?`Quantum-owned ${k.actionPluralLowerCase} are selected and will be skipped`:`Selected ${k.actionPluralLowerCase} are quantum-owned and cannot be deleted`:void 0,shouldWrapChildren:!0,children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!J||!j||c,onClick:I,children:"Delete Selected"})}),h&&!r&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!z,onClick:$,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx(Be,{setSearch:C,actions:i,updateUseCases:L,hideUseCaseFilter:v})]}),w&&F&&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:X.map(s=>e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(t.FormLabel,{fontSize:"sm",children:s.label}),e.jsxRuntimeExports.jsx(ie.st,{chakraStyles:{menu:a=>({...a,zIndex:2})},isMulti:s.multi,value:F[s.key]?.filter(a=>O.includes(a.id)),onChange:a=>{u(s.key,a)},options:F[s.key],placeholder:`Select ${s.multi?"one or more":"one"} ${s.label.toLowerCase()}`,isClearable:s.multi})]},s.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"," ",o??i.length,")"]}),e.jsxRuntimeExports.jsx(t.Th,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Th,{children:"Sensor Locations"}),!v&&e.jsxRuntimeExports.jsx(t.Th,{children:"Use Case"}),e.jsxRuntimeExports.jsx(t.Th,{})]})}),e.jsxRuntimeExports.jsx(t.Tbody,{children:Z?.map(s=>e.jsxRuntimeExports.jsxs(t.Tr,{className:Te.cn("hover:bg-[#f7f7f7]",!r&&"cursor-pointer",s.selected&&"bg-gray-200"),onClick:()=>{r||m?.(s,!s.selected)},children:[e.jsxRuntimeExports.jsx(t.Td,{children:e.jsxRuntimeExports.jsxs(t.Flex,{children:[!r&&e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:s.selected?e.jsxRuntimeExports.jsx(Se.FaCheckSquare,{className:"text-blue-500"}):e.jsxRuntimeExports.jsx(Se.FaSquare,{className:"text-gray-400"})}),(s.quantumOwned||!R)&&p&&e.jsxRuntimeExports.jsx(t.Button,{ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:a=>{a.stopPropagation(),p(s.id)},children:"View"}),!s.quantumOwned&&R&&e.jsxRuntimeExports.jsx(t.Button,{isDisabled:g,ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:a=>{a.stopPropagation(),R(s.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:s,quantumIconSrc:d}),s.name]})}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",whiteSpace:"break-spaces",children:Qe(s.sensorLocations)}),!v&&e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:e.jsxRuntimeExports.jsx(ze,{containerProps:{flexWrap:"wrap"},tags:s.useCases?.map(a=>a.name)??[]})})]},s.id))})]})})]})},Je=({onSave:i,onCancel:o,onError:l,hideButtons:j=!1,setButtonDisabled:R,setButtonOnClick:p,quantumOwned:m})=>{const h=t.useToast(),{getLabel:r}=re.useUiLabelContext(),c=n.useMemo(()=>({singular:r("action"),plural:r("action_plural"),pluralLowerCase:r("action_plural").toLowerCase(),singularLowerCase:r("action").toLowerCase()}),[r]),[g,S]=n.useState("copy"),[v,w]=n.useState(""),[M,T]=n.useState([]),[d,x]=n.useState(!1),[C]=ee.useQuery({query:E.GET_GROUPS}),[b]=ee.useQuery({query:E.GET_ACTIONS_BY_GROUP,variables:{groupId:v},pause:!v}),[,L]=ee.useMutation(E.CREATE_ACTION),[,O]=ee.useMutation(E.CONVERT_ACTION_TO_QUANTUM_OWNED),D=n.useMemo(()=>C.data?.groups?C.data.groups.map(u=>A.getFragmentData(E.GROUP_FRAGMENT,u)):[],[C.data]),F=n.useMemo(()=>b.data?b.data.actions.map(s=>{const a=A.getFragmentData(E.ACTION_FRAGMENT,s),y=A.getFragmentData(E.REPORT_FRAGMENT,a.reports),q=A.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,a.categories),W=A.getFragmentData(E.METADATA_GROUP_FRAGMENT,a.metadataGroups).map(B=>({...B,data:B.data.map(Q=>A.getFragmentData(E.METADATA_ITEM_FRAGMENT,Q))}));return{...a,thresholds:A.getFragmentData(E.THRESHOLD_FRAGMENT,a.thresholds),reports:y.map(B=>({...B,thresholds:A.getFragmentData(E.THRESHOLD_FRAGMENT,B.thresholds)})),categories:q,metadataGroups:W}}):[],[b.data]),N=n.useMemo(()=>F.filter(u=>M.includes(u.id)),[F,M]),Y=n.useCallback(u=>{const s=u?.value||"";w(s),T([])},[]),se=n.useCallback(u=>{const s=u.map(a=>a.value);T(s)},[]),k=n.useCallback(async u=>{const s={...u,name:`${u.name} (Copy)`,description:u.description||void 0,instructionsPointOfInterest:u.instructionsPointOfInterest||void 0,instructionsMovementReport:u.instructionsMovementReport||void 0,laterality:u.laterality,activityKind:u.activityKind,sensorLocations:u.sensorLocations,thresholds:u.thresholds.map(y=>({...y,id:void 0})),categories:u.categories.map(y=>y.id),quantumOwned:m,metadataItemIds:u.metadataGroups.flatMap(y=>y.data.map(q=>q.id)).filter(y=>y!==void 0),reports:u.reports.map(y=>({...y,id:void 0,thresholds:y.thresholds.map(q=>({...q,id:void 0}))})),id:void 0},a=await L({fields:s});if(a.error)throw new Error(a.error.message);if(a.data?.createAction)return A.getFragmentData(E.ACTION_FRAGMENT,a.data.createAction);throw new Error("No action data returned")},[L,m]),X=n.useCallback(async u=>{const s=await O({id:u.id});if(s.error)throw new Error(s.error.message);if(s.data?.convertActionToQuantumOwned)return A.getFragmentData(E.ACTION_FRAGMENT,s.data.convertActionToQuantumOwned);throw new Error("No action data returned")},[O]),Z=n.useCallback(async()=>{if(x(!0),!N.length){const u=new Error(`No ${c.pluralLowerCase} selected for ${g==="copy"?"copying":"converting"}`);l?.(u),x(!1);return}try{const u=[];let s=0;const a=g==="copy"?k:X,y=g==="copy"?"copy":"convert";for(const q of N)try{const K=await a(q);u.push(K)}catch(K){console.error(`Failed to ${y} ${c.singularLowerCase} "${q.name}":`,K),s++}if(u.length>0){const q=u.length,K=N.length,W=g==="copy"?"copied":"converted",B=g==="copy"?"copy":"convert";h({title:s>0?`Partial ${B} completed`:`${c.plural} ${W} successfully`,description:s>0?`${q} of ${K} ${c.pluralLowerCase} ${W} successfully`:`${q} ${q>1?c.pluralLowerCase:c.singularLowerCase} ${W} successfully`,status:s>0?"warning":"success",duration:3e3,isClosable:!0}),i?.(),w(""),T([])}else throw new Error(`Failed to ${y} any ${c.pluralLowerCase}`)}catch(u){const s=g==="copy"?"copy":"convert",a=u instanceof Error?u.message:`Failed to ${s} ${c.pluralLowerCase}`;h({title:`${g==="copy"?"Copy":"Convert"} failed`,description:a,status:"error",duration:5e3,isClosable:!0}),l?.(u instanceof Error?u:new Error(a))}finally{x(!1)}},[N,g,k,X,h,i,l,c]),I=n.useCallback(()=>{w(""),T([]),S("copy"),o?.()},[o]);n.useEffect(()=>{R&&R({cancelButton:!1,saveButton:N.length===0||d})},[N.length,d,R]),n.useEffect(()=>{p&&p({cancelButton:I,saveButton:Z})},[p,I,Z]);const $=n.useMemo(()=>D.map(u=>({value:u.id,label:u.name})),[D]),J=n.useMemo(()=>F.filter(u=>g==="copy"?!0:!u.quantumOwned).map(u=>({value:u.id,label:u.name,isQuantumOwned:u.quantumOwned})),[F,g]),z=C.fetching,H=b.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[m&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:g,onChange:u=>{S(u),T([])},children:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:6,children:[e.jsxRuntimeExports.jsx(t.Radio,{value:"copy",colorScheme:"blue",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"medium",children:["Copy ",c.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",c.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 ",c.singular]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Convert existing"," ",c.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:$,value:$.find(u=>u.value===v)||null,onChange:Y,isLoading:z,isDisabled:z,isClearable:!0}),C.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",C.error.message]})]})]}),v&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsxs(ue,{children:["Select ",c.plural," to"," ",g==="copy"?"Copy":"Convert"]}),H?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 ",c.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(ie.st,{placeholder:`Choose ${c.pluralLowerCase} to ${g}...`,options:J,value:J.filter(u=>M.includes(u.value)),onChange:se,isDisabled:J.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(u,{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:u.label}),s==="value"&&u.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),u.isQuantumOwned&&s==="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 ",c.pluralLowerCase," found"]})]}),b.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load ",c.pluralLowerCase,":"," ",b.error.message]})]})]}),N.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:N.length===1?`${c.singular} to ${g==="copy"?"Copy":"Convert"}:`:`${N.length} ${c.plural} to ${g==="copy"?"Copy":"Convert"}:`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[N.map((u,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,". ",u.name]}),u.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:[u.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",u.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Type:"})," ",u.activityKind]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Laterality:"})," ",u.laterality]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Sensor Locations:"})," ",u.sensorLocations.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Thresholds:"})," ",u.thresholds.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Use Cases:"})," ",u.useCases.map(a=>a.name).join(", ")||"None"]})]})]},u.id)),N.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: ",N.length," ",c.pluralLowerCase," will be"," ",g==="copy"?"copied":"converted"]})})]})]}),!j&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:I,isDisabled:d,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:g==="copy"?"blue":"green",onClick:Z,isDisabled:N.length===0||d,isLoading:d,loadingText:`${g==="copy"?"Copying":"Converting"}...`,children:[g==="copy"?"Copy":"Convert"," ",N.length===1?c.singular:`${N.length} ${c.plural}`]})]})]})})},Ve=({onSave:i,onCancel:o,onError:l,hideButtons:j=!1,setButtonDisabled:R,setButtonOnClick:p,quantumOwned:m})=>{const h=t.useToast(),{getLabel:r}=re.useUiLabelContext(),c=n.useMemo(()=>({singular:r("module"),plural:r("module_plural"),pluralLowerCase:r("module_plural").toLowerCase(),singularLowerCase:r("module").toLowerCase()}),[r]),g=n.useMemo(()=>({singular:r("action"),plural:r("action_plural"),pluralLowerCase:r("action_plural").toLowerCase(),singularLowerCase:r("action").toLowerCase()}),[r]),[S,v]=n.useState(""),[w,M]=n.useState([]),[T,d]=n.useState(!1),[x,C]=n.useState("copy"),[b]=ee.useQuery({query:E.GET_GROUPS}),[L]=ee.useQuery({query:E.GET_MODULES_BY_GROUP,variables:{groupId:S},pause:!S}),[,O]=ee.useMutation(E.CREATE_MODULE),[,D]=ee.useMutation(E.UPDATE_MODULE),[,F]=ee.useMutation(E.CREATE_ACTION),[,N]=ee.useMutation(E.CONVERT_ACTION_TO_QUANTUM_OWNED),Y=n.useMemo(()=>b.data?.groups?b.data.groups.map(s=>A.getFragmentData(E.GROUP_FRAGMENT,s)):[],[b.data]),se=n.useMemo(()=>L.data?.modules?A.getFragmentData(E.ACTION_MODULE_FRAGMENT,L.data?.modules).map(a=>{const y=A.getFragmentData(E.MODULE_ACTION_FRAGMENT,a.moduleActions),K=A.getFragmentData(E.METADATA_GROUP_FRAGMENT,a.metadataGroups).map(W=>A.getFragmentData(E.METADATA_ITEM_FRAGMENT,W.data)).flat();return{...a,moduleActions:y.map(W=>({...W,action:A.getFragmentData(E.ACTION_FRAGMENT,W.action)})),categories:A.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,a.categories),metadataItems:K}}):[],[L.data]),k=n.useMemo(()=>se.filter(s=>w.includes(s.id)),[se,w]),X=n.useCallback(s=>{const a=s?.value||"";v(a),M([])},[]),Z=n.useCallback(s=>{const a=s.map(y=>y.value);M(a)},[]),I=n.useCallback(async()=>{if(d(!0),!k.length){d(!1);const s=new Error(`No modules selected for ${x==="convert"?"converting":"copying"}`);l?.(s);return}try{const s=[];let a=0;for(const y of k)try{let q=y.moduleActions.map(K=>K.actionId);if(m){const K=y.moduleActions.map(Q=>Q.action),W=async Q=>{if(x==="copy"){if(Q.quantumOwned)return Q;const de=A.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,Q.categories),je=A.getFragmentData(E.METADATA_GROUP_FRAGMENT,Q.metadataGroups).map(ae=>A.getFragmentData(E.METADATA_ITEM_FRAGMENT,ae.data).map(ge=>ge.id)).flat(),fe=A.getFragmentData(E.REPORT_FRAGMENT,Q.reports).map(ae=>({...ae,id:void 0,thresholds:A.getFragmentData(E.THRESHOLD_FRAGMENT,ae.thresholds).map(ge=>({...ge,id:void 0}))})),Ae=A.getFragmentData(E.THRESHOLD_FRAGMENT,Q.thresholds).map(ae=>({...ae,id:void 0})),he={...Q,quantumOwned:!0,thresholds:Ae,categories:de?.map(ae=>ae.id),reports:fe,metadataIds:je,id:void 0},xe=await F({fields:he});return xe.error||!xe.data?.createAction?null:A.getFragmentData(E.ACTION_FRAGMENT,xe.data.createAction)}if(Q.quantumOwned)return Q;const oe=await N({id:Q.id});return oe.error||!oe.data?.convertActionToQuantumOwned?null:A.getFragmentData(E.ACTION_FRAGMENT,oe.data.convertActionToQuantumOwned)};q=(await Promise.all(K.map(W))).filter(Q=>!!Q?.id).map(Q=>Q.id)}if(x==="convert"){const K={name:y.name,description:y.description||void 0,actions:q,categories:y.categories.map(B=>B.id),quantumOwned:!0},W=await D({id:y.id,input:K});if(W.error)throw new Error(W.error.message);if(W.data?.updateModule){const B=A.getFragmentData(E.ACTION_MODULE_FRAGMENT,W.data.updateModule);s.push(B)}}else{const K={name:`${y.name} (Copy)`,description:y.description||void 0,actions:q,categories:y.categories.map(B=>B.id),quantumOwned:m,metadataItemIds:y.metadataItems.map(B=>B.id),actionReports:y.moduleActions.filter(B=>!!B.reportId).map(B=>({actionId:B.actionId,reportId:B.reportId}))},W=await O({input:K});if(W.error)throw new Error(W.error.message);if(W.data?.createModule){const B=A.getFragmentData(E.ACTION_MODULE_FRAGMENT,W.data.createModule);s.push(B)}}}catch(q){console.error(`Failed to ${x==="convert"?"convert":"copy"} module "${y.name}":`,q),a++}if(s.length>0){const y=s.length,q=k.length;h({title:a>0?`Partial ${x==="convert"?"convert":"copy"} completed`:`${c.plural} ${x==="convert"?"converted":"copied"} successfully`,description:a>0?`${y} of ${q} ${c.plural} ${x==="convert"?"converted":"copied"} successfully`:`${y} ${y>1?c.plural:c.singular} ${x==="convert"?"converted":"copied"} successfully`,status:a>0?"warning":"success",duration:3e3,isClosable:!0}),s.length>0&&i?.(),v(""),M([])}else throw new Error(`Failed to ${x==="convert"?"convert":"copy"} any modules`)}catch(s){const a=s instanceof Error?s.message:`Failed to ${x==="convert"?"convert":"copy"} modules`;h({title:x==="convert"?"Convert failed":"Copy failed",description:a,status:"error",duration:5e3,isClosable:!0}),l?.(s instanceof Error?s:new Error(a))}finally{d(!1)}},[k,O,D,h,i,l,m,F,N,x,c]),$=n.useCallback(()=>{v(""),M([]),C("copy"),o?.()},[o]);n.useEffect(()=>{R&&R({cancelButton:!1,saveButton:k.length===0||T})},[k.length,T,R]),n.useEffect(()=>{p&&p({cancelButton:$,saveButton:I})},[p,$,I]);const J=n.useMemo(()=>Y.map(s=>({value:s.id,label:s.name})),[Y]),z=n.useMemo(()=>se.filter(s=>x==="copy"?!0:!s.quantumOwned).map(s=>({value:s.id,label:s.name,isQuantumOwned:s.quantumOwned})),[se,x]),H=b.fetching,u=L.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[m&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:x,onChange:s=>{C(s),M([])},children:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:6,children:[e.jsxRuntimeExports.jsx(t.Radio,{value:"copy",colorScheme:"blue",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"medium",children:["Copy ",c.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",c.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 ",c.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(s=>s.value===S)||null,onChange:X,isLoading:H,isDisabled:H,isClearable:!0}),b.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",b.error.message]})]})]}),S&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:x==="convert"?`Select ${c.plural} to Convert`:`Select ${c.plural} to Copy`}),u?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 ",c.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(ie.st,{placeholder:x==="convert"?`Choose ${c.pluralLowerCase} to convert...`:`Choose ${c.pluralLowerCase} to copy...`,options:z,value:z.filter(s=>w.includes(s.value)),onChange:Z,isDisabled:z.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(s,{context:a})=>e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",w:"100%",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(t.Text,{children:s.label}),a==="value"&&s.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),s.isQuantumOwned&&a==="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 ",c.pluralLowerCase," found in this group"]})]}),L.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load ",c.pluralLowerCase,":"," ",L.error.message]})]})]}),k.length>0&&e.jsxRuntimeExports.jsxs(t.Box,{p:4,bg:"gray.50",borderRadius:"md",children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"semibold",mb:3,children:k.length===1?`${c.singular} to ${x==="copy"?"Copy":"Convert"}`:`${k.length} ${c.plural} to ${x==="copy"?"Copy":"Convert"}`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[k.map((s,a)=>e.jsxRuntimeExports.jsxs(t.Box,{w:"100%",p:3,bg:"white",borderRadius:"md",border:"1px solid",borderColor:"gray.200",children:[e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",align:"start",mb:2,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"medium",fontSize:"sm",children:[a+1,". ",s.name]}),s.quantumOwned&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,fontSize:"sm",color:"gray.600",children:[s.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",s.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Activities:"})," ",s.moduleActions.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Categories:"})," ",s.categories.map(y=>y.name).join(", ")||"None"]})]})]},s.id)),k.length>1&&e.jsxRuntimeExports.jsx(t.Box,{w:"100%",p:2,bg:"blue.50",borderRadius:"md",border:"1px solid",borderColor:"blue.200",children:e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",fontWeight:"medium",color:"blue.800",children:["Total: ",k.length," ",c.pluralLowerCase," will be"," ",x==="copy"?"copied":"converted"]})}),m&&k.filter(s=>s.moduleActions.some(a=>!a.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:x==="convert"?`Converting ${c.plural} will convert non QM-Owned ${g.plural} to QM-Owned ${g.plural}`:`Copying ${c.plural} with Non QM-Owned ${g.plural} will create corresponding QM-Owned ${g.plural}`})})]})]}),!j&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:$,isDisabled:T,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:x==="copy"?"blue":"green",onClick:I,isDisabled:k.length===0||T,isLoading:T,loadingText:`${x==="copy"?"Copying":"Converting"}...`,children:[x==="copy"?"Copy":"Convert"," ",k.length===1?c.singular:`${k.length} ${c.plural}`]})]})]})})},ke=n.createContext(void 0),Re=()=>{const i=n.useContext(ke);if(!i)throw new Error("useUpsertModuleFormContext must be used within a UpsertModuleFormProvider");return i},Ne=({name:i,setName:o,actions:l,selectedActionIds:j,setSelectedActionIds:R,availableCategories:p,selectedCategoryIds:m,setSelectedCategoryIds:h,description:r,setDescription:c,selectedMetadataIds:g,setSelectedMetadataIds:S,actionReportIds:v,setActionReportIds:w,...M})=>{const T=t.useDisclosure(),d=n.useMemo(()=>l.map(D=>({...D,selected:j.includes(D.id)})),[l,j]),x=n.useMemo(()=>l.reduce((D,F)=>(D[F.id]=F,D),{}),[l]),C=n.useMemo(()=>j.map(D=>x[D]),[j,x]),b=n.useCallback((D,F)=>{R(F?[...j,D.id]:j.filter(N=>N!==D.id))},[j,R]),L=n.useCallback(D=>{o(D.target.value)},[o]),O=n.useCallback(D=>{c?.(D.target.value)},[c]);return e.jsxRuntimeExports.jsxs(t.Box,{...M,children:[e.jsxRuntimeExports.jsxs(t.HStack,{gap:"2rem",children:[e.jsxRuntimeExports.jsx(Xe,{name:i??"",onInputChange:L}),e.jsxRuntimeExports.jsx(Ze,{availableCategories:p,value:m,onChange:h})]}),e.jsxRuntimeExports.jsx(et,{description:r??"",onInputChange:O}),e.jsxRuntimeExports.jsx(ot,{selectedMetadataIds:g,setSelectedMetadataIds:S}),e.jsxRuntimeExports.jsx(tt,{value:C,onChange:R,onAdjustActivities:()=>T.onOpen(),actionReportIds:v,setActionReportIds:w}),e.jsxRuntimeExports.jsxs(t.Modal,{isOpen:T.isOpen,onClose:T.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(Ie,{actions:d,onSelected:b,disableCreate:!0,disableDelete:!0,tableProps:{height:"28rem",overflowY:"auto"}})}),e.jsxRuntimeExports.jsx(t.ModalFooter,{children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:T.onClose,isDisabled:j.length===0,children:"Done"})})]})]})]})},Xe=n.memo(({name:i,onInputChange:o})=>{const{getLabel:l}=re.useUiLabelContext(),j=l("module"),{isView:R}=Re();return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(ue,{children:[j," Name"]}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. ACL RTP Test Battery",value:i,onChange:o,isRequired:!0,isDisabled:R})]})}),Ze=n.memo(({availableCategories:i,value:o,onChange:l})=>{const{getLabel:j}=re.useUiLabelContext(),R=j("module"),{isView:p}=Re(),m=n.useMemo(()=>[...i,{id:"other",name:"Other"}],[i]),h=n.useMemo(()=>m.map(r=>({value:r.id,label:r.name})),[m]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(ue,{children:[R," Category"]}),e.jsxRuntimeExports.jsx(ie.st,{isDisabled:i.length===0||p,options:h,value:o.length===0?{value:"other",label:"Other"}:m.filter(r=>o.includes(r.id)).map(r=>({value:r.id,label:r.name}))[0],onChange:r=>l(r?[r.value]:[]),placeholder:"Select category"})]})}),et=n.memo(({description:i,onInputChange:o})=>{const{getLabel:l}=re.useUiLabelContext(),j=l("module"),{isView:R}=Re();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"," ",j.toLocaleLowerCase(),". Max 40 words."]})]})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. Assess readiness to return to play post-ACL reconstruction",value:i,onChange:o,isDisabled:R})]})}),tt=n.memo(({value:i,onChange:o,onAdjustActivities:l,actionReportIds:j,setActionReportIds:R})=>{const{getLabel:p}=re.useUiLabelContext(),{isView:m}=Re(),h=n.useMemo(()=>({module:p("module"),moduleLowerCase:p("module").toLocaleLowerCase(),action:p("action"),actionPlural:p("action_plural"),actionPluralLowerCase:p("action_plural").toLocaleLowerCase()}),[p]),r=n.useMemo(()=>i.filter(c=>!!c?.id).map(c=>({id:c.id,name:c.name,reports:A.getFragmentData(E.REPORT_FRAGMENT,c.reports)||[],selectedReportId:j[c.id]||null})),[i,j]);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:[h.actionPlural,!m&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",children:["Drag and drop to reorder the ",h.actionPluralLowerCase," ","in this ",h.moduleLowerCase,"."]})]})}),!m&&e.jsxRuntimeExports.jsxs(t.Button,{size:"sm",variant:"solid",colorScheme:"blue",onClick:l,children:["Add / Remove ",h.actionPlural]})]}),r.length===0?e.jsxRuntimeExports.jsx(t.VStack,{children:e.jsxRuntimeExports.jsxs(t.Text,{color:"gray.500",fontSize:"lg",mb:"4rem",mt:"4rem",children:["No ",h.actionPluralLowerCase," selected for this"," ",h.moduleLowerCase,".",!m&&e.jsxRuntimeExports.jsxs(t.Button,{ml:"0.5em",size:"sm",variant:"link",colorScheme:"blue",onClick:l,children:["Add ",h.actionPluralLowerCase,"."]})]})}):e.jsxRuntimeExports.jsx(st,{value:r,onChange:c=>{const g=c(r);o(g.map(S=>S.id))},disabled:m,actionReportIds:j,setActionReportIds:R})]})}),st=n.memo(({value:i,onChange:o,disabled:l,actionReportIds:j,setActionReportIds:R})=>{const[p]=n.useState(()=>Math.random().toString(36).substring(2,15)),m=n.useCallback((h,r)=>{l||o(c=>{const g=[...c],[S]=g.splice(h,1);return g.splice(r,0,S),g})},[o,l]);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:i.map((h,r)=>e.jsxRuntimeExports.jsx(nt,{listKey:p,item:h,index:r,disabled:!!l,move:m,onReportChange:c=>{R({...j,[h.id]:c})}},h.id))})})})}),nt=n.memo(({listKey:i,item:o,index:l,disabled:j,move:R,onReportChange:p})=>{const m=n.useRef(null),{getLabel:h}=re.useUiLabelContext(),r=h("action"),[{handlerId:c},g]=Me.useDrop({accept:i,collect:d=>({handlerId:d.getHandlerId()?.toString()??""}),hover:(d,x)=>{if(!m.current)return;const C=d.index,b=l;if(C===b)return;const L=m.current?.getBoundingClientRect(),O=(L.bottom-L.top)/2,F=x.getClientOffset().y-L.top;C<b&&F<O||C>b&&F>O||(R(C,b),d.index=b)}}),[{isDragging:S},v]=Me.useDrag({type:i,item:()=>({id:o.id,index:l}),collect:d=>({isDragging:d.isDragging()}),canDrag:!j}),w=n.useMemo(()=>[{value:null,label:"No Report"},...o.reports.map(d=>{const x=d.name&&d.name.length>0?d.name:"No Name",C=me.reportKindName(d.reportKind);return{value:d.id,label:`${x} (${C})`}})],[o.reports]),M=S?.6:1,T=j?"default":S?"grabbing":"grab";return v(g(m)),e.jsxRuntimeExports.jsx(t.Box,{ref:m,p:3,border:"1px solid",borderColor:"gray.200",borderRadius:"md",bg:"gray.50",style:{opacity:M,cursor:T},"data-handler-id":c,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:[l+1,"."]}),e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"medium",children:o.name})]}),e.jsxRuntimeExports.jsxs(t.HStack,{spacing:3,align:"center",children:[e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:[r," Report:"]}),e.jsxRuntimeExports.jsx(t.Box,{width:"450px",children:e.jsxRuntimeExports.jsx(ie.st,{value:w.find(d=>d.value===o.selectedReportId),onChange:d=>{p(d?.value||null)},options:w,placeholder:"Select report...",isDisabled:j})})]})]})})}),ot=n.memo(({selectedMetadataIds:i,setSelectedMetadataIds:o})=>{const{getLabel:l}=re.useUiLabelContext(),{isView:j,metadataOptions:R}=Re(),p=n.useMemo(()=>[{key:"activity_type",label:`${l("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}],[l]),m=n.useCallback((h,r)=>{const c=p.find(S=>S.key===h);if(!c)return;const g=c.multi?(r??[]).map(S=>S.id):r?[r.id]:[];o(S=>[...S.filter(w=>Object.values(R||{}).flat().find(T=>T.id===w)&&!Object.keys(R||{}).find(T=>R?.[T]?.some(d=>d.id===w&&T===h))),...g])},[p,R,o]);return R?e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(ue,{children:"Metadata Tags"}),e.jsxRuntimeExports.jsx(t.HStack,{gap:"1rem",align:"start",children:p.map(h=>e.jsxRuntimeExports.jsxs(t.FormControl,{flex:"1",children:[e.jsxRuntimeExports.jsx(t.FormLabel,{fontSize:"sm",children:h.label}),e.jsxRuntimeExports.jsx(ie.st,{isMulti:h.multi,value:R[h.key]?.filter(r=>i.includes(r.id)),onChange:r=>{m(h.key,r)},options:R[h.key],placeholder:`Select ${h.multi?"one or more":"one"} ${h.label.toLowerCase()}`,isDisabled:j,isClearable:h.multi})]},h.key))})]}):null}),Oe=({value:i,onChange:o,forceKind:l,disableRemove:j,disableKind:R,isDisabled:p,lockRanges:m,...h})=>{const r=n.useMemo(()=>[...i].sort((v,w)=>{const M=pe.availablePlanes.indexOf(v.plane),T=pe.availablePlanes.indexOf(w.plane);return M-T}),[i]),c=n.useCallback(v=>"segment"in v.id?ce.getSegmentNameWithPlane(v.id.segment,v.plane,!0)??"Unknown":ce.getJointNameWithPlane(v.id.joint,v.plane,!0)??"Unknown",[]),g=n.useCallback((v,w)=>{const M=r.findIndex(d=>d.id===w.id&&d.plane===w.plane);let T=[...r];l&&(w={...w,kind:l}),T[M]=w,m&&(T=T.map(d=>({...d,min:w.min,max:w.max}))),o(T)},[o,r,l,m]),S=n.useCallback(v=>{const w=r.filter(M=>M.id!==v.id||M.plane!==v.plane);o(w)},[o,r]);return e.jsxRuntimeExports.jsx(t.VStack,{alignItems:"flex-start",overflowY:"auto",...h,children:r.map((v,w)=>e.jsxRuntimeExports.jsx(rt,{label:c(v),parameter:v,onChange:M=>g(w,M),onRemove:j||p?void 0:()=>S(v),forceKind:l,disableKind:R||p,isDisabled:p},`${JSON.stringify(v.id)}-${v.plane}`))})},rt=({label:i,parameter:o,onChange:l,onRemove:j,forceKind:R,disableKind:p,isDisabled:m})=>{const h=n.useCallback(g=>"joint"in o.id?ce.getJointAngleDirectionName(o.id.joint,o.plane,g<0?-1:1):ce.getSegmentAngleDirectionName(o.id.segment,o.plane,g<0?-1:1),[o]),{min:r,max:c}="joint"in o.id?ce.getNormativeJointRange(o.id.joint,o.plane):{min:-180,max:180};return e.jsxRuntimeExports.jsxs(t.VStack,{borderRadius:"md",p:2,px:4,bg:"gray.100",w:"100%",overflow:"hidden",flexShrink:"0",children:[e.jsxRuntimeExports.jsxs(t.HStack,{w:"100%",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",flex:1,textTransform:"capitalize",fontWeight:"semibold",children:i}),o.sensorOnly&&e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor Only"}),j&&!m&&e.jsxRuntimeExports.jsx(t.IconButton,{size:"xs",variant:"ghost","aria-label":"delete",icon:e.jsxRuntimeExports.jsx(t.Icon,{as:Se.FaTrash}),onClick:j}),!R&&e.jsxRuntimeExports.jsx($e,{selectedItem:o?.kind??_.ThresholdKind.Limit,onChange:({value:g})=>l({...o,kind:g}),isDisabled:p||m,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:r,max:c,zeroMarker:!0,value:[o.min,o.max],onChange:g=>l({...o,min:g[0],max:g[1]}),formatValue:g=>`${Math.abs(g)}°`,valueLabel:g=>h(g)??"",positiveNegativeLabels:h(0)?[h(-1)??"",h(1)??""]:void 0,isDisabled:m})]})},ye=(i,o)=>"segment"in i&&"segment"in o&&i.segment===o.segment||"joint"in i&&"joint"in o&&i.joint===o.joint,Fe=({options:i,value:o,onChange:l,forceKind:j,singleValue:R,singleValueSideless:p,editOnly:m,disableKind:h,maxParameters:r,...c})=>{const g=p?2:r,S=n.useMemo(()=>{const d=new Map;return i.forEach(x=>{const C="joint"in x.id;let b,L;if(C?(b=ce.getJointNameWithPlane(x.id.joint,x.plane,!0)??"Unknown",L=`joint:${x.id.joint}`):(b=ce.getSegmentNameWithPlane(x.id.segment,x.plane,!0)??"Unknown",L=`segment:${x.id.segment}`),!d.has(L)){const F=C?ce.getPartName(x.id.joint)??"Unknown Joint":ce.getPartName(x.id.segment)??"Unknown Segment";d.set(L,{label:F,options:[]})}const O=d.get(L),D=[b,C?x.id.joint:x.id.segment,x.plane].filter(Boolean).map(F=>String(F).toLowerCase().replace(/\s+|_/g,""));O.options.push({label:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:2,justify:"space-between",w:"100%",pl:3,children:[e.jsxRuntimeExports.jsx(t.Text,{children:b}),x.sensorOnly&&e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor Only"})]}),value:x.id,plane:x.plane,sensorOnly:x.sensorOnly,searchTokens:D})}),Array.from(d.values())},[i]),v=n.useMemo(()=>{if(!p||o.length===0)return S;const d=o[0];return S.map(x=>({...x,options:x.options.filter(C=>pe.getAnalysisPartIdNoSide(C.value)===pe.getAnalysisPartIdNoSide(d.id)&&C.plane===d.plane)})).filter(x=>x.options.length>0)},[S,o,p]),w=n.useMemo(()=>S.flatMap(x=>x.options).filter(x=>o.some(C=>ye(C.id,x.value)&&C.plane===x.plane)),[S,o]),M=n.useCallback((d,x)=>{if(!x)return!0;const C=x.toLowerCase().replace(/\s+|_/g,""),b=d.data;return!b||!b.searchTokens?!1:b.searchTokens.some(L=>L.includes(C))},[]),T=n.useCallback(d=>{const x=d.map(C=>{const b=o.find(N=>ye(N.id,C.value)&&N.plane===C.plane),L=i.find(N=>ye(N.id,C.value)&&N.plane===C.plane),O=p?o.find(N=>pe.getAnalysisPartIdNoSide(N.id)===pe.getAnalysisPartIdNoSide(C.value)&&N.plane===C.plane):void 0,D=O&&!b?O.min:L&&L.min?L.min:0,F=O&&!b?O.max:L&&L.max?L.max:0;return b??{id:C.value,plane:C.plane,min:D,max:F,sensorOnly:C.sensorOnly,kind:j??_.ThresholdKind.Limit}});l(x)},[l,o,i,j,p]);return n.useEffect(()=>{const d=o.filter(x=>i.some(C=>ye(C.id,x.id)&&C.plane===x.plane));d.length!==o.length&&l(d)},[i,l,o]),e.jsxRuntimeExports.jsxs(t.Box,{...c,children:[e.jsxRuntimeExports.jsx(ie.st,{isMulti:!R,placeholder:o.length?`${o.length} selected`:"Search...",value:w,isDisabled:m||w.length>=(g??1/0),onChange:d=>Array.isArray(d)?T([...d]):T(d!==null?[d]:[]),options:v,controlShouldRenderValue:!1,formatOptionLabel:d=>d.label,filterOption:M,isSearchable:!0}),e.jsxRuntimeExports.jsx(Oe,{marginTop:2,maxH:"28rem",value:o,onChange:l,forceKind:j,disableKind:h,isDisabled:m,lockRanges:p})]})},Le=i=>{switch(i){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"}},it=({id:i,onError:o,onCancel:l,onSave:j,hideButtons:R,setButtonOnClick:p,setButtonDisabled:m,quantumOwned:h,isView:r})=>{const c=ee.useClient(),[{fetching:g},S]=ee.useMutation(E.CREATE_ACTION),[{fetching:v},w]=ee.useMutation(E.UPDATE_ACTION),[{data:M}]=ee.useQuery({query:E.GET_ACTION_BY_ID,variables:{id:i??""},pause:!i}),T=n.useMemo(()=>{const f=A.getFragmentData(E.ACTION_FRAGMENT,M?.getActionById);if(!f)return null;const G=(A.getFragmentData(E.REPORT_FRAGMENT,f.reports)||[]).map(P=>({...P,thresholds:A.getFragmentData(E.THRESHOLD_FRAGMENT,P.thresholds)}));return{...f,thresholds:A.getFragmentData(E.THRESHOLD_FRAGMENT,f.thresholds),reports:G}},[M]),d=g||v,x=!!T&&!!i,{getLabel:C}=re.useUiLabelContext(),b=n.useMemo(()=>({action:C("action")}),[C]),L=n.useMemo(()=>[{key:"module_category",label:"Link Category",multi:!0},{key:"activity_type",label:`${b.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}],[b.action]),[O,D]=n.useState(""),[F,N]=n.useState(""),[Y,se]=n.useState(""),[k,X]=n.useState(""),[Z,I]=n.useState([]),[$,J]=n.useState({}),[z,H]=n.useState(null),[u,s]=n.useState(""),[a,y]=n.useState([]),[q,K]=n.useState([]),[W,B]=n.useState(""),[Q,oe]=n.useState([]),de=re.useAllPartParameters(),ve=n.useMemo(()=>de.filter(f=>f.sensorOnly),[de]),je=[{label:me.reportKindName(_.ReportKind.GeneralActivity),value:_.ReportKind.GeneralActivity},{label:me.reportKindName(_.ReportKind.MovementCoordination),value:_.ReportKind.MovementCoordination},{label:me.reportKindName(_.ReportKind.Range),value:_.ReportKind.Range},{label:me.reportKindName(_.ReportKind.StabilityBalance),value:_.ReportKind.StabilityBalance},{label:me.reportKindName(_.ReportKind.PointOfInterest),value:_.ReportKind.PointOfInterest}],Ee=O.length>0,[fe,Ae]=n.useState({});n.useEffect(()=>{const f=L.map(U=>c.query(E.GET_METADATA_BY_KEY,{key:U.key}));Promise.all(f).then(U=>{const G={};U.forEach(P=>{if(P.error||!P.data)return;const V=A.getFragmentData(E.METADATA_GROUP_FRAGMENT,P.data.getMetadataByKey),te=A.getFragmentData(E.METADATA_ITEM_FRAGMENT,V.data);G[V.key]=te.map(le=>({label:le.label||le.value,value:le.value,id:le.id}))}),J(G)})},[c,L]),n.useEffect(()=>{if(T){const U=A.getFragmentData(E.METADATA_GROUP_FRAGMENT,T.metadataGroups).map(V=>V.data.map(te=>A.getFragmentData(E.METADATA_ITEM_FRAGMENT,te).id)),G=T.reports.map(V=>({id:V.id,name:V.name??"",instructions:V.instructions??"",kind:V.reportKind,parameters:V.thresholds.map(te=>({id:{[te.partKind]:te.partId},kind:te.kind,min:te.min,max:te.max,plane:te.partDimension,oldId:te.id,sensorOnly:ve.some(le=>{const we=le.id[te.partKind];return we?we===te.partId&&le.plane===te.partDimension:!1})})),sensorLocations:V.sensorLocations})),P={name:T.name,description:T.description||"",cameraPlacement:T.cameraPlacement||"",videoLink:T.videoLink||"",metadataIds:U.flat(),reports:G};D(P.name),N(P.description),se(P.cameraPlacement),X(P.videoLink),I(P.metadataIds),oe(G),Ae(P)}},[T,ve]);const he=n.useMemo(()=>JSON.stringify(fe)!==JSON.stringify({name:O,description:F,cameraPlacement:Y,videoLink:k,metadataIds:Z,reports:Q}),[fe,O,F,Y,k,Z,Q]),xe=n.useCallback(()=>{const f={name:O,description:F,cameraPlacement:Y,videoLink:k,metadataItemIds:Z,laterality:_.ActionLaterality.Either,quantumOwned:h,sessionType:[],thresholds:[],reports:Q.map(G=>({id:G.isNew?void 0:G.id,name:G.name,reportKind:G.kind,sensorLocations:G.sensorLocations,instructions:G.instructions,thresholds:G.parameters.map(P=>({id:P.oldId,kind:P.kind,min:P.min,max:P.max,partKind:"joint"in P.id?"joint":"segment",partId:"joint"in P.id?P.id.joint:P.id.segment,partDimension:P.plane}))}))};let U;x&&i?U=w({id:i,fields:f}):U=S({fields:f}),U.then(({error:G})=>{G?o(G):j()})},[h,S,w,i,O,F,Y,k,Z,Q,x,j,o]);n.useEffect(()=>{m&&m({cancelButton:d,saveButton:r?!0:d||!Ee||!he})},[d,m,Ee,he,r]),n.useEffect(()=>{p&&p({cancelButton:l,saveButton:r?()=>{}:xe})},[p,l,xe,r]);const ae=n.useCallback(f=>{const U=ce.getSuggestedSensorLocations(f.map(G=>"joint"in G.id?G.id.joint:G.id.segment));K(U)},[]);n.useEffect(()=>{ae(a)},[a,ae]);const ge=n.useCallback(()=>{if(!z||!u.trim())return;const f=z===_.ReportKind.PointOfInterest,U={id:Date.now().toString(),name:u.trim(),kind:z,parameters:f?[]:a,sensorLocations:f?[]:q,instructions:f?W:"",isNew:!0};oe(G=>[...G,U]),H(null),s(""),y([]),K([]),B("")},[z,u,a,q,W]),De=n.useCallback(f=>{oe(U=>U.filter(G=>G.id!==f))},[]),_e=(f,U)=>{const G=L.find(V=>V.key===f);if(!G)return;const P=G.multi?(U??[]).map(V=>V.id):U?[U.id]:[];I(V=>[...V.filter(le=>Object.values($).flat().find(be=>be.id===le)&&!Object.keys($).find(be=>$[be]?.some(Ge=>Ge.id===le&&be===f))),...P])};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(ne,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:O,onChange:f=>D(f.target.value),type:"text",placeholder:"i.e. Lunge & Return",isDisabled:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Camera Placement"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:Y,onChange:f=>se(f.target.value),rows:2,placeholder:"(optional) Describe camera setup, placement, angles",isDisabled:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Video Link"}),e.jsxRuntimeExports.jsx(t.Input,{value:k,onChange:f=>X(f.target.value),type:"url",placeholder:"(optional) https://...",isDisabled:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Description"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:F,onChange:f=>N(f.target.value),rows:2,placeholder:"(optional) Describe how to perform the test or exercise",isDisabled:r})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(ne,{children:"Metadata Tags"}),L.map(f=>e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:f.label}),e.jsxRuntimeExports.jsx(ie.st,{isMulti:f.multi,value:$[f.key]?.filter(U=>Z.includes(U.id)),onChange:U=>{_e(f.key,U)},options:$[f.key],placeholder:`Select ${f.multi?"one or more":"one"} ${f.label.toLowerCase()}`,isDisabled:r,isClearable:f.multi})]},f.key))]})]})}),e.jsxRuntimeExports.jsx(t.TabPanel,{px:0,children:e.jsxRuntimeExports.jsxs("div",{className:Te.cn("grid grid-cols-1 gap-6",!r&&"md:grid-cols-2"),children:[e.jsxRuntimeExports.jsxs("div",{className:Te.cn("space-y-4",r&&"hidden"),children:[e.jsxRuntimeExports.jsx(ne,{children:"Add New Report"}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Report Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:u,onChange:f=>s(f.target.value),type:"text",placeholder:"Enter report name...",isDisabled:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Report Type"}),e.jsxRuntimeExports.jsx(ie.st,{value:z?je.find(f=>f.value===z):null,onChange:f=>H(f?.value||null),options:je,placeholder:"Select report type...",isDisabled:r,isClearable:!0})]}),z!==_.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(Fe,{options:de,value:a,onChange:y,editOnly:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Suggested Sensor Locations"}),e.jsxRuntimeExports.jsx(t.Input,{value:q.map(f=>Le(f)).join(", "),placeholder:"Auto-filled based on parameters...",isDisabled:!0})]})]}),z===_.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:W,onChange:f=>B(f.target.value),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:r})]}),e.jsxRuntimeExports.jsx("div",{className:"w-full flex justify-end",children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:ge,isDisabled:!z||!u.trim()||r||je.length===0||z!==_.ReportKind.PointOfInterest&&a.length===0,children:"Add Report"})})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(ne,{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(f=>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:me.reportKindName(f.kind)}),!r&&e.jsxRuntimeExports.jsx(t.Button,{size:"xs",colorScheme:"red",variant:"ghost",onClick:()=>De(f.id),children:"Remove"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Report Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:f.name,onChange:U=>oe(G=>G.map(P=>P.id===f.id?{...P,name:U.target.value}:P)),placeholder:"Enter report name...",isDisabled:r})]}),f.kind===_.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:f.instructions,onChange:U=>oe(G=>G.map(P=>P.id===f.id?{...P,instructions:U.target.value}:P)),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:r})]}),f.kind!==_.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs("div",{className:"flex flex-col",children:[e.jsxRuntimeExports.jsx(ne,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(Fe,{options:de,value:f.parameters,onChange:U=>{const G=U.map(V=>V.id.joint??V.id.segment),P=ce.getSuggestedSensorLocations(G);oe(V=>V.map(te=>te.id===f.id?{...te,parameters:U,sensorLocations:P}:te))},editOnly:r})]}),f.kind!==_.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Sensors:"," ",f.sensorLocations.map(U=>Le(U)).join(", ")]})]},f.id))})]})]})})]})]}),e.jsxRuntimeExports.jsx(t.HStack,{justify:"end",className:Te.cn((R||r)&&"!hidden"),children:e.jsxRuntimeExports.jsxs(t.ButtonGroup,{gap:4,children:[e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:d,onClick:l,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:d||!Ee||!he,isLoading:d,onClick:xe,children:"Save changes"})]})})]})},ne=({children:i})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:i}),at=({children:i,isView:o,metadataKeys:l})=>{const[j,R]=n.useState({}),p=ee.useClient();return n.useEffect(()=>{let m=!1;return(async()=>{const r=(l??[]).map(S=>p.query(E.GET_METADATA_BY_KEY,{key:S}).toPromise()),c=await Promise.all(r),g={};for(const S of c){if(S.error||!S.data?.getMetadataByKey)continue;const v=A.getFragmentData(E.METADATA_GROUP_FRAGMENT,S.data.getMetadataByKey);if(!v)continue;const w=A.getFragmentData(E.METADATA_ITEM_FRAGMENT,v.data)??[];g[v.key]=w.map(M=>({label:M.label||M.value,value:M.value,id:M.id}))}m||R(g)})(),()=>{m=!0}},[p,l]),e.jsxRuntimeExports.jsx(ke.Provider,{value:{isView:o,metadataOptions:j},children:i})},lt=({id:i,onCancel:o,onSave:l,onError:j,hideButtons:R,quantumOwned:p,setButtonOnClick:m,setButtonDisabled:h,isView:r})=>{const[{data:c,fetching:g}]=ee.useQuery({query:p?E.GET_QUANTUM_OWNED_ACTIONS:E.GET_ACTIONS}),[{data:S}]=ee.useQuery({query:E.GET_MODULE_BY_ID,variables:{id:i},pause:!i}),[{data:v}]=ee.useQuery({query:E.GET_ALL_MODULE_CATEGORIES}),w=A.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,v?.moduleCategories),[{fetching:M},T]=ee.useMutation(E.UPDATE_MODULE),[{fetching:d},x]=ee.useMutation(E.CREATE_MODULE),C=n.useMemo(()=>!c||g?[]:A.getFragmentData(E.ACTION_FRAGMENT,p?c?.quantumOwnedActions??[]:c?.actions??[]).filter(u=>!!u?.id),[c,p,g]),b=A.getFragmentData(E.ACTION_MODULE_FRAGMENT,S?.module),L=n.useMemo(()=>A.getFragmentData(E.MODULE_ACTION_FRAGMENT,b?.moduleActions)??[],[b?.moduleActions]),[O,D]=n.useState([...L.map(H=>H.actionId)??[]]),[F,N]=n.useState(b?.name??""),[Y,se]=n.useState([]),[k,X]=n.useState(b?.description??""),[Z,I]=n.useState([]),[$,J]=n.useState({});n.useEffect(()=>{if(b){D(L.map(a=>a.actionId)),N(b.name),X(b.description??""),se(b.categories.map(a=>A.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,a).id)??[]);const u=A.getFragmentData(E.METADATA_GROUP_FRAGMENT,b.metadataGroups).map(a=>a.data.map(y=>A.getFragmentData(E.METADATA_ITEM_FRAGMENT,y).id));I(u.flat());const s={};L.forEach(a=>{s[a.actionId]=a.reportId||null}),J(s)}},[b,L]);const z=n.useCallback(()=>{let H;const u=Object.entries($).filter(([,a])=>a!==null).map(([a,y])=>({actionId:a,reportId:y})),s={actions:O,name:F,categories:Y.filter(a=>a!=="other"),description:k,quantumOwned:p,metadataItemIds:Z,actionReports:u};b?H=T({id:b.id,input:s}):H=x({input:s}),H.then(({error:a})=>{a?j(a instanceof Error?a:new Error(String(a))):l()})},[x,T,O,F,k,Y,Z,$,b,l,j,p]);return n.useEffect(()=>{h&&h({cancelButton:M||d,saveButton:M||d||!F||k.trim().split(/\s+/).filter(Boolean).length>40})},[h,M,d,O,F,k]),n.useEffect(()=>{m&&m({cancelButton:o,saveButton:z})},[m,o,z]),e.jsxRuntimeExports.jsx(t.Box,{width:"100%",children:e.jsxRuntimeExports.jsxs(at,{isView:r,metadataKeys:["activity_type","session_type","body_region","sport"],children:[e.jsxRuntimeExports.jsx(Ne,{name:F,setName:N,actions:C,selectedActionIds:O,setSelectedActionIds:D,availableCategories:w??[],selectedCategoryIds:Y,setSelectedCategoryIds:se,description:k,setDescription:X,selectedMetadataIds:Z,setSelectedMetadataIds:I,actionReportIds:$,setActionReportIds:J}),!R&&!r&&e.jsxRuntimeExports.jsx(t.HStack,{justifyContent:"flex-start",children:e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mt:16,gap:4,children:[e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:M||d,onClick:o,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:M||d||!F||k.trim().split(/\s+/).filter(Boolean).length>40,isLoading:M||d,onClick:z,children:"Save"})]})})]})})};exports.ActivityList=Ie;exports.CopyActivityForm=Je;exports.CopyModuleForm=Ve;exports.ModuleForm=Ne;exports.ParameterEditList=Oe;exports.ParameterEditSelect=Fe;exports.UpsertActivityForm=it;exports.UpsertModuleForm=lt;