quantum-component-library 1.4.47-dev.3 → 1.4.47-dev.4

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"),o=require("react"),he=require("./ufuzzy-vendor-7qHa_k39.cjs"),K=require("./react-select-vendor-D_Q2fL5j.cjs"),ce=require("./react-icons-vendor-D2s8zw9h.cjs"),z=require("./graphql-vendor-B-QTAQSb.cjs"),h=require("./generated-Cis5yU-9.cjs"),T=require("./graphql-CWEN3o54.cjs"),ae=require("./react-dnd-vendor-BPzSDojS.cjs"),J=require("./services.cjs"),te=require("./types.cjs"),oe=require("./utils.cjs"),je=require("./hooks.cjs"),ge=({setSearch:r,actions:n,updateUseCases:i})=>{const x=o.useMemo(()=>n?.flatMap(l=>l.useCases).filter((l,c,m)=>m.findIndex(R=>R.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:ce.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:x,onChange:l=>i(l.map(c=>c.value))})})]})},X=({children:r})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:r}),Ee=({value:r,onChange:n})=>{const i=o.useState(()=>Math.random().toString(36).substring(2,15))[0],x=o.useCallback((l,c)=>{n(m=>{const R=[...m],[u]=R.splice(l,1);return R.splice(c,0,u),R})},[n]);return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsx(ae.DndProvider,{backend:ae.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(Re,{listKey:i,index:c,id:l.id,name:l.name,move:x},l.id))})]})})})})},Re=({listKey:r,index:n,id:i,name:x,move:l})=>{const c=o.useRef(null),[{handlerId:m},R]=ae.useDrop({accept:r,collect:f=>({handlerId:f.getHandlerId()?.toString()??""}),hover:(f,v)=>{if(!c.current)return;const a=f.index,d=n;if(a===d)return;const g=c.current?.getBoundingClientRect(),E=(g.bottom-g.top)/2,w=v.getClientOffset().y-g.top;a<d&&w<E||a>d&&w>E||(l(a,d),f.index=d)}}),[{isDragging:u},S]=ae.useDrag({type:r,item:()=>({id:i,index:n}),collect:f=>({isDragging:f.isDragging()})}),L=u?.6:1,j=u?"grabbing":"grab";return S(R(c)),e.jsxRuntimeExports.jsxs(t.Tr,{ref:c,style:{opacity:L,cursor:j},"data-handler-id":m,children:[e.jsxRuntimeExports.jsx(t.Td,{children:n+1}),e.jsxRuntimeExports.jsx(t.Td,{children:x})]})},fe=({items:r,onChange:n,selectedItem:i,isDisabled:x,selectedProps:l,buttonProps:c})=>{const m=u=>u===i||u.value===i,R=u=>m(u)?{...c,...l}:c;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:x,children:r.map((u,S)=>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,S),isDisabled:u.disabled,...R(u),children:u.label})},S))})},re=(r,n)=>n<0?-1*Math.abs(r):Math.abs(r),ve=({isReversed:r,min:n,max:i,value:x,onChange:l,inputProps:c,size:m,zeroMarker:R,formatValue:u,valueLabel:S,positiveNegativeLabels:L,isDisabled:j,...f})=>{const[v,a]=o.useState([void 0,void 0]),d=v[0],g=v[1],E=R&&n<-5&&i>5,y=Number(x?.[0]??g??n)>0?1:-1,w=Number(x?.[1]??g??i)<0?-1:1,b=L?.[0]===L?.[1],A=x?.[0],F=x?.[1];o.useEffect(()=>{A!==void 0&&F!==void 0&&a([A.toFixed(0),F.toFixed(0)])},[A,F,a]);const _=o.useCallback(([C,G])=>{C<G&&a([C.toFixed(0),G.toFixed(0)])},[a]),O=o.useCallback(([C,G])=>{C<G&&l([C,G])},[l]),$=o.useCallback(()=>{a(([C,G])=>{const W=isNaN(Number(C))?n:Number(C),s=isNaN(Number(G))?i:Number(G),p=re(Number(W),y),M=re(Number(s),w),I=y<0?Math.max(p,n):Math.min(p,i),k=w<0?Math.max(M,n):Math.min(M,i);return I>k?(l([k,I]),[k.toFixed(0),I.toFixed(0)]):(l([I,k]),[I.toFixed(0),k.toFixed(0)])})},[l,a,y,w,n,i]),H=o.useCallback(C=>{const G=C===""||isNaN(Number(C))?C:re(Number(C),y);a(([W,s])=>[G.toString(),s])},[a,y]),q=o.useCallback(C=>{const G=C===""||isNaN(Number(C))?C:re(Number(C),w);a(([W,s])=>[W,G.toString()])},[a,w]),D=o.useMemo(()=>m==="xs"?"0.75rem":void 0,[m]),V=o.useCallback((C,G)=>{const W=Number(G.target.value);if(!d||!g||![-1,1].includes(W))return;const s=I=>W<0?-1*Math.abs(I):Math.abs(I),p=C?s(Number(d)):Number(d),M=C?Number(g):s(Number(g));p>M?l([M,p]):l([p,M])},[d,g,l]);return e.jsxRuntimeExports.jsxs(t.Flex,{direction:"column",...f,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(d??n),Number(g??i)],max:i,min:n,minStepsBetweenThumbs:3,step:1,onChange:_,onChangeEnd:O,isDisabled:j,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:i,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:m??"sm",fontWeight:"semibold",style:{transform:"translateX(-100%)"},whiteSpace:"nowrap",children:u?u(i):i})}),E&&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:D,h:D}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:1,w:D,h:D})]})}),S&&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:S(n)}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:m??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:S(i)})]}),e.jsxRuntimeExports.jsxs(t.Flex,{direction:r?"row-reverse":"row",justifyContent:"center",alignItems:"center",gap:"0.125em",children:[L&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:m,fontWeight:"bold",value:y,onChange:C=>V(!0,C),isDisabled:b||j,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:L[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:L[1]})]}),e.jsxRuntimeExports.jsx(t.NumberInput,{precision:0,size:m??"sm",min:0,max:y<0?Math.abs(n):F??i,value:d===""?"":Math.abs(Number(d??n)),onChange:H,onBlur:$,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:j,...c,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),e.jsxRuntimeExports.jsx(t.NumberInput,{size:m??"sm",min:0,max:w<0?Math.abs(A??n):i,precision:0,value:g===""?"":Math.abs(Number(g??i)),onChange:q,onBlur:$,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:j,...c,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),L&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:m,fontWeight:"bold",value:w,onChange:C=>V(!1,C),isDisabled:b||j,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:L[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:L[1]})]})]})]})},Ce=({tags:r,containerProps:n,...i})=>e.jsxRuntimeExports.jsx(t.HStack,{...n,children:r.map((x,l)=>e.jsxRuntimeExports.jsx(t.Tag,{...i,children:x},l))}),ye=new he.uFuzzy({}),be=(r,n)=>{if(!n||!n.trim().length)return r;const i=r.map(l=>l.name??"");return ye.filter(i,n)?.map(l=>r[l])??[]},Te=(r,n)=>!n||n.length==0?r:r.filter(i=>i.useCases.some(x=>n.includes(x.id))),ue=({actions:r,totalActions:n,onCreate:i,onDelete:x,onEdit:l,onSelected:c,onDuplicate:m,disableMultiSelect:R,disableDelete:u,disableEdit:S,disableCreate:L,tableProps:j,...f})=>{const[v,a]=o.useState(""),[d,g]=o.useState(),E=o.useMemo(()=>{if(!r)return;const b=be(r,v);return Te(b,d).sort((F,_)=>F.name.localeCompare(_.name))},[r,v,d]),y=o.useCallback(()=>{if(!x)return;const b=r.filter(A=>A.selected).map(A=>A.id);x(b)},[r,x]),w=o.useCallback(()=>{if(!m)return;const b=r.filter(A=>A.selected);m(b.map(A=>A.id)),c&&b.forEach(A=>c(A,!1))},[r,m,c]);return e.jsxRuntimeExports.jsxs(t.Box,{...f,children:[e.jsxRuntimeExports.jsxs(t.Flex,{alignContent:"space-between",gap:4,children:[(i||x||m)&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mb:"1rem",gap:4,children:[i&&e.jsxRuntimeExports.jsx(t.Button,{isDisabled:!i||L,colorScheme:"blackAlpha",backgroundColor:"gray.700",onClick:i,children:"Create New Activity"}),x&&!R&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:r.length<=0||!x||u,onClick:y,children:"Delete Selected"}),m&&!R&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:r.length<=0,onClick:w,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx(ge,{setSearch:a,actions:r,updateUseCases:g})]}),e.jsxRuntimeExports.jsx(t.TableContainer,{mr:"2rem",overflowX:"hidden",...j,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 ",E?.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:E?.map(b=>e.jsxRuntimeExports.jsxs(t.Tr,{title:R&&b.selected?"This activity is selected. Click it again to deselect.":void 0,bg:R&&b.selected?"gray.200":void 0,_hover:{bg:R&&!b.selected?"#f7f7f7":void 0},cursor:R?"pointer":"default",onClick:()=>R?c?.(b,!b.selected):void 0,children:[e.jsxRuntimeExports.jsx(t.Td,{children:e.jsxRuntimeExports.jsxs(t.Flex,{children:[c&&!R&&e.jsxRuntimeExports.jsx(t.Checkbox,{isChecked:b.selected,onChange:A=>c(b,A.target.checked)}),l&&e.jsxRuntimeExports.jsx(t.Button,{disabled:S,ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:()=>l(b.id),children:"edit"})]})}),e.jsxRuntimeExports.jsx(t.Td,{whiteSpace:"break-spaces",children:b.name}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:b.sensorLocations.length}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:e.jsxRuntimeExports.jsx(Ce,{containerProps:{flexWrap:"wrap"},tags:b.useCases?.map(A=>A.name)??[]})})]},b.id))})]})})]})},Se=({onSave:r,onCancel:n,onError:i,hideButtons:x=!1,setButtonDisabled:l,setButtonOnClick:c,quantumOwned:m})=>{const R=t.useToast(),[u,S]=o.useState("copy"),[L,j]=o.useState(""),[f,v]=o.useState([]),[a,d]=o.useState(!1),[g]=z.useQuery({query:T.GET_GROUPS}),[E]=z.useQuery({query:T.GET_ACTIONS_BY_GROUP,variables:{groupId:L},pause:!L}),[,y]=z.useMutation(T.CREATE_ACTION),[,w]=z.useMutation(T.CONVERT_ACTION_TO_QUANTUM_OWNED),b=o.useMemo(()=>g.data?.groups?g.data.groups.map(s=>h.getFragmentData(T.GROUP_FRAGMENT,s)):[],[g.data]),A=o.useMemo(()=>E.data?E.data.actions.map(p=>h.getFragmentData(T.ACTION_FRAGMENT,p)):[],[E.data]),F=o.useMemo(()=>A.filter(s=>f.includes(s.id)),[A,f]),_=o.useCallback(s=>{const p=s?.value||"";j(p),v([])},[]),O=o.useCallback(s=>{const p=s.map(M=>M.value);v(p)},[]),$=o.useCallback(async s=>{const p=h.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,s.categories),M={...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(k=>({...k,id:void 0})),categories:p?.map(k=>k.id),quantumOwned:m,id:void 0},I=await y({fields:M});if(I.error)throw new Error(I.error.message);if(I.data?.createAction)return h.getFragmentData(T.ACTION_FRAGMENT,I.data.createAction);throw new Error("No action data returned")},[y,m]),H=o.useCallback(async s=>{const p=await w({id:s.id});if(p.error)throw new Error(p.error.message);if(p.data?.convertActionToQuantumOwned)return h.getFragmentData(T.ACTION_FRAGMENT,p.data.convertActionToQuantumOwned);throw new Error("No action data returned")},[w]),q=o.useCallback(async()=>{if(d(!0),!F.length){const s=new Error(`No activities selected for ${u==="copy"?"copying":"converting"}`);i?.(s),d(!1);return}try{const s=[];let p=0;const M=u==="copy"?$:H,I=u==="copy"?"copy":"convert";for(const k of F)try{const P=await M(k);s.push(P)}catch(P){console.error(`Failed to ${I} activity "${k.name}":`,P),p++}if(s.length>0){const k=s.length,P=F.length,Q=u==="copy"?"copied":"converted",U=u==="copy"?"copy":"convert";R({title:p>0?`Partial ${U} completed`:`Activities ${Q} successfully`,description:p>0?`${k} of ${P} activities ${Q} successfully`:`${k} activit${k>1?"ies":"y"} ${Q} successfully`,status:p>0?"warning":"success",duration:3e3,isClosable:!0}),r?.(),j(""),v([])}else throw new Error(`Failed to ${I} any activities`)}catch(s){const p=u==="copy"?"copy":"convert",M=s instanceof Error?s.message:`Failed to ${p} activities`;R({title:`${u==="copy"?"Copy":"Convert"} failed`,description:M,status:"error",duration:5e3,isClosable:!0}),i?.(s instanceof Error?s:new Error(M))}finally{d(!1)}},[F,u,$,H,R,r,i]),D=o.useCallback(()=>{j(""),v([]),S("copy"),n?.()},[n]);o.useEffect(()=>{l&&l({cancelButton:!1,saveButton:F.length===0||a})},[F.length,a,l]),o.useEffect(()=>{c&&c({cancelButton:D,saveButton:q})},[c,D,q]);const V=o.useMemo(()=>b.map(s=>({value:s.id,label:s.name})),[b]),C=o.useMemo(()=>A.filter(s=>u==="copy"?!0:!s.quantumOwned).map(s=>({value:s.id,label:s.name,isQuantumOwned:s.quantumOwned})),[A,u]),G=g.fetching,W=E.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(X,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:u,onChange:s=>{S(s),v([])},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(X,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(K.st,{placeholder:"Choose a group...",options:V,value:V.find(s=>s.value===L)||null,onChange:_,isLoading:G,isDisabled:G,isClearable:!0}),g.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",g.error.message]})]})]}),L&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsxs(X,{children:["Select Activities to"," ",u==="copy"?"Copy":"Convert"]}),W?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:C,value:C.filter(s=>f.includes(s.value)),onChange:O,isDisabled:C.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"})]})}),C.length===0&&e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:"No activities found"})]}),E.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load activities: ",E.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(M=>M.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"]})})]})]}),!x&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:D,isDisabled:a,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:u==="copy"?"blue":"green",onClick:q,isDisabled:F.length===0||a,isLoading:a,loadingText:`${u==="copy"?"Copying":"Converting"}...`,children:[u==="copy"?"Copy":"Convert"," ",F.length===1?"Activity":`${F.length} Activities`]})]})]})})},Me=({onSave:r,onCancel:n,onError:i,hideButtons:x=!1,setButtonDisabled:l,setButtonOnClick:c,quantumOwned:m})=>{const R=t.useToast(),[u,S]=o.useState(""),[L,j]=o.useState([]),[f,v]=o.useState(!1),[a,d]=o.useState("copy"),[g]=z.useQuery({query:T.GET_GROUPS}),[E]=z.useQuery({query:T.GET_MODULES_BY_GROUP,variables:{groupId:u},pause:!u}),[,y]=z.useMutation(T.CREATE_MODULE),[,w]=z.useMutation(T.UPDATE_MODULE),[,b]=z.useMutation(T.CREATE_ACTION),[,A]=z.useMutation(T.CONVERT_ACTION_TO_QUANTUM_OWNED),F=o.useMemo(()=>g.data?.groups?g.data.groups.map(s=>h.getFragmentData(T.GROUP_FRAGMENT,s)):[],[g.data]),_=o.useMemo(()=>E.data?.modules?h.getFragmentData(T.ACTION_MODULE_FRAGMENT,E.data?.modules).map(p=>{const M=h.getFragmentData(T.MODULE_ACTION_FRAGMENT,p.moduleActions);return{...p,moduleActions:M.map(I=>({...I,action:h.getFragmentData(T.ACTION_FRAGMENT,I.action)})),categories:h.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,p.categories)}}):[],[E.data]),O=o.useMemo(()=>_.filter(s=>L.includes(s.id)),[_,L]),$=o.useCallback(s=>{const p=s?.value||"";S(p),j([])},[]),H=o.useCallback(s=>{const p=s.map(M=>M.value);j(p)},[]),q=o.useCallback(async()=>{if(v(!0),!O.length){v(!1);const s=new Error(`No modules selected for ${a==="convert"?"converting":"copying"}`);i?.(s);return}try{const s=[];let p=0;for(const M of O)try{let I=M.moduleActions.map(k=>k.actionId);if(m){const k=M.moduleActions.map(U=>U.action),P=async U=>{if(a==="copy"){if(U.quantumOwned)return U;const ee=h.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,U.categories),ne={...U,quantumOwned:!0,thresholds:U.thresholds.map(B=>({...B,id:void 0})),categories:ee?.map(B=>B.id),id:void 0},N=await b({fields:ne});return N.error||!N.data?.createAction?null:h.getFragmentData(T.ACTION_FRAGMENT,N.data.createAction)}if(U.quantumOwned)return U;const se=await A({id:U.id});return se.error||!se.data?.convertActionToQuantumOwned?null:h.getFragmentData(T.ACTION_FRAGMENT,se.data.convertActionToQuantumOwned)};I=(await Promise.all(k.map(P))).filter(U=>!!U).map(U=>U.id)}if(a==="convert"){const k={name:M.name,description:M.description||void 0,actions:I,categories:M.categories.map(Q=>Q.id),quantumOwned:!0},P=await w({id:M.id,input:k});if(P.error)throw new Error(P.error.message);if(P.data?.updateModule){const Q=h.getFragmentData(T.ACTION_MODULE_FRAGMENT,P.data.updateModule);s.push(Q)}}else{const k={name:`${M.name} (Copy)`,description:M.description||void 0,actions:I,categories:M.categories.map(Q=>Q.id),quantumOwned:m},P=await y({input:k});if(P.error)throw new Error(P.error.message);if(P.data?.createModule){const Q=h.getFragmentData(T.ACTION_MODULE_FRAGMENT,P.data.createModule);s.push(Q)}}}catch(I){console.error(`Failed to ${a==="convert"?"convert":"copy"} module "${M.name}":`,I),p++}if(s.length>0){const M=s.length,I=O.length;R({title:p>0?`Partial ${a==="convert"?"convert":"copy"} completed`:`Modules ${a==="convert"?"converted":"copied"} successfully`,description:p>0?`${M} of ${I} modules ${a==="convert"?"converted":"copied"} successfully`:`${M} module${M>1?"s":""} ${a==="convert"?"converted":"copied"} successfully`,status:p>0?"warning":"success",duration:3e3,isClosable:!0}),s.length>0&&r?.(),S(""),j([])}else throw new Error(`Failed to ${a==="convert"?"convert":"copy"} any modules`)}catch(s){const p=s instanceof Error?s.message:`Failed to ${a==="convert"?"convert":"copy"} modules`;R({title:a==="convert"?"Convert failed":"Copy failed",description:p,status:"error",duration:5e3,isClosable:!0}),i?.(s instanceof Error?s:new Error(p))}finally{v(!1)}},[O,y,w,R,r,i,m,b,A,a]),D=o.useCallback(()=>{S(""),j([]),d("copy"),n?.()},[n]);o.useEffect(()=>{l&&l({cancelButton:!1,saveButton:O.length===0||f})},[O.length,f,l]),o.useEffect(()=>{c&&c({cancelButton:D,saveButton:q})},[c,D,q]);const V=o.useMemo(()=>F.map(s=>({value:s.id,label:s.name})),[F]),C=o.useMemo(()=>_.filter(s=>a==="copy"?!0:!s.quantumOwned).map(s=>({value:s.id,label:s.name,isQuantumOwned:s.quantumOwned})),[_,a]),G=g.fetching,W=E.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(X,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:a,onChange:s=>{d(s),j([])},children:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:6,children:[e.jsxRuntimeExports.jsx(t.Radio,{value:"copy",colorScheme:"blue",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.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(X,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(K.st,{placeholder:"Choose a group...",options:V,value:V.find(s=>s.value===u)||null,onChange:$,isLoading:G,isDisabled:G,isClearable:!0}),g.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",g.error.message]})]})]}),u&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(X,{children:a==="convert"?"Select Module to Convert":"Select Module to Copy"}),W?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:a==="convert"?"Choose modules to convert...":"Choose modules to copy...",options:C,value:C.filter(s=>L.includes(s.value)),onChange:H,isDisabled:C.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"})]})}),C.length===0&&e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:"No modules found in this group"})]}),E.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load modules: ",E.error.message]})]})]}),O.length>0&&e.jsxRuntimeExports.jsxs(t.Box,{p:4,bg:"gray.50",borderRadius:"md",children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"semibold",mb:3,children:O.length===1?`Module to ${a==="copy"?"Copy":"Convert"}`:`${O.length} Modules to ${a==="copy"?"Copy":"Convert"}`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[O.map((s,p)=>e.jsxRuntimeExports.jsxs(t.Box,{w:"100%",p:3,bg:"white",borderRadius:"md",border:"1px solid",borderColor:"gray.200",children:[e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",align:"start",mb:2,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"medium",fontSize:"sm",children:[p+1,". ",s.name]}),s.quantumOwned&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,fontSize:"sm",color:"gray.600",children:[s.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",s.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Actions:"})," ",s.moduleActions.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Categories:"})," ",s.categories.map(M=>M.name).join(", ")||"None"]})]})]},s.id)),O.length>1&&e.jsxRuntimeExports.jsx(t.Box,{w:"100%",p:2,bg:"blue.50",borderRadius:"md",border:"1px solid",borderColor:"blue.200",children:e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",fontWeight:"medium",color:"blue.800",children:["Total: ",O.length," modules will be"," ",a==="copy"?"copied":"converted"]})}),m&&O.filter(s=>s.moduleActions.some(p=>!p.action.quantumOwned)).length>0&&e.jsxRuntimeExports.jsx(t.Box,{p:2,bg:"yellow.50",borderRadius:"md",border:"1px solid",borderColor:"yellow.200",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",fontWeight:"medium",color:"yellow.800",children: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"})})]})]}),!x&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:D,isDisabled:f,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:a==="copy"?"blue":"green",onClick:q,isDisabled:O.length===0||f,isLoading:f,loadingText:`${a==="copy"?"Copying":"Converting"}...`,children:[a==="copy"?"Copy":"Convert"," ",O.length===1?"Module":`${O.length} Modules`]})]})]})})},xe=({name:r,setName:n,actions:i,selectedActionIds:x,setSelectedActionIds:l,availableCategories:c,selectedCategoryIds:m,setSelectedCategoryIds:R,description:u,setDescription:S,...L})=>{const j=t.useDisclosure(),f=o.useMemo(()=>i.map(y=>({...y,selected:x.includes(y.id)})),[i,x]),v=o.useMemo(()=>i.reduce((y,w)=>(y[w.id]=w,y),{}),[i]),a=o.useMemo(()=>x.map(y=>v[y]),[f,x]),d=o.useCallback((y,w)=>{l(w?[...x,y.id]:x.filter(b=>b!==y.id))},[x,l]),g=o.useCallback(y=>{n(y.target.value)},[n]),E=o.useCallback(y=>{S?.(y.target.value)},[S]);return e.jsxRuntimeExports.jsxs(t.Box,{...L,children:[e.jsxRuntimeExports.jsxs(t.HStack,{gap:"2rem",children:[e.jsxRuntimeExports.jsx(Ae,{name:r??"",onInputChange:g}),e.jsxRuntimeExports.jsx(we,{availableCategories:c,value:m,onChange:R})]}),e.jsxRuntimeExports.jsx(Fe,{description:u??"",onInputChange:E}),e.jsxRuntimeExports.jsx(Oe,{value:a,onChange:l,onAdjustActivities:()=>j.onOpen()}),e.jsxRuntimeExports.jsxs(t.Modal,{isOpen:j.isOpen,onClose:j.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(ue,{actions:f,onSelected:d,disableCreate:!0,disableDelete:!0,tableProps:{height:"28rem",overflowY:"auto"}})}),e.jsxRuntimeExports.jsx(t.ModalFooter,{children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:j.onClose,isDisabled:x.length===0,children:"Done"})})]})]})]})},Ae=o.memo(({name:r,onInputChange:n})=>e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(X,{children:"Module Name"}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. ACL RTP Test Battery",value:r,onChange:n,isRequired:!0})]})),we=o.memo(({availableCategories:r,value:n,onChange:i})=>{const x=o.useMemo(()=>[...r,{id:"other",name:"Other"}],[r]),l=o.useMemo(()=>x.map(c=>({value:c.id,label:c.name})),[x]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(X,{children:"Module Category"}),e.jsxRuntimeExports.jsx(K.st,{isDisabled:r.length===0,isClearable:!0,options:l,value:x.filter(c=>n.includes(c.id)).map(c=>({value:c.id,label:c.name})),onChange:c=>i(c?[c.value]:[]),placeholder:"Select category"})]})}),Fe=o.memo(({description:r,onInputChange:n})=>e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(X,{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})]})),Oe=o.memo(({value:r,onChange:n,onAdjustActivities:i})=>{const x=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(X,{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"})]}),x.length===0?e.jsxRuntimeExports.jsx(t.VStack,{children:e.jsxRuntimeExports.jsxs(t.Text,{color:"gray.500",fontSize:"lg",mb:"4rem",mt:"4rem",children:["No activities selected for this module.",e.jsxRuntimeExports.jsx(t.Button,{ml:"0.5em",size:"sm",variant:"link",colorScheme:"blue",onClick:i,children:"Add activities."})]})}):e.jsxRuntimeExports.jsx(Ee,{value:x,onChange:l=>{const c=l(x);n(c.map(m=>m.id))}})]})}),de=({value:r,onChange:n,forceKind:i,disableRemove:x,disableKind:l,lockRanges:c,...m})=>{const R=o.useMemo(()=>[...r].sort((j,f)=>{const v=te.availablePlanes.indexOf(j.plane),a=te.availablePlanes.indexOf(f.plane);return v-a}),[r]),u=o.useCallback(j=>"segment"in j.id?J.getSegmentNameWithPlane(j.id.segment,j.plane,!0)??"Unknown":J.getJointNameWithPlane(j.id.joint,j.plane,!0)??"Unknown",[]),S=o.useCallback((j,f)=>{const v=R.findIndex(d=>d.id===f.id&&d.plane===f.plane);let a=[...R];i&&(f={...f,kind:i}),a[v]=f,c&&(a=a.map(d=>({...d,min:f.min,max:f.max}))),n(a)},[n,R,i,c]),L=o.useCallback(j=>{const f=R.filter(v=>v.id!==j.id||v.plane!==j.plane);n(f)},[n,R]);return e.jsxRuntimeExports.jsx(t.VStack,{alignItems:"flex-start",overflowY:"auto",...m,children:R.map((j,f)=>e.jsxRuntimeExports.jsx(Ne,{label:u(j),parameter:j,onChange:v=>S(f,v),onRemove:x?void 0:()=>L(j),forceKind:i,disableKind:l},`${JSON.stringify(j.id)}-${j.plane}`))})},Ne=({label:r,parameter:n,onChange:i,onRemove:x,forceKind:l,disableKind:c})=>{const m=o.useCallback(S=>"joint"in n.id?J.getJointAngleDirectionName(n.id.joint,n.plane,S<0?-1:1):J.getSegmentAngleDirectionName(n.id.segment,n.plane,S<0?-1:1),[n]),{min:R,max:u}="joint"in n.id?J.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}),x&&e.jsxRuntimeExports.jsx(t.IconButton,{size:"xs",variant:"ghost","aria-label":"delete",icon:e.jsxRuntimeExports.jsx(t.Icon,{as:ce.FaTrash}),onClick:x}),!l&&e.jsxRuntimeExports.jsx(fe,{selectedItem:n?.kind??h.ThresholdKind.Limit,onChange:({value:S})=>i({...n,kind:S}),isDisabled:c,buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:h.ThresholdKind.Limit,label:"limit"},{value:h.ThresholdKind.Target,label:"target"}]})]}),e.jsxRuntimeExports.jsx(ve,{w:"100%",size:"xs",min:R,max:u,zeroMarker:!0,value:[n.min,n.max],onChange:S=>i({...n,min:S[0],max:S[1]}),formatValue:S=>`${Math.abs(S)}°`,valueLabel:S=>m(S)??"",positiveNegativeLabels:m(0)?[m(-1)??"",m(1)??""]:void 0})]})},ie=(r,n)=>"segment"in r&&"segment"in n&&r.segment===n.segment||"joint"in r&&"joint"in n&&r.joint===n.joint,me=({options:r,value:n,onChange:i,forceKind:x,singleValue:l,singleValueSideless:c,editOnly:m,disableKind:R,maxParameters:u,...S})=>{const L=c?2:u,j=o.useMemo(()=>r.map(d=>({label:"segment"in d.id?J.getSegmentNameWithPlane(d.id.segment,d.plane,!0)??"Unknown":J.getJointNameWithPlane(d.id.joint,d.plane,!0)??"Unknown",value:d.id,plane:d.plane})),[r]),f=o.useMemo(()=>{if(!c||n.length===0)return j;const d=n[0];return j.filter(g=>te.getAnalysisPartIdNoSide(g.value)===te.getAnalysisPartIdNoSide(d.id)&&g.plane===d.plane)},[j,n,c]),v=o.useMemo(()=>j.filter(d=>n.some(g=>ie(g.id,d.value)&&g.plane===d.plane)),[j,n]),a=o.useCallback(d=>{const g=d.map(E=>{const y=n.find(_=>ie(_.id,E.value)&&_.plane===E.plane),w=r.find(_=>ie(_.id,E.value)&&_.plane===E.plane),b=c?n.find(_=>te.getAnalysisPartIdNoSide(_.id)===te.getAnalysisPartIdNoSide(E.value)&&_.plane===E.plane):void 0,A=b&&!y?b.min:w&&w.min?w.min:0,F=b&&!y?b.max:w&&w.max?w.max:0;return y??{id:E.value,plane:E.plane,min:A,max:F,kind:x??h.ThresholdKind.Limit}});i(g)},[i,n,r,x,c]);return o.useEffect(()=>{const d=n.filter(g=>r.some(E=>ie(E.id,g.id)&&E.plane===g.plane));d.length!==n.length&&i(d)},[r,i]),e.jsxRuntimeExports.jsxs(t.Box,{...S,children:[e.jsxRuntimeExports.jsx(K.st,{isMulti:!l,placeholder:n.length?`${n.length} selected`:"Search...",value:v,isDisabled:m||v.length>=(L??1/0),onChange:d=>Array.isArray(d)?a([...d]):a(d!==null?[d]:[]),options:f,controlShouldRenderValue:!1}),e.jsxRuntimeExports.jsx(de,{marginTop:2,maxH:"28rem",value:n,onChange:i,forceKind:x,disableKind:R,lockRanges:c})]})},pe=r=>{switch(r){case h.SensorLocation.Thorax:return"Thorax";case h.SensorLocation.CenterBack:return"Center Back";case h.SensorLocation.Pelvis:return"Pelvis";case h.SensorLocation.LeftThigh:return"Left Thigh";case h.SensorLocation.RightThigh:return"Right Thigh";case h.SensorLocation.LeftShank:return"Left Shank";case h.SensorLocation.RightShank:return"Right Shank";case h.SensorLocation.LeftFoot:return"Left Foot";case h.SensorLocation.RightFoot:return"Right Foot";case h.SensorLocation.LeftUpperArm:return"Left Upper Arm";case h.SensorLocation.RightUpperArm:return"Right Upper Arm";case h.SensorLocation.LeftForearm:return"Left Forearm";case h.SensorLocation.RightForearm:return"Right Forearm";case h.SensorLocation.Head:return"Head"}return console.warn(`Unknown sensor location: ${r}`),"Unknown"},Le=6,ke=[h.SensorLocation.LeftFoot,h.SensorLocation.LeftShank,h.SensorLocation.LeftThigh,h.SensorLocation.Pelvis,h.SensorLocation.RightFoot,h.SensorLocation.RightShank,h.SensorLocation.RightThigh,h.SensorLocation.Thorax,h.SensorLocation.CenterBack,h.SensorLocation.Head],Ie=ke.map(r=>({label:pe(r),value:r})),le=(r,n)=>r.map(i=>({label:n?n(i):i,value:i})),De=({id:r,onError:n,onCancel:i,onSave:x,hideButtons:l,setButtonOnClick:c,setButtonDisabled:m,quantumOwned:R})=>{const[{fetching:u},S]=z.useMutation(T.CREATE_ACTION),[{fetching:L},j]=z.useMutation(T.UPDATE_ACTION),[{data:f}]=z.useQuery({query:T.GET_ACTION_BY_ID,variables:{id:r??""},pause:!r}),v=h.getFragmentData(T.ACTION_FRAGMENT,f?.getActionById),a=u||L,d=!!v&&!!r,[g,E]=o.useState(""),[y,w]=o.useState(""),[b,A]=o.useState(""),[F,_]=o.useState(""),[O,$]=o.useState(),[H,q]=o.useState([]),[D,V]=o.useState([]),[C,G]=o.useState([]),W=o.useMemo(()=>D.map(N=>N.value),[D]),s=je.usePartOptionsForSensorLocations(W),[{data:p}]=z.useQuery({query:T.GET_ALL_MODULE_CATEGORIES}),M=o.useMemo(()=>h.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,p?.moduleCategories)?.map(B=>({label:B.name,value:B.id})),[p?.moduleCategories]),I=o.useMemo(()=>le(Object.values(h.SessionType),J.mapSessionTypeEnumToLabel),[]),[k,P]=o.useState([]),Q=g.length>0,[U,se]=o.useState({});o.useEffect(()=>{if(v){const N=h.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,v.categories),B={name:v.name,activityType:v.activityType??void 0,description:v.description||"",cameraPlacement:v.cameraPlacement||"",videoLink:v.videoLink||"",sessionType:v.sessionType.map(Y=>({label:J.mapSessionTypeEnumToLabel(Y),value:Y})),categories:N?.map(Y=>Y.id)||[],sensorLocations:v.sensorLocations.map(Y=>({label:pe(Y),value:Y})),thresholds:oe.thresholdsToParameters(v.thresholds)};E(B.name),$(B.activityType??void 0),w(B.description),A(B.cameraPlacement),_(B.videoLink),q(B.sessionType),G(N?.map(Y=>Y.id)||[]),V(B.sensorLocations),P(B.thresholds),se(B)}},[v]);const ee=o.useMemo(()=>JSON.stringify(U)!==JSON.stringify({name:g,description:y,cameraPlacement:b,videoLink:F,activityType:O,sessionType:H.map(N=>N.value),categories:C,sensorLocations:W,thresholds:oe.parametersToThresholds(k)}),[U,g,W,y,b,F,O,H,C,k]),ne=o.useCallback(()=>{const N={name:g,description:y,cameraPlacement:b,videoLink:F,activityType:O,activityKind:J.getActivityKindFromActivityType(O),sessionType:H.map(Y=>Y.value),categories:C,sensorLocations:W,thresholds:oe.parametersToThresholds(k),laterality:h.ActionLaterality.Either,quantumOwned:R};let B;d&&r?B=j({id:r,fields:N}):B=S({fields:N}),B.then(({error:Y})=>{Y?n(Y):x()})},[R,S,j,r,g,W,y,b,F,O,H,C,d,k,x,n]);return o.useEffect(()=>{m&&m({cancelButton:a,saveButton:a||!Q||!ee})},[a,m,Q,ee]),o.useEffect(()=>{c&&c({cancelButton:i,saveButton:ne})},[c,i,ne]),console.log(Q,ee,a,U),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(Z,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:g,onChange:N=>E(N.target.value),type:"text",placeholder:"i.e. Lunge & Return"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:"Activity Type"}),e.jsxRuntimeExports.jsx(K.st,{isClearable:!0,isMulti:!1,value:O?{label:J.mapActivityTypeEnumToLabel(O),value:O}:null,onChange:N=>$(N?.value),options:le(Object.values(h.ActivityType),J.mapActivityTypeEnumToLabel),placeholder:"(optional) Select activity type"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:"Camera Placement"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:b,onChange:N=>A(N.target.value),rows:2,placeholder:"(optional) Describe camera setup, placement, angles"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:"Video Link"}),e.jsxRuntimeExports.jsx(t.Input,{value:F,onChange:N=>_(N.target.value),type:"url",placeholder:"(optional) https://..."})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:"Description"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:y,onChange:N=>w(N.target.value),rows:2,placeholder:"(optional) Describe how to perform the test or exercise"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:"Link to Category"}),e.jsxRuntimeExports.jsx(K.st,{isMulti:!0,value:M?.filter(N=>C.includes(N.value)),onChange:N=>G((N??[]).map(B=>B.value)),options:M,placeholder:"Select one or more categories"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:"Session Types"}),e.jsxRuntimeExports.jsx(K.st,{isMulti:!0,value:H,onChange:N=>q(N??[]),options:I,placeholder:"Select one or more session types"})]})]}),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(Z,{children:"Sensor Locations"}),e.jsxRuntimeExports.jsx(K.st,{isMulti:!0,value:D,onChange:N=>V([...N]),options:Ie,isOptionDisabled:()=>D.length>=Le})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(me,{options:s,value:k,onChange:P})]})]}),e.jsxRuntimeExports.jsx("div",{className:oe.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:a,onClick:i,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:a||!Q||!ee,isLoading:a,onClick:ne,children:"Save changes"})]})})]})},Z=({children:r})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:r}),_e=({id:r,onCancel:n,onSave:i,onError:x,hideButtons:l,quantumOwned:c,setButtonOnClick:m,setButtonDisabled:R})=>{const[{data:u}]=z.useQuery({query:c?T.GET_QUANTUM_OWNED_ACTIONS:T.GET_ACTIONS}),[{data:S}]=z.useQuery({query:T.GET_MODULE_BY_ID,variables:{id:r},pause:!r}),[{data:L}]=z.useQuery({query:T.GET_ALL_MODULE_CATEGORIES}),j=h.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,L?.moduleCategories),[{fetching:f},v]=z.useMutation(T.UPDATE_MODULE),[{fetching:a},d]=z.useMutation(T.CREATE_MODULE),g=h.getFragmentData(T.ACTION_FRAGMENT,c?u?.quantumOwnedActions:u?.actions)??[],E=h.getFragmentData(T.ACTION_MODULE_FRAGMENT,S?.module),y=h.getFragmentData(T.MODULE_ACTION_FRAGMENT,E?.moduleActions)??[],[w,b]=o.useState([...y.map(D=>D.actionId)??[]]),[A,F]=o.useState(E?.name??""),[_,O]=o.useState([]),[$,H]=o.useState(E?.description??"");o.useEffect(()=>{E&&(b(y.map(D=>D.actionId)),F(E.name),H(E.description??""),O(E.categories.map(D=>h.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,D).id)??[]))},[E,y]);const q=o.useCallback(()=>{let D;const V={actions:w,name:A,categories:_.filter(C=>C!=="other"),description:$,quantumOwned:c};E?D=v({id:E.id,input:V}):D=d({input:V}),D.then(({error:C})=>{C?x(C):i()})},[d,v,w,A,$,_,E,i,x]);return o.useEffect(()=>{R&&R({cancelButton:f||a,saveButton:f||a||!A||$.trim().split(/\s+/).filter(Boolean).length>40})},[R,f,a,w,A,$]),o.useEffect(()=>{m&&m({cancelButton:n,saveButton:q})},[m,n,q]),e.jsxRuntimeExports.jsxs(t.Box,{width:"100%",children:[e.jsxRuntimeExports.jsx(xe,{name:A,setName:F,actions:g,selectedActionIds:w,setSelectedActionIds:b,availableCategories:j??[],selectedCategoryIds:_,setSelectedCategoryIds:O,description:$,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:f||a,onClick:n,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:f||a||!A||$.trim().split(/\s+/).filter(Boolean).length>40,isLoading:f||a,onClick:q,children:"Save"})]})})]})};exports.ActivityList=ue;exports.CopyActivityForm=Se;exports.CopyModuleForm=Me;exports.ModuleForm=xe;exports.ParameterEditList=de;exports.ParameterEditSelect=me;exports.UpsertActivityForm=De;exports.UpsertModuleForm=_e;
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"),he=require("./ufuzzy-vendor-7qHa_k39.cjs"),K=require("./react-select-vendor-D_Q2fL5j.cjs"),ce=require("./react-icons-vendor-D2s8zw9h.cjs"),z=require("./graphql-vendor-B-QTAQSb.cjs"),h=require("./generated-DdOST8v9.cjs"),T=require("./graphql-B8Qfs-lB.cjs"),ae=require("./react-dnd-vendor-BPzSDojS.cjs"),J=require("./services.cjs"),te=require("./types.cjs"),oe=require("./utils.cjs"),je=require("./hooks.cjs"),ge=({setSearch:r,actions:n,updateUseCases:i})=>{const x=o.useMemo(()=>n?.flatMap(l=>l.useCases).filter((l,c,m)=>m.findIndex(R=>R.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:ce.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:x,onChange:l=>i(l.map(c=>c.value))})})]})},X=({children:r})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:r}),Ee=({value:r,onChange:n})=>{const i=o.useState(()=>Math.random().toString(36).substring(2,15))[0],x=o.useCallback((l,c)=>{n(m=>{const R=[...m],[u]=R.splice(l,1);return R.splice(c,0,u),R})},[n]);return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsx(ae.DndProvider,{backend:ae.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(Re,{listKey:i,index:c,id:l.id,name:l.name,move:x},l.id))})]})})})})},Re=({listKey:r,index:n,id:i,name:x,move:l})=>{const c=o.useRef(null),[{handlerId:m},R]=ae.useDrop({accept:r,collect:f=>({handlerId:f.getHandlerId()?.toString()??""}),hover:(f,v)=>{if(!c.current)return;const a=f.index,d=n;if(a===d)return;const g=c.current?.getBoundingClientRect(),E=(g.bottom-g.top)/2,w=v.getClientOffset().y-g.top;a<d&&w<E||a>d&&w>E||(l(a,d),f.index=d)}}),[{isDragging:u},S]=ae.useDrag({type:r,item:()=>({id:i,index:n}),collect:f=>({isDragging:f.isDragging()})}),L=u?.6:1,j=u?"grabbing":"grab";return S(R(c)),e.jsxRuntimeExports.jsxs(t.Tr,{ref:c,style:{opacity:L,cursor:j},"data-handler-id":m,children:[e.jsxRuntimeExports.jsx(t.Td,{children:n+1}),e.jsxRuntimeExports.jsx(t.Td,{children:x})]})},fe=({items:r,onChange:n,selectedItem:i,isDisabled:x,selectedProps:l,buttonProps:c})=>{const m=u=>u===i||u.value===i,R=u=>m(u)?{...c,...l}:c;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:x,children:r.map((u,S)=>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,S),isDisabled:u.disabled,...R(u),children:u.label})},S))})},re=(r,n)=>n<0?-1*Math.abs(r):Math.abs(r),ve=({isReversed:r,min:n,max:i,value:x,onChange:l,inputProps:c,size:m,zeroMarker:R,formatValue:u,valueLabel:S,positiveNegativeLabels:L,isDisabled:j,...f})=>{const[v,a]=o.useState([void 0,void 0]),d=v[0],g=v[1],E=R&&n<-5&&i>5,y=Number(x?.[0]??g??n)>0?1:-1,w=Number(x?.[1]??g??i)<0?-1:1,b=L?.[0]===L?.[1],A=x?.[0],F=x?.[1];o.useEffect(()=>{A!==void 0&&F!==void 0&&a([A.toFixed(0),F.toFixed(0)])},[A,F,a]);const _=o.useCallback(([C,G])=>{C<G&&a([C.toFixed(0),G.toFixed(0)])},[a]),O=o.useCallback(([C,G])=>{C<G&&l([C,G])},[l]),$=o.useCallback(()=>{a(([C,G])=>{const W=isNaN(Number(C))?n:Number(C),s=isNaN(Number(G))?i:Number(G),p=re(Number(W),y),M=re(Number(s),w),I=y<0?Math.max(p,n):Math.min(p,i),k=w<0?Math.max(M,n):Math.min(M,i);return I>k?(l([k,I]),[k.toFixed(0),I.toFixed(0)]):(l([I,k]),[I.toFixed(0),k.toFixed(0)])})},[l,a,y,w,n,i]),H=o.useCallback(C=>{const G=C===""||isNaN(Number(C))?C:re(Number(C),y);a(([W,s])=>[G.toString(),s])},[a,y]),q=o.useCallback(C=>{const G=C===""||isNaN(Number(C))?C:re(Number(C),w);a(([W,s])=>[W,G.toString()])},[a,w]),D=o.useMemo(()=>m==="xs"?"0.75rem":void 0,[m]),V=o.useCallback((C,G)=>{const W=Number(G.target.value);if(!d||!g||![-1,1].includes(W))return;const s=I=>W<0?-1*Math.abs(I):Math.abs(I),p=C?s(Number(d)):Number(d),M=C?Number(g):s(Number(g));p>M?l([M,p]):l([p,M])},[d,g,l]);return e.jsxRuntimeExports.jsxs(t.Flex,{direction:"column",...f,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(d??n),Number(g??i)],max:i,min:n,minStepsBetweenThumbs:3,step:1,onChange:_,onChangeEnd:O,isDisabled:j,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:i,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:m??"sm",fontWeight:"semibold",style:{transform:"translateX(-100%)"},whiteSpace:"nowrap",children:u?u(i):i})}),E&&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:D,h:D}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:1,w:D,h:D})]})}),S&&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:S(n)}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:m??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:S(i)})]}),e.jsxRuntimeExports.jsxs(t.Flex,{direction:r?"row-reverse":"row",justifyContent:"center",alignItems:"center",gap:"0.125em",children:[L&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:m,fontWeight:"bold",value:y,onChange:C=>V(!0,C),isDisabled:b||j,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:L[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:L[1]})]}),e.jsxRuntimeExports.jsx(t.NumberInput,{precision:0,size:m??"sm",min:0,max:y<0?Math.abs(n):F??i,value:d===""?"":Math.abs(Number(d??n)),onChange:H,onBlur:$,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:j,...c,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),e.jsxRuntimeExports.jsx(t.NumberInput,{size:m??"sm",min:0,max:w<0?Math.abs(A??n):i,precision:0,value:g===""?"":Math.abs(Number(g??i)),onChange:q,onBlur:$,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:j,...c,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),L&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:m,fontWeight:"bold",value:w,onChange:C=>V(!1,C),isDisabled:b||j,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:L[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:L[1]})]})]})]})},Ce=({tags:r,containerProps:n,...i})=>e.jsxRuntimeExports.jsx(t.HStack,{...n,children:r.map((x,l)=>e.jsxRuntimeExports.jsx(t.Tag,{...i,children:x},l))}),ye=new he.uFuzzy({}),be=(r,n)=>{if(!n||!n.trim().length)return r;const i=r.map(l=>l.name??"");return ye.filter(i,n)?.map(l=>r[l])??[]},Te=(r,n)=>!n||n.length==0?r:r.filter(i=>i.useCases.some(x=>n.includes(x.id))),ue=({actions:r,totalActions:n,onCreate:i,onDelete:x,onEdit:l,onSelected:c,onDuplicate:m,disableMultiSelect:R,disableDelete:u,disableEdit:S,disableCreate:L,tableProps:j,...f})=>{const[v,a]=o.useState(""),[d,g]=o.useState(),E=o.useMemo(()=>{if(!r)return;const b=be(r,v);return Te(b,d).sort((F,_)=>F.name.localeCompare(_.name))},[r,v,d]),y=o.useCallback(()=>{if(!x)return;const b=r.filter(A=>A.selected).map(A=>A.id);x(b)},[r,x]),w=o.useCallback(()=>{if(!m)return;const b=r.filter(A=>A.selected);m(b.map(A=>A.id)),c&&b.forEach(A=>c(A,!1))},[r,m,c]);return e.jsxRuntimeExports.jsxs(t.Box,{...f,children:[e.jsxRuntimeExports.jsxs(t.Flex,{alignContent:"space-between",gap:4,children:[(i||x||m)&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mb:"1rem",gap:4,children:[i&&e.jsxRuntimeExports.jsx(t.Button,{isDisabled:!i||L,colorScheme:"blackAlpha",backgroundColor:"gray.700",onClick:i,children:"Create New Activity"}),x&&!R&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:r.length<=0||!x||u,onClick:y,children:"Delete Selected"}),m&&!R&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:r.length<=0,onClick:w,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx(ge,{setSearch:a,actions:r,updateUseCases:g})]}),e.jsxRuntimeExports.jsx(t.TableContainer,{mr:"2rem",overflowX:"hidden",...j,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 ",E?.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:E?.map(b=>e.jsxRuntimeExports.jsxs(t.Tr,{title:R&&b.selected?"This activity is selected. Click it again to deselect.":void 0,bg:R&&b.selected?"gray.200":void 0,_hover:{bg:R&&!b.selected?"#f7f7f7":void 0},cursor:R?"pointer":"default",onClick:()=>R?c?.(b,!b.selected):void 0,children:[e.jsxRuntimeExports.jsx(t.Td,{children:e.jsxRuntimeExports.jsxs(t.Flex,{children:[c&&!R&&e.jsxRuntimeExports.jsx(t.Checkbox,{isChecked:b.selected,onChange:A=>c(b,A.target.checked)}),l&&e.jsxRuntimeExports.jsx(t.Button,{disabled:S,ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:()=>l(b.id),children:"edit"})]})}),e.jsxRuntimeExports.jsx(t.Td,{whiteSpace:"break-spaces",children:b.name}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:b.sensorLocations.length}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:e.jsxRuntimeExports.jsx(Ce,{containerProps:{flexWrap:"wrap"},tags:b.useCases?.map(A=>A.name)??[]})})]},b.id))})]})})]})},Se=({onSave:r,onCancel:n,onError:i,hideButtons:x=!1,setButtonDisabled:l,setButtonOnClick:c,quantumOwned:m})=>{const R=t.useToast(),[u,S]=o.useState("copy"),[L,j]=o.useState(""),[f,v]=o.useState([]),[a,d]=o.useState(!1),[g]=z.useQuery({query:T.GET_GROUPS}),[E]=z.useQuery({query:T.GET_ACTIONS_BY_GROUP,variables:{groupId:L},pause:!L}),[,y]=z.useMutation(T.CREATE_ACTION),[,w]=z.useMutation(T.CONVERT_ACTION_TO_QUANTUM_OWNED),b=o.useMemo(()=>g.data?.groups?g.data.groups.map(s=>h.getFragmentData(T.GROUP_FRAGMENT,s)):[],[g.data]),A=o.useMemo(()=>E.data?E.data.actions.map(p=>h.getFragmentData(T.ACTION_FRAGMENT,p)):[],[E.data]),F=o.useMemo(()=>A.filter(s=>f.includes(s.id)),[A,f]),_=o.useCallback(s=>{const p=s?.value||"";j(p),v([])},[]),O=o.useCallback(s=>{const p=s.map(M=>M.value);v(p)},[]),$=o.useCallback(async s=>{const p=h.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,s.categories),M={...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(k=>({...k,id:void 0})),categories:p?.map(k=>k.id),quantumOwned:m,id:void 0},I=await y({fields:M});if(I.error)throw new Error(I.error.message);if(I.data?.createAction)return h.getFragmentData(T.ACTION_FRAGMENT,I.data.createAction);throw new Error("No action data returned")},[y,m]),H=o.useCallback(async s=>{const p=await w({id:s.id});if(p.error)throw new Error(p.error.message);if(p.data?.convertActionToQuantumOwned)return h.getFragmentData(T.ACTION_FRAGMENT,p.data.convertActionToQuantumOwned);throw new Error("No action data returned")},[w]),q=o.useCallback(async()=>{if(d(!0),!F.length){const s=new Error(`No activities selected for ${u==="copy"?"copying":"converting"}`);i?.(s),d(!1);return}try{const s=[];let p=0;const M=u==="copy"?$:H,I=u==="copy"?"copy":"convert";for(const k of F)try{const P=await M(k);s.push(P)}catch(P){console.error(`Failed to ${I} activity "${k.name}":`,P),p++}if(s.length>0){const k=s.length,P=F.length,Q=u==="copy"?"copied":"converted",U=u==="copy"?"copy":"convert";R({title:p>0?`Partial ${U} completed`:`Activities ${Q} successfully`,description:p>0?`${k} of ${P} activities ${Q} successfully`:`${k} activit${k>1?"ies":"y"} ${Q} successfully`,status:p>0?"warning":"success",duration:3e3,isClosable:!0}),r?.(),j(""),v([])}else throw new Error(`Failed to ${I} any activities`)}catch(s){const p=u==="copy"?"copy":"convert",M=s instanceof Error?s.message:`Failed to ${p} activities`;R({title:`${u==="copy"?"Copy":"Convert"} failed`,description:M,status:"error",duration:5e3,isClosable:!0}),i?.(s instanceof Error?s:new Error(M))}finally{d(!1)}},[F,u,$,H,R,r,i]),D=o.useCallback(()=>{j(""),v([]),S("copy"),n?.()},[n]);o.useEffect(()=>{l&&l({cancelButton:!1,saveButton:F.length===0||a})},[F.length,a,l]),o.useEffect(()=>{c&&c({cancelButton:D,saveButton:q})},[c,D,q]);const V=o.useMemo(()=>b.map(s=>({value:s.id,label:s.name})),[b]),C=o.useMemo(()=>A.filter(s=>u==="copy"?!0:!s.quantumOwned).map(s=>({value:s.id,label:s.name,isQuantumOwned:s.quantumOwned})),[A,u]),G=g.fetching,W=E.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(X,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:u,onChange:s=>{S(s),v([])},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(X,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(K.st,{placeholder:"Choose a group...",options:V,value:V.find(s=>s.value===L)||null,onChange:_,isLoading:G,isDisabled:G,isClearable:!0}),g.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",g.error.message]})]})]}),L&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsxs(X,{children:["Select Activities to"," ",u==="copy"?"Copy":"Convert"]}),W?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:C,value:C.filter(s=>f.includes(s.value)),onChange:O,isDisabled:C.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"})]})}),C.length===0&&e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:"No activities found"})]}),E.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load activities: ",E.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(M=>M.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"]})})]})]}),!x&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:D,isDisabled:a,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:u==="copy"?"blue":"green",onClick:q,isDisabled:F.length===0||a,isLoading:a,loadingText:`${u==="copy"?"Copying":"Converting"}...`,children:[u==="copy"?"Copy":"Convert"," ",F.length===1?"Activity":`${F.length} Activities`]})]})]})})},Me=({onSave:r,onCancel:n,onError:i,hideButtons:x=!1,setButtonDisabled:l,setButtonOnClick:c,quantumOwned:m})=>{const R=t.useToast(),[u,S]=o.useState(""),[L,j]=o.useState([]),[f,v]=o.useState(!1),[a,d]=o.useState("copy"),[g]=z.useQuery({query:T.GET_GROUPS}),[E]=z.useQuery({query:T.GET_MODULES_BY_GROUP,variables:{groupId:u},pause:!u}),[,y]=z.useMutation(T.CREATE_MODULE),[,w]=z.useMutation(T.UPDATE_MODULE),[,b]=z.useMutation(T.CREATE_ACTION),[,A]=z.useMutation(T.CONVERT_ACTION_TO_QUANTUM_OWNED),F=o.useMemo(()=>g.data?.groups?g.data.groups.map(s=>h.getFragmentData(T.GROUP_FRAGMENT,s)):[],[g.data]),_=o.useMemo(()=>E.data?.modules?h.getFragmentData(T.ACTION_MODULE_FRAGMENT,E.data?.modules).map(p=>{const M=h.getFragmentData(T.MODULE_ACTION_FRAGMENT,p.moduleActions);return{...p,moduleActions:M.map(I=>({...I,action:h.getFragmentData(T.ACTION_FRAGMENT,I.action)})),categories:h.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,p.categories)}}):[],[E.data]),O=o.useMemo(()=>_.filter(s=>L.includes(s.id)),[_,L]),$=o.useCallback(s=>{const p=s?.value||"";S(p),j([])},[]),H=o.useCallback(s=>{const p=s.map(M=>M.value);j(p)},[]),q=o.useCallback(async()=>{if(v(!0),!O.length){v(!1);const s=new Error(`No modules selected for ${a==="convert"?"converting":"copying"}`);i?.(s);return}try{const s=[];let p=0;for(const M of O)try{let I=M.moduleActions.map(k=>k.actionId);if(m){const k=M.moduleActions.map(U=>U.action),P=async U=>{if(a==="copy"){if(U.quantumOwned)return U;const ee=h.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,U.categories),ne={...U,quantumOwned:!0,thresholds:U.thresholds.map(B=>({...B,id:void 0})),categories:ee?.map(B=>B.id),id:void 0},N=await b({fields:ne});return N.error||!N.data?.createAction?null:h.getFragmentData(T.ACTION_FRAGMENT,N.data.createAction)}if(U.quantumOwned)return U;const se=await A({id:U.id});return se.error||!se.data?.convertActionToQuantumOwned?null:h.getFragmentData(T.ACTION_FRAGMENT,se.data.convertActionToQuantumOwned)};I=(await Promise.all(k.map(P))).filter(U=>!!U).map(U=>U.id)}if(a==="convert"){const k={name:M.name,description:M.description||void 0,actions:I,categories:M.categories.map(Q=>Q.id),quantumOwned:!0},P=await w({id:M.id,input:k});if(P.error)throw new Error(P.error.message);if(P.data?.updateModule){const Q=h.getFragmentData(T.ACTION_MODULE_FRAGMENT,P.data.updateModule);s.push(Q)}}else{const k={name:`${M.name} (Copy)`,description:M.description||void 0,actions:I,categories:M.categories.map(Q=>Q.id),quantumOwned:m},P=await y({input:k});if(P.error)throw new Error(P.error.message);if(P.data?.createModule){const Q=h.getFragmentData(T.ACTION_MODULE_FRAGMENT,P.data.createModule);s.push(Q)}}}catch(I){console.error(`Failed to ${a==="convert"?"convert":"copy"} module "${M.name}":`,I),p++}if(s.length>0){const M=s.length,I=O.length;R({title:p>0?`Partial ${a==="convert"?"convert":"copy"} completed`:`Modules ${a==="convert"?"converted":"copied"} successfully`,description:p>0?`${M} of ${I} modules ${a==="convert"?"converted":"copied"} successfully`:`${M} module${M>1?"s":""} ${a==="convert"?"converted":"copied"} successfully`,status:p>0?"warning":"success",duration:3e3,isClosable:!0}),s.length>0&&r?.(),S(""),j([])}else throw new Error(`Failed to ${a==="convert"?"convert":"copy"} any modules`)}catch(s){const p=s instanceof Error?s.message:`Failed to ${a==="convert"?"convert":"copy"} modules`;R({title:a==="convert"?"Convert failed":"Copy failed",description:p,status:"error",duration:5e3,isClosable:!0}),i?.(s instanceof Error?s:new Error(p))}finally{v(!1)}},[O,y,w,R,r,i,m,b,A,a]),D=o.useCallback(()=>{S(""),j([]),d("copy"),n?.()},[n]);o.useEffect(()=>{l&&l({cancelButton:!1,saveButton:O.length===0||f})},[O.length,f,l]),o.useEffect(()=>{c&&c({cancelButton:D,saveButton:q})},[c,D,q]);const V=o.useMemo(()=>F.map(s=>({value:s.id,label:s.name})),[F]),C=o.useMemo(()=>_.filter(s=>a==="copy"?!0:!s.quantumOwned).map(s=>({value:s.id,label:s.name,isQuantumOwned:s.quantumOwned})),[_,a]),G=g.fetching,W=E.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(X,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:a,onChange:s=>{d(s),j([])},children:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:6,children:[e.jsxRuntimeExports.jsx(t.Radio,{value:"copy",colorScheme:"blue",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.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(X,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(K.st,{placeholder:"Choose a group...",options:V,value:V.find(s=>s.value===u)||null,onChange:$,isLoading:G,isDisabled:G,isClearable:!0}),g.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",g.error.message]})]})]}),u&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(X,{children:a==="convert"?"Select Module to Convert":"Select Module to Copy"}),W?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:a==="convert"?"Choose modules to convert...":"Choose modules to copy...",options:C,value:C.filter(s=>L.includes(s.value)),onChange:H,isDisabled:C.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"})]})}),C.length===0&&e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:"No modules found in this group"})]}),E.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load modules: ",E.error.message]})]})]}),O.length>0&&e.jsxRuntimeExports.jsxs(t.Box,{p:4,bg:"gray.50",borderRadius:"md",children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"semibold",mb:3,children:O.length===1?`Module to ${a==="copy"?"Copy":"Convert"}`:`${O.length} Modules to ${a==="copy"?"Copy":"Convert"}`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[O.map((s,p)=>e.jsxRuntimeExports.jsxs(t.Box,{w:"100%",p:3,bg:"white",borderRadius:"md",border:"1px solid",borderColor:"gray.200",children:[e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",align:"start",mb:2,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"medium",fontSize:"sm",children:[p+1,". ",s.name]}),s.quantumOwned&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,fontSize:"sm",color:"gray.600",children:[s.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",s.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Actions:"})," ",s.moduleActions.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Categories:"})," ",s.categories.map(M=>M.name).join(", ")||"None"]})]})]},s.id)),O.length>1&&e.jsxRuntimeExports.jsx(t.Box,{w:"100%",p:2,bg:"blue.50",borderRadius:"md",border:"1px solid",borderColor:"blue.200",children:e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",fontWeight:"medium",color:"blue.800",children:["Total: ",O.length," modules will be"," ",a==="copy"?"copied":"converted"]})}),m&&O.filter(s=>s.moduleActions.some(p=>!p.action.quantumOwned)).length>0&&e.jsxRuntimeExports.jsx(t.Box,{p:2,bg:"yellow.50",borderRadius:"md",border:"1px solid",borderColor:"yellow.200",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",fontWeight:"medium",color:"yellow.800",children: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"})})]})]}),!x&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:D,isDisabled:f,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:a==="copy"?"blue":"green",onClick:q,isDisabled:O.length===0||f,isLoading:f,loadingText:`${a==="copy"?"Copying":"Converting"}...`,children:[a==="copy"?"Copy":"Convert"," ",O.length===1?"Module":`${O.length} Modules`]})]})]})})},xe=({name:r,setName:n,actions:i,selectedActionIds:x,setSelectedActionIds:l,availableCategories:c,selectedCategoryIds:m,setSelectedCategoryIds:R,description:u,setDescription:S,...L})=>{const j=t.useDisclosure(),f=o.useMemo(()=>i.map(y=>({...y,selected:x.includes(y.id)})),[i,x]),v=o.useMemo(()=>i.reduce((y,w)=>(y[w.id]=w,y),{}),[i]),a=o.useMemo(()=>x.map(y=>v[y]),[f,x]),d=o.useCallback((y,w)=>{l(w?[...x,y.id]:x.filter(b=>b!==y.id))},[x,l]),g=o.useCallback(y=>{n(y.target.value)},[n]),E=o.useCallback(y=>{S?.(y.target.value)},[S]);return e.jsxRuntimeExports.jsxs(t.Box,{...L,children:[e.jsxRuntimeExports.jsxs(t.HStack,{gap:"2rem",children:[e.jsxRuntimeExports.jsx(Ae,{name:r??"",onInputChange:g}),e.jsxRuntimeExports.jsx(we,{availableCategories:c,value:m,onChange:R})]}),e.jsxRuntimeExports.jsx(Fe,{description:u??"",onInputChange:E}),e.jsxRuntimeExports.jsx(Oe,{value:a,onChange:l,onAdjustActivities:()=>j.onOpen()}),e.jsxRuntimeExports.jsxs(t.Modal,{isOpen:j.isOpen,onClose:j.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(ue,{actions:f,onSelected:d,disableCreate:!0,disableDelete:!0,tableProps:{height:"28rem",overflowY:"auto"}})}),e.jsxRuntimeExports.jsx(t.ModalFooter,{children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:j.onClose,isDisabled:x.length===0,children:"Done"})})]})]})]})},Ae=o.memo(({name:r,onInputChange:n})=>e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(X,{children:"Module Name"}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. ACL RTP Test Battery",value:r,onChange:n,isRequired:!0})]})),we=o.memo(({availableCategories:r,value:n,onChange:i})=>{const x=o.useMemo(()=>[...r,{id:"other",name:"Other"}],[r]),l=o.useMemo(()=>x.map(c=>({value:c.id,label:c.name})),[x]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(X,{children:"Module Category"}),e.jsxRuntimeExports.jsx(K.st,{isDisabled:r.length===0,isClearable:!0,options:l,value:x.filter(c=>n.includes(c.id)).map(c=>({value:c.id,label:c.name})),onChange:c=>i(c?[c.value]:[]),placeholder:"Select category"})]})}),Fe=o.memo(({description:r,onInputChange:n})=>e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(X,{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})]})),Oe=o.memo(({value:r,onChange:n,onAdjustActivities:i})=>{const x=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(X,{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"})]}),x.length===0?e.jsxRuntimeExports.jsx(t.VStack,{children:e.jsxRuntimeExports.jsxs(t.Text,{color:"gray.500",fontSize:"lg",mb:"4rem",mt:"4rem",children:["No activities selected for this module.",e.jsxRuntimeExports.jsx(t.Button,{ml:"0.5em",size:"sm",variant:"link",colorScheme:"blue",onClick:i,children:"Add activities."})]})}):e.jsxRuntimeExports.jsx(Ee,{value:x,onChange:l=>{const c=l(x);n(c.map(m=>m.id))}})]})}),de=({value:r,onChange:n,forceKind:i,disableRemove:x,disableKind:l,lockRanges:c,...m})=>{const R=o.useMemo(()=>[...r].sort((j,f)=>{const v=te.availablePlanes.indexOf(j.plane),a=te.availablePlanes.indexOf(f.plane);return v-a}),[r]),u=o.useCallback(j=>"segment"in j.id?J.getSegmentNameWithPlane(j.id.segment,j.plane,!0)??"Unknown":J.getJointNameWithPlane(j.id.joint,j.plane,!0)??"Unknown",[]),S=o.useCallback((j,f)=>{const v=R.findIndex(d=>d.id===f.id&&d.plane===f.plane);let a=[...R];i&&(f={...f,kind:i}),a[v]=f,c&&(a=a.map(d=>({...d,min:f.min,max:f.max}))),n(a)},[n,R,i,c]),L=o.useCallback(j=>{const f=R.filter(v=>v.id!==j.id||v.plane!==j.plane);n(f)},[n,R]);return e.jsxRuntimeExports.jsx(t.VStack,{alignItems:"flex-start",overflowY:"auto",...m,children:R.map((j,f)=>e.jsxRuntimeExports.jsx(Ne,{label:u(j),parameter:j,onChange:v=>S(f,v),onRemove:x?void 0:()=>L(j),forceKind:i,disableKind:l},`${JSON.stringify(j.id)}-${j.plane}`))})},Ne=({label:r,parameter:n,onChange:i,onRemove:x,forceKind:l,disableKind:c})=>{const m=o.useCallback(S=>"joint"in n.id?J.getJointAngleDirectionName(n.id.joint,n.plane,S<0?-1:1):J.getSegmentAngleDirectionName(n.id.segment,n.plane,S<0?-1:1),[n]),{min:R,max:u}="joint"in n.id?J.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}),x&&e.jsxRuntimeExports.jsx(t.IconButton,{size:"xs",variant:"ghost","aria-label":"delete",icon:e.jsxRuntimeExports.jsx(t.Icon,{as:ce.FaTrash}),onClick:x}),!l&&e.jsxRuntimeExports.jsx(fe,{selectedItem:n?.kind??h.ThresholdKind.Limit,onChange:({value:S})=>i({...n,kind:S}),isDisabled:c,buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:h.ThresholdKind.Limit,label:"limit"},{value:h.ThresholdKind.Target,label:"target"}]})]}),e.jsxRuntimeExports.jsx(ve,{w:"100%",size:"xs",min:R,max:u,zeroMarker:!0,value:[n.min,n.max],onChange:S=>i({...n,min:S[0],max:S[1]}),formatValue:S=>`${Math.abs(S)}°`,valueLabel:S=>m(S)??"",positiveNegativeLabels:m(0)?[m(-1)??"",m(1)??""]:void 0})]})},ie=(r,n)=>"segment"in r&&"segment"in n&&r.segment===n.segment||"joint"in r&&"joint"in n&&r.joint===n.joint,me=({options:r,value:n,onChange:i,forceKind:x,singleValue:l,singleValueSideless:c,editOnly:m,disableKind:R,maxParameters:u,...S})=>{const L=c?2:u,j=o.useMemo(()=>r.map(d=>({label:"segment"in d.id?J.getSegmentNameWithPlane(d.id.segment,d.plane,!0)??"Unknown":J.getJointNameWithPlane(d.id.joint,d.plane,!0)??"Unknown",value:d.id,plane:d.plane})),[r]),f=o.useMemo(()=>{if(!c||n.length===0)return j;const d=n[0];return j.filter(g=>te.getAnalysisPartIdNoSide(g.value)===te.getAnalysisPartIdNoSide(d.id)&&g.plane===d.plane)},[j,n,c]),v=o.useMemo(()=>j.filter(d=>n.some(g=>ie(g.id,d.value)&&g.plane===d.plane)),[j,n]),a=o.useCallback(d=>{const g=d.map(E=>{const y=n.find(_=>ie(_.id,E.value)&&_.plane===E.plane),w=r.find(_=>ie(_.id,E.value)&&_.plane===E.plane),b=c?n.find(_=>te.getAnalysisPartIdNoSide(_.id)===te.getAnalysisPartIdNoSide(E.value)&&_.plane===E.plane):void 0,A=b&&!y?b.min:w&&w.min?w.min:0,F=b&&!y?b.max:w&&w.max?w.max:0;return y??{id:E.value,plane:E.plane,min:A,max:F,kind:x??h.ThresholdKind.Limit}});i(g)},[i,n,r,x,c]);return o.useEffect(()=>{const d=n.filter(g=>r.some(E=>ie(E.id,g.id)&&E.plane===g.plane));d.length!==n.length&&i(d)},[r,i]),e.jsxRuntimeExports.jsxs(t.Box,{...S,children:[e.jsxRuntimeExports.jsx(K.st,{isMulti:!l,placeholder:n.length?`${n.length} selected`:"Search...",value:v,isDisabled:m||v.length>=(L??1/0),onChange:d=>Array.isArray(d)?a([...d]):a(d!==null?[d]:[]),options:f,controlShouldRenderValue:!1}),e.jsxRuntimeExports.jsx(de,{marginTop:2,maxH:"28rem",value:n,onChange:i,forceKind:x,disableKind:R,lockRanges:c})]})},pe=r=>{switch(r){case h.SensorLocation.Thorax:return"Thorax";case h.SensorLocation.CenterBack:return"Center Back";case h.SensorLocation.Pelvis:return"Pelvis";case h.SensorLocation.LeftThigh:return"Left Thigh";case h.SensorLocation.RightThigh:return"Right Thigh";case h.SensorLocation.LeftShank:return"Left Shank";case h.SensorLocation.RightShank:return"Right Shank";case h.SensorLocation.LeftFoot:return"Left Foot";case h.SensorLocation.RightFoot:return"Right Foot";case h.SensorLocation.LeftUpperArm:return"Left Upper Arm";case h.SensorLocation.RightUpperArm:return"Right Upper Arm";case h.SensorLocation.LeftForearm:return"Left Forearm";case h.SensorLocation.RightForearm:return"Right Forearm";case h.SensorLocation.Head:return"Head"}return console.warn(`Unknown sensor location: ${r}`),"Unknown"},Le=6,ke=[h.SensorLocation.LeftFoot,h.SensorLocation.LeftShank,h.SensorLocation.LeftThigh,h.SensorLocation.Pelvis,h.SensorLocation.RightFoot,h.SensorLocation.RightShank,h.SensorLocation.RightThigh,h.SensorLocation.Thorax,h.SensorLocation.CenterBack,h.SensorLocation.Head],Ie=ke.map(r=>({label:pe(r),value:r})),le=(r,n)=>r.map(i=>({label:n?n(i):i,value:i})),De=({id:r,onError:n,onCancel:i,onSave:x,hideButtons:l,setButtonOnClick:c,setButtonDisabled:m,quantumOwned:R})=>{const[{fetching:u},S]=z.useMutation(T.CREATE_ACTION),[{fetching:L},j]=z.useMutation(T.UPDATE_ACTION),[{data:f}]=z.useQuery({query:T.GET_ACTION_BY_ID,variables:{id:r??""},pause:!r}),v=h.getFragmentData(T.ACTION_FRAGMENT,f?.getActionById),a=u||L,d=!!v&&!!r,[g,E]=o.useState(""),[y,w]=o.useState(""),[b,A]=o.useState(""),[F,_]=o.useState(""),[O,$]=o.useState(),[H,q]=o.useState([]),[D,V]=o.useState([]),[C,G]=o.useState([]),W=o.useMemo(()=>D.map(N=>N.value),[D]),s=je.usePartOptionsForSensorLocations(W),[{data:p}]=z.useQuery({query:T.GET_ALL_MODULE_CATEGORIES}),M=o.useMemo(()=>h.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,p?.moduleCategories)?.map(B=>({label:B.name,value:B.id})),[p?.moduleCategories]),I=o.useMemo(()=>le(Object.values(h.SessionType),J.mapSessionTypeEnumToLabel),[]),[k,P]=o.useState([]),Q=g.length>0,[U,se]=o.useState({});o.useEffect(()=>{if(v){const N=h.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,v.categories),B={name:v.name,activityType:v.activityType??void 0,description:v.description||"",cameraPlacement:v.cameraPlacement||"",videoLink:v.videoLink||"",sessionType:v.sessionType.map(Y=>({label:J.mapSessionTypeEnumToLabel(Y),value:Y})),categories:N?.map(Y=>Y.id)||[],sensorLocations:v.sensorLocations.map(Y=>({label:pe(Y),value:Y})),thresholds:oe.thresholdsToParameters(v.thresholds)};E(B.name),$(B.activityType??void 0),w(B.description),A(B.cameraPlacement),_(B.videoLink),q(B.sessionType),G(N?.map(Y=>Y.id)||[]),V(B.sensorLocations),P(B.thresholds),se(B)}},[v]);const ee=o.useMemo(()=>JSON.stringify(U)!==JSON.stringify({name:g,description:y,cameraPlacement:b,videoLink:F,activityType:O,sessionType:H.map(N=>N.value),categories:C,sensorLocations:W,thresholds:oe.parametersToThresholds(k)}),[U,g,W,y,b,F,O,H,C,k]),ne=o.useCallback(()=>{const N={name:g,description:y,cameraPlacement:b,videoLink:F,activityType:O,activityKind:J.getActivityKindFromActivityType(O),sessionType:H.map(Y=>Y.value),categories:C,sensorLocations:W,thresholds:oe.parametersToThresholds(k),laterality:h.ActionLaterality.Either,quantumOwned:R};let B;d&&r?B=j({id:r,fields:N}):B=S({fields:N}),B.then(({error:Y})=>{Y?n(Y):x()})},[R,S,j,r,g,W,y,b,F,O,H,C,d,k,x,n]);return o.useEffect(()=>{m&&m({cancelButton:a,saveButton:a||!Q||!ee})},[a,m,Q,ee]),o.useEffect(()=>{c&&c({cancelButton:i,saveButton:ne})},[c,i,ne]),console.log(Q,ee,a,U),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(Z,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:g,onChange:N=>E(N.target.value),type:"text",placeholder:"i.e. Lunge & Return"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:"Activity Type"}),e.jsxRuntimeExports.jsx(K.st,{isClearable:!0,isMulti:!1,value:O?{label:J.mapActivityTypeEnumToLabel(O),value:O}:null,onChange:N=>$(N?.value),options:le(Object.values(h.ActivityType),J.mapActivityTypeEnumToLabel),placeholder:"(optional) Select activity type"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:"Camera Placement"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:b,onChange:N=>A(N.target.value),rows:2,placeholder:"(optional) Describe camera setup, placement, angles"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:"Video Link"}),e.jsxRuntimeExports.jsx(t.Input,{value:F,onChange:N=>_(N.target.value),type:"url",placeholder:"(optional) https://..."})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:"Description"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:y,onChange:N=>w(N.target.value),rows:2,placeholder:"(optional) Describe how to perform the test or exercise"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:"Link to Category"}),e.jsxRuntimeExports.jsx(K.st,{isMulti:!0,value:M?.filter(N=>C.includes(N.value)),onChange:N=>G((N??[]).map(B=>B.value)),options:M,placeholder:"Select one or more categories"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:"Session Types"}),e.jsxRuntimeExports.jsx(K.st,{isMulti:!0,value:H,onChange:N=>q(N??[]),options:I,placeholder:"Select one or more session types"})]})]}),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(Z,{children:"Sensor Locations"}),e.jsxRuntimeExports.jsx(K.st,{isMulti:!0,value:D,onChange:N=>V([...N]),options:Ie,isOptionDisabled:()=>D.length>=Le})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(Z,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(me,{options:s,value:k,onChange:P})]})]}),e.jsxRuntimeExports.jsx("div",{className:oe.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:a,onClick:i,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:a||!Q||!ee,isLoading:a,onClick:ne,children:"Save changes"})]})})]})},Z=({children:r})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:r}),_e=({id:r,onCancel:n,onSave:i,onError:x,hideButtons:l,quantumOwned:c,setButtonOnClick:m,setButtonDisabled:R})=>{const[{data:u}]=z.useQuery({query:c?T.GET_QUANTUM_OWNED_ACTIONS:T.GET_ACTIONS}),[{data:S}]=z.useQuery({query:T.GET_MODULE_BY_ID,variables:{id:r},pause:!r}),[{data:L}]=z.useQuery({query:T.GET_ALL_MODULE_CATEGORIES}),j=h.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,L?.moduleCategories),[{fetching:f},v]=z.useMutation(T.UPDATE_MODULE),[{fetching:a},d]=z.useMutation(T.CREATE_MODULE),g=h.getFragmentData(T.ACTION_FRAGMENT,c?u?.quantumOwnedActions:u?.actions)??[],E=h.getFragmentData(T.ACTION_MODULE_FRAGMENT,S?.module),y=h.getFragmentData(T.MODULE_ACTION_FRAGMENT,E?.moduleActions)??[],[w,b]=o.useState([...y.map(D=>D.actionId)??[]]),[A,F]=o.useState(E?.name??""),[_,O]=o.useState([]),[$,H]=o.useState(E?.description??"");o.useEffect(()=>{E&&(b(y.map(D=>D.actionId)),F(E.name),H(E.description??""),O(E.categories.map(D=>h.getFragmentData(T.MODULE_CATEGORY_FRAGMENT,D).id)??[]))},[E,y]);const q=o.useCallback(()=>{let D;const V={actions:w,name:A,categories:_.filter(C=>C!=="other"),description:$,quantumOwned:c};E?D=v({id:E.id,input:V}):D=d({input:V}),D.then(({error:C})=>{C?x(C):i()})},[d,v,w,A,$,_,E,i,x]);return o.useEffect(()=>{R&&R({cancelButton:f||a,saveButton:f||a||!A||$.trim().split(/\s+/).filter(Boolean).length>40})},[R,f,a,w,A,$]),o.useEffect(()=>{m&&m({cancelButton:n,saveButton:q})},[m,n,q]),e.jsxRuntimeExports.jsxs(t.Box,{width:"100%",children:[e.jsxRuntimeExports.jsx(xe,{name:A,setName:F,actions:g,selectedActionIds:w,setSelectedActionIds:b,availableCategories:j??[],selectedCategoryIds:_,setSelectedCategoryIds:O,description:$,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:f||a,onClick:n,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:f||a||!A||$.trim().split(/\s+/).filter(Boolean).length>40,isLoading:f||a,onClick:q,children:"Save"})]})})]})};exports.ActivityList=ue;exports.CopyActivityForm=Se;exports.CopyModuleForm=Me;exports.ModuleForm=xe;exports.ParameterEditList=de;exports.ParameterEditSelect=me;exports.UpsertActivityForm=De;exports.UpsertModuleForm=_e;
@@ -5,8 +5,8 @@ import { u as wt } from "./ufuzzy-vendor-Dl0ZI6Av.js";
5
5
  import { s as ne } from "./react-select-vendor-BlY9Il4Q.js";
