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