quantum-component-library 1.4.67 → 1.4.68

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