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