6
6
  import { F as St, a as Tt } from "./react-icons-vendor-TETORdU9.js";
7
7
  import { u as le, a as oe } from "./graphql-vendor-B0NjgbDB.js";
8
- import { g as _, T as Ce, S as P, a as At, A as Mt, b as Ot } from "./generated-BTI7tPmv.js";
9
- import { M as de, A as ae, G as Ke, a as Nt, C as Ie, b as Ve, c as Ze, d as we, e as et, f as It, U as tt, g as st, h as Lt, i as Ft, j as nt, k as Rt, l as kt, m as Dt } from "./graphql-BZ2WVM1o.js";
8
+ import { g as _, T as Ce, S as P, a as At, A as Mt, b as Ot } from "./generated-CB1E0us8.js";
9
+ import { M as de, A as ae, G as Ke, a as Nt, C as Ie, b as Ve, c as Ze, d as we, e as et, f as It, U as tt, g as st, h as Lt, i as Ft, j as nt, k as Rt, l as kt, m as Dt } from "./graphql-BqoQHgu9.js";
10
10
  import { D as Et, H as zt, u as Pt, a as $t } from "./react-dnd-vendor-D4nn9Mqx.js";
11
11
  import { getSegmentNameWithPlane as ot, getJointNameWithPlane as rt, getJointAngleDirectionName as _t, getSegmentAngleDirectionName as Gt, getNormativeJointRange as Ut, mapSessionTypeEnumToLabel as ze, getActivityKindFromActivityType as Wt, mapActivityTypeEnumToLabel as Pe } from "./services.js";
12
12
  import { availablePlanes as $e, getAnalysisPartIdNoSide as ve } from "./types.js";