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