quantum-component-library 1.4.45-dev.13 → 1.4.45-dev.14

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