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