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