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