quantum-component-library 1.4.47-dev.10 → 1.4.47-dev.11

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.
@@ -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"),ge=require("./ufuzzy-vendor-7qHa_k39.cjs"),X=require("./react-select-vendor-D_Q2fL5j.cjs"),de=require("./react-icons-vendor-D2s8zw9h.cjs"),Q=require("./graphql-vendor-B-QTAQSb.cjs"),$=require("./generated.cjs"),y=require("./graphql-C6M9oyU0.cjs"),le=require("./react-dnd-vendor-BPzSDojS.cjs"),F=require("./generated-graphql.cjs"),K=require("./services.cjs"),oe=require("./types.cjs"),re=require("./utils.cjs"),Ee=require("./hooks.cjs"),Re=({setSearch:o,actions:n,updateUseCases:l,hideUseCaseFilter:d=!1})=>{const m=r.useMemo(()=>n?.flatMap(c=>c.useCases).filter((c,x,f)=>f.findIndex(i=>i.id===c.id)===x).map(c=>({label:c.name,value:c.id}))||[],[n]);return e.jsxRuntimeExports.jsxs(t.Flex,{width:"100%",alignContent:"space-evenly",gap:4,children:[e.jsxRuntimeExports.jsxs(t.InputGroup,{size:"md",flex:1,children:[e.jsxRuntimeExports.jsx(t.InputLeftElement,{children:e.jsxRuntimeExports.jsx(t.Icon,{as:de.FaSearch,color:"gray.300"})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"Search by name...",width:"100%",maxW:d?void 0:"30rem",onChange:c=>o(c.target.value)})]}),!d&&e.jsxRuntimeExports.jsx(t.InputGroup,{size:"md",children:e.jsxRuntimeExports.jsx(X.st,{size:"md",chakraStyles:{container:c=>({...c,width:"100%"})},menuPortalTarget:document.body,placeholder:"Filter use case",isMulti:!0,options:m,onChange:c=>l(c.map(x=>x.value))})})]})},Z=({children:o})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:o}),fe=({value:o,onChange:n})=>{const l=r.useState(()=>Math.random().toString(36).substring(2,15))[0],d=r.useCallback((m,c)=>{n(x=>{const f=[...x],[i]=f.splice(m,1);return f.splice(c,0,i),f})},[n]);return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsx(le.DndProvider,{backend:le.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,c)=>e.jsxRuntimeExports.jsx(be,{listKey:l,index:c,id:m.id,name:m.name,move:d},m.id))})]})})})})},be=({listKey:o,index:n,id:l,name:d,move:m})=>{const c=r.useRef(null),[{handlerId:x},f]=le.useDrop({accept:o,collect:p=>({handlerId:p.getHandlerId()?.toString()??""}),hover:(p,S)=>{if(!c.current)return;const a=p.index,u=n;if(a===u)return;const j=c.current?.getBoundingClientRect(),g=(j.bottom-j.top)/2,C=S.getClientOffset().y-j.top;a<u&&C<g||a>u&&C>g||(m(a,u),p.index=u)}}),[{isDragging:i},N]=le.useDrag({type:o,item:()=>({id:l,index:n}),collect:p=>({isDragging:p.isDragging()})}),E=i?.6:1,M=i?"grabbing":"grab";return N(f(c)),e.jsxRuntimeExports.jsxs(t.Tr,{ref:c,style:{opacity:E,cursor:M},"data-handler-id":x,children:[e.jsxRuntimeExports.jsx(t.Td,{children:n+1}),e.jsxRuntimeExports.jsx(t.Td,{children:d})]})},ve=({items:o,onChange:n,selectedItem:l,isDisabled:d,selectedProps:m,buttonProps:c})=>{const x=i=>i===l||i.value===l,f=i=>x(i)?{...c,...m}:c;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:d,children:o.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:()=>x(i)?null:n(i,N),isDisabled:i.disabled,...f(i),children:i.label})},N))})},ie=(o,n)=>n<0?-1*Math.abs(o):Math.abs(o),ye=({isReversed:o,min:n,max:l,value:d,onChange:m,inputProps:c,size:x,zeroMarker:f,formatValue:i,valueLabel:N,positiveNegativeLabels:E,isDisabled:M,...p})=>{const[S,a]=r.useState([void 0,void 0]),u=S[0],j=S[1],g=f&&n<-5&&l>5,b=Number(d?.[0]??j??n)>0?1:-1,C=Number(d?.[1]??j??l)<0?-1:1,z=E?.[0]===E?.[1],D=d?.[0],A=d?.[1];r.useEffect(()=>{D!==void 0&&A!==void 0&&a([D.toFixed(0),A.toFixed(0)])},[D,A,a]);const L=r.useCallback(([v,G])=>{v<G&&a([v.toFixed(0),G.toFixed(0)])},[a]),_=r.useCallback(([v,G])=>{v<G&&m([v,G])},[m]),P=r.useCallback(()=>{a(([v,G])=>{const J=isNaN(Number(v))?n:Number(v),s=isNaN(Number(G))?l:Number(G),h=ie(Number(J),b),T=ie(Number(s),C),I=b<0?Math.max(h,n):Math.min(h,l),B=C<0?Math.max(T,n):Math.min(T,l);return I>B?(m([B,I]),[B.toFixed(0),I.toFixed(0)]):(m([I,B]),[I.toFixed(0),B.toFixed(0)])})},[m,a,b,C,n,l]),R=r.useCallback(v=>{const G=v===""||isNaN(Number(v))?v:ie(Number(v),b);a(([J,s])=>[G.toString(),s])},[a,b]),w=r.useCallback(v=>{const G=v===""||isNaN(Number(v))?v:ie(Number(v),C);a(([J,s])=>[J,G.toString()])},[a,C]),k=r.useMemo(()=>x==="xs"?"0.75rem":void 0,[x]),H=r.useCallback((v,G)=>{const J=Number(G.target.value);if(!u||!j||![-1,1].includes(J))return;const s=I=>J<0?-1*Math.abs(I):Math.abs(I),h=v?s(Number(u)):Number(u),T=v?Number(j):s(Number(j));h>T?m([T,h]):m([h,T])},[u,j,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:o,value:[Number(u??n),Number(j??l)],max:l,min:n,minStepsBetweenThumbs:3,step:1,onChange:L,onChangeEnd:_,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:k,h:k}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:1,w:k,h:k})]})}),N&&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:N(n)}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:x??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:N(l)})]}),e.jsxRuntimeExports.jsxs(t.Flex,{direction:o?"row-reverse":"row",justifyContent:"center",alignItems:"center",gap:"0.125em",children:[E&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:x,fontWeight:"bold",value:b,onChange:v=>H(!0,v),isDisabled:z||M,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:E[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:E[1]})]}),e.jsxRuntimeExports.jsx(t.NumberInput,{precision:0,size:x??"sm",min:0,max:b<0?Math.abs(n):A??l,value:u===""?"":Math.abs(Number(u??n)),onChange:R,onBlur:P,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:M,...c,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),e.jsxRuntimeExports.jsx(t.NumberInput,{size:x??"sm",min:0,max:C<0?Math.abs(D??n):l,precision:0,value:j===""?"":Math.abs(Number(j??l)),onChange:w,onBlur:P,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:M,...c,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),E&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:x,fontWeight:"bold",value:C,onChange:v=>H(!1,v),isDisabled:z||M,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:E[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:E[1]})]})]})]})},Ce=({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))}),Te=new ge.uFuzzy({}),Se=({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,Me=(o,n)=>{if(!n||!n.trim().length)return o;const l=o.map(m=>m.name??"");return Te.filter(l,n)?.map(m=>o[m])??[]},Ae=o=>!o||o.length===0?"None":o.map(n=>n.replace(/([A-Z])/g," $1").trim()).join(", "),we=(o,n)=>!n||n.length==0?o:o.filter(l=>l.useCases?.some(d=>n.includes(d.id))??!1),xe=({actions:o,totalActions:n,onCreate:l,onDelete:d,onEdit:m,onView:c,onSelected:x,onDuplicate:f,disableMultiSelect:i,disableDelete:N,disableEdit:E,disableCreate:M,hideUseCase:p=!0,tableProps:S,containerProps:a,quantumIconSrc:u="/favicon.ico"})=>{const[j,g]=r.useState(""),[b,C]=r.useState(),z=r.useMemo(()=>{if(!o)return;const R=Me(o,j);return p?R:we(R,b)},[o,j,b,p]),D=r.useCallback(()=>{if(!d)return;const w=o.filter(k=>k.selected&&!k.quantumOwned).map(k=>k.id);d(w)},[o,d]),A=r.useCallback(()=>{if(!f)return;const R=o.filter(w=>w.selected);f(R.map(w=>w.id)),x&&R.forEach(w=>x(w,!1))},[o,f,x]),L=r.useMemo(()=>o.some(R=>R.selected&&!R.quantumOwned),[o]),_=r.useMemo(()=>o.some(R=>R.selected),[o]),P=r.useMemo(()=>o.some(R=>R.selected&&R.quantumOwned),[o]);return e.jsxRuntimeExports.jsxs(t.Box,{...a,children:[e.jsxRuntimeExports.jsxs(t.Flex,{alignContent:"space-between",gap:4,children:[(l||d||f)&&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:P?L?"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:!L||!d||N,onClick:D,children:"Delete Selected"})}),f&&!i&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!_,onClick:A,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx(Re,{setSearch:g,actions:o,updateUseCases:C,hideUseCaseFilter:p})]}),e.jsxRuntimeExports.jsx(t.TableContainer,{mr:"2rem",overflowX:"hidden",...S,children:e.jsxRuntimeExports.jsxs(t.Table,{size:"md",variant:"simple",children:[e.jsxRuntimeExports.jsx(t.Thead,{position:"sticky",top:0,bg:"white",zIndex:1,children:e.jsxRuntimeExports.jsxs(t.Tr,{children:[e.jsxRuntimeExports.jsxs(t.Th,{fontWeight:"normal",children:["(showing ",z?.length??0," of"," ",n??o.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:z?.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:w=>x(R,w.target.checked)}),(R.quantumOwned||!m)&&c&&e.jsxRuntimeExports.jsx(t.Button,{ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:()=>c(R.id),children:"View"}),!R.quantumOwned&&m&&e.jsxRuntimeExports.jsx(t.Button,{isDisabled:E,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(Se,{action:R,quantumIconSrc:u}),R.name]})}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",whiteSpace:"break-spaces",children:Ae(R.sensorLocations)}),!p&&e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:e.jsxRuntimeExports.jsx(Ce,{containerProps:{flexWrap:"wrap"},tags:R.useCases?.map(w=>w.name)??[]})})]},R.id))})]})})]})},Oe=({onSave:o,onCancel:n,onError:l,hideButtons:d=!1,setButtonDisabled:m,setButtonOnClick:c,quantumOwned:x})=>{const f=t.useToast(),[i,N]=r.useState("copy"),[E,M]=r.useState(""),[p,S]=r.useState([]),[a,u]=r.useState(!1),[j]=Q.useQuery({query:y.GET_GROUPS}),[g]=Q.useQuery({query:y.GET_ACTIONS_BY_GROUP,variables:{groupId:E},pause:!E}),[,b]=Q.useMutation(y.CREATE_ACTION),[,C]=Q.useMutation(y.CONVERT_ACTION_TO_QUANTUM_OWNED),z=r.useMemo(()=>j.data?.groups?j.data.groups.map(s=>$.getFragmentData(y.GROUP_FRAGMENT,s)):[],[j.data]),D=r.useMemo(()=>g.data?g.data.actions.map(h=>$.getFragmentData(y.ACTION_FRAGMENT,h)):[],[g.data]),A=r.useMemo(()=>D.filter(s=>p.includes(s.id)),[D,p]),L=r.useCallback(s=>{const h=s?.value||"";M(h),S([])},[]),_=r.useCallback(s=>{const h=s.map(T=>T.value);S(h)},[]),P=r.useCallback(async s=>{const h=$.getFragmentData(y.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(B=>({...B,id:void 0})),categories:h?.map(B=>B.id),quantumOwned:x,id:void 0},I=await b({fields:T});if(I.error)throw new Error(I.error.message);if(I.data?.createAction)return $.getFragmentData(y.ACTION_FRAGMENT,I.data.createAction);throw new Error("No action data returned")},[b,x]),R=r.useCallback(async s=>{const h=await C({id:s.id});if(h.error)throw new Error(h.error.message);if(h.data?.convertActionToQuantumOwned)return $.getFragmentData(y.ACTION_FRAGMENT,h.data.convertActionToQuantumOwned);throw new Error("No action data returned")},[C]),w=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 h=0;const T=i==="copy"?P:R,I=i==="copy"?"copy":"convert";for(const B of A)try{const U=await T(B);s.push(U)}catch(U){console.error(`Failed to ${I} activity "${B.name}":`,U),h++}if(s.length>0){const B=s.length,U=A.length,Y=i==="copy"?"copied":"converted",q=i==="copy"?"copy":"convert";f({title:h>0?`Partial ${q} completed`:`Activities ${Y} successfully`,description:h>0?`${B} of ${U} activities ${Y} successfully`:`${B} activit${B>1?"ies":"y"} ${Y} successfully`,status:h>0?"warning":"success",duration:3e3,isClosable:!0}),o?.(),M(""),S([])}else throw new Error(`Failed to ${I} any activities`)}catch(s){const h=i==="copy"?"copy":"convert",T=s instanceof Error?s.message:`Failed to ${h} activities`;f({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,P,R,f,o,l]),k=r.useCallback(()=>{M(""),S([]),N("copy"),n?.()},[n]);r.useEffect(()=>{m&&m({cancelButton:!1,saveButton:A.length===0||a})},[A.length,a,m]),r.useEffect(()=>{c&&c({cancelButton:k,saveButton:w})},[c,k,w]);const H=r.useMemo(()=>z.map(s=>({value:s.id,label:s.name})),[z]),v=r.useMemo(()=>D.filter(s=>i==="copy"?!0:!s.quantumOwned).map(s=>({value:s.id,label:s.name,isQuantumOwned:s.quantumOwned})),[D,i]),G=j.fetching,J=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=>{N(s),S([])},children:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:6,children:[e.jsxRuntimeExports.jsx(t.Radio,{value:"copy",colorScheme:"blue",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.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(X.st,{placeholder:"Choose a group...",options:H,value:H.find(s=>s.value===E)||null,onChange:L,isLoading:G,isDisabled:G,isClearable:!0}),j.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",j.error.message]})]})]}),E&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsxs(Z,{children:["Select Activities to"," ",i==="copy"?"Copy":"Convert"]}),J?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(X.st,{placeholder:`Choose activities to ${i}...`,options:v,value:v.filter(s=>p.includes(s.value)),onChange:_,isDisabled:v.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(s,{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:s.label}),h==="value"&&s.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),s.isQuantumOwned&&h==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),v.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,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,". ",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:k,isDisabled:a,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:i==="copy"?"blue":"green",onClick:w,isDisabled:A.length===0||a,isLoading:a,loadingText:`${i==="copy"?"Copying":"Converting"}...`,children:[i==="copy"?"Copy":"Convert"," ",A.length===1?"Activity":`${A.length} Activities`]})]})]})})},Fe=({onSave:o,onCancel:n,onError:l,hideButtons:d=!1,setButtonDisabled:m,setButtonOnClick:c,quantumOwned:x})=>{const f=t.useToast(),[i,N]=r.useState(""),[E,M]=r.useState([]),[p,S]=r.useState(!1),[a,u]=r.useState("copy"),[j]=Q.useQuery({query:y.GET_GROUPS}),[g]=Q.useQuery({query:y.GET_MODULES_BY_GROUP,variables:{groupId:i},pause:!i}),[,b]=Q.useMutation(y.CREATE_MODULE),[,C]=Q.useMutation(y.UPDATE_MODULE),[,z]=Q.useMutation(y.CREATE_ACTION),[,D]=Q.useMutation(y.CONVERT_ACTION_TO_QUANTUM_OWNED),A=r.useMemo(()=>j.data?.groups?j.data.groups.map(s=>$.getFragmentData(y.GROUP_FRAGMENT,s)):[],[j.data]),L=r.useMemo(()=>g.data?.modules?$.getFragmentData(y.ACTION_MODULE_FRAGMENT,g.data?.modules).map(h=>{const T=$.getFragmentData(y.MODULE_ACTION_FRAGMENT,h.moduleActions);return{...h,moduleActions:T.map(I=>({...I,action:$.getFragmentData(y.ACTION_FRAGMENT,I.action)})),categories:$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,h.categories)}}):[],[g.data]),_=r.useMemo(()=>L.filter(s=>E.includes(s.id)),[L,E]),P=r.useCallback(s=>{const h=s?.value||"";N(h),M([])},[]),R=r.useCallback(s=>{const h=s.map(T=>T.value);M(h)},[]),w=r.useCallback(async()=>{if(S(!0),!_.length){S(!1);const s=new Error(`No modules selected for ${a==="convert"?"converting":"copying"}`);l?.(s);return}try{const s=[];let h=0;for(const T of _)try{let I=T.moduleActions.map(B=>B.actionId);if(x){const B=T.moduleActions.map(q=>q.action),U=async q=>{if(a==="copy"){if(q.quantumOwned)return q;const ce=$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,q.categories),ne={...q,quantumOwned:!0,thresholds:q.thresholds.map(O=>({...O,id:void 0})),categories:ce?.map(O=>O.id),id:void 0},se=await z({fields:ne});return se.error||!se.data?.createAction?null:$.getFragmentData(y.ACTION_FRAGMENT,se.data.createAction)}if(q.quantumOwned)return q;const te=await D({id:q.id});return te.error||!te.data?.convertActionToQuantumOwned?null:$.getFragmentData(y.ACTION_FRAGMENT,te.data.convertActionToQuantumOwned)};I=(await Promise.all(B.map(U))).filter(q=>!!q).map(q=>q.id)}if(a==="convert"){const B={name:T.name,description:T.description||void 0,actions:I,categories:T.categories.map(Y=>Y.id),quantumOwned:!0},U=await C({id:T.id,input:B});if(U.error)throw new Error(U.error.message);if(U.data?.updateModule){const Y=$.getFragmentData(y.ACTION_MODULE_FRAGMENT,U.data.updateModule);s.push(Y)}}else{const B={name:`${T.name} (Copy)`,description:T.description||void 0,actions:I,categories:T.categories.map(Y=>Y.id),quantumOwned:x},U=await b({input:B});if(U.error)throw new Error(U.error.message);if(U.data?.createModule){const Y=$.getFragmentData(y.ACTION_MODULE_FRAGMENT,U.data.createModule);s.push(Y)}}}catch(I){console.error(`Failed to ${a==="convert"?"convert":"copy"} module "${T.name}":`,I),h++}if(s.length>0){const T=s.length,I=_.length;f({title:h>0?`Partial ${a==="convert"?"convert":"copy"} completed`:`Modules ${a==="convert"?"converted":"copied"} successfully`,description:h>0?`${T} of ${I} modules ${a==="convert"?"converted":"copied"} successfully`:`${T} module${T>1?"s":""} ${a==="convert"?"converted":"copied"} successfully`,status:h>0?"warning":"success",duration:3e3,isClosable:!0}),s.length>0&&o?.(),N(""),M([])}else throw new Error(`Failed to ${a==="convert"?"convert":"copy"} any modules`)}catch(s){const h=s instanceof Error?s.message:`Failed to ${a==="convert"?"convert":"copy"} modules`;f({title:a==="convert"?"Convert failed":"Copy failed",description:h,status:"error",duration:5e3,isClosable:!0}),l?.(s instanceof Error?s:new Error(h))}finally{S(!1)}},[_,b,C,f,o,l,x,z,D,a]),k=r.useCallback(()=>{N(""),M([]),u("copy"),n?.()},[n]);r.useEffect(()=>{m&&m({cancelButton:!1,saveButton:_.length===0||p})},[_.length,p,m]),r.useEffect(()=>{c&&c({cancelButton:k,saveButton:w})},[c,k,w]);const H=r.useMemo(()=>A.map(s=>({value:s.id,label:s.name})),[A]),v=r.useMemo(()=>L.filter(s=>a==="copy"?!0:!s.quantumOwned).map(s=>({value:s.id,label:s.name,isQuantumOwned:s.quantumOwned})),[L,a]),G=j.fetching,J=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:a,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(X.st,{placeholder:"Choose a group...",options:H,value:H.find(s=>s.value===i)||null,onChange:P,isLoading:G,isDisabled:G,isClearable:!0}),j.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",j.error.message]})]})]}),i&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:a==="convert"?"Select Module to Convert":"Select Module to Copy"}),J?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(X.st,{placeholder:a==="convert"?"Choose modules to convert...":"Choose modules to copy...",options:v,value:v.filter(s=>E.includes(s.value)),onChange:R,isDisabled:v.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(s,{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:s.label}),h==="value"&&s.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),s.isQuantumOwned&&h==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),v.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]})]})]}),_.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:_.length===1?`Module to ${a==="copy"?"Copy":"Convert"}`:`${_.length} Modules to ${a==="copy"?"Copy":"Convert"}`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[_.map((s,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,". ",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)),_.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: ",_.length," modules will be"," ",a==="copy"?"copied":"converted"]})}),x&&_.filter(s=>s.moduleActions.some(h=>!h.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:a==="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:k,isDisabled:p,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:a==="copy"?"blue":"green",onClick:w,isDisabled:_.length===0||p,isLoading:p,loadingText:`${a==="copy"?"Copying":"Converting"}...`,children:[a==="copy"?"Copy":"Convert"," ",_.length===1?"Module":`${_.length} Modules`]})]})]})})},me=({name:o,setName:n,actions:l,selectedActionIds:d,setSelectedActionIds:m,availableCategories:c,selectedCategoryIds:x,setSelectedCategoryIds:f,description:i,setDescription:N,...E})=>{const M=t.useDisclosure(),p=r.useMemo(()=>l.map(b=>({...b,selected:d.includes(b.id)})),[l,d]),S=r.useMemo(()=>l.reduce((b,C)=>(b[C.id]=C,b),{}),[l]),a=r.useMemo(()=>d.map(b=>S[b]),[p,d]),u=r.useCallback((b,C)=>{m(C?[...d,b.id]:d.filter(z=>z!==b.id))},[d,m]),j=r.useCallback(b=>{n(b.target.value)},[n]),g=r.useCallback(b=>{N?.(b.target.value)},[N]);return e.jsxRuntimeExports.jsxs(t.Box,{...E,children:[e.jsxRuntimeExports.jsxs(t.HStack,{gap:"2rem",children:[e.jsxRuntimeExports.jsx(Ne,{name:o??"",onInputChange:j}),e.jsxRuntimeExports.jsx(Le,{availableCategories:c,value:x,onChange:f})]}),e.jsxRuntimeExports.jsx(ke,{description:i??"",onInputChange:g}),e.jsxRuntimeExports.jsx(Ie,{value:a,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(xe,{actions:p,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"})})]})]})]})},Ne=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})]})),Le=r.memo(({availableCategories:o,value:n,onChange:l})=>{const d=r.useMemo(()=>[...o,{id:"other",name:"Other"}],[o]),m=r.useMemo(()=>d.map(c=>({value:c.id,label:c.name})),[d]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(Z,{children:"Module Category"}),e.jsxRuntimeExports.jsx(X.st,{isDisabled:o.length===0,isClearable:!0,options:m,value:d.filter(c=>n.includes(c.id)).map(c=>({value:c.id,label:c.name})),onChange:c=>l(c?[c.value]:[]),placeholder:"Select category"})]})}),ke=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})]})),Ie=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(fe,{value:d,onChange:m=>{const c=m(d);n(c.map(x=>x.id))}})]})}),pe=({value:o,onChange:n,forceKind:l,disableRemove:d,disableKind:m,isDisabled:c,lockRanges:x,...f})=>{const i=r.useMemo(()=>[...o].sort((p,S)=>{const a=oe.availablePlanes.indexOf(p.plane),u=oe.availablePlanes.indexOf(S.plane);return a-u}),[o]),N=r.useCallback(p=>"segment"in p.id?K.getSegmentNameWithPlane(p.id.segment,p.plane,!0)??"Unknown":K.getJointNameWithPlane(p.id.joint,p.plane,!0)??"Unknown",[]),E=r.useCallback((p,S)=>{const a=i.findIndex(j=>j.id===S.id&&j.plane===S.plane);let u=[...i];l&&(S={...S,kind:l}),u[a]=S,x&&(u=u.map(j=>({...j,min:S.min,max:S.max}))),n(u)},[n,i,l,x]),M=r.useCallback(p=>{const S=i.filter(a=>a.id!==p.id||a.plane!==p.plane);n(S)},[n,i]);return e.jsxRuntimeExports.jsx(t.VStack,{alignItems:"flex-start",overflowY:"auto",...f,children:i.map((p,S)=>e.jsxRuntimeExports.jsx(De,{label:N(p),parameter:p,onChange:a=>E(S,a),onRemove:d||c?void 0:()=>M(p),forceKind:l,disableKind:m||c,isDisabled:c},`${JSON.stringify(p.id)}-${p.plane}`))})},De=({label:o,parameter:n,onChange:l,onRemove:d,forceKind:m,disableKind:c,isDisabled:x})=>{const f=r.useCallback(E=>"joint"in n.id?K.getJointAngleDirectionName(n.id.joint,n.plane,E<0?-1:1):K.getSegmentAngleDirectionName(n.id.segment,n.plane,E<0?-1:1),[n]),{min:i,max:N}="joint"in n.id?K.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:de.FaTrash}),onClick:d}),!m&&e.jsxRuntimeExports.jsx(ve,{selectedItem:n?.kind??F.ThresholdKind.Limit,onChange:({value:E})=>l({...n,kind:E}),isDisabled:c||x,buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:F.ThresholdKind.Limit,label:"limit"},{value:F.ThresholdKind.Target,label:"target"}]})]}),e.jsxRuntimeExports.jsx(ye,{w:"100%",size:"xs",min:i,max:N,zeroMarker:!0,value:[n.min,n.max],onChange:E=>l({...n,min:E[0],max:E[1]}),formatValue:E=>`${Math.abs(E)}°`,valueLabel:E=>f(E)??"",positiveNegativeLabels:f(0)?[f(-1)??"",f(1)??""]:void 0,isDisabled:x})]})},ae=(o,n)=>"segment"in o&&"segment"in n&&o.segment===n.segment||"joint"in o&&"joint"in n&&o.joint===n.joint,he=({options:o,value:n,onChange:l,forceKind:d,singleValue:m,singleValueSideless:c,editOnly:x,disableKind:f,maxParameters:i,...N})=>{const E=c?2:i,M=r.useMemo(()=>o.map(u=>({label:"segment"in u.id?K.getSegmentNameWithPlane(u.id.segment,u.plane,!0)??"Unknown":K.getJointNameWithPlane(u.id.joint,u.plane,!0)??"Unknown",value:u.id,plane:u.plane})),[o]),p=r.useMemo(()=>{if(!c||n.length===0)return M;const u=n[0];return M.filter(j=>oe.getAnalysisPartIdNoSide(j.value)===oe.getAnalysisPartIdNoSide(u.id)&&j.plane===u.plane)},[M,n,c]),S=r.useMemo(()=>M.filter(u=>n.some(j=>ae(j.id,u.value)&&j.plane===u.plane)),[M,n]),a=r.useCallback(u=>{const j=u.map(g=>{const b=n.find(L=>ae(L.id,g.value)&&L.plane===g.plane),C=o.find(L=>ae(L.id,g.value)&&L.plane===g.plane),z=c?n.find(L=>oe.getAnalysisPartIdNoSide(L.id)===oe.getAnalysisPartIdNoSide(g.value)&&L.plane===g.plane):void 0,D=z&&!b?z.min:C&&C.min?C.min:0,A=z&&!b?z.max:C&&C.max?C.max:0;return b??{id:g.value,plane:g.plane,min:D,max:A,kind:d??F.ThresholdKind.Limit}});l(j)},[l,n,o,d,c]);return r.useEffect(()=>{const u=n.filter(j=>o.some(g=>ae(g.id,j.id)&&g.plane===j.plane));u.length!==n.length&&l(u)},[o,l]),e.jsxRuntimeExports.jsxs(t.Box,{...N,children:[e.jsxRuntimeExports.jsx(X.st,{isMulti:!m,placeholder:n.length?`${n.length} selected`:"Search...",value:S,isDisabled:x||S.length>=(E??1/0),onChange:u=>Array.isArray(u)?a([...u]):a(u!==null?[u]:[]),options:p,controlShouldRenderValue:!1}),e.jsxRuntimeExports.jsx(pe,{marginTop:2,maxH:"28rem",value:n,onChange:l,forceKind:d,disableKind:f,isDisabled:x,lockRanges:c})]})},je=o=>{switch(o){case F.SensorLocation.Thorax:return"Thorax";case F.SensorLocation.CenterBack:return"Center Back";case F.SensorLocation.Pelvis:return"Pelvis";case F.SensorLocation.LeftThigh:return"Left Thigh";case F.SensorLocation.RightThigh:return"Right Thigh";case F.SensorLocation.LeftShank:return"Left Shank";case F.SensorLocation.RightShank:return"Right Shank";case F.SensorLocation.LeftFoot:return"Left Foot";case F.SensorLocation.RightFoot:return"Right Foot";case F.SensorLocation.LeftUpperArm:return"Left Upper Arm";case F.SensorLocation.RightUpperArm:return"Right Upper Arm";case F.SensorLocation.LeftForearm:return"Left Forearm";case F.SensorLocation.RightForearm:return"Right Forearm";case F.SensorLocation.Head:return"Head"}return console.warn(`Unknown sensor location: ${o}`),"Unknown"},_e=6,Ge=[F.SensorLocation.LeftFoot,F.SensorLocation.LeftShank,F.SensorLocation.LeftThigh,F.SensorLocation.Pelvis,F.SensorLocation.RightFoot,F.SensorLocation.RightShank,F.SensorLocation.RightThigh,F.SensorLocation.Thorax,F.SensorLocation.CenterBack,F.SensorLocation.Head],Be=Ge.map(o=>({label:je(o),value:o})),ue=(o,n)=>o.map(l=>({label:n?n(l):l,value:l})),Pe=({id:o,onError:n,onCancel:l,onSave:d,hideButtons:m,setButtonOnClick:c,setButtonDisabled:x,quantumOwned:f,isView:i})=>{const[{fetching:N},E]=Q.useMutation(y.CREATE_ACTION),[{fetching:M},p]=Q.useMutation(y.UPDATE_ACTION),[{data:S}]=Q.useQuery({query:y.GET_ACTION_BY_ID,variables:{id:o??""},pause:!o}),a=$.getFragmentData(y.ACTION_FRAGMENT,S?.getActionById),u=N||M,j=!!a&&!!o,[g,b]=r.useState(""),[C,z]=r.useState(""),[D,A]=r.useState(""),[L,_]=r.useState(""),[P,R]=r.useState(),[w,k]=r.useState([]),[H,v]=r.useState([]),[G,J]=r.useState([]),s=r.useMemo(()=>H.map(O=>O.value),[H]),h=Ee.usePartOptionsForSensorLocations(s),[{data:T}]=Q.useQuery({query:y.GET_ALL_MODULE_CATEGORIES}),I=r.useMemo(()=>$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,T?.moduleCategories)?.map(W=>({label:W.name,value:W.id})),[T?.moduleCategories]),B=r.useMemo(()=>ue(Object.values(F.SessionType),K.mapSessionTypeEnumToLabel),[]),[U,Y]=r.useState([]),q=g.length>0,[te,ce]=r.useState({});r.useEffect(()=>{if(a){const O=$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,a.categories),W={name:a.name,activityType:a.activityType??void 0,description:a.description||"",cameraPlacement:a.cameraPlacement||"",videoLink:a.videoLink||"",sessionType:a.sessionType.map(V=>({label:K.mapSessionTypeEnumToLabel(V),value:V})),categories:O?.map(V=>V.id)||[],sensorLocations:a.sensorLocations.map(V=>({label:je(V),value:V})),thresholds:re.thresholdsToParameters(a.thresholds)};b(W.name),R(W.activityType??void 0),z(W.description),A(W.cameraPlacement),_(W.videoLink),k(W.sessionType),J(O?.map(V=>V.id)||[]),v(W.sensorLocations),Y(W.thresholds),ce(W)}},[a]);const ne=r.useMemo(()=>JSON.stringify(te)!==JSON.stringify({name:g,description:C,cameraPlacement:D,videoLink:L,activityType:P,sessionType:w.map(O=>O.value),categories:G,sensorLocations:s,thresholds:re.parametersToThresholds(U)}),[te,g,s,C,D,L,P,w,G,U]),se=r.useCallback(()=>{const O={name:g,description:C,cameraPlacement:D,videoLink:L,activityType:P,activityKind:K.getActivityKindFromActivityType(P),sessionType:w.map(V=>V.value),categories:G,sensorLocations:s,thresholds:re.parametersToThresholds(U),laterality:F.ActionLaterality.Either,quantumOwned:f};let W;j&&o?W=p({id:o,fields:O}):W=E({fields:O}),W.then(({error:V})=>{V?n(V):d()})},[f,E,p,o,g,s,C,D,L,P,w,G,j,U,d,n]);return r.useEffect(()=>{x&&x({cancelButton:u,saveButton:i?!0:u||!q||!ne})},[u,x,q,ne,i]),r.useEffect(()=>{c&&c({cancelButton:l,saveButton:i?()=>{}:se})},[c,l,se,i]),console.log(q,ne,u,te),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(ee,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:g,onChange:O=>b(O.target.value),type:"text",placeholder:"i.e. Lunge & Return",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Activity Type"}),e.jsxRuntimeExports.jsx(X.st,{isClearable:!0,isMulti:!1,value:P?{label:K.mapActivityTypeEnumToLabel(P),value:P}:null,onChange:O=>R(O?.value),options:ue(Object.values(F.ActivityType),K.mapActivityTypeEnumToLabel),placeholder:"(optional) Select activity type",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Camera Placement"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:D,onChange:O=>A(O.target.value),rows:2,placeholder:"(optional) Describe camera setup, placement, angles",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Video Link"}),e.jsxRuntimeExports.jsx(t.Input,{value:L,onChange:O=>_(O.target.value),type:"url",placeholder:"(optional) https://...",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Description"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:C,onChange:O=>z(O.target.value),rows:2,placeholder:"(optional) Describe how to perform the test or exercise",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Link to Category"}),e.jsxRuntimeExports.jsx(X.st,{isMulti:!0,value:I?.filter(O=>G.includes(O.value)),onChange:O=>J((O??[]).map(W=>W.value)),options:I,placeholder:"Select one or more categories",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Session Types"}),e.jsxRuntimeExports.jsx(X.st,{isMulti:!0,value:w,onChange:O=>k(O??[]),options:B,placeholder:"Select one or more session types",isDisabled:i})]})]}),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(ee,{children:"Sensor Locations"}),e.jsxRuntimeExports.jsx(X.st,{isMulti:!0,value:H,onChange:O=>v([...O]),options:Be,isOptionDisabled:()=>H.length>=_e,isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(he,{options:h,value:U,onChange:Y,editOnly:i})]})]}),e.jsxRuntimeExports.jsx("div",{className:re.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:u,onClick:l,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:u||!q||!ne,isLoading:u,onClick:se,children:"Save changes"})]})})]})},ee=({children:o})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:o}),ze=({id:o,onCancel:n,onSave:l,onError:d,hideButtons:m,quantumOwned:c,setButtonOnClick:x,setButtonDisabled:f})=>{const[{data:i}]=Q.useQuery({query:c?y.GET_QUANTUM_OWNED_ACTIONS:y.GET_ACTIONS}),[{data:N}]=Q.useQuery({query:y.GET_MODULE_BY_ID,variables:{id:o},pause:!o}),[{data:E}]=Q.useQuery({query:y.GET_ALL_MODULE_CATEGORIES}),M=$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,E?.moduleCategories),[{fetching:p},S]=Q.useMutation(y.UPDATE_MODULE),[{fetching:a},u]=Q.useMutation(y.CREATE_MODULE),j=$.getFragmentData(y.ACTION_FRAGMENT,c?i?.quantumOwnedActions:i?.actions)??[],g=$.getFragmentData(y.ACTION_MODULE_FRAGMENT,N?.module),b=$.getFragmentData(y.MODULE_ACTION_FRAGMENT,g?.moduleActions)??[],[C,z]=r.useState([...b.map(k=>k.actionId)??[]]),[D,A]=r.useState(g?.name??""),[L,_]=r.useState([]),[P,R]=r.useState(g?.description??"");r.useEffect(()=>{g&&(z(b.map(k=>k.actionId)),A(g.name),R(g.description??""),_(g.categories.map(k=>$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,k).id)??[]))},[g,b]);const w=r.useCallback(()=>{let k;const H={actions:C,name:D,categories:L.filter(v=>v!=="other"),description:P,quantumOwned:c};g?k=S({id:g.id,input:H}):k=u({input:H}),k.then(({error:v})=>{v?d(v):l()})},[u,S,C,D,P,L,g,l,d]);return r.useEffect(()=>{f&&f({cancelButton:p||a,saveButton:p||a||!D||P.trim().split(/\s+/).filter(Boolean).length>40})},[f,p,a,C,D,P]),r.useEffect(()=>{x&&x({cancelButton:n,saveButton:w})},[x,n,w]),e.jsxRuntimeExports.jsxs(t.Box,{width:"100%",children:[e.jsxRuntimeExports.jsx(me,{name:D,setName:A,actions:j,selectedActionIds:C,setSelectedActionIds:z,availableCategories:M??[],selectedCategoryIds:L,setSelectedCategoryIds:_,description:P,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:p||a,onClick:n,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:p||a||!D||P.trim().split(/\s+/).filter(Boolean).length>40,isLoading:p||a,onClick:w,children:"Save"})]})})]})};exports.ActivityList=xe;exports.CopyActivityForm=Oe;exports.CopyModuleForm=Fe;exports.ModuleForm=me;exports.ParameterEditList=pe;exports.ParameterEditSelect=he;exports.UpsertActivityForm=Pe;exports.UpsertModuleForm=ze;
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"),ge=require("./ufuzzy-vendor-7qHa_k39.cjs"),X=require("./react-select-vendor-D_Q2fL5j.cjs"),de=require("./react-icons-vendor-D2s8zw9h.cjs"),q=require("./graphql-vendor-B-QTAQSb.cjs"),$=require("./generated.cjs"),y=require("./graphql-C6M9oyU0.cjs"),le=require("./react-dnd-vendor-BPzSDojS.cjs"),F=require("./generated-graphql.cjs"),K=require("./services.cjs"),oe=require("./types.cjs"),re=require("./utils.cjs"),Ee=require("./hooks.cjs"),Re=({setSearch:o,actions:n,updateUseCases:l,hideUseCaseFilter:d=!1})=>{const m=r.useMemo(()=>n?.flatMap(c=>c.useCases).filter((c,x,f)=>f.findIndex(i=>i.id===c.id)===x).map(c=>({label:c.name,value:c.id}))||[],[n]);return e.jsxRuntimeExports.jsxs(t.Flex,{width:"100%",alignContent:"space-evenly",gap:4,children:[e.jsxRuntimeExports.jsxs(t.InputGroup,{size:"md",flex:1,children:[e.jsxRuntimeExports.jsx(t.InputLeftElement,{children:e.jsxRuntimeExports.jsx(t.Icon,{as:de.FaSearch,color:"gray.300"})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"Search by name...",width:"100%",maxW:d?void 0:"30rem",onChange:c=>o(c.target.value)})]}),!d&&e.jsxRuntimeExports.jsx(t.InputGroup,{size:"md",children:e.jsxRuntimeExports.jsx(X.st,{size:"md",chakraStyles:{container:c=>({...c,width:"100%"})},menuPortalTarget:document.body,placeholder:"Filter use case",isMulti:!0,options:m,onChange:c=>l(c.map(x=>x.value))})})]})},Z=({children:o})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:o}),fe=({value:o,onChange:n})=>{const l=r.useState(()=>Math.random().toString(36).substring(2,15))[0],d=r.useCallback((m,c)=>{n(x=>{const f=[...x],[i]=f.splice(m,1);return f.splice(c,0,i),f})},[n]);return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsx(le.DndProvider,{backend:le.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,c)=>e.jsxRuntimeExports.jsx(be,{listKey:l,index:c,id:m.id,name:m.name,move:d},m.id))})]})})})})},be=({listKey:o,index:n,id:l,name:d,move:m})=>{const c=r.useRef(null),[{handlerId:x},f]=le.useDrop({accept:o,collect:p=>({handlerId:p.getHandlerId()?.toString()??""}),hover:(p,C)=>{if(!c.current)return;const a=p.index,u=n;if(a===u)return;const j=c.current?.getBoundingClientRect(),g=(j.bottom-j.top)/2,T=C.getClientOffset().y-j.top;a<u&&T<g||a>u&&T>g||(m(a,u),p.index=u)}}),[{isDragging:i},N]=le.useDrag({type:o,item:()=>({id:l,index:n}),collect:p=>({isDragging:p.isDragging()})}),E=i?.6:1,M=i?"grabbing":"grab";return N(f(c)),e.jsxRuntimeExports.jsxs(t.Tr,{ref:c,style:{opacity:E,cursor:M},"data-handler-id":x,children:[e.jsxRuntimeExports.jsx(t.Td,{children:n+1}),e.jsxRuntimeExports.jsx(t.Td,{children:d})]})},ve=({items:o,onChange:n,selectedItem:l,isDisabled:d,selectedProps:m,buttonProps:c})=>{const x=i=>i===l||i.value===l,f=i=>x(i)?{...c,...m}:c;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:d,children:o.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:()=>x(i)?null:n(i,N),isDisabled:i.disabled,...f(i),children:i.label})},N))})},ie=(o,n)=>n<0?-1*Math.abs(o):Math.abs(o),ye=({isReversed:o,min:n,max:l,value:d,onChange:m,inputProps:c,size:x,zeroMarker:f,formatValue:i,valueLabel:N,positiveNegativeLabels:E,isDisabled:M,...p})=>{const[C,a]=r.useState([void 0,void 0]),u=C[0],j=C[1],g=f&&n<-5&&l>5,b=Number(d?.[0]??j??n)>0?1:-1,T=Number(d?.[1]??j??l)<0?-1:1,z=E?.[0]===E?.[1],D=d?.[0],A=d?.[1];r.useEffect(()=>{D!==void 0&&A!==void 0&&a([D.toFixed(0),A.toFixed(0)])},[D,A,a]);const L=r.useCallback(([v,G])=>{v<G&&a([v.toFixed(0),G.toFixed(0)])},[a]),_=r.useCallback(([v,G])=>{v<G&&m([v,G])},[m]),P=r.useCallback(()=>{a(([v,G])=>{const J=isNaN(Number(v))?n:Number(v),s=isNaN(Number(G))?l:Number(G),h=ie(Number(J),b),S=ie(Number(s),T),I=b<0?Math.max(h,n):Math.min(h,l),B=T<0?Math.max(S,n):Math.min(S,l);return I>B?(m([B,I]),[B.toFixed(0),I.toFixed(0)]):(m([I,B]),[I.toFixed(0),B.toFixed(0)])})},[m,a,b,T,n,l]),R=r.useCallback(v=>{const G=v===""||isNaN(Number(v))?v:ie(Number(v),b);a(([J,s])=>[G.toString(),s])},[a,b]),w=r.useCallback(v=>{const G=v===""||isNaN(Number(v))?v:ie(Number(v),T);a(([J,s])=>[J,G.toString()])},[a,T]),k=r.useMemo(()=>x==="xs"?"0.75rem":void 0,[x]),H=r.useCallback((v,G)=>{const J=Number(G.target.value);if(!u||!j||![-1,1].includes(J))return;const s=I=>J<0?-1*Math.abs(I):Math.abs(I),h=v?s(Number(u)):Number(u),S=v?Number(j):s(Number(j));h>S?m([S,h]):m([h,S])},[u,j,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:o,value:[Number(u??n),Number(j??l)],max:l,min:n,minStepsBetweenThumbs:3,step:1,onChange:L,onChangeEnd:_,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:k,h:k}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:1,w:k,h:k})]})}),N&&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:N(n)}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:x??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:N(l)})]}),e.jsxRuntimeExports.jsxs(t.Flex,{direction:o?"row-reverse":"row",justifyContent:"center",alignItems:"center",gap:"0.125em",children:[E&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:x,fontWeight:"bold",value:b,onChange:v=>H(!0,v),isDisabled:z||M,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:E[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:E[1]})]}),e.jsxRuntimeExports.jsx(t.NumberInput,{precision:0,size:x??"sm",min:0,max:b<0?Math.abs(n):A??l,value:u===""?"":Math.abs(Number(u??n)),onChange:R,onBlur:P,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:M,...c,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),e.jsxRuntimeExports.jsx(t.NumberInput,{size:x??"sm",min:0,max:T<0?Math.abs(D??n):l,precision:0,value:j===""?"":Math.abs(Number(j??l)),onChange:w,onBlur:P,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:M,...c,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),E&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:x,fontWeight:"bold",value:T,onChange:v=>H(!1,v),isDisabled:z||M,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:E[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:E[1]})]})]})]})},Ce=({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))}),Te=new ge.uFuzzy({}),Se=({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,Me=(o,n)=>{if(!n||!n.trim().length)return o;const l=o.map(m=>m.name??"");return Te.filter(l,n)?.map(m=>o[m])??[]},Ae=o=>!o||o.length===0?"None":o.map(n=>n.replace(/([A-Z])/g," $1").trim()).join(", "),we=(o,n)=>!n||n.length==0?o:o.filter(l=>l.useCases?.some(d=>n.includes(d.id))??!1),xe=({actions:o,totalActions:n,onCreate:l,onDelete:d,onEdit:m,onView:c,onSelected:x,onDuplicate:f,disableMultiSelect:i,disableDelete:N,disableEdit:E,disableCreate:M,hideUseCase:p=!0,tableProps:C,containerProps:a,quantumIconSrc:u="/favicon.ico"})=>{const[j,g]=r.useState(""),[b,T]=r.useState(),z=r.useMemo(()=>{if(!o)return;const R=Me(o,j);return p?R:we(R,b)},[o,j,b,p]),D=r.useCallback(()=>{if(!d)return;const w=o.filter(k=>k.selected&&!k.quantumOwned).map(k=>k.id);d(w)},[o,d]),A=r.useCallback(()=>{if(!f)return;const R=o.filter(w=>w.selected);f(R.map(w=>w.id)),x&&R.forEach(w=>x(w,!1))},[o,f,x]),L=r.useMemo(()=>o.some(R=>R.selected&&!R.quantumOwned),[o]),_=r.useMemo(()=>o.some(R=>R.selected),[o]),P=r.useMemo(()=>o.some(R=>R.selected&&R.quantumOwned),[o]);return e.jsxRuntimeExports.jsxs(t.Box,{...a,children:[e.jsxRuntimeExports.jsxs(t.Flex,{alignContent:"space-between",gap:4,children:[(l||d||f)&&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:P?L?"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:!L||!d||N,onClick:D,children:"Delete Selected"})}),f&&!i&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!_,onClick:A,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx(Re,{setSearch:g,actions:o,updateUseCases:T,hideUseCaseFilter:p})]}),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 ",z?.length??0," of"," ",n??o.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:z?.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:w=>x(R,w.target.checked)}),(R.quantumOwned||!m)&&c&&e.jsxRuntimeExports.jsx(t.Button,{ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:()=>c(R.id),children:"View"}),!R.quantumOwned&&m&&e.jsxRuntimeExports.jsx(t.Button,{isDisabled:E,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(Se,{action:R,quantumIconSrc:u}),R.name]})}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",whiteSpace:"break-spaces",children:Ae(R.sensorLocations)}),!p&&e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:e.jsxRuntimeExports.jsx(Ce,{containerProps:{flexWrap:"wrap"},tags:R.useCases?.map(w=>w.name)??[]})})]},R.id))})]})})]})},Oe=({onSave:o,onCancel:n,onError:l,hideButtons:d=!1,setButtonDisabled:m,setButtonOnClick:c,quantumOwned:x})=>{const f=t.useToast(),[i,N]=r.useState("copy"),[E,M]=r.useState(""),[p,C]=r.useState([]),[a,u]=r.useState(!1),[j]=q.useQuery({query:y.GET_GROUPS}),[g]=q.useQuery({query:y.GET_ACTIONS_BY_GROUP,variables:{groupId:E},pause:!E}),[,b]=q.useMutation(y.CREATE_ACTION),[,T]=q.useMutation(y.CONVERT_ACTION_TO_QUANTUM_OWNED),z=r.useMemo(()=>j.data?.groups?j.data.groups.map(s=>$.getFragmentData(y.GROUP_FRAGMENT,s)):[],[j.data]),D=r.useMemo(()=>g.data?g.data.actions.map(h=>$.getFragmentData(y.ACTION_FRAGMENT,h)):[],[g.data]),A=r.useMemo(()=>D.filter(s=>p.includes(s.id)),[D,p]),L=r.useCallback(s=>{const h=s?.value||"";M(h),C([])},[]),_=r.useCallback(s=>{const h=s.map(S=>S.value);C(h)},[]),P=r.useCallback(async s=>{const h=$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,s.categories),S={...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(B=>({...B,id:void 0})),categories:h?.map(B=>B.id),quantumOwned:x,id:void 0},I=await b({fields:S});if(I.error)throw new Error(I.error.message);if(I.data?.createAction)return $.getFragmentData(y.ACTION_FRAGMENT,I.data.createAction);throw new Error("No action data returned")},[b,x]),R=r.useCallback(async s=>{const h=await T({id:s.id});if(h.error)throw new Error(h.error.message);if(h.data?.convertActionToQuantumOwned)return $.getFragmentData(y.ACTION_FRAGMENT,h.data.convertActionToQuantumOwned);throw new Error("No action data returned")},[T]),w=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 h=0;const S=i==="copy"?P:R,I=i==="copy"?"copy":"convert";for(const B of A)try{const U=await S(B);s.push(U)}catch(U){console.error(`Failed to ${I} activity "${B.name}":`,U),h++}if(s.length>0){const B=s.length,U=A.length,Y=i==="copy"?"copied":"converted",Q=i==="copy"?"copy":"convert";f({title:h>0?`Partial ${Q} completed`:`Activities ${Y} successfully`,description:h>0?`${B} of ${U} activities ${Y} successfully`:`${B} activit${B>1?"ies":"y"} ${Y} successfully`,status:h>0?"warning":"success",duration:3e3,isClosable:!0}),o?.(),M(""),C([])}else throw new Error(`Failed to ${I} any activities`)}catch(s){const h=i==="copy"?"copy":"convert",S=s instanceof Error?s.message:`Failed to ${h} activities`;f({title:`${i==="copy"?"Copy":"Convert"} failed`,description:S,status:"error",duration:5e3,isClosable:!0}),l?.(s instanceof Error?s:new Error(S))}finally{u(!1)}},[A,i,P,R,f,o,l]),k=r.useCallback(()=>{M(""),C([]),N("copy"),n?.()},[n]);r.useEffect(()=>{m&&m({cancelButton:!1,saveButton:A.length===0||a})},[A.length,a,m]),r.useEffect(()=>{c&&c({cancelButton:k,saveButton:w})},[c,k,w]);const H=r.useMemo(()=>z.map(s=>({value:s.id,label:s.name})),[z]),v=r.useMemo(()=>D.filter(s=>i==="copy"?!0:!s.quantumOwned).map(s=>({value:s.id,label:s.name,isQuantumOwned:s.quantumOwned})),[D,i]),G=j.fetching,J=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=>{N(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(X.st,{placeholder:"Choose a group...",options:H,value:H.find(s=>s.value===E)||null,onChange:L,isLoading:G,isDisabled:G,isClearable:!0}),j.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",j.error.message]})]})]}),E&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsxs(Z,{children:["Select Activities to"," ",i==="copy"?"Copy":"Convert"]}),J?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(X.st,{placeholder:`Choose activities to ${i}...`,options:v,value:v.filter(s=>p.includes(s.value)),onChange:_,isDisabled:v.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(s,{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:s.label}),h==="value"&&s.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),s.isQuantumOwned&&h==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),v.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,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,". ",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(S=>S.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:k,isDisabled:a,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:i==="copy"?"blue":"green",onClick:w,isDisabled:A.length===0||a,isLoading:a,loadingText:`${i==="copy"?"Copying":"Converting"}...`,children:[i==="copy"?"Copy":"Convert"," ",A.length===1?"Activity":`${A.length} Activities`]})]})]})})},Fe=({onSave:o,onCancel:n,onError:l,hideButtons:d=!1,setButtonDisabled:m,setButtonOnClick:c,quantumOwned:x})=>{const f=t.useToast(),[i,N]=r.useState(""),[E,M]=r.useState([]),[p,C]=r.useState(!1),[a,u]=r.useState("copy"),[j]=q.useQuery({query:y.GET_GROUPS}),[g]=q.useQuery({query:y.GET_MODULES_BY_GROUP,variables:{groupId:i},pause:!i}),[,b]=q.useMutation(y.CREATE_MODULE),[,T]=q.useMutation(y.UPDATE_MODULE),[,z]=q.useMutation(y.CREATE_ACTION),[,D]=q.useMutation(y.CONVERT_ACTION_TO_QUANTUM_OWNED),A=r.useMemo(()=>j.data?.groups?j.data.groups.map(s=>$.getFragmentData(y.GROUP_FRAGMENT,s)):[],[j.data]),L=r.useMemo(()=>g.data?.modules?$.getFragmentData(y.ACTION_MODULE_FRAGMENT,g.data?.modules).map(h=>{const S=$.getFragmentData(y.MODULE_ACTION_FRAGMENT,h.moduleActions);return{...h,moduleActions:S.map(I=>({...I,action:$.getFragmentData(y.ACTION_FRAGMENT,I.action)})),categories:$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,h.categories)}}):[],[g.data]),_=r.useMemo(()=>L.filter(s=>E.includes(s.id)),[L,E]),P=r.useCallback(s=>{const h=s?.value||"";N(h),M([])},[]),R=r.useCallback(s=>{const h=s.map(S=>S.value);M(h)},[]),w=r.useCallback(async()=>{if(C(!0),!_.length){C(!1);const s=new Error(`No modules selected for ${a==="convert"?"converting":"copying"}`);l?.(s);return}try{const s=[];let h=0;for(const S of _)try{let I=S.moduleActions.map(B=>B.actionId);if(x){const B=S.moduleActions.map(Q=>Q.action),U=async Q=>{if(a==="copy"){if(Q.quantumOwned)return Q;const ce=$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,Q.categories),ne={...Q,quantumOwned:!0,thresholds:Q.thresholds.map(O=>({...O,id:void 0})),categories:ce?.map(O=>O.id),id:void 0},se=await z({fields:ne});return se.error||!se.data?.createAction?null:$.getFragmentData(y.ACTION_FRAGMENT,se.data.createAction)}if(Q.quantumOwned)return Q;const te=await D({id:Q.id});return te.error||!te.data?.convertActionToQuantumOwned?null:$.getFragmentData(y.ACTION_FRAGMENT,te.data.convertActionToQuantumOwned)};I=(await Promise.all(B.map(U))).filter(Q=>!!Q).map(Q=>Q.id)}if(a==="convert"){const B={name:S.name,description:S.description||void 0,actions:I,categories:S.categories.map(Y=>Y.id),quantumOwned:!0},U=await T({id:S.id,input:B});if(U.error)throw new Error(U.error.message);if(U.data?.updateModule){const Y=$.getFragmentData(y.ACTION_MODULE_FRAGMENT,U.data.updateModule);s.push(Y)}}else{const B={name:`${S.name} (Copy)`,description:S.description||void 0,actions:I,categories:S.categories.map(Y=>Y.id),quantumOwned:x},U=await b({input:B});if(U.error)throw new Error(U.error.message);if(U.data?.createModule){const Y=$.getFragmentData(y.ACTION_MODULE_FRAGMENT,U.data.createModule);s.push(Y)}}}catch(I){console.error(`Failed to ${a==="convert"?"convert":"copy"} module "${S.name}":`,I),h++}if(s.length>0){const S=s.length,I=_.length;f({title:h>0?`Partial ${a==="convert"?"convert":"copy"} completed`:`Modules ${a==="convert"?"converted":"copied"} successfully`,description:h>0?`${S} of ${I} modules ${a==="convert"?"converted":"copied"} successfully`:`${S} module${S>1?"s":""} ${a==="convert"?"converted":"copied"} successfully`,status:h>0?"warning":"success",duration:3e3,isClosable:!0}),s.length>0&&o?.(),N(""),M([])}else throw new Error(`Failed to ${a==="convert"?"convert":"copy"} any modules`)}catch(s){const h=s instanceof Error?s.message:`Failed to ${a==="convert"?"convert":"copy"} modules`;f({title:a==="convert"?"Convert failed":"Copy failed",description:h,status:"error",duration:5e3,isClosable:!0}),l?.(s instanceof Error?s:new Error(h))}finally{C(!1)}},[_,b,T,f,o,l,x,z,D,a]),k=r.useCallback(()=>{N(""),M([]),u("copy"),n?.()},[n]);r.useEffect(()=>{m&&m({cancelButton:!1,saveButton:_.length===0||p})},[_.length,p,m]),r.useEffect(()=>{c&&c({cancelButton:k,saveButton:w})},[c,k,w]);const H=r.useMemo(()=>A.map(s=>({value:s.id,label:s.name})),[A]),v=r.useMemo(()=>L.filter(s=>a==="copy"?!0:!s.quantumOwned).map(s=>({value:s.id,label:s.name,isQuantumOwned:s.quantumOwned})),[L,a]),G=j.fetching,J=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:a,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(X.st,{placeholder:"Choose a group...",options:H,value:H.find(s=>s.value===i)||null,onChange:P,isLoading:G,isDisabled:G,isClearable:!0}),j.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",j.error.message]})]})]}),i&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:a==="convert"?"Select Module to Convert":"Select Module to Copy"}),J?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(X.st,{placeholder:a==="convert"?"Choose modules to convert...":"Choose modules to copy...",options:v,value:v.filter(s=>E.includes(s.value)),onChange:R,isDisabled:v.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(s,{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:s.label}),h==="value"&&s.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),s.isQuantumOwned&&h==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),v.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]})]})]}),_.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:_.length===1?`Module to ${a==="copy"?"Copy":"Convert"}`:`${_.length} Modules to ${a==="copy"?"Copy":"Convert"}`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[_.map((s,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,". ",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(S=>S.name).join(", ")||"None"]})]})]},s.id)),_.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: ",_.length," modules will be"," ",a==="copy"?"copied":"converted"]})}),x&&_.filter(s=>s.moduleActions.some(h=>!h.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:a==="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:k,isDisabled:p,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:a==="copy"?"blue":"green",onClick:w,isDisabled:_.length===0||p,isLoading:p,loadingText:`${a==="copy"?"Copying":"Converting"}...`,children:[a==="copy"?"Copy":"Convert"," ",_.length===1?"Module":`${_.length} Modules`]})]})]})})},me=({name:o,setName:n,actions:l,selectedActionIds:d,setSelectedActionIds:m,availableCategories:c,selectedCategoryIds:x,setSelectedCategoryIds:f,description:i,setDescription:N,...E})=>{const M=t.useDisclosure(),p=r.useMemo(()=>l.map(b=>({...b,selected:d.includes(b.id)})),[l,d]),C=r.useMemo(()=>l.reduce((b,T)=>(b[T.id]=T,b),{}),[l]),a=r.useMemo(()=>d.map(b=>C[b]),[d,C]),u=r.useCallback((b,T)=>{m(T?[...d,b.id]:d.filter(z=>z!==b.id))},[d,m]),j=r.useCallback(b=>{n(b.target.value)},[n]),g=r.useCallback(b=>{N?.(b.target.value)},[N]);return e.jsxRuntimeExports.jsxs(t.Box,{...E,children:[e.jsxRuntimeExports.jsxs(t.HStack,{gap:"2rem",children:[e.jsxRuntimeExports.jsx(Ne,{name:o??"",onInputChange:j}),e.jsxRuntimeExports.jsx(Le,{availableCategories:c,value:x,onChange:f})]}),e.jsxRuntimeExports.jsx(ke,{description:i??"",onInputChange:g}),e.jsxRuntimeExports.jsx(Ie,{value:a,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(xe,{actions:p,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"})})]})]})]})},Ne=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})]})),Le=r.memo(({availableCategories:o,value:n,onChange:l})=>{const d=r.useMemo(()=>[...o,{id:"other",name:"Other"}],[o]),m=r.useMemo(()=>d.map(c=>({value:c.id,label:c.name})),[d]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(Z,{children:"Module Category"}),e.jsxRuntimeExports.jsx(X.st,{isDisabled:o.length===0,options:m,value:n.length===0?{value:"other",label:"Other"}:d.filter(c=>n.includes(c.id)).map(c=>({value:c.id,label:c.name}))[0],onChange:c=>l(c?[c.value]:[]),placeholder:"Select category"})]})}),ke=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})]})),Ie=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(fe,{value:d,onChange:m=>{const c=m(d);n(c.map(x=>x.id))}})]})}),pe=({value:o,onChange:n,forceKind:l,disableRemove:d,disableKind:m,isDisabled:c,lockRanges:x,...f})=>{const i=r.useMemo(()=>[...o].sort((p,C)=>{const a=oe.availablePlanes.indexOf(p.plane),u=oe.availablePlanes.indexOf(C.plane);return a-u}),[o]),N=r.useCallback(p=>"segment"in p.id?K.getSegmentNameWithPlane(p.id.segment,p.plane,!0)??"Unknown":K.getJointNameWithPlane(p.id.joint,p.plane,!0)??"Unknown",[]),E=r.useCallback((p,C)=>{const a=i.findIndex(j=>j.id===C.id&&j.plane===C.plane);let u=[...i];l&&(C={...C,kind:l}),u[a]=C,x&&(u=u.map(j=>({...j,min:C.min,max:C.max}))),n(u)},[n,i,l,x]),M=r.useCallback(p=>{const C=i.filter(a=>a.id!==p.id||a.plane!==p.plane);n(C)},[n,i]);return e.jsxRuntimeExports.jsx(t.VStack,{alignItems:"flex-start",overflowY:"auto",...f,children:i.map((p,C)=>e.jsxRuntimeExports.jsx(De,{label:N(p),parameter:p,onChange:a=>E(C,a),onRemove:d||c?void 0:()=>M(p),forceKind:l,disableKind:m||c,isDisabled:c},`${JSON.stringify(p.id)}-${p.plane}`))})},De=({label:o,parameter:n,onChange:l,onRemove:d,forceKind:m,disableKind:c,isDisabled:x})=>{const f=r.useCallback(E=>"joint"in n.id?K.getJointAngleDirectionName(n.id.joint,n.plane,E<0?-1:1):K.getSegmentAngleDirectionName(n.id.segment,n.plane,E<0?-1:1),[n]),{min:i,max:N}="joint"in n.id?K.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:de.FaTrash}),onClick:d}),!m&&e.jsxRuntimeExports.jsx(ve,{selectedItem:n?.kind??F.ThresholdKind.Limit,onChange:({value:E})=>l({...n,kind:E}),isDisabled:c||x,buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:F.ThresholdKind.Limit,label:"limit"},{value:F.ThresholdKind.Target,label:"target"}]})]}),e.jsxRuntimeExports.jsx(ye,{w:"100%",size:"xs",min:i,max:N,zeroMarker:!0,value:[n.min,n.max],onChange:E=>l({...n,min:E[0],max:E[1]}),formatValue:E=>`${Math.abs(E)}°`,valueLabel:E=>f(E)??"",positiveNegativeLabels:f(0)?[f(-1)??"",f(1)??""]:void 0,isDisabled:x})]})},ae=(o,n)=>"segment"in o&&"segment"in n&&o.segment===n.segment||"joint"in o&&"joint"in n&&o.joint===n.joint,he=({options:o,value:n,onChange:l,forceKind:d,singleValue:m,singleValueSideless:c,editOnly:x,disableKind:f,maxParameters:i,...N})=>{const E=c?2:i,M=r.useMemo(()=>o.map(u=>({label:"segment"in u.id?K.getSegmentNameWithPlane(u.id.segment,u.plane,!0)??"Unknown":K.getJointNameWithPlane(u.id.joint,u.plane,!0)??"Unknown",value:u.id,plane:u.plane})),[o]),p=r.useMemo(()=>{if(!c||n.length===0)return M;const u=n[0];return M.filter(j=>oe.getAnalysisPartIdNoSide(j.value)===oe.getAnalysisPartIdNoSide(u.id)&&j.plane===u.plane)},[M,n,c]),C=r.useMemo(()=>M.filter(u=>n.some(j=>ae(j.id,u.value)&&j.plane===u.plane)),[M,n]),a=r.useCallback(u=>{const j=u.map(g=>{const b=n.find(L=>ae(L.id,g.value)&&L.plane===g.plane),T=o.find(L=>ae(L.id,g.value)&&L.plane===g.plane),z=c?n.find(L=>oe.getAnalysisPartIdNoSide(L.id)===oe.getAnalysisPartIdNoSide(g.value)&&L.plane===g.plane):void 0,D=z&&!b?z.min:T&&T.min?T.min:0,A=z&&!b?z.max:T&&T.max?T.max:0;return b??{id:g.value,plane:g.plane,min:D,max:A,kind:d??F.ThresholdKind.Limit}});l(j)},[l,n,o,d,c]);return r.useEffect(()=>{const u=n.filter(j=>o.some(g=>ae(g.id,j.id)&&g.plane===j.plane));u.length!==n.length&&l(u)},[o,l]),e.jsxRuntimeExports.jsxs(t.Box,{...N,children:[e.jsxRuntimeExports.jsx(X.st,{isMulti:!m,placeholder:n.length?`${n.length} selected`:"Search...",value:C,isDisabled:x||C.length>=(E??1/0),onChange:u=>Array.isArray(u)?a([...u]):a(u!==null?[u]:[]),options:p,controlShouldRenderValue:!1}),e.jsxRuntimeExports.jsx(pe,{marginTop:2,maxH:"28rem",value:n,onChange:l,forceKind:d,disableKind:f,isDisabled:x,lockRanges:c})]})},je=o=>{switch(o){case F.SensorLocation.Thorax:return"Thorax";case F.SensorLocation.CenterBack:return"Center Back";case F.SensorLocation.Pelvis:return"Pelvis";case F.SensorLocation.LeftThigh:return"Left Thigh";case F.SensorLocation.RightThigh:return"Right Thigh";case F.SensorLocation.LeftShank:return"Left Shank";case F.SensorLocation.RightShank:return"Right Shank";case F.SensorLocation.LeftFoot:return"Left Foot";case F.SensorLocation.RightFoot:return"Right Foot";case F.SensorLocation.LeftUpperArm:return"Left Upper Arm";case F.SensorLocation.RightUpperArm:return"Right Upper Arm";case F.SensorLocation.LeftForearm:return"Left Forearm";case F.SensorLocation.RightForearm:return"Right Forearm";case F.SensorLocation.Head:return"Head"}return console.warn(`Unknown sensor location: ${o}`),"Unknown"},_e=6,Ge=[F.SensorLocation.LeftFoot,F.SensorLocation.LeftShank,F.SensorLocation.LeftThigh,F.SensorLocation.Pelvis,F.SensorLocation.RightFoot,F.SensorLocation.RightShank,F.SensorLocation.RightThigh,F.SensorLocation.Thorax,F.SensorLocation.CenterBack,F.SensorLocation.Head],Be=Ge.map(o=>({label:je(o),value:o})),ue=(o,n)=>o.map(l=>({label:n?n(l):l,value:l})),Pe=({id:o,onError:n,onCancel:l,onSave:d,hideButtons:m,setButtonOnClick:c,setButtonDisabled:x,quantumOwned:f,isView:i})=>{const[{fetching:N},E]=q.useMutation(y.CREATE_ACTION),[{fetching:M},p]=q.useMutation(y.UPDATE_ACTION),[{data:C}]=q.useQuery({query:y.GET_ACTION_BY_ID,variables:{id:o??""},pause:!o}),a=$.getFragmentData(y.ACTION_FRAGMENT,C?.getActionById),u=N||M,j=!!a&&!!o,[g,b]=r.useState(""),[T,z]=r.useState(""),[D,A]=r.useState(""),[L,_]=r.useState(""),[P,R]=r.useState(),[w,k]=r.useState([]),[H,v]=r.useState([]),[G,J]=r.useState([]),s=r.useMemo(()=>H.map(O=>O.value),[H]),h=Ee.usePartOptionsForSensorLocations(s),[{data:S}]=q.useQuery({query:y.GET_ALL_MODULE_CATEGORIES}),I=r.useMemo(()=>$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,S?.moduleCategories)?.map(W=>({label:W.name,value:W.id})),[S?.moduleCategories]),B=r.useMemo(()=>ue(Object.values(F.SessionType),K.mapSessionTypeEnumToLabel),[]),[U,Y]=r.useState([]),Q=g.length>0,[te,ce]=r.useState({});r.useEffect(()=>{if(a){const O=$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,a.categories),W={name:a.name,activityType:a.activityType??void 0,description:a.description||"",cameraPlacement:a.cameraPlacement||"",videoLink:a.videoLink||"",sessionType:a.sessionType.map(V=>({label:K.mapSessionTypeEnumToLabel(V),value:V})),categories:O?.map(V=>V.id)||[],sensorLocations:a.sensorLocations.map(V=>({label:je(V),value:V})),thresholds:re.thresholdsToParameters(a.thresholds)};b(W.name),R(W.activityType??void 0),z(W.description),A(W.cameraPlacement),_(W.videoLink),k(W.sessionType),J(O?.map(V=>V.id)||[]),v(W.sensorLocations),Y(W.thresholds),ce(W)}},[a]);const ne=r.useMemo(()=>JSON.stringify(te)!==JSON.stringify({name:g,description:T,cameraPlacement:D,videoLink:L,activityType:P,sessionType:w.map(O=>O.value),categories:G,sensorLocations:s,thresholds:re.parametersToThresholds(U)}),[te,g,s,T,D,L,P,w,G,U]),se=r.useCallback(()=>{const O={name:g,description:T,cameraPlacement:D,videoLink:L,activityType:P,activityKind:K.getActivityKindFromActivityType(P),sessionType:w.map(V=>V.value),categories:G,sensorLocations:s,thresholds:re.parametersToThresholds(U),laterality:F.ActionLaterality.Either,quantumOwned:f};let W;j&&o?W=p({id:o,fields:O}):W=E({fields:O}),W.then(({error:V})=>{V?n(V):d()})},[f,E,p,o,g,s,T,D,L,P,w,G,j,U,d,n]);return r.useEffect(()=>{x&&x({cancelButton:u,saveButton:i?!0:u||!Q||!ne})},[u,x,Q,ne,i]),r.useEffect(()=>{c&&c({cancelButton:l,saveButton:i?()=>{}:se})},[c,l,se,i]),console.log(Q,ne,u,te),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(ee,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:g,onChange:O=>b(O.target.value),type:"text",placeholder:"i.e. Lunge & Return",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Activity Type"}),e.jsxRuntimeExports.jsx(X.st,{isClearable:!0,isMulti:!1,value:P?{label:K.mapActivityTypeEnumToLabel(P),value:P}:null,onChange:O=>R(O?.value),options:ue(Object.values(F.ActivityType),K.mapActivityTypeEnumToLabel),placeholder:"(optional) Select activity type",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Camera Placement"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:D,onChange:O=>A(O.target.value),rows:2,placeholder:"(optional) Describe camera setup, placement, angles",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Video Link"}),e.jsxRuntimeExports.jsx(t.Input,{value:L,onChange:O=>_(O.target.value),type:"url",placeholder:"(optional) https://...",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Description"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:T,onChange:O=>z(O.target.value),rows:2,placeholder:"(optional) Describe how to perform the test or exercise",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Link to Category"}),e.jsxRuntimeExports.jsx(X.st,{isMulti:!0,value:I?.filter(O=>G.includes(O.value)),onChange:O=>J((O??[]).map(W=>W.value)),options:I,placeholder:"Select one or more categories",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Session Types"}),e.jsxRuntimeExports.jsx(X.st,{isMulti:!0,value:w,onChange:O=>k(O??[]),options:B,placeholder:"Select one or more session types",isDisabled:i})]})]}),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(ee,{children:"Sensor Locations"}),e.jsxRuntimeExports.jsx(X.st,{isMulti:!0,value:H,onChange:O=>v([...O]),options:Be,isOptionDisabled:()=>H.length>=_e,isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ee,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(he,{options:h,value:U,onChange:Y,editOnly:i})]})]}),e.jsxRuntimeExports.jsx("div",{className:re.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:u,onClick:l,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:u||!Q||!ne,isLoading:u,onClick:se,children:"Save changes"})]})})]})},ee=({children:o})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:o}),ze=({id:o,onCancel:n,onSave:l,onError:d,hideButtons:m,quantumOwned:c,setButtonOnClick:x,setButtonDisabled:f})=>{const[{data:i}]=q.useQuery({query:c?y.GET_QUANTUM_OWNED_ACTIONS:y.GET_ACTIONS}),[{data:N}]=q.useQuery({query:y.GET_MODULE_BY_ID,variables:{id:o},pause:!o}),[{data:E}]=q.useQuery({query:y.GET_ALL_MODULE_CATEGORIES}),M=$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,E?.moduleCategories),[{fetching:p},C]=q.useMutation(y.UPDATE_MODULE),[{fetching:a},u]=q.useMutation(y.CREATE_MODULE),j=$.getFragmentData(y.ACTION_FRAGMENT,c?i?.quantumOwnedActions:i?.actions)??[],g=$.getFragmentData(y.ACTION_MODULE_FRAGMENT,N?.module),b=$.getFragmentData(y.MODULE_ACTION_FRAGMENT,g?.moduleActions)??[],[T,z]=r.useState([...b.map(k=>k.actionId)??[]]),[D,A]=r.useState(g?.name??""),[L,_]=r.useState([]),[P,R]=r.useState(g?.description??"");r.useEffect(()=>{g&&(z(b.map(k=>k.actionId)),A(g.name),R(g.description??""),_(g.categories.map(k=>$.getFragmentData(y.MODULE_CATEGORY_FRAGMENT,k).id)??[]))},[g,b]);const w=r.useCallback(()=>{let k;const H={actions:T,name:D,categories:L.filter(v=>v!=="other"),description:P,quantumOwned:c};g?k=C({id:g.id,input:H}):k=u({input:H}),k.then(({error:v})=>{v?d(v):l()})},[u,C,T,D,P,L,g,l,d,c]);return r.useEffect(()=>{f&&f({cancelButton:p||a,saveButton:p||a||!D||P.trim().split(/\s+/).filter(Boolean).length>40})},[f,p,a,T,D,P]),r.useEffect(()=>{x&&x({cancelButton:n,saveButton:w})},[x,n,w]),e.jsxRuntimeExports.jsxs(t.Box,{width:"100%",children:[e.jsxRuntimeExports.jsx(me,{name:D,setName:A,actions:j,selectedActionIds:T,setSelectedActionIds:z,availableCategories:M??[],selectedCategoryIds:L,setSelectedCategoryIds:_,description:P,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:p||a,onClick:n,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:p||a||!D||P.trim().split(/\s+/).filter(Boolean).length>40,isLoading:p||a,onClick:w,children:"Save"})]})})]})};exports.ActivityList=xe;exports.CopyActivityForm=Oe;exports.CopyModuleForm=Fe;exports.ModuleForm=me;exports.ParameterEditList=pe;exports.ParameterEditSelect=he;exports.UpsertActivityForm=Pe;exports.UpsertModuleForm=ze;
@@ -94,14 +94,14 @@ const Jt = ({
94
94
  collect: (h) => ({
95
95
  handlerId: h.getHandlerId()?.toString() ?? ""
96
96
  }),
97
- hover: (h, S) => {
97
+ hover: (h, C) => {
98
98
  if (!l.current)
99
99
  return;
100
100
  const r = h.index, a = n;
101
101
  if (r === a)
102
102
  return;
103
- const p = l.current?.getBoundingClientRect(), g = (p.bottom - p.top) / 2, C = S.getClientOffset().y - p.top;
104
- r < a && C < g || r > a && C > g || (u(r, a), h.index = a);
103
+ const p = l.current?.getBoundingClientRect(), g = (p.bottom - p.top) / 2, w = C.getClientOffset().y - p.top;
104
+ r < a && w < g || r > a && w > g || (u(r, a), h.index = a);
105
105
  }
106
106
  }), [{ isDragging: o }, I] = $t({
107
107
  type: s,
@@ -159,7 +159,7 @@ const Jt = ({
159
159
  isDisabled: A,
160
160
  ...h
161
161
  }) => {
162
- const [S, r] = P([void 0, void 0]), a = S[0], p = S[1], g = v && n < -5 && i > 5, y = Number(c?.[0] ?? p ?? n) > 0 ? 1 : -1, C = Number(c?.[1] ?? p ?? i) < 0 ? -1 : 1, G = j?.[0] === j?.[1], k = c?.[0], T = c?.[1];
162
+ const [C, r] = P([void 0, void 0]), a = C[0], p = C[1], g = v && n < -5 && i > 5, y = Number(c?.[0] ?? p ?? n) > 0 ? 1 : -1, w = Number(c?.[1] ?? p ?? i) < 0 ? -1 : 1, G = j?.[0] === j?.[1], k = c?.[0], T = c?.[1];
163
163
  ne(() => {
164
164
  k !== void 0 && T !== void 0 && r([k.toFixed(0), T.toFixed(0)]);
165
165
  }, [k, T, r]);
@@ -175,10 +175,10 @@ const Jt = ({
175
175
  [u]
176
176
  ), _ = R(() => {
177
177
  r(([b, z]) => {
178
- const Z = isNaN(Number(b)) ? n : Number(b), t = isNaN(Number(z)) ? i : Number(z), m = ye(Number(Z), y), w = ye(Number(t), C), D = y < 0 ? Math.max(m, n) : Math.min(m, i), $ = C < 0 ? Math.max(w, n) : Math.min(w, i);
178
+ const Z = isNaN(Number(b)) ? n : Number(b), t = isNaN(Number(z)) ? i : Number(z), m = ye(Number(Z), y), S = ye(Number(t), w), D = y < 0 ? Math.max(m, n) : Math.min(m, i), $ = w < 0 ? Math.max(S, n) : Math.min(S, i);
179
179
  return D > $ ? (u([$, D]), [$.toFixed(0), D.toFixed(0)]) : (u([D, $]), [D.toFixed(0), $.toFixed(0)]);
180
180
  });
181
- }, [u, r, y, C, n, i]), f = R(
181
+ }, [u, r, y, w, n, i]), f = R(
182
182
  (b) => {
183
183
  const z = b === "" || isNaN(Number(b)) ? b : ye(Number(b), y);
184
184
  r(([Z, t]) => [z.toString(), t]);
@@ -186,10 +186,10 @@ const Jt = ({
186
186
  [r, y]
187
187
  ), M = R(
188
188
  (b) => {
189
- const z = b === "" || isNaN(Number(b)) ? b : ye(Number(b), C);
189
+ const z = b === "" || isNaN(Number(b)) ? b : ye(Number(b), w);
190
190
  r(([Z, t]) => [Z, z.toString()]);
191
191
  },
192
- [r, C]
192
+ [r, w]
193
193
  ), L = F(
194
194
  () => d === "xs" ? "0.75rem" : void 0,
195
195
  [d]
@@ -198,8 +198,8 @@ const Jt = ({
198
198
  const Z = Number(z.target.value);
199
199
  if (!a || !p || ![-1, 1].includes(Z))
200
200
  return;
201
- const t = (D) => Z < 0 ? -1 * Math.abs(D) : Math.abs(D), m = b ? t(Number(a)) : Number(a), w = b ? Number(p) : t(Number(p));
202
- m > w ? u([w, m]) : u([m, w]);
201
+ const t = (D) => Z < 0 ? -1 * Math.abs(D) : Math.abs(D), m = b ? t(Number(a)) : Number(a), S = b ? Number(p) : t(Number(p));
202
+ m > S ? u([S, m]) : u([m, S]);
203
203
  },
204
204
  [a, p, u]
205
205
  );
@@ -337,7 +337,7 @@ const Jt = ({
337
337
  {
338
338
  size: d ?? "sm",
339
339
  min: 0,
340
- max: C < 0 ? Math.abs(k ?? n) : i,
340
+ max: w < 0 ? Math.abs(k ?? n) : i,
341
341
  precision: 0,
342
342
  value: p === "" ? "" : Math.abs(Number(p ?? i)),
343
343
  onChange: M,
@@ -363,7 +363,7 @@ const Jt = ({
363
363
  width: "auto",
364
364
  size: d,
365
365
  fontWeight: "bold",
366
- value: C,
366
+ value: w,
367
367
  onChange: (b) => X(!1, b),
368
368
  isDisabled: G || A,
369
369
  children: [
@@ -430,11 +430,11 @@ const Jt = ({
430
430
  disableEdit: j,
431
431
  disableCreate: A,
432
432
  hideUseCase: h = !0,
433
- tableProps: S,
433
+ tableProps: C,
434
434
  containerProps: r,
435
435
  quantumIconSrc: a = "/favicon.ico"
436
436
  }) => {
437
- const [p, g] = P(""), [y, C] = P(), G = F(() => {
437
+ const [p, g] = P(""), [y, w] = P(), G = F(() => {
438
438
  if (!s)
439
439
  return;
440
440
  const f = sn(s, p);
@@ -496,12 +496,12 @@ const Jt = ({
496
496
  {
497
497
  setSearch: g,
498
498
  actions: s,
499
- updateUseCases: C,
499
+ updateUseCases: w,
500
500
  hideUseCaseFilter: h
501
501
  }
502
502
  )
503
503
  ] }),
504
- /* @__PURE__ */ e.jsx(qe, { mr: "2rem", overflowX: "hidden", ...S, children: /* @__PURE__ */ e.jsxs(He, { size: "md", variant: "simple", children: [
504
+ /* @__PURE__ */ e.jsx(qe, { mr: "2rem", overflowX: "hidden", ...C, children: /* @__PURE__ */ e.jsxs(He, { size: "md", variant: "simple", children: [
505
505
  /* @__PURE__ */ e.jsx(Ye, { position: "sticky", top: 0, bg: "white", zIndex: 1, children: /* @__PURE__ */ e.jsxs(Se, { children: [
506
506
  /* @__PURE__ */ e.jsxs(ue, { fontWeight: "normal", children: [
507
507
  "(showing ",
@@ -593,14 +593,14 @@ const Jt = ({
593
593
  setButtonOnClick: l,
594
594
  quantumOwned: d
595
595
  }) => {
596
- const v = Xe(), [o, I] = P("copy"), [j, A] = P(""), [h, S] = P([]), [r, a] = P(!1), [p] = le({
596
+ const v = Xe(), [o, I] = P("copy"), [j, A] = P(""), [h, C] = P([]), [r, a] = P(!1), [p] = le({
597
597
  query: Ve
598
598
  }), [g] = le({
599
599
  query: Ot,
600
600
  variables: { groupId: j },
601
601
  pause: !j
602
602
  // Only run when group is selected
603
- }), [, y] = oe(De), [, C] = oe(
603
+ }), [, y] = oe(De), [, w] = oe(
604
604
  et
605
605
  ), G = F(() => p.data?.groups ? p.data.groups.map(
606
606
  (t) => U(tt, t)
@@ -611,13 +611,13 @@ const Jt = ({
611
611
  ), [k, h]), N = R(
612
612
  (t) => {
613
613
  const m = t?.value || "";
614
- A(m), S([]);
614
+ A(m), C([]);
615
615
  },
616
616
  []
617
617
  ), E = R(
618
618
  (t) => {
619
- const m = t.map((w) => w.value);
620
- S(m);
619
+ const m = t.map((S) => S.value);
620
+ C(m);
621
621
  },
622
622
  []
623
623
  ), _ = R(
@@ -625,7 +625,7 @@ const Jt = ({
625
625
  const m = U(
626
626
  me,
627
627
  t.categories
628
- ), w = {
628
+ ), S = {
629
629
  ...t,
630
630
  name: `${t.name} (Copy)`,
631
631
  // Add "(Copy)" suffix to distinguish
@@ -642,7 +642,7 @@ const Jt = ({
642
642
  categories: m?.map(($) => $.id),
643
643
  quantumOwned: d,
644
644
  id: void 0
645
- }, D = await y({ fields: w });
645
+ }, D = await y({ fields: S });
646
646
  if (D.error)
647
647
  throw new Error(D.error.message);
648
648
  if (D.data?.createAction)
@@ -652,7 +652,7 @@ const Jt = ({
652
652
  [y, d]
653
653
  ), f = R(
654
654
  async (t) => {
655
- const m = await C({ id: t.id });
655
+ const m = await w({ id: t.id });
656
656
  if (m.error)
657
657
  throw new Error(m.error.message);
658
658
  if (m.data?.convertActionToQuantumOwned)
@@ -662,7 +662,7 @@ const Jt = ({
662
662
  );
663
663
  throw new Error("No action data returned");
664
664
  },
665
- [C]
665
+ [w]
666
666
  ), M = R(async () => {
667
667
  if (a(!0), !T.length) {
668
668
  const t = new Error(
@@ -674,10 +674,10 @@ const Jt = ({
674
674
  try {
675
675
  const t = [];
676
676
  let m = 0;
677
- const w = o === "copy" ? _ : f, D = o === "copy" ? "copy" : "convert";
677
+ const S = o === "copy" ? _ : f, D = o === "copy" ? "copy" : "convert";
678
678
  for (const $ of T)
679
679
  try {
680
- const Q = await w($);
680
+ const Q = await S($);
681
681
  t.push(Q);
682
682
  } catch (Q) {
683
683
  console.error(
@@ -693,18 +693,18 @@ const Jt = ({
693
693
  status: m > 0 ? "warning" : "success",
694
694
  duration: 3e3,
695
695
  isClosable: !0
696
- }), s?.(), A(""), S([]);
696
+ }), s?.(), A(""), C([]);
697
697
  } else
698
698
  throw new Error(`Failed to ${D} any activities`);
699
699
  } catch (t) {
700
- const m = o === "copy" ? "copy" : "convert", w = t instanceof Error ? t.message : `Failed to ${m} activities`;
700
+ const m = o === "copy" ? "copy" : "convert", S = t instanceof Error ? t.message : `Failed to ${m} activities`;
701
701
  v({
702
702
  title: `${o === "copy" ? "Copy" : "Convert"} failed`,
703
- description: w,
703
+ description: S,
704
704
  status: "error",
705
705
  duration: 5e3,
706
706
  isClosable: !0
707
- }), i?.(t instanceof Error ? t : new Error(w));
707
+ }), i?.(t instanceof Error ? t : new Error(S));
708
708
  } finally {
709
709
  a(!1);
710
710
  }
@@ -717,7 +717,7 @@ const Jt = ({
717
717
  s,
718
718
  i
719
719
  ]), L = R(() => {
720
- A(""), S([]), I("copy"), n?.();
720
+ A(""), C([]), I("copy"), n?.();
721
721
  }, [n]);
722
722
  ne(() => {
723
723
  u && u({
@@ -747,7 +747,7 @@ const Jt = ({
747
747
  {
748
748
  value: o,
749
749
  onChange: (t) => {
750
- I(t), S([]);
750
+ I(t), C([]);
751
751
  },
752
752
  children: /* @__PURE__ */ e.jsxs(te, { spacing: 6, children: [
753
753
  /* @__PURE__ */ e.jsx(Ae, { value: "copy", colorScheme: "blue", children: /* @__PURE__ */ e.jsxs(ee, { align: "start", spacing: 1, children: [
@@ -883,7 +883,7 @@ const Jt = ({
883
883
  /* @__PURE__ */ e.jsxs(x, { children: [
884
884
  /* @__PURE__ */ e.jsx("strong", { children: "Use Cases:" }),
885
885
  " ",
886
- t.useCases.map((w) => w.name).join(", ") || "None"
886
+ t.useCases.map((S) => S.name).join(", ") || "None"
887
887
  ] })
888
888
  ]
889
889
  }
@@ -948,14 +948,14 @@ const Jt = ({
948
948
  setButtonOnClick: l,
949
949
  quantumOwned: d
950
950
  }) => {
951
- const v = Xe(), [o, I] = P(""), [j, A] = P([]), [h, S] = P(!1), [r, a] = P("copy"), [p] = le({
951
+ const v = Xe(), [o, I] = P(""), [j, A] = P([]), [h, C] = P(!1), [r, a] = P("copy"), [p] = le({
952
952
  query: Ve
953
953
  }), [g] = le({
954
954
  query: It,
955
955
  variables: { groupId: o },
956
956
  pause: !o
957
957
  // Only run when group is selected
958
- }), [, y] = oe(ot), [, C] = oe(st), [, G] = oe(De), [, k] = oe(
958
+ }), [, y] = oe(ot), [, w] = oe(st), [, G] = oe(De), [, k] = oe(
959
959
  et
960
960
  ), T = F(() => p.data?.groups ? p.data.groups.map(
961
961
  (t) => U(tt, t)
@@ -963,13 +963,13 @@ const Jt = ({
963
963
  Ce,
964
964
  g.data?.modules
965
965
  ).map((m) => {
966
- const w = U(
966
+ const S = U(
967
967
  nt,
968
968
  m.moduleActions
969
969
  );
970
970
  return {
971
971
  ...m,
972
- moduleActions: w.map((D) => ({
972
+ moduleActions: S.map((D) => ({
973
973
  ...D,
974
974
  action: U(ae, D.action)
975
975
  })),
@@ -988,13 +988,13 @@ const Jt = ({
988
988
  []
989
989
  ), f = R(
990
990
  (t) => {
991
- const m = t.map((w) => w.value);
991
+ const m = t.map((S) => S.value);
992
992
  A(m);
993
993
  },
994
994
  []
995
995
  ), M = R(async () => {
996
- if (S(!0), !E.length) {
997
- S(!1);
996
+ if (C(!0), !E.length) {
997
+ C(!1);
998
998
  const t = new Error(
999
999
  `No modules selected for ${r === "convert" ? "converting" : "copying"}`
1000
1000
  );
@@ -1004,11 +1004,11 @@ const Jt = ({
1004
1004
  try {
1005
1005
  const t = [];
1006
1006
  let m = 0;
1007
- for (const w of E)
1007
+ for (const S of E)
1008
1008
  try {
1009
- let D = w.moduleActions.map(($) => $.actionId);
1009
+ let D = S.moduleActions.map(($) => $.actionId);
1010
1010
  if (d) {
1011
- const $ = w.moduleActions.map((B) => B.action), Q = async (B) => {
1011
+ const $ = S.moduleActions.map((B) => B.action), Q = async (B) => {
1012
1012
  if (r === "copy") {
1013
1013
  if (B.quantumOwned) return B;
1014
1014
  const Ie = U(
@@ -1044,13 +1044,13 @@ const Jt = ({
1044
1044
  }
1045
1045
  if (r === "convert") {
1046
1046
  const $ = {
1047
- name: w.name,
1048
- description: w.description || void 0,
1047
+ name: S.name,
1048
+ description: S.description || void 0,
1049
1049
  actions: D,
1050
- categories: w.categories.map((K) => K.id),
1050
+ categories: S.categories.map((K) => K.id),
1051
1051
  quantumOwned: !0
1052
- }, Q = await C({
1053
- id: w.id,
1052
+ }, Q = await w({
1053
+ id: S.id,
1054
1054
  input: $
1055
1055
  });
1056
1056
  if (Q.error) throw new Error(Q.error.message);
@@ -1063,10 +1063,10 @@ const Jt = ({
1063
1063
  }
1064
1064
  } else {
1065
1065
  const $ = {
1066
- name: `${w.name} (Copy)`,
1067
- description: w.description || void 0,
1066
+ name: `${S.name} (Copy)`,
1067
+ description: S.description || void 0,
1068
1068
  actions: D,
1069
- categories: w.categories.map((K) => K.id),
1069
+ categories: S.categories.map((K) => K.id),
1070
1070
  quantumOwned: d
1071
1071
  }, Q = await y({ input: $ });
1072
1072
  if (Q.error) throw new Error(Q.error.message);
@@ -1080,15 +1080,15 @@ const Jt = ({
1080
1080
  }
1081
1081
  } catch (D) {
1082
1082
  console.error(
1083
- `Failed to ${r === "convert" ? "convert" : "copy"} module "${w.name}":`,
1083
+ `Failed to ${r === "convert" ? "convert" : "copy"} module "${S.name}":`,
1084
1084
  D
1085
1085
  ), m++;
1086
1086
  }
1087
1087
  if (t.length > 0) {
1088
- const w = t.length, D = E.length;
1088
+ const S = t.length, D = E.length;
1089
1089
  v({
1090
1090
  title: m > 0 ? `Partial ${r === "convert" ? "convert" : "copy"} completed` : `Modules ${r === "convert" ? "converted" : "copied"} successfully`,
1091
- description: m > 0 ? `${w} of ${D} modules ${r === "convert" ? "converted" : "copied"} successfully` : `${w} module${w > 1 ? "s" : ""} ${r === "convert" ? "converted" : "copied"} successfully`,
1091
+ description: m > 0 ? `${S} of ${D} modules ${r === "convert" ? "converted" : "copied"} successfully` : `${S} module${S > 1 ? "s" : ""} ${r === "convert" ? "converted" : "copied"} successfully`,
1092
1092
  status: m > 0 ? "warning" : "success",
1093
1093
  duration: 3e3,
1094
1094
  isClosable: !0
@@ -1107,12 +1107,12 @@ const Jt = ({
1107
1107
  isClosable: !0
1108
1108
  }), i?.(t instanceof Error ? t : new Error(m));
1109
1109
  } finally {
1110
- S(!1);
1110
+ C(!1);
1111
1111
  }
1112
1112
  }, [
1113
1113
  E,
1114
1114
  y,
1115
- C,
1115
+ w,
1116
1116
  v,
1117
1117
  s,
1118
1118
  i,
@@ -1268,7 +1268,7 @@ const Jt = ({
1268
1268
  /* @__PURE__ */ e.jsxs(x, { children: [
1269
1269
  /* @__PURE__ */ e.jsx("strong", { children: "Categories:" }),
1270
1270
  " ",
1271
- t.categories.map((w) => w.name).join(", ") || "None"
1271
+ t.categories.map((S) => S.name).join(", ") || "None"
1272
1272
  ] })
1273
1273
  ]
1274
1274
  }
@@ -1351,12 +1351,12 @@ const Jt = ({
1351
1351
  const A = gt(), h = F(() => i.map((y) => ({
1352
1352
  ...y,
1353
1353
  selected: c.includes(y.id)
1354
- })), [i, c]), S = F(() => i.reduce((y, C) => (y[C.id] = C, y), {}), [i]), r = F(
1355
- () => c.map((y) => S[y]),
1356
- [h, c]
1354
+ })), [i, c]), C = F(() => i.reduce((y, w) => (y[w.id] = w, y), {}), [i]), r = F(
1355
+ () => c.map((y) => C[y]),
1356
+ [c, C]
1357
1357
  ), a = R(
1358
- (y, C) => {
1359
- u(C ? [...c, y.id] : c.filter((G) => G !== y.id));
1358
+ (y, w) => {
1359
+ u(w ? [...c, y.id] : c.filter((G) => G !== y.id));
1360
1360
  },
1361
1361
  [c, u]
1362
1362
  ), p = R(
@@ -1473,12 +1473,11 @@ const Jt = ({
1473
1473
  se,
1474
1474
  {
1475
1475
  isDisabled: s.length === 0,
1476
- isClearable: !0,
1477
1476
  options: u,
1478
- value: c.filter((l) => n.includes(l.id)).map((l) => ({
1477
+ value: n.length === 0 ? { value: "other", label: "Other" } : c.filter((l) => n.includes(l.id)).map((l) => ({
1479
1478
  value: l.id,
1480
1479
  label: l.name
1481
- })),
1480
+ }))[0],
1482
1481
  onChange: (l) => i(l ? [l.value] : []),
1483
1482
  placeholder: "Select category"
1484
1483
  }
@@ -1568,37 +1567,37 @@ const Jt = ({
1568
1567
  lockRanges: d,
1569
1568
  ...v
1570
1569
  }) => {
1571
- const o = F(() => [...s].sort((h, S) => {
1572
- const r = Ge.indexOf(h.plane), a = Ge.indexOf(S.plane);
1570
+ const o = F(() => [...s].sort((h, C) => {
1571
+ const r = Ge.indexOf(h.plane), a = Ge.indexOf(C.plane);
1573
1572
  return r - a;
1574
1573
  }), [s]), I = R((h) => "segment" in h.id ? it(h.id.segment, h.plane, !0) ?? "Unknown" : lt(h.id.joint, h.plane, !0) ?? "Unknown", []), j = R(
1575
- (h, S) => {
1574
+ (h, C) => {
1576
1575
  const r = o.findIndex(
1577
- (p) => p.id === S.id && p.plane === S.plane
1576
+ (p) => p.id === C.id && p.plane === C.plane
1578
1577
  );
1579
1578
  let a = [...o];
1580
- i && (S = { ...S, kind: i }), a[r] = S, d && (a = a.map((p) => ({
1579
+ i && (C = { ...C, kind: i }), a[r] = C, d && (a = a.map((p) => ({
1581
1580
  ...p,
1582
- min: S.min,
1583
- max: S.max
1581
+ min: C.min,
1582
+ max: C.max
1584
1583
  }))), n(a);
1585
1584
  },
1586
1585
  [n, o, i, d]
1587
1586
  ), A = R(
1588
1587
  (h) => {
1589
- const S = o.filter(
1588
+ const C = o.filter(
1590
1589
  (r) => r.id !== h.id || r.plane !== h.plane
1591
1590
  );
1592
- n(S);
1591
+ n(C);
1593
1592
  },
1594
1593
  [n, o]
1595
1594
  );
1596
- return /* @__PURE__ */ e.jsx(ee, { alignItems: "flex-start", overflowY: "auto", ...v, children: o.map((h, S) => /* @__PURE__ */ e.jsx(
1595
+ return /* @__PURE__ */ e.jsx(ee, { alignItems: "flex-start", overflowY: "auto", ...v, children: o.map((h, C) => /* @__PURE__ */ e.jsx(
1597
1596
  pn,
1598
1597
  {
1599
1598
  label: I(h),
1600
1599
  parameter: h,
1601
- onChange: (r) => j(S, r),
1600
+ onChange: (r) => j(C, r),
1602
1601
  onRemove: c || l ? void 0 : () => A(h),
1603
1602
  forceKind: i,
1604
1603
  disableKind: u || l,
@@ -1726,7 +1725,7 @@ const Jt = ({
1726
1725
  return A.filter(
1727
1726
  (p) => ve(p.value) === ve(a.id) && p.plane === a.plane
1728
1727
  );
1729
- }, [A, n, l]), S = F(
1728
+ }, [A, n, l]), C = F(
1730
1729
  () => A.filter(
1731
1730
  (a) => n.some((p) => be(p.id, a.value) && p.plane === a.plane)
1732
1731
  ),
@@ -1736,11 +1735,11 @@ const Jt = ({
1736
1735
  const p = a.map((g) => {
1737
1736
  const y = n.find(
1738
1737
  (N) => be(N.id, g.value) && N.plane === g.plane
1739
- ), C = s.find(
1738
+ ), w = s.find(
1740
1739
  (N) => be(N.id, g.value) && N.plane === g.plane
1741
1740
  ), G = l ? n.find(
1742
1741
  (N) => ve(N.id) === ve(g.value) && N.plane === g.plane
1743
- ) : void 0, k = G && !y ? G.min : C && C.min ? C.min : 0, T = G && !y ? G.max : C && C.max ? C.max : 0;
1742
+ ) : void 0, k = G && !y ? G.min : w && w.min ? w.min : 0, T = G && !y ? G.max : w && w.max ? w.max : 0;
1744
1743
  return y ?? {
1745
1744
  id: g.value,
1746
1745
  plane: g.plane,
@@ -1764,8 +1763,8 @@ const Jt = ({
1764
1763
  {
1765
1764
  isMulti: !u,
1766
1765
  placeholder: n.length ? `${n.length} selected` : "Search...",
1767
- value: S,
1768
- isDisabled: d || S.length >= (j ?? 1 / 0),
1766
+ value: C,
1767
+ isDisabled: d || C.length >= (j ?? 1 / 0),
1769
1768
  onChange: (a) => Array.isArray(a) ? r([...a]) : r(a !== null ? [a] : []),
1770
1769
  options: h,
1771
1770
  controlShouldRenderValue: !1
@@ -1842,25 +1841,25 @@ const Jt = ({
1842
1841
  quantumOwned: v,
1843
1842
  isView: o
1844
1843
  }) => {
1845
- const [{ fetching: I }, j] = oe(De), [{ fetching: A }, h] = oe(Nt), [{ data: S }] = le({
1844
+ const [{ fetching: I }, j] = oe(De), [{ fetching: A }, h] = oe(Nt), [{ data: C }] = le({
1846
1845
  query: Lt,
1847
1846
  variables: { id: s ?? "" },
1848
1847
  pause: !s
1849
1848
  }), r = U(
1850
1849
  ae,
1851
- S?.getActionById
1852
- ), a = I || A, p = !!r && !!s, [g, y] = P(""), [C, G] = P(""), [k, T] = P(""), [N, E] = P(""), [_, f] = P(), [M, L] = P([]), [X, b] = P([]), [z, Z] = P([]), t = F(
1850
+ C?.getActionById
1851
+ ), a = I || A, p = !!r && !!s, [g, y] = P(""), [w, G] = P(""), [k, T] = P(""), [N, E] = P(""), [_, f] = P(), [M, L] = P([]), [X, b] = P([]), [z, Z] = P([]), t = F(
1853
1852
  () => X.map((O) => O.value),
1854
1853
  [X]
1855
- ), m = Yt(t), [{ data: w }] = le({
1854
+ ), m = Yt(t), [{ data: S }] = le({
1856
1855
  query: rt
1857
1856
  }), D = F(() => U(
1858
1857
  me,
1859
- w?.moduleCategories
1858
+ S?.moduleCategories
1860
1859
  )?.map((H) => ({
1861
1860
  label: H.name,
1862
1861
  value: H.id
1863
- })), [w?.moduleCategories]), $ = F(
1862
+ })), [S?.moduleCategories]), $ = F(
1864
1863
  () => Qe(Object.values(Pt), Pe),
1865
1864
  []
1866
1865
  ), [Q, K] = P([]), B = g.length > 0, [ce, Ie] = P({});
@@ -1892,7 +1891,7 @@ const Jt = ({
1892
1891
  const pe = F(
1893
1892
  () => JSON.stringify(ce) !== JSON.stringify({
1894
1893
  name: g,
1895
- description: C,
1894
+ description: w,
1896
1895
  cameraPlacement: k,
1897
1896
  videoLink: N,
1898
1897
  activityType: _,
@@ -1905,7 +1904,7 @@ const Jt = ({
1905
1904
  ce,
1906
1905
  g,
1907
1906
  t,
1908
- C,
1907
+ w,
1909
1908
  k,
1910
1909
  N,
1911
1910
  _,
@@ -1916,7 +1915,7 @@ const Jt = ({
1916
1915
  ), de = R(() => {
1917
1916
  const O = {
1918
1917
  name: g,
1919
- description: C,
1918
+ description: w,
1920
1919
  cameraPlacement: k,
1921
1920
  videoLink: N,
1922
1921
  activityType: _,
@@ -1945,7 +1944,7 @@ const Jt = ({
1945
1944
  s,
1946
1945
  g,
1947
1946
  t,
1948
- C,
1947
+ w,
1949
1948
  k,
1950
1949
  N,
1951
1950
  _,
@@ -2034,7 +2033,7 @@ const Jt = ({
2034
2033
  /* @__PURE__ */ e.jsx(
2035
2034
  $e,
2036
2035
  {
2037
- value: C,
2036
+ value: w,
2038
2037
  onChange: (O) => G(O.target.value),
2039
2038
  rows: 2,
2040
2039
  placeholder: "(optional) Describe how to perform the test or exercise",
@@ -2151,10 +2150,10 @@ const Jt = ({
2151
2150
  }), A = U(
2152
2151
  me,
2153
2152
  j?.moduleCategories
2154
- ), [{ fetching: h }, S] = oe(st), [{ fetching: r }, a] = oe(ot), p = U(
2153
+ ), [{ fetching: h }, C] = oe(st), [{ fetching: r }, a] = oe(ot), p = U(
2155
2154
  ae,
2156
2155
  l ? o?.quantumOwnedActions : o?.actions
2157
- ) ?? [], g = U(Ce, I?.module), y = U(nt, g?.moduleActions) ?? [], [C, G] = P([
2156
+ ) ?? [], g = U(Ce, I?.module), y = U(nt, g?.moduleActions) ?? [], [w, G] = P([
2158
2157
  ...y.map((L) => L.actionId) ?? []
2159
2158
  ]), [k, T] = P(g?.name ?? ""), [N, E] = P([]), [_, f] = P(g?.description ?? "");
2160
2159
  ne(() => {
@@ -2167,13 +2166,13 @@ const Jt = ({
2167
2166
  const M = R(() => {
2168
2167
  let L;
2169
2168
  const X = {
2170
- actions: C,
2169
+ actions: w,
2171
2170
  name: k,
2172
2171
  categories: N.filter((b) => b !== "other"),
2173
2172
  description: _,
2174
2173
  quantumOwned: l
2175
2174
  };
2176
- g ? L = S({
2175
+ g ? L = C({
2177
2176
  id: g.id,
2178
2177
  input: X
2179
2178
  }) : L = a({
@@ -2183,21 +2182,22 @@ const Jt = ({
2183
2182
  });
2184
2183
  }, [
2185
2184
  a,
2186
- S,
2187
2185
  C,
2186
+ w,
2188
2187
  k,
2189
2188
  _,
2190
2189
  N,
2191
2190
  g,
2192
2191
  i,
2193
- c
2192
+ c,
2193
+ l
2194
2194
  ]);
2195
2195
  return ne(() => {
2196
2196
  v && v({
2197
2197
  cancelButton: h || r,
2198
2198
  saveButton: h || r || !k || _.trim().split(/\s+/).filter(Boolean).length > 40
2199
2199
  });
2200
- }, [v, h, r, C, k, _]), ne(() => {
2200
+ }, [v, h, r, w, k, _]), ne(() => {
2201
2201
  d && d({
2202
2202
  cancelButton: n,
2203
2203
  saveButton: M
@@ -2209,7 +2209,7 @@ const Jt = ({
2209
2209
  name: k,
2210
2210
  setName: T,
2211
2211
  actions: p,
2212
- selectedActionIds: C,
2212
+ selectedActionIds: w,
2213
2213
  setSelectedActionIds: G,
2214
2214
  availableCategories: A ?? [],
2215
2215
  selectedCategoryIds: N,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quantum-component-library",
3
- "version": "1.4.47-dev.10",
3
+ "version": "1.4.47-dev.11",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.cjs",