quantum-component-library 1.4.50-dev.0 → 1.4.50-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/components.cjs
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"),s=require("react"),ye=require("./utils-cn-FIKrq5Mb.cjs");require("./moment-vendor-1cRqq0AH.cjs");require("./lodash-vendor-C3e6C_PJ.cjs");const Z=require("urql"),le=require("./hooks.cjs"),Ie=require("./ufuzzy-vendor-7qHa_k39.cjs"),Te=require("./react-icons-vendor-BF_sZq07.cjs"),ce=require("./react-select-vendor-CZ69mhgt.cjs"),F=require("./generated.cjs"),E=require("./graphql-BhVmuiCG.cjs"),Se=require("./react-dnd-vendor-BGRUqrp9.cjs"),I=require("./generated-graphql.cjs"),re=require("./services-human-CGLf7B6Q.cjs"),de=require("./types.cjs"),ke=({setSearch:o,actions:n,updateUseCases:l,hideUseCaseFilter:x=!1})=>{const h=s.useMemo(()=>n?.flatMap(d=>d.useCases).filter((d,j,f)=>f.findIndex(i=>i.id===d.id)===j).map(d=>({label:d.name,value:d.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:Te.FaSearch,color:"gray.300"})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"Search by name...",width:"100%",maxW:x?void 0:"30rem",onChange:d=>o(d.target.value)})]}),!x&&e.jsxRuntimeExports.jsx(t.InputGroup,{size:"md",children:e.jsxRuntimeExports.jsx(ce.st,{size:"md",chakraStyles:{container:d=>({...d,width:"100%"})},menuPortalTarget:document.body,placeholder:"Filter use case",isMulti:!0,options:h,onChange:d=>l(d.map(j=>j.value))})})]})},ae=({children:o})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:o}),De=({value:o,onChange:n})=>{const l=s.useState(()=>Math.random().toString(36).substring(2,15))[0],x=s.useCallback((h,d)=>{n(j=>{const f=[...j],[i]=f.splice(h,1);return f.splice(d,0,i),f})},[n]);return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsx(Se.DndProvider,{backend:Se.HTML5Backend,children:e.jsxRuntimeExports.jsx(t.TableContainer,{children:e.jsxRuntimeExports.jsxs(t.Table,{variant:"simple",size:"md",children:[e.jsxRuntimeExports.jsx(t.Thead,{children:e.jsxRuntimeExports.jsxs(t.Tr,{children:[e.jsxRuntimeExports.jsx(t.Th,{children:"Order"}),e.jsxRuntimeExports.jsx(t.Th,{children:"Name"})]})}),e.jsxRuntimeExports.jsx(t.Tbody,{children:o.map((h,d)=>e.jsxRuntimeExports.jsx(_e,{listKey:l,index:d,id:h.id,name:h.name,move:x},h.id))})]})})})})},_e=({listKey:o,index:n,id:l,name:x,move:h})=>{const d=s.useRef(null),[{handlerId:j},f]=Se.useDrop({accept:o,collect:b=>({handlerId:b.getHandlerId()?.toString()??""}),hover:(b,A)=>{if(!d.current)return;const v=b.index,y=n;if(v===y)return;const p=d.current?.getBoundingClientRect(),a=(p.bottom-p.top)/2,C=A.getClientOffset().y-p.top;v<y&&C<a||v>y&&C>a||(h(v,y),b.index=y)}}),[{isDragging:i},u]=Se.useDrag({type:o,item:()=>({id:l,index:n}),collect:b=>({isDragging:b.isDragging()})}),R=i?.6:1,N=i?"grabbing":"grab";return u(f(d)),e.jsxRuntimeExports.jsxs(t.Tr,{ref:d,style:{opacity:R,cursor:N},"data-handler-id":j,children:[e.jsxRuntimeExports.jsx(t.Td,{children:n+1}),e.jsxRuntimeExports.jsx(t.Td,{children:x})]})},Ge=({items:o,onChange:n,selectedItem:l,isDisabled:x,selectedProps:h,buttonProps:d})=>{const j=i=>i===l||i.value===l,f=i=>j(i)?{...d,...h}:d;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:x,children:o.map((i,u)=>e.jsxRuntimeExports.jsx(t.Tooltip,{label:i.tooltip,openDelay:50,closeDelay:200,placement:"top",visibility:i.tooltip?"visible":"hidden",hasArrow:!0,children:e.jsxRuntimeExports.jsx(t.Button,{onClick:()=>j(i)?null:n(i,u),isDisabled:i.disabled,...f(i),children:i.label})},u))})},be=(o,n)=>n<0?-1*Math.abs(o):Math.abs(o),Pe=({isReversed:o,min:n,max:l,value:x,onChange:h,inputProps:d,size:j,zeroMarker:f,formatValue:i,valueLabel:u,positiveNegativeLabels:R,isDisabled:N,...b})=>{const[A,v]=s.useState([void 0,void 0]),y=A[0],p=A[1],a=f&&n<-5&&l>5,m=Number(x?.[0]??p??n)>0?1:-1,C=Number(x?.[1]??p??l)<0?-1:1,w=R?.[0]===R?.[1],k=x?.[0],Q=x?.[1];s.useEffect(()=>{k!==void 0&&Q!==void 0&&v([k.toFixed(0),Q.toFixed(0)])},[k,Q,v]);const W=s.useCallback(([M,B])=>{M<B&&v([M.toFixed(0),B.toFixed(0)])},[v]),O=s.useCallback(([M,B])=>{M<B&&h([M,B])},[h]),H=s.useCallback(()=>{v(([M,B])=>{const V=isNaN(Number(M))?n:Number(M),q=isNaN(Number(B))?l:Number(B),se=be(Number(V),m),c=be(Number(q),C),r=m<0?Math.max(se,n):Math.min(se,l),T=C<0?Math.max(c,n):Math.min(c,l);return r>T?(h([T,r]),[T.toFixed(0),r.toFixed(0)]):(h([r,T]),[r.toFixed(0),T.toFixed(0)])})},[h,v,m,C,n,l]),te=s.useCallback(M=>{const B=M===""||isNaN(Number(M))?M:be(Number(M),m);v(([V,q])=>[B.toString(),q])},[v,m]),D=s.useCallback(M=>{const B=M===""||isNaN(Number(M))?M:be(Number(M),C);v(([V,q])=>[V,B.toString()])},[v,C]),S=s.useMemo(()=>j==="xs"?"0.75rem":void 0,[j]),P=s.useCallback((M,B)=>{const V=Number(B.target.value);if(!y||!p||![-1,1].includes(V))return;const q=r=>V<0?-1*Math.abs(r):Math.abs(r),se=M?q(Number(y)):Number(y),c=M?Number(p):q(Number(p));se>c?h([c,se]):h([se,c])},[y,p,h]);return e.jsxRuntimeExports.jsxs(t.Flex,{direction:"column",...b,children:[e.jsxRuntimeExports.jsx(t.Box,{pt:"1em",mb:"-0.5em",children:e.jsxRuntimeExports.jsxs(t.RangeSlider,{"aria-label":["min","max"],isReversed:o,value:[Number(y??n),Number(p??l)],max:l,min:n,minStepsBetweenThumbs:3,step:1,onChange:W,onChangeEnd:O,isDisabled:N,children:[e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:n,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:j??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:i?i?.(n):n})}),e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:l,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:j??"sm",fontWeight:"semibold",style:{transform:"translateX(-100%)"},whiteSpace:"nowrap",children:i?i(l):l})}),a&&e.jsxRuntimeExports.jsxs(t.RangeSliderMark,{value:0,top:"-1em",pos:"relative",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:j,fontWeight:"semibold",children:i?.(0)??"0"}),e.jsxRuntimeExports.jsx(t.Box,{position:"absolute",width:"2px",height:"1em",top:"90%",left:"20%",backgroundColor:"var(--chakra-colors-gray-300)"})]}),e.jsxRuntimeExports.jsx(t.RangeSliderTrack,{children:e.jsxRuntimeExports.jsx(t.RangeSliderFilledTrack,{})}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:0,w:S,h:S}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:1,w:S,h:S})]})}),u&&e.jsxRuntimeExports.jsxs(t.Flex,{direction:o?"row-reverse":"row",justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:j??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:u(n)}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:j??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:u(l)})]}),e.jsxRuntimeExports.jsxs(t.Flex,{direction:o?"row-reverse":"row",justifyContent:"center",alignItems:"center",gap:"0.125em",children:[R&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:j,fontWeight:"bold",value:m,onChange:M=>P(!0,M),isDisabled:w||N,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:R[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:R[1]})]}),e.jsxRuntimeExports.jsx(t.NumberInput,{precision:0,size:j??"sm",min:0,max:m<0?Math.abs(n):Q??l,value:y===""?"":Math.abs(Number(y??n)),onChange:te,onBlur:H,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:N,...d,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),e.jsxRuntimeExports.jsx(t.NumberInput,{size:j??"sm",min:0,max:C<0?Math.abs(k??n):l,precision:0,value:p===""?"":Math.abs(Number(p??l)),onChange:D,onBlur:H,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:N,...d,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),R&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:j,fontWeight:"bold",value:C,onChange:M=>P(!1,M),isDisabled:w||N,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:R[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:R[1]})]})]})]})},$e=({tags:o,containerProps:n,...l})=>e.jsxRuntimeExports.jsx(t.HStack,{...n,children:o.map((x,h)=>e.jsxRuntimeExports.jsx(t.Tag,{...l,children:x},h))}),Be=new Ie.uFuzzy({}),ze=({action:o,quantumIconSrc:n})=>{const{getLabel:l}=le.useUiLabelContext(),x=s.useMemo(()=>({actionLowerCase:l("action").toLocaleLowerCase()}),[l]);return o.quantumOwned?e.jsxRuntimeExports.jsx(t.Tooltip,{label:`This ${x.actionLowerCase} is owned by Quantum`,"aria-label":"Quantum owned",children:e.jsxRuntimeExports.jsx(t.Box,{boxSize:"1.5em",borderRadius:"full",bg:"black",display:"flex",alignItems:"center",justifyContent:"center",children:e.jsxRuntimeExports.jsx(t.Image,{src:n,boxSize:"1em",alt:`Quantum-owned ${x.actionLowerCase}`})})}):null},Ue=(o,n)=>{if(!n||!n.trim().length)return o;const l=o.map(h=>h.name??"");return Be.filter(l,n)?.map(h=>o[h])??[]},qe=o=>!o||o.length===0?"None":o.map(n=>n.replace(/([A-Z])/g," $1").trim()).join(", "),Qe=(o,n)=>!n||n.length==0?o:o.filter(l=>l.useCases?.some(x=>n.includes(x.id))??!1),Le=({actions:o,totalActions:n,onCreate:l,onDelete:x,onEdit:h,onView:d,onSelected:j,onDuplicate:f,disableMultiSelect:i,disableDelete:u,disableEdit:R,disableCreate:N,hideUseCase:b=!0,tableProps:A,containerProps:v,quantumIconSrc:y="/favicon.ico"})=>{const[p,a]=s.useState(""),[m,C]=s.useState(),{getLabel:w}=le.useUiLabelContext(),k=s.useMemo(()=>({action:w("action"),actionPlural:w("action_plural"),actionLowerCase:w("action").toLocaleLowerCase(),actionPluralLowerCase:w("action_plural").toLocaleLowerCase()}),[w]),Q=s.useMemo(()=>{if(!o)return;const S=Ue(o,p);return b?S:Qe(S,m)},[o,p,m,b]),W=s.useCallback(()=>{if(!x)return;const P=o.filter(M=>M.selected&&!M.quantumOwned).map(M=>M.id);x(P)},[o,x]),O=s.useCallback(()=>{if(!f)return;const S=o.filter(P=>P.selected);f(S.map(P=>P.id)),j&&S.forEach(P=>j(P,!1))},[o,f,j]),H=s.useMemo(()=>o.some(S=>S.selected&&!S.quantumOwned),[o]),te=s.useMemo(()=>o.some(S=>S.selected),[o]),D=s.useMemo(()=>o.some(S=>S.selected&&S.quantumOwned),[o]);return e.jsxRuntimeExports.jsxs(t.Box,{...v,children:[e.jsxRuntimeExports.jsxs(t.Flex,{alignContent:"space-between",gap:4,children:[(l||x||f)&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mb:"1rem",gap:4,children:[l&&e.jsxRuntimeExports.jsxs(t.Button,{isDisabled:!l||N,colorScheme:"blackAlpha",backgroundColor:"gray.700",onClick:l,children:["Create New ",k.action]}),x&&!i&&e.jsxRuntimeExports.jsx(t.Tooltip,{label:D?H?`Quantum-owned ${k.actionPluralLowerCase} are selected and will be skipped`:`Selected ${k.actionPluralLowerCase} are quantum-owned and cannot be deleted`:void 0,shouldWrapChildren:!0,children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!H||!x||u,onClick:W,children:"Delete Selected"})}),f&&!i&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!te,onClick:O,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx(ke,{setSearch:a,actions:o,updateUseCases:C,hideUseCaseFilter:b})]}),e.jsxRuntimeExports.jsx(t.TableContainer,{mr:"2rem",overflowX:"hidden",...A,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 ",Q?.length??0," of"," ",n??o.length,")"]}),e.jsxRuntimeExports.jsx(t.Th,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Th,{children:"Sensor Locations"}),!b&&e.jsxRuntimeExports.jsx(t.Th,{children:"Use Case"}),e.jsxRuntimeExports.jsx(t.Th,{})]})}),e.jsxRuntimeExports.jsx(t.Tbody,{children:Q?.map(S=>e.jsxRuntimeExports.jsxs(t.Tr,{className:ye.cn("hover:bg-[#f7f7f7]",!i&&"cursor-pointer",S.selected&&"bg-gray-200"),onClick:()=>{i||j?.(S,!S.selected)},children:[e.jsxRuntimeExports.jsx(t.Td,{children:e.jsxRuntimeExports.jsxs(t.Flex,{children:[!i&&e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:S.selected?e.jsxRuntimeExports.jsx(Te.FaCheckSquare,{className:"text-blue-500"}):e.jsxRuntimeExports.jsx(Te.FaSquare,{className:"text-gray-400"})}),(S.quantumOwned||!h)&&d&&e.jsxRuntimeExports.jsx(t.Button,{ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:P=>{P.stopPropagation(),d(S.id)},children:"View"}),!S.quantumOwned&&h&&e.jsxRuntimeExports.jsx(t.Button,{isDisabled:R,ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:P=>{P.stopPropagation(),h(S.id)},children:"Edit"})]})}),e.jsxRuntimeExports.jsx(t.Td,{whiteSpace:"break-spaces",children:e.jsxRuntimeExports.jsxs(t.Flex,{align:"center",gap:2,children:[e.jsxRuntimeExports.jsx(ze,{action:S,quantumIconSrc:y}),S.name]})}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",whiteSpace:"break-spaces",children:qe(S.sensorLocations)}),!b&&e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:e.jsxRuntimeExports.jsx($e,{containerProps:{flexWrap:"wrap"},tags:S.useCases?.map(P=>P.name)??[]})})]},S.id))})]})})]})},We=({onSave:o,onCancel:n,onError:l,hideButtons:x=!1,setButtonDisabled:h,setButtonOnClick:d,quantumOwned:j})=>{const f=t.useToast(),{getLabel:i}=le.useUiLabelContext(),u=s.useMemo(()=>({singular:i("action"),plural:i("action_plural"),pluralLowerCase:i("action_plural").toLowerCase(),singularLowerCase:i("action").toLowerCase()}),[i]),[R,N]=s.useState("copy"),[b,A]=s.useState(""),[v,y]=s.useState([]),[p,a]=s.useState(!1),[m]=Z.useQuery({query:E.GET_GROUPS}),[C]=Z.useQuery({query:E.GET_ACTIONS_BY_GROUP,variables:{groupId:b},pause:!b}),[,w]=Z.useMutation(E.CREATE_ACTION),[,k]=Z.useMutation(E.CONVERT_ACTION_TO_QUANTUM_OWNED),Q=s.useMemo(()=>m.data?.groups?m.data.groups.map(c=>F.getFragmentData(E.GROUP_FRAGMENT,c)):[],[m.data]),W=s.useMemo(()=>C.data?C.data.actions.map(r=>{const T=F.getFragmentData(E.ACTION_FRAGMENT,r),L=F.getFragmentData(E.REPORT_FRAGMENT,T.reports),z=F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,T.categories),U=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,T.metadataGroups).map(Y=>({...Y,data:Y.data.map(K=>F.getFragmentData(E.METADATA_ITEM_FRAGMENT,K))}));return{...T,thresholds:F.getFragmentData(E.THRESHOLD_FRAGMENT,T.thresholds),reports:L.map(Y=>({...Y,thresholds:F.getFragmentData(E.THRESHOLD_FRAGMENT,Y.thresholds)})),categories:z,metadataGroups:U}}):[],[C.data]),O=s.useMemo(()=>W.filter(c=>v.includes(c.id)),[W,v]),H=s.useCallback(c=>{const r=c?.value||"";A(r),y([])},[]),te=s.useCallback(c=>{const r=c.map(T=>T.value);y(r)},[]),D=s.useCallback(async c=>{const r={...c,name:`${c.name} (Copy)`,description:c.description||void 0,instructionsPointOfInterest:c.instructionsPointOfInterest||void 0,instructionsMovementReport:c.instructionsMovementReport||void 0,laterality:c.laterality,activityKind:c.activityKind,sensorLocations:c.sensorLocations,thresholds:c.thresholds.map(L=>({...L,id:void 0})),categories:c.categories.map(L=>L.id),quantumOwned:j,metadataItemIds:c.metadataGroups.flatMap(L=>L.data.map(z=>z.id)).filter(L=>L!==void 0),reports:c.reports.map(L=>({...L,id:void 0,thresholds:L.thresholds.map(z=>({...z,id:void 0}))})),id:void 0},T=await w({fields:r});if(T.error)throw new Error(T.error.message);if(T.data?.createAction)return F.getFragmentData(E.ACTION_FRAGMENT,T.data.createAction);throw new Error("No action data returned")},[w,j]),S=s.useCallback(async c=>{const r=await k({id:c.id});if(r.error)throw new Error(r.error.message);if(r.data?.convertActionToQuantumOwned)return F.getFragmentData(E.ACTION_FRAGMENT,r.data.convertActionToQuantumOwned);throw new Error("No action data returned")},[k]),P=s.useCallback(async()=>{if(a(!0),!O.length){const c=new Error(`No ${u.pluralLowerCase} selected for ${R==="copy"?"copying":"converting"}`);l?.(c),a(!1);return}try{const c=[];let r=0;const T=R==="copy"?D:S,L=R==="copy"?"copy":"convert";for(const z of O)try{const ee=await T(z);c.push(ee)}catch(ee){console.error(`Failed to ${L} ${u.singularLowerCase} "${z.name}":`,ee),r++}if(c.length>0){const z=c.length,ee=O.length,U=R==="copy"?"copied":"converted",Y=R==="copy"?"copy":"convert";f({title:r>0?`Partial ${Y} completed`:`${u.plural} ${U} successfully`,description:r>0?`${z} of ${ee} ${u.pluralLowerCase} ${U} successfully`:`${z} ${z>1?u.pluralLowerCase:u.singularLowerCase} ${U} successfully`,status:r>0?"warning":"success",duration:3e3,isClosable:!0}),o?.(),A(""),y([])}else throw new Error(`Failed to ${L} any ${u.pluralLowerCase}`)}catch(c){const r=R==="copy"?"copy":"convert",T=c instanceof Error?c.message:`Failed to ${r} ${u.pluralLowerCase}`;f({title:`${R==="copy"?"Copy":"Convert"} failed`,description:T,status:"error",duration:5e3,isClosable:!0}),l?.(c instanceof Error?c:new Error(T))}finally{a(!1)}},[O,R,D,S,f,o,l,u]),M=s.useCallback(()=>{A(""),y([]),N("copy"),n?.()},[n]);s.useEffect(()=>{h&&h({cancelButton:!1,saveButton:O.length===0||p})},[O.length,p,h]),s.useEffect(()=>{d&&d({cancelButton:M,saveButton:P})},[d,M,P]);const B=s.useMemo(()=>Q.map(c=>({value:c.id,label:c.name})),[Q]),V=s.useMemo(()=>W.filter(c=>R==="copy"?!0:!c.quantumOwned).map(c=>({value:c.id,label:c.name,isQuantumOwned:c.quantumOwned})),[W,R]),q=m.fetching,se=C.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[j&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ae,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:R,onChange:c=>{N(c),y([])},children:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:6,children:[e.jsxRuntimeExports.jsx(t.Radio,{value:"copy",colorScheme:"blue",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"medium",children:["Copy ",u.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",u.plural.toLocaleLowerCase()," ","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.jsxs(t.Text,{fontWeight:"medium",children:["Convert to Quantum Owned ",u.singular]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Convert existing"," ",u.plural.toLocaleLowerCase()," to quantum-owned"]})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ae,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(ce.st,{placeholder:"Choose a group...",options:B,value:B.find(c=>c.value===b)||null,onChange:H,isLoading:q,isDisabled:q,isClearable:!0}),m.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: ",m.error.message]})]})]}),b&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsxs(ae,{children:["Select ",u.plural," to"," ",R==="copy"?"Copy":"Convert"]}),se?e.jsxRuntimeExports.jsxs(t.HStack,{children:[e.jsxRuntimeExports.jsx(t.Spinner,{size:"sm"}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Loading ",u.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(ce.st,{placeholder:`Choose ${u.pluralLowerCase} to ${R}...`,options:V,value:V.filter(c=>v.includes(c.value)),onChange:te,isDisabled:V.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(c,{context:r})=>e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",w:"100%",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(t.Text,{children:c.label}),r==="value"&&c.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),c.isQuantumOwned&&r==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),V.length===0&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:["No ",u.pluralLowerCase," found"]})]}),C.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load ",u.pluralLowerCase,":"," ",C.error.message]})]})]}),O.length>0&&e.jsxRuntimeExports.jsxs(t.Box,{p:4,bg:"gray.50",borderRadius:"md",children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"semibold",mb:3,children:O.length===1?`${u.singular} to ${R==="copy"?"Copy":"Convert"}:`:`${O.length} ${u.plural} to ${R==="copy"?"Copy":"Convert"}:`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[O.map((c,r)=>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:[r+1,". ",c.name]}),c.quantumOwned&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,fontSize:"sm",color:"gray.600",children:[c.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",c.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Type:"})," ",c.activityKind]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Laterality:"})," ",c.laterality]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Sensor Locations:"})," ",c.sensorLocations.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Thresholds:"})," ",c.thresholds.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Use Cases:"})," ",c.useCases.map(T=>T.name).join(", ")||"None"]})]})]},c.id)),O.length>1&&e.jsxRuntimeExports.jsx(t.Box,{w:"100%",p:2,bg:"blue.50",borderRadius:"md",border:"1px solid",borderColor:"blue.200",children:e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",fontWeight:"medium",color:"blue.800",children:["Total: ",O.length," ",u.pluralLowerCase," will be"," ",R==="copy"?"copied":"converted"]})})]})]}),!x&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:M,isDisabled:p,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:R==="copy"?"blue":"green",onClick:P,isDisabled:O.length===0||p,isLoading:p,loadingText:`${R==="copy"?"Copying":"Converting"}...`,children:[R==="copy"?"Copy":"Convert"," ",O.length===1?u.singular:`${O.length} ${u.plural}`]})]})]})})},He=({onSave:o,onCancel:n,onError:l,hideButtons:x=!1,setButtonDisabled:h,setButtonOnClick:d,quantumOwned:j})=>{const f=t.useToast(),{getLabel:i}=le.useUiLabelContext(),u=s.useMemo(()=>({singular:i("module"),plural:i("module_plural"),pluralLowerCase:i("module_plural").toLowerCase(),singularLowerCase:i("module").toLowerCase()}),[i]),R=s.useMemo(()=>({singular:i("action"),plural:i("action_plural"),pluralLowerCase:i("action_plural").toLowerCase(),singularLowerCase:i("action").toLowerCase()}),[i]),[N,b]=s.useState(""),[A,v]=s.useState([]),[y,p]=s.useState(!1),[a,m]=s.useState("copy"),[C]=Z.useQuery({query:E.GET_GROUPS}),[w]=Z.useQuery({query:E.GET_MODULES_BY_GROUP,variables:{groupId:N},pause:!N}),[,k]=Z.useMutation(E.CREATE_MODULE),[,Q]=Z.useMutation(E.UPDATE_MODULE),[,W]=Z.useMutation(E.CREATE_ACTION),[,O]=Z.useMutation(E.CONVERT_ACTION_TO_QUANTUM_OWNED),H=s.useMemo(()=>C.data?.groups?C.data.groups.map(r=>F.getFragmentData(E.GROUP_FRAGMENT,r)):[],[C.data]),te=s.useMemo(()=>w.data?.modules?F.getFragmentData(E.ACTION_MODULE_FRAGMENT,w.data?.modules).map(T=>{const L=F.getFragmentData(E.MODULE_ACTION_FRAGMENT,T.moduleActions);return{...T,moduleActions:L.map(z=>({...z,action:F.getFragmentData(E.ACTION_FRAGMENT,z.action)})),categories:F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,T.categories)}}):[],[w.data]),D=s.useMemo(()=>te.filter(r=>A.includes(r.id)),[te,A]),S=s.useCallback(r=>{const T=r?.value||"";b(T),v([])},[]),P=s.useCallback(r=>{const T=r.map(L=>L.value);v(T)},[]),M=s.useCallback(async()=>{if(p(!0),!D.length){p(!1);const r=new Error(`No modules selected for ${a==="convert"?"converting":"copying"}`);l?.(r);return}try{const r=[];let T=0;for(const L of D)try{let z=L.moduleActions.map(ee=>ee.actionId);if(j){const ee=L.moduleActions.map(K=>K.action),U=async K=>{if(a==="copy"){if(K.quantumOwned)return K;const ue=F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,K.categories),Re=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,K.metadataGroups).map(ie=>F.getFragmentData(E.METADATA_ITEM_FRAGMENT,ie.data).map(he=>he.id)).flat(),me=F.getFragmentData(E.REPORT_FRAGMENT,K.reports).map(ie=>({...ie,id:void 0,thresholds:F.getFragmentData(E.THRESHOLD_FRAGMENT,ie.thresholds).map(he=>({...he,id:void 0}))})),pe=F.getFragmentData(E.THRESHOLD_FRAGMENT,K.thresholds).map(ie=>({...ie,id:void 0})),Ee={...K,quantumOwned:!0,thresholds:pe,categories:ue?.map(ie=>ie.id),reports:me,metadataIds:Re,id:void 0},je=await W({fields:Ee});return je.error||!je.data?.createAction?null:F.getFragmentData(E.ACTION_FRAGMENT,je.data.createAction)}if(K.quantumOwned)return K;const xe=await O({id:K.id});return xe.error||!xe.data?.convertActionToQuantumOwned?null:F.getFragmentData(E.ACTION_FRAGMENT,xe.data.convertActionToQuantumOwned)};z=(await Promise.all(ee.map(U))).filter(K=>!!K).map(K=>K.id)}if(a==="convert"){const ee={name:L.name,description:L.description||void 0,actions:z,categories:L.categories.map(Y=>Y.id),quantumOwned:!0},U=await Q({id:L.id,input:ee});if(U.error)throw new Error(U.error.message);if(U.data?.updateModule){const Y=F.getFragmentData(E.ACTION_MODULE_FRAGMENT,U.data.updateModule);r.push(Y)}}else{const ee={name:`${L.name} (Copy)`,description:L.description||void 0,actions:z,categories:L.categories.map(Y=>Y.id),quantumOwned:j},U=await k({input:ee});if(U.error)throw new Error(U.error.message);if(U.data?.createModule){const Y=F.getFragmentData(E.ACTION_MODULE_FRAGMENT,U.data.createModule);r.push(Y)}}}catch(z){console.error(`Failed to ${a==="convert"?"convert":"copy"} module "${L.name}":`,z),T++}if(r.length>0){const L=r.length,z=D.length;f({title:T>0?`Partial ${a==="convert"?"convert":"copy"} completed`:`${u.plural} ${a==="convert"?"converted":"copied"} successfully`,description:T>0?`${L} of ${z} ${u.plural} ${a==="convert"?"converted":"copied"} successfully`:`${L} ${L>1?u.plural:u.singular} ${a==="convert"?"converted":"copied"} successfully`,status:T>0?"warning":"success",duration:3e3,isClosable:!0}),r.length>0&&o?.(),b(""),v([])}else throw new Error(`Failed to ${a==="convert"?"convert":"copy"} any modules`)}catch(r){const T=r instanceof Error?r.message:`Failed to ${a==="convert"?"convert":"copy"} modules`;f({title:a==="convert"?"Convert failed":"Copy failed",description:T,status:"error",duration:5e3,isClosable:!0}),l?.(r instanceof Error?r:new Error(T))}finally{p(!1)}},[D,k,Q,f,o,l,j,W,O,a,u]),B=s.useCallback(()=>{b(""),v([]),m("copy"),n?.()},[n]);s.useEffect(()=>{h&&h({cancelButton:!1,saveButton:D.length===0||y})},[D.length,y,h]),s.useEffect(()=>{d&&d({cancelButton:B,saveButton:M})},[d,B,M]);const V=s.useMemo(()=>H.map(r=>({value:r.id,label:r.name})),[H]),q=s.useMemo(()=>te.filter(r=>a==="copy"?!0:!r.quantumOwned).map(r=>({value:r.id,label:r.name,isQuantumOwned:r.quantumOwned})),[te,a]),se=C.fetching,c=w.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[j&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ae,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:a,onChange:r=>{m(r),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.jsxs(t.Text,{fontWeight:"medium",children:["Copy ",u.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",u.pluralLowerCase," based on selected ones"]})]})}),e.jsxRuntimeExports.jsx(t.Radio,{value:"convert",colorScheme:"green",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"medium",children:"Convert to Quantum Owned"}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Convert existing ",u.pluralLowerCase," to quantum-owned"]})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ae,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(ce.st,{placeholder:"Choose a group...",options:V,value:V.find(r=>r.value===N)||null,onChange:S,isLoading:se,isDisabled:se,isClearable:!0}),C.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",C.error.message]})]})]}),N&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ae,{children:a==="convert"?`Select ${u.plural} to Convert`:`Select ${u.plural} to Copy`}),c?e.jsxRuntimeExports.jsxs(t.HStack,{children:[e.jsxRuntimeExports.jsx(t.Spinner,{size:"sm"}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Loading ",u.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(ce.st,{placeholder:a==="convert"?`Choose ${u.pluralLowerCase} to convert...`:`Choose ${u.pluralLowerCase} to copy...`,options:q,value:q.filter(r=>A.includes(r.value)),onChange:P,isDisabled:q.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(r,{context:T})=>e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",w:"100%",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(t.Text,{children:r.label}),T==="value"&&r.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),r.isQuantumOwned&&T==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),q.length===0&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:["No ",u.pluralLowerCase," found in this group"]})]}),w.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 ",u.pluralLowerCase,":"," ",w.error.message]})]})]}),D.length>0&&e.jsxRuntimeExports.jsxs(t.Box,{p:4,bg:"gray.50",borderRadius:"md",children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"semibold",mb:3,children:D.length===1?`${u.singular} to ${a==="copy"?"Copy":"Convert"}`:`${D.length} ${u.plural} to ${a==="copy"?"Copy":"Convert"}`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[D.map((r,T)=>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:[T+1,". ",r.name]}),r.quantumOwned&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,fontSize:"sm",color:"gray.600",children:[r.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",r.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Activities:"})," ",r.moduleActions.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Categories:"})," ",r.categories.map(L=>L.name).join(", ")||"None"]})]})]},r.id)),D.length>1&&e.jsxRuntimeExports.jsx(t.Box,{w:"100%",p:2,bg:"blue.50",borderRadius:"md",border:"1px solid",borderColor:"blue.200",children:e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",fontWeight:"medium",color:"blue.800",children:["Total: ",D.length," ",u.pluralLowerCase," will be"," ",a==="copy"?"copied":"converted"]})}),j&&D.filter(r=>r.moduleActions.some(T=>!T.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 ${u.plural} will convert non QM-Owned ${R.plural} to QM-Owned ${R.plural}`:`Copying ${u.plural} with Non QM-Owned ${R.plural} will create corresponding QM-Owned ${R.plural}`})})]})]}),!x&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:B,isDisabled:y,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:a==="copy"?"blue":"green",onClick:M,isDisabled:D.length===0||y,isLoading:y,loadingText:`${a==="copy"?"Copying":"Converting"}...`,children:[a==="copy"?"Copy":"Convert"," ",D.length===1?u.singular:`${D.length} ${u.plural}`]})]})]})})},Fe=({name:o,setName:n,actions:l,selectedActionIds:x,setSelectedActionIds:h,availableCategories:d,selectedCategoryIds:j,setSelectedCategoryIds:f,description:i,setDescription:u,...R})=>{const N=t.useDisclosure(),b=s.useMemo(()=>l.map(m=>({...m,selected:x.includes(m.id)})),[l,x]),A=s.useMemo(()=>l.reduce((m,C)=>(m[C.id]=C,m),{}),[l]),v=s.useMemo(()=>x.map(m=>A[m]),[x,A]),y=s.useCallback((m,C)=>{h(C?[...x,m.id]:x.filter(w=>w!==m.id))},[x,h]),p=s.useCallback(m=>{n(m.target.value)},[n]),a=s.useCallback(m=>{u?.(m.target.value)},[u]);return e.jsxRuntimeExports.jsxs(t.Box,{...R,children:[e.jsxRuntimeExports.jsxs(t.HStack,{gap:"2rem",children:[e.jsxRuntimeExports.jsx(Ke,{name:o??"",onInputChange:p}),e.jsxRuntimeExports.jsx(Ye,{availableCategories:d,value:j,onChange:f})]}),e.jsxRuntimeExports.jsx(Je,{description:i??"",onInputChange:a}),e.jsxRuntimeExports.jsx(Xe,{value:v,onChange:h,onAdjustActivities:()=>N.onOpen()}),e.jsxRuntimeExports.jsxs(t.Modal,{isOpen:N.isOpen,onClose:N.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(Le,{actions:b,onSelected:y,disableCreate:!0,disableDelete:!0,tableProps:{height:"28rem",overflowY:"auto"}})}),e.jsxRuntimeExports.jsx(t.ModalFooter,{children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:N.onClose,isDisabled:x.length===0,children:"Done"})})]})]})]})},Ke=s.memo(({name:o,onInputChange:n})=>{const{getLabel:l}=le.useUiLabelContext(),x=l("module");return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(ae,{children:[x," Name"]}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. ACL RTP Test Battery",value:o,onChange:n,isRequired:!0})]})}),Ye=s.memo(({availableCategories:o,value:n,onChange:l})=>{const{getLabel:x}=le.useUiLabelContext(),h=x("module"),d=s.useMemo(()=>[...o,{id:"other",name:"Other"}],[o]),j=s.useMemo(()=>d.map(f=>({value:f.id,label:f.name})),[d]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(ae,{children:[h," Category"]}),e.jsxRuntimeExports.jsx(ce.st,{isDisabled:o.length===0,options:j,value:n.length===0?{value:"other",label:"Other"}:d.filter(f=>n.includes(f.id)).map(f=>({value:f.id,label:f.name}))[0],onChange:f=>l(f?[f.value]:[]),placeholder:"Select category"})]})}),Je=s.memo(({description:o,onInputChange:n})=>{const{getLabel:l}=le.useUiLabelContext(),x=l("module");return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(ae,{children:e.jsxRuntimeExports.jsxs("span",{children:["Description",e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",children:["Briefly describe the objective of this"," ",x.toLocaleLowerCase(),". Max 40 words."]})]})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. Assess readiness to return to play post-ACL reconstruction",value:o,onChange:n})]})}),Xe=s.memo(({value:o,onChange:n,onAdjustActivities:l})=>{const{getLabel:x}=le.useUiLabelContext(),h=s.useMemo(()=>({module:x("module"),moduleLowerCase:x("module").toLocaleLowerCase(),action:x("action"),actionPlural:x("action_plural"),actionPluralLowerCase:x("action_plural").toLocaleLowerCase()}),[x]),d=s.useMemo(()=>o.map(j=>({id:j.id,name:j.name})),[o]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(t.HStack,{justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(ae,{children:e.jsxRuntimeExports.jsxs("span",{children:[h.actionPlural,e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",children:["Drag and drop to reorder the ",h.actionPluralLowerCase," in this ",h.moduleLowerCase,"."]})]})}),e.jsxRuntimeExports.jsxs(t.Button,{size:"sm",variant:"solid",colorScheme:"blue",onClick:l,children:["Add / Remove ",h.actionPlural]})]}),d.length===0?e.jsxRuntimeExports.jsx(t.VStack,{children:e.jsxRuntimeExports.jsxs(t.Text,{color:"gray.500",fontSize:"lg",mb:"4rem",mt:"4rem",children:["No ",h.actionPluralLowerCase," selected for this"," ",h.moduleLowerCase,".",e.jsxRuntimeExports.jsxs(t.Button,{ml:"0.5em",size:"sm",variant:"link",colorScheme:"blue",onClick:l,children:["Add ",h.actionPluralLowerCase,"."]})]})}):e.jsxRuntimeExports.jsx(De,{value:d,onChange:j=>{const f=j(d);n(f.map(i=>i.id))}})]})}),Oe=({value:o,onChange:n,forceKind:l,disableRemove:x,disableKind:h,isDisabled:d,lockRanges:j,...f})=>{const i=s.useMemo(()=>[...o].sort((b,A)=>{const v=de.availablePlanes.indexOf(b.plane),y=de.availablePlanes.indexOf(A.plane);return v-y}),[o]),u=s.useCallback(b=>"segment"in b.id?re.getSegmentNameWithPlane(b.id.segment,b.plane,!0)??"Unknown":re.getJointNameWithPlane(b.id.joint,b.plane,!0)??"Unknown",[]),R=s.useCallback((b,A)=>{const v=i.findIndex(p=>p.id===A.id&&p.plane===A.plane);let y=[...i];l&&(A={...A,kind:l}),y[v]=A,j&&(y=y.map(p=>({...p,min:A.min,max:A.max}))),n(y)},[n,i,l,j]),N=s.useCallback(b=>{const A=i.filter(v=>v.id!==b.id||v.plane!==b.plane);n(A)},[n,i]);return e.jsxRuntimeExports.jsx(t.VStack,{alignItems:"flex-start",overflowY:"auto",...f,children:i.map((b,A)=>e.jsxRuntimeExports.jsx(Ze,{label:u(b),parameter:b,onChange:v=>R(A,v),onRemove:x||d?void 0:()=>N(b),forceKind:l,disableKind:h||d,isDisabled:d},`${JSON.stringify(b.id)}-${b.plane}`))})},Ze=({label:o,parameter:n,onChange:l,onRemove:x,forceKind:h,disableKind:d,isDisabled:j})=>{const f=s.useCallback(R=>"joint"in n.id?re.getJointAngleDirectionName(n.id.joint,n.plane,R<0?-1:1):re.getSegmentAngleDirectionName(n.id.segment,n.plane,R<0?-1:1),[n]),{min:i,max:u}="joint"in n.id?re.getNormativeJointRange(n.id.joint,n.plane):{min:-180,max:180};return e.jsxRuntimeExports.jsxs(t.VStack,{borderRadius:"md",p:2,px:4,bg:"gray.100",w:"100%",overflow:"hidden",flexShrink:"0",children:[e.jsxRuntimeExports.jsxs(t.HStack,{w:"100%",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",flex:1,textTransform:"capitalize",fontWeight:"semibold",children:o}),n.sensorOnly&&e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor Only"}),x&&!j&&e.jsxRuntimeExports.jsx(t.IconButton,{size:"xs",variant:"ghost","aria-label":"delete",icon:e.jsxRuntimeExports.jsx(t.Icon,{as:Te.FaTrash}),onClick:x}),!h&&e.jsxRuntimeExports.jsx(Ge,{selectedItem:n?.kind??I.ThresholdKind.Limit,onChange:({value:R})=>l({...n,kind:R}),isDisabled:d||j,buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:I.ThresholdKind.Limit,label:"limit"},{value:I.ThresholdKind.Target,label:"target"}]})]}),e.jsxRuntimeExports.jsx(Pe,{w:"100%",size:"xs",min:i,max:u,zeroMarker:!0,value:[n.min,n.max],onChange:R=>l({...n,min:R[0],max:R[1]}),formatValue:R=>`${Math.abs(R)}°`,valueLabel:R=>f(R)??"",positiveNegativeLabels:f(0)?[f(-1)??"",f(1)??""]:void 0,isDisabled:j})]})},Ce=(o,n)=>"segment"in o&&"segment"in n&&o.segment===n.segment||"joint"in o&&"joint"in n&&o.joint===n.joint,Me=({options:o,value:n,onChange:l,forceKind:x,singleValue:h,singleValueSideless:d,editOnly:j,disableKind:f,maxParameters:i,...u})=>{const R=d?2:i,N=s.useMemo(()=>{const p=new Map;return o.forEach(a=>{const m="joint"in a.id;let C,w;if(m?(C=re.getJointNameWithPlane(a.id.joint,a.plane,!0)??"Unknown",w=`joint:${a.id.joint}`):(C=re.getSegmentNameWithPlane(a.id.segment,a.plane,!0)??"Unknown",w=`segment:${a.id.segment}`),!p.has(w)){const Q=m?re.getPartName(a.id.joint)??"Unknown Joint":re.getPartName(a.id.segment)??"Unknown Segment";p.set(w,{label:Q,options:[]})}p.get(w).options.push({label:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:2,justify:"space-between",w:"100%",pl:3,children:[e.jsxRuntimeExports.jsx(t.Text,{children:C}),a.sensorOnly&&e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor Only"})]}),value:a.id,plane:a.plane,sensorOnly:a.sensorOnly})}),Array.from(p.values())},[o]),b=s.useMemo(()=>{if(!d||n.length===0)return N;const p=n[0];return N.map(a=>({...a,options:a.options.filter(m=>de.getAnalysisPartIdNoSide(m.value)===de.getAnalysisPartIdNoSide(p.id)&&m.plane===p.plane)})).filter(a=>a.options.length>0)},[N,n,d]),A=s.useMemo(()=>N.flatMap(a=>a.options).filter(a=>n.some(m=>Ce(m.id,a.value)&&m.plane===a.plane)),[N,n]),v=s.useCallback((p,a)=>{if(!a)return!0;const m=a.toLowerCase().split(" ").join(""),C=p.data;if(!C||!C.value)return!1;const w=C.value.joint??C.value.segment;return!w||typeof w!="string"?!1:w.toLowerCase().includes(m)||C.plane&&C.plane.toLowerCase().includes(m)},[]),y=s.useCallback(p=>{const a=p.map(m=>{const C=n.find(O=>Ce(O.id,m.value)&&O.plane===m.plane),w=o.find(O=>Ce(O.id,m.value)&&O.plane===m.plane),k=d?n.find(O=>de.getAnalysisPartIdNoSide(O.id)===de.getAnalysisPartIdNoSide(m.value)&&O.plane===m.plane):void 0,Q=k&&!C?k.min:w&&w.min?w.min:0,W=k&&!C?k.max:w&&w.max?w.max:0;return C??{id:m.value,plane:m.plane,min:Q,max:W,sensorOnly:m.sensorOnly,kind:x??I.ThresholdKind.Limit}});l(a)},[l,n,o,x,d]);return s.useEffect(()=>{const p=n.filter(a=>o.some(m=>Ce(m.id,a.id)&&m.plane===a.plane));p.length!==n.length&&l(p)},[o,l,n]),e.jsxRuntimeExports.jsxs(t.Box,{...u,children:[e.jsxRuntimeExports.jsx(ce.st,{isMulti:!h,placeholder:n.length?`${n.length} selected`:"Search...",value:A,isDisabled:j||A.length>=(R??1/0),onChange:p=>Array.isArray(p)?y([...p]):y(p!==null?[p]:[]),options:b,controlShouldRenderValue:!1,formatOptionLabel:p=>p.label,filterOption:v,isSearchable:!0}),e.jsxRuntimeExports.jsx(Oe,{marginTop:2,maxH:"28rem",value:n,onChange:l,forceKind:x,disableKind:f,isDisabled:j,lockRanges:d})]})},Ae=o=>{switch(o){case I.SensorLocation.Thorax:return"Thorax";case I.SensorLocation.CenterBack:return"Center Back";case I.SensorLocation.Pelvis:return"Pelvis";case I.SensorLocation.LeftThigh:return"Left Thigh";case I.SensorLocation.RightThigh:return"Right Thigh";case I.SensorLocation.LeftShank:return"Left Shank";case I.SensorLocation.RightShank:return"Right Shank";case I.SensorLocation.LeftFoot:return"Left Foot";case I.SensorLocation.RightFoot:return"Right Foot";case I.SensorLocation.LeftUpperArm:return"Left Upper Arm";case I.SensorLocation.RightUpperArm:return"Right Upper Arm";case I.SensorLocation.LeftForearm:return"Left Forearm";case I.SensorLocation.RightForearm:return"Right Forearm";case I.SensorLocation.Head:return"Head"}},Ve=o=>{switch(o){case I.ReportKind.GeneralActivity:return"General Activity";case I.ReportKind.MovementCoordination:return"Movement Coordination";case I.ReportKind.PointOfInterest:return"Point of Interest";case I.ReportKind.Range:return"Range";case I.ReportKind.StabilityBalance:return"Stability Balance"}},et=({id:o,onError:n,onCancel:l,onSave:x,hideButtons:h,setButtonOnClick:d,setButtonDisabled:j,quantumOwned:f,isView:i})=>{const u=Z.useClient(),[{fetching:R},N]=Z.useMutation(E.CREATE_ACTION),[{fetching:b},A]=Z.useMutation(E.UPDATE_ACTION),[{data:v}]=Z.useQuery({query:E.GET_ACTION_BY_ID,variables:{id:o??""},pause:!o}),y=s.useMemo(()=>{const g=F.getFragmentData(E.ACTION_FRAGMENT,v?.getActionById);if(!g)return null;const G=F.getFragmentData(E.REPORT_FRAGMENT,g.reports).map($=>({...$,thresholds:F.getFragmentData(E.THRESHOLD_FRAGMENT,$.thresholds)}));return{...g,thresholds:F.getFragmentData(E.THRESHOLD_FRAGMENT,g.thresholds),reports:G}},[v]),p=R||b,a=!!y&&!!o,{getLabel:m}=le.useUiLabelContext(),C=s.useMemo(()=>({action:m("action")}),[m]),w=s.useMemo(()=>[{key:"module_category",label:"Link Category",multi:!0},{key:"activity_type",label:`${C.action} Type`,multi:!1},{key:"session_type",label:"Session Type",multi:!0},{key:"body_region",label:"Body Region",multi:!0},{key:"sport",label:"Sport",multi:!0}],[C.action]),[k,Q]=s.useState(""),[W,O]=s.useState(""),[H,te]=s.useState(""),[D,S]=s.useState(""),[P,M]=s.useState([]),[B,V]=s.useState({}),[q,se]=s.useState(null),[c,r]=s.useState([]),[T,L]=s.useState([]),[z,ee]=s.useState(""),[U,Y]=s.useState([]),K=le.useAllPartParameters(),xe=s.useMemo(()=>K.filter(g=>g.sensorOnly),[K]),ue=s.useMemo(()=>{const g=[{label:"General Activity",value:I.ReportKind.GeneralActivity},{label:"Movement Coordination",value:I.ReportKind.MovementCoordination},{label:"Point of Interest",value:I.ReportKind.PointOfInterest},{label:"Range",value:I.ReportKind.Range},{label:"Stability Balance",value:I.ReportKind.StabilityBalance}],_=U.map(G=>G.kind);return g.filter(G=>!_.includes(G.value))},[U]),ge=k.length>0,[Re,we]=s.useState({});s.useEffect(()=>{const g=w.map(_=>u.query(E.GET_METADATA_BY_KEY,{key:_.key}));Promise.all(g).then(_=>{const G={};_.forEach($=>{if($.error||!$.data)return;const J=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,$.data.getMetadataByKey),X=F.getFragmentData(E.METADATA_ITEM_FRAGMENT,J.data);G[J.key]=X.map(oe=>({label:oe.label||oe.value,value:oe.value,id:oe.id}))}),V(G)})},[u,w]),s.useEffect(()=>{if(y){const _=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,y.metadataGroups).map(J=>J.data.map(X=>F.getFragmentData(E.METADATA_ITEM_FRAGMENT,X).id)),G=y.reports.map(J=>({id:J.id,instructions:J.instructions??"",kind:J.reportKind,parameters:J.thresholds.map(X=>({id:{[X.partKind]:X.partId},kind:X.kind,min:X.min,max:X.max,plane:X.partDimension,oldId:X.id,sensorOnly:xe.some(oe=>{const ve=oe.id[X.partKind];return ve?ve===X.partId&&oe.plane===X.partDimension:!1})})),sensorLocations:J.sensorLocations})),$={name:y.name,description:y.description||"",cameraPlacement:y.cameraPlacement||"",videoLink:y.videoLink||"",metadataIds:_.flat(),reports:G};Q($.name),O($.description),te($.cameraPlacement),S($.videoLink),M($.metadataIds),Y(G),we($)}},[y]);const me=s.useMemo(()=>JSON.stringify(Re)!==JSON.stringify({name:k,description:W,cameraPlacement:H,videoLink:D,metadataIds:P,reports:U}),[Re,k,W,H,D,P,U]),pe=s.useCallback(()=>{const g={name:k,description:W,cameraPlacement:H,videoLink:D,metadataItemIds:P,laterality:I.ActionLaterality.Either,quantumOwned:f,sessionType:[],thresholds:[],reports:U.map(G=>({id:G.id,reportKind:G.kind,sensorLocations:G.sensorLocations,instructions:G.instructions,thresholds:G.parameters.map($=>({id:$.oldId,kind:$.kind,min:$.min,max:$.max,partKind:"joint"in $.id?"joint":"segment",partId:"joint"in $.id?$.id.joint:$.id.segment,partDimension:$.plane}))}))};let _;a&&o?_=A({id:o,fields:g}):_=N({fields:g}),_.then(({error:G})=>{G?n(G):x()})},[f,N,A,o,k,W,H,D,P,U,a,x,n]);s.useEffect(()=>{j&&j({cancelButton:p,saveButton:i?!0:p||!ge||!me})},[p,j,ge,me,i]),s.useEffect(()=>{d&&d({cancelButton:l,saveButton:i?()=>{}:pe})},[d,l,pe,i]);const Ee=s.useCallback(g=>{const _=re.getSuggestedSensorLocations(g.map(G=>"joint"in G.id?G.id.joint:G.id.segment));L(_)},[]);s.useEffect(()=>{Ee(c)},[c,Ee]);const je=s.useCallback(()=>{if(!q)return;const g={id:Date.now().toString(),kind:q,parameters:c,sensorLocations:T,instructions:z};Y(_=>[..._,g]),se(null),r([]),L([]),ee("")},[q,c,T,z]),ie=s.useCallback(g=>{Y(_=>_.filter(G=>G.id!==g))},[]),he=(g,_)=>{const G=w.find(J=>J.key===g);if(!G)return;const $=G.multi?(_??[]).map(J=>J.id):_?[_.id]:[];M(J=>[...J.filter(oe=>Object.values(B).flat().find(fe=>fe.id===oe)&&!Object.keys(B).find(fe=>B[fe]?.some(Ne=>Ne.id===oe&&fe===g))),...$])};return e.jsxRuntimeExports.jsxs(t.VStack,{spacing:4,w:"full",align:"stretch",children:[e.jsxRuntimeExports.jsxs(t.Tabs,{children:[e.jsxRuntimeExports.jsxs(t.TabList,{children:[e.jsxRuntimeExports.jsx(t.Tab,{children:"Basic Information"}),e.jsxRuntimeExports.jsx(t.Tab,{children:"Reports"})]}),e.jsxRuntimeExports.jsxs(t.TabPanels,{children:[e.jsxRuntimeExports.jsx(t.TabPanel,{px:0,children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:k,onChange:g=>Q(g.target.value),type:"text",placeholder:"i.e. Lunge & Return",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Camera Placement"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:H,onChange:g=>te(g.target.value),rows:2,placeholder:"(optional) Describe camera setup, placement, angles",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Video Link"}),e.jsxRuntimeExports.jsx(t.Input,{value:D,onChange:g=>S(g.target.value),type:"url",placeholder:"(optional) https://...",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Description"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:W,onChange:g=>O(g.target.value),rows:2,placeholder:"(optional) Describe how to perform the test or exercise",isDisabled:i})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(ne,{children:"Metadata Tags"}),w.map(g=>e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:g.label}),e.jsxRuntimeExports.jsx(ce.st,{isMulti:g.multi,value:B[g.key]?.filter(_=>P.includes(_.id)),onChange:_=>{he(g.key,_)},options:B[g.key],placeholder:`Select ${g.multi?"one or more":"one"} ${g.label.toLowerCase()}`,isDisabled:i,isClearable:g.multi})]},g.key))]})]})}),e.jsxRuntimeExports.jsx(t.TabPanel,{px:0,children:e.jsxRuntimeExports.jsxs("div",{className:ye.cn("grid grid-cols-1 gap-6",!i&&"md:grid-cols-2"),children:[e.jsxRuntimeExports.jsxs("div",{className:ye.cn("space-y-4",i&&"hidden"),children:[e.jsxRuntimeExports.jsx(ne,{children:"Add New Report"}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Report Kind"}),ue.length===0?e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",p:2,children:"All report kinds have been used. Remove an existing report to add a new one."}):e.jsxRuntimeExports.jsx(ce.st,{value:q?ue.find(g=>g.value===q):null,onChange:g=>se(g?.value||null),options:ue,placeholder:"Select report kind...",isDisabled:i,isClearable:!0})]}),q!==I.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(Me,{options:K,value:c,onChange:r,editOnly:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Suggested Sensor Locations"}),e.jsxRuntimeExports.jsx(t.Input,{value:T.map(g=>Ae(g)).join(", "),placeholder:"Auto-filled based on parameters...",isDisabled:!0})]})]}),q===I.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:z,onChange:g=>ee(g.target.value),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:i})]}),e.jsxRuntimeExports.jsx("div",{className:"w-full flex justify-end",children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:je,isDisabled:!q||i||ue.length===0||q!==I.ReportKind.PointOfInterest&&c.length===0,children:"Add Report"})})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(ne,{children:"Configured Reports"}),U.length===0?e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",children:"No reports created yet"}):e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:U.map(g=>e.jsxRuntimeExports.jsxs("div",{className:"p-3 border border-gray-200 rounded-md bg-gray-50",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex justify-between items-start mb-2",children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"semibold",children:Ve(g.kind)}),!i&&e.jsxRuntimeExports.jsx(t.Button,{size:"xs",colorScheme:"red",variant:"ghost",onClick:()=>ie(g.id),children:"Remove"})]}),g.kind===I.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:g.instructions,onChange:_=>Y(G=>G.map($=>$.id===g.id?{...$,instructions:_.target.value}:$)),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:i})]}),g.kind!==I.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsx(Me,{options:K,value:g.parameters,onChange:_=>{const G=_.map(J=>J.id.joint??J.id.segment),$=re.getSuggestedSensorLocations(G);Y(J=>J.map(X=>X.id===g.id?{...X,parameters:_,sensorLocations:$}:X))},editOnly:i}),g.kind!==I.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",mt:2,children:["Sensors:"," ",g.sensorLocations.map(_=>Ae(_)).join(", ")]})]},g.id))})]})]})})]})]}),e.jsxRuntimeExports.jsx(t.HStack,{justify:"end",className:ye.cn((h||i)&&"!hidden"),children:e.jsxRuntimeExports.jsxs(t.ButtonGroup,{gap:4,children:[e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:p,onClick:l,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:p||!ge||!me,isLoading:p,onClick:pe,children:"Save changes"})]})})]})},ne=({children:o})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:o}),tt=({id:o,onCancel:n,onSave:l,onError:x,hideButtons:h,quantumOwned:d,setButtonOnClick:j,setButtonDisabled:f})=>{const[{data:i}]=Z.useQuery({query:d?E.GET_QUANTUM_OWNED_ACTIONS:E.GET_ACTIONS}),[{data:u}]=Z.useQuery({query:E.GET_MODULE_BY_ID,variables:{id:o},pause:!o}),[{data:R}]=Z.useQuery({query:E.GET_ALL_MODULE_CATEGORIES}),N=F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,R?.moduleCategories),[{fetching:b},A]=Z.useMutation(E.UPDATE_MODULE),[{fetching:v},y]=Z.useMutation(E.CREATE_MODULE),p=F.getFragmentData(E.ACTION_FRAGMENT,d?i?.quantumOwnedActions:i?.actions)??[],a=F.getFragmentData(E.ACTION_MODULE_FRAGMENT,u?.module),m=F.getFragmentData(E.MODULE_ACTION_FRAGMENT,a?.moduleActions)??[],[C,w]=s.useState([...m.map(S=>S.actionId)??[]]),[k,Q]=s.useState(a?.name??""),[W,O]=s.useState([]),[H,te]=s.useState(a?.description??"");s.useEffect(()=>{a&&(w(m.map(S=>S.actionId)),Q(a.name),te(a.description??""),O(a.categories.map(S=>F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,S).id)??[]))},[a,m]);const D=s.useCallback(()=>{let S;const P={actions:C,name:k,categories:W.filter(M=>M!=="other"),description:H,quantumOwned:d};a?S=A({id:a.id,input:P}):S=y({input:P}),S.then(({error:M})=>{M?x(M):l()})},[y,A,C,k,H,W,a,l,x,d]);return s.useEffect(()=>{f&&f({cancelButton:b||v,saveButton:b||v||!k||H.trim().split(/\s+/).filter(Boolean).length>40})},[f,b,v,C,k,H]),s.useEffect(()=>{j&&j({cancelButton:n,saveButton:D})},[j,n,D]),e.jsxRuntimeExports.jsxs(t.Box,{width:"100%",children:[e.jsxRuntimeExports.jsx(Fe,{name:k,setName:Q,actions:p,selectedActionIds:C,setSelectedActionIds:w,availableCategories:N??[],selectedCategoryIds:W,setSelectedCategoryIds:O,description:H,setDescription:te}),!h&&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:b||v,onClick:n,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:b||v||!k||H.trim().split(/\s+/).filter(Boolean).length>40,isLoading:b||v,onClick:D,children:"Save"})]})})]})};exports.ActivityList=Le;exports.CopyActivityForm=We;exports.CopyModuleForm=He;exports.ModuleForm=Fe;exports.ParameterEditList=Oe;exports.ParameterEditSelect=Me;exports.UpsertActivityForm=et;exports.UpsertModuleForm=tt;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./react-jsx-runtime-vendor-Dszzpdy0.cjs"),t=require("@chakra-ui/react"),s=require("react"),ye=require("./utils-cn-FIKrq5Mb.cjs");require("./moment-vendor-1cRqq0AH.cjs");require("./lodash-vendor-C3e6C_PJ.cjs");const Z=require("urql"),le=require("./hooks.cjs"),Ie=require("./ufuzzy-vendor-7qHa_k39.cjs"),Te=require("./react-icons-vendor-BF_sZq07.cjs"),ce=require("./react-select-vendor-CZ69mhgt.cjs"),F=require("./generated.cjs"),E=require("./graphql-BhVmuiCG.cjs"),Se=require("./react-dnd-vendor-BGRUqrp9.cjs"),I=require("./generated-graphql.cjs"),re=require("./services-human-CGLf7B6Q.cjs"),de=require("./types.cjs"),ke=({setSearch:o,actions:n,updateUseCases:l,hideUseCaseFilter:x=!1})=>{const h=s.useMemo(()=>n?.flatMap(d=>d.useCases).filter((d,j,f)=>f.findIndex(i=>i.id===d.id)===j).map(d=>({label:d.name,value:d.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:Te.FaSearch,color:"gray.300"})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"Search by name...",width:"100%",maxW:x?void 0:"30rem",onChange:d=>o(d.target.value)})]}),!x&&e.jsxRuntimeExports.jsx(t.InputGroup,{size:"md",children:e.jsxRuntimeExports.jsx(ce.st,{size:"md",chakraStyles:{container:d=>({...d,width:"100%"})},menuPortalTarget:document.body,placeholder:"Filter use case",isMulti:!0,options:h,onChange:d=>l(d.map(j=>j.value))})})]})},ae=({children:o})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:o}),De=({value:o,onChange:n})=>{const l=s.useState(()=>Math.random().toString(36).substring(2,15))[0],x=s.useCallback((h,d)=>{n(j=>{const f=[...j],[i]=f.splice(h,1);return f.splice(d,0,i),f})},[n]);return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsx(Se.DndProvider,{backend:Se.HTML5Backend,children:e.jsxRuntimeExports.jsx(t.TableContainer,{children:e.jsxRuntimeExports.jsxs(t.Table,{variant:"simple",size:"md",children:[e.jsxRuntimeExports.jsx(t.Thead,{children:e.jsxRuntimeExports.jsxs(t.Tr,{children:[e.jsxRuntimeExports.jsx(t.Th,{children:"Order"}),e.jsxRuntimeExports.jsx(t.Th,{children:"Name"})]})}),e.jsxRuntimeExports.jsx(t.Tbody,{children:o.map((h,d)=>e.jsxRuntimeExports.jsx(_e,{listKey:l,index:d,id:h.id,name:h.name,move:x},h.id))})]})})})})},_e=({listKey:o,index:n,id:l,name:x,move:h})=>{const d=s.useRef(null),[{handlerId:j},f]=Se.useDrop({accept:o,collect:b=>({handlerId:b.getHandlerId()?.toString()??""}),hover:(b,A)=>{if(!d.current)return;const v=b.index,y=n;if(v===y)return;const p=d.current?.getBoundingClientRect(),a=(p.bottom-p.top)/2,C=A.getClientOffset().y-p.top;v<y&&C<a||v>y&&C>a||(h(v,y),b.index=y)}}),[{isDragging:i},u]=Se.useDrag({type:o,item:()=>({id:l,index:n}),collect:b=>({isDragging:b.isDragging()})}),R=i?.6:1,N=i?"grabbing":"grab";return u(f(d)),e.jsxRuntimeExports.jsxs(t.Tr,{ref:d,style:{opacity:R,cursor:N},"data-handler-id":j,children:[e.jsxRuntimeExports.jsx(t.Td,{children:n+1}),e.jsxRuntimeExports.jsx(t.Td,{children:x})]})},Ge=({items:o,onChange:n,selectedItem:l,isDisabled:x,selectedProps:h,buttonProps:d})=>{const j=i=>i===l||i.value===l,f=i=>j(i)?{...d,...h}:d;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:x,children:o.map((i,u)=>e.jsxRuntimeExports.jsx(t.Tooltip,{label:i.tooltip,openDelay:50,closeDelay:200,placement:"top",visibility:i.tooltip?"visible":"hidden",hasArrow:!0,children:e.jsxRuntimeExports.jsx(t.Button,{onClick:()=>j(i)?null:n(i,u),isDisabled:i.disabled,...f(i),children:i.label})},u))})},be=(o,n)=>n<0?-1*Math.abs(o):Math.abs(o),Pe=({isReversed:o,min:n,max:l,value:x,onChange:h,inputProps:d,size:j,zeroMarker:f,formatValue:i,valueLabel:u,positiveNegativeLabels:R,isDisabled:N,...b})=>{const[A,v]=s.useState([void 0,void 0]),y=A[0],p=A[1],a=f&&n<-5&&l>5,m=Number(x?.[0]??p??n)>0?1:-1,C=Number(x?.[1]??p??l)<0?-1:1,w=R?.[0]===R?.[1],k=x?.[0],Q=x?.[1];s.useEffect(()=>{k!==void 0&&Q!==void 0&&v([k.toFixed(0),Q.toFixed(0)])},[k,Q,v]);const W=s.useCallback(([M,B])=>{M<B&&v([M.toFixed(0),B.toFixed(0)])},[v]),O=s.useCallback(([M,B])=>{M<B&&h([M,B])},[h]),H=s.useCallback(()=>{v(([M,B])=>{const V=isNaN(Number(M))?n:Number(M),q=isNaN(Number(B))?l:Number(B),se=be(Number(V),m),c=be(Number(q),C),r=m<0?Math.max(se,n):Math.min(se,l),T=C<0?Math.max(c,n):Math.min(c,l);return r>T?(h([T,r]),[T.toFixed(0),r.toFixed(0)]):(h([r,T]),[r.toFixed(0),T.toFixed(0)])})},[h,v,m,C,n,l]),te=s.useCallback(M=>{const B=M===""||isNaN(Number(M))?M:be(Number(M),m);v(([V,q])=>[B.toString(),q])},[v,m]),_=s.useCallback(M=>{const B=M===""||isNaN(Number(M))?M:be(Number(M),C);v(([V,q])=>[V,B.toString()])},[v,C]),S=s.useMemo(()=>j==="xs"?"0.75rem":void 0,[j]),P=s.useCallback((M,B)=>{const V=Number(B.target.value);if(!y||!p||![-1,1].includes(V))return;const q=r=>V<0?-1*Math.abs(r):Math.abs(r),se=M?q(Number(y)):Number(y),c=M?Number(p):q(Number(p));se>c?h([c,se]):h([se,c])},[y,p,h]);return e.jsxRuntimeExports.jsxs(t.Flex,{direction:"column",...b,children:[e.jsxRuntimeExports.jsx(t.Box,{pt:"1em",mb:"-0.5em",children:e.jsxRuntimeExports.jsxs(t.RangeSlider,{"aria-label":["min","max"],isReversed:o,value:[Number(y??n),Number(p??l)],max:l,min:n,minStepsBetweenThumbs:3,step:1,onChange:W,onChangeEnd:O,isDisabled:N,children:[e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:n,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:j??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:i?i?.(n):n})}),e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:l,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:j??"sm",fontWeight:"semibold",style:{transform:"translateX(-100%)"},whiteSpace:"nowrap",children:i?i(l):l})}),a&&e.jsxRuntimeExports.jsxs(t.RangeSliderMark,{value:0,top:"-1em",pos:"relative",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:j,fontWeight:"semibold",children:i?.(0)??"0"}),e.jsxRuntimeExports.jsx(t.Box,{position:"absolute",width:"2px",height:"1em",top:"90%",left:"20%",backgroundColor:"var(--chakra-colors-gray-300)"})]}),e.jsxRuntimeExports.jsx(t.RangeSliderTrack,{children:e.jsxRuntimeExports.jsx(t.RangeSliderFilledTrack,{})}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:0,w:S,h:S}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:1,w:S,h:S})]})}),u&&e.jsxRuntimeExports.jsxs(t.Flex,{direction:o?"row-reverse":"row",justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:j??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:u(n)}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:j??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:u(l)})]}),e.jsxRuntimeExports.jsxs(t.Flex,{direction:o?"row-reverse":"row",justifyContent:"center",alignItems:"center",gap:"0.125em",children:[R&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:j,fontWeight:"bold",value:m,onChange:M=>P(!0,M),isDisabled:w||N,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:R[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:R[1]})]}),e.jsxRuntimeExports.jsx(t.NumberInput,{precision:0,size:j??"sm",min:0,max:m<0?Math.abs(n):Q??l,value:y===""?"":Math.abs(Number(y??n)),onChange:te,onBlur:H,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:N,...d,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),e.jsxRuntimeExports.jsx(t.NumberInput,{size:j??"sm",min:0,max:C<0?Math.abs(k??n):l,precision:0,value:p===""?"":Math.abs(Number(p??l)),onChange:_,onBlur:H,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:N,...d,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),R&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:j,fontWeight:"bold",value:C,onChange:M=>P(!1,M),isDisabled:w||N,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:R[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:R[1]})]})]})]})},$e=({tags:o,containerProps:n,...l})=>e.jsxRuntimeExports.jsx(t.HStack,{...n,children:o.map((x,h)=>e.jsxRuntimeExports.jsx(t.Tag,{...l,children:x},h))}),Be=new Ie.uFuzzy({}),ze=({action:o,quantumIconSrc:n})=>{const{getLabel:l}=le.useUiLabelContext(),x=s.useMemo(()=>({actionLowerCase:l("action").toLocaleLowerCase()}),[l]);return o.quantumOwned?e.jsxRuntimeExports.jsx(t.Tooltip,{label:`This ${x.actionLowerCase} is owned by Quantum`,"aria-label":"Quantum owned",children:e.jsxRuntimeExports.jsx(t.Box,{boxSize:"1.5em",borderRadius:"full",bg:"black",display:"flex",alignItems:"center",justifyContent:"center",children:e.jsxRuntimeExports.jsx(t.Image,{src:n,boxSize:"1em",alt:`Quantum-owned ${x.actionLowerCase}`})})}):null},Ue=(o,n)=>{if(!n||!n.trim().length)return o;const l=o.map(h=>h.name??"");return Be.filter(l,n)?.map(h=>o[h])??[]},qe=o=>!o||o.length===0?"None":o.map(n=>n.replace(/([A-Z])/g," $1").trim()).join(", "),Qe=(o,n)=>!n||n.length==0?o:o.filter(l=>l.useCases?.some(x=>n.includes(x.id))??!1),Le=({actions:o,totalActions:n,onCreate:l,onDelete:x,onEdit:h,onView:d,onSelected:j,onDuplicate:f,disableMultiSelect:i,disableDelete:u,disableEdit:R,disableCreate:N,hideUseCase:b=!0,tableProps:A,containerProps:v,quantumIconSrc:y="/favicon.ico"})=>{const[p,a]=s.useState(""),[m,C]=s.useState(),{getLabel:w}=le.useUiLabelContext(),k=s.useMemo(()=>({action:w("action"),actionPlural:w("action_plural"),actionLowerCase:w("action").toLocaleLowerCase(),actionPluralLowerCase:w("action_plural").toLocaleLowerCase()}),[w]),Q=s.useMemo(()=>{if(!o)return;const S=Ue(o,p);return b?S:Qe(S,m)},[o,p,m,b]),W=s.useCallback(()=>{if(!x)return;const P=o.filter(M=>M.selected&&!M.quantumOwned).map(M=>M.id);x(P)},[o,x]),O=s.useCallback(()=>{if(!f)return;const S=o.filter(P=>P.selected);f(S.map(P=>P.id)),j&&S.forEach(P=>j(P,!1))},[o,f,j]),H=s.useMemo(()=>o.some(S=>S.selected&&!S.quantumOwned),[o]),te=s.useMemo(()=>o.some(S=>S.selected),[o]),_=s.useMemo(()=>o.some(S=>S.selected&&S.quantumOwned),[o]);return e.jsxRuntimeExports.jsxs(t.Box,{...v,children:[e.jsxRuntimeExports.jsxs(t.Flex,{alignContent:"space-between",gap:4,children:[(l||x||f)&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mb:"1rem",gap:4,children:[l&&e.jsxRuntimeExports.jsxs(t.Button,{isDisabled:!l||N,colorScheme:"blackAlpha",backgroundColor:"gray.700",onClick:l,children:["Create New ",k.action]}),x&&!i&&e.jsxRuntimeExports.jsx(t.Tooltip,{label:_?H?`Quantum-owned ${k.actionPluralLowerCase} are selected and will be skipped`:`Selected ${k.actionPluralLowerCase} are quantum-owned and cannot be deleted`:void 0,shouldWrapChildren:!0,children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!H||!x||u,onClick:W,children:"Delete Selected"})}),f&&!i&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!te,onClick:O,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx(ke,{setSearch:a,actions:o,updateUseCases:C,hideUseCaseFilter:b})]}),e.jsxRuntimeExports.jsx(t.TableContainer,{mr:"2rem",overflowX:"hidden",...A,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 ",Q?.length??0," of"," ",n??o.length,")"]}),e.jsxRuntimeExports.jsx(t.Th,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Th,{children:"Sensor Locations"}),!b&&e.jsxRuntimeExports.jsx(t.Th,{children:"Use Case"}),e.jsxRuntimeExports.jsx(t.Th,{})]})}),e.jsxRuntimeExports.jsx(t.Tbody,{children:Q?.map(S=>e.jsxRuntimeExports.jsxs(t.Tr,{className:ye.cn("hover:bg-[#f7f7f7]",!i&&"cursor-pointer",S.selected&&"bg-gray-200"),onClick:()=>{i||j?.(S,!S.selected)},children:[e.jsxRuntimeExports.jsx(t.Td,{children:e.jsxRuntimeExports.jsxs(t.Flex,{children:[!i&&e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:S.selected?e.jsxRuntimeExports.jsx(Te.FaCheckSquare,{className:"text-blue-500"}):e.jsxRuntimeExports.jsx(Te.FaSquare,{className:"text-gray-400"})}),(S.quantumOwned||!h)&&d&&e.jsxRuntimeExports.jsx(t.Button,{ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:P=>{P.stopPropagation(),d(S.id)},children:"View"}),!S.quantumOwned&&h&&e.jsxRuntimeExports.jsx(t.Button,{isDisabled:R,ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:P=>{P.stopPropagation(),h(S.id)},children:"Edit"})]})}),e.jsxRuntimeExports.jsx(t.Td,{whiteSpace:"break-spaces",children:e.jsxRuntimeExports.jsxs(t.Flex,{align:"center",gap:2,children:[e.jsxRuntimeExports.jsx(ze,{action:S,quantumIconSrc:y}),S.name]})}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",whiteSpace:"break-spaces",children:qe(S.sensorLocations)}),!b&&e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:e.jsxRuntimeExports.jsx($e,{containerProps:{flexWrap:"wrap"},tags:S.useCases?.map(P=>P.name)??[]})})]},S.id))})]})})]})},We=({onSave:o,onCancel:n,onError:l,hideButtons:x=!1,setButtonDisabled:h,setButtonOnClick:d,quantumOwned:j})=>{const f=t.useToast(),{getLabel:i}=le.useUiLabelContext(),u=s.useMemo(()=>({singular:i("action"),plural:i("action_plural"),pluralLowerCase:i("action_plural").toLowerCase(),singularLowerCase:i("action").toLowerCase()}),[i]),[R,N]=s.useState("copy"),[b,A]=s.useState(""),[v,y]=s.useState([]),[p,a]=s.useState(!1),[m]=Z.useQuery({query:E.GET_GROUPS}),[C]=Z.useQuery({query:E.GET_ACTIONS_BY_GROUP,variables:{groupId:b},pause:!b}),[,w]=Z.useMutation(E.CREATE_ACTION),[,k]=Z.useMutation(E.CONVERT_ACTION_TO_QUANTUM_OWNED),Q=s.useMemo(()=>m.data?.groups?m.data.groups.map(c=>F.getFragmentData(E.GROUP_FRAGMENT,c)):[],[m.data]),W=s.useMemo(()=>C.data?C.data.actions.map(r=>{const T=F.getFragmentData(E.ACTION_FRAGMENT,r),L=F.getFragmentData(E.REPORT_FRAGMENT,T.reports),z=F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,T.categories),U=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,T.metadataGroups).map(Y=>({...Y,data:Y.data.map(K=>F.getFragmentData(E.METADATA_ITEM_FRAGMENT,K))}));return{...T,thresholds:F.getFragmentData(E.THRESHOLD_FRAGMENT,T.thresholds),reports:L.map(Y=>({...Y,thresholds:F.getFragmentData(E.THRESHOLD_FRAGMENT,Y.thresholds)})),categories:z,metadataGroups:U}}):[],[C.data]),O=s.useMemo(()=>W.filter(c=>v.includes(c.id)),[W,v]),H=s.useCallback(c=>{const r=c?.value||"";A(r),y([])},[]),te=s.useCallback(c=>{const r=c.map(T=>T.value);y(r)},[]),_=s.useCallback(async c=>{const r={...c,name:`${c.name} (Copy)`,description:c.description||void 0,instructionsPointOfInterest:c.instructionsPointOfInterest||void 0,instructionsMovementReport:c.instructionsMovementReport||void 0,laterality:c.laterality,activityKind:c.activityKind,sensorLocations:c.sensorLocations,thresholds:c.thresholds.map(L=>({...L,id:void 0})),categories:c.categories.map(L=>L.id),quantumOwned:j,metadataItemIds:c.metadataGroups.flatMap(L=>L.data.map(z=>z.id)).filter(L=>L!==void 0),reports:c.reports.map(L=>({...L,id:void 0,thresholds:L.thresholds.map(z=>({...z,id:void 0}))})),id:void 0},T=await w({fields:r});if(T.error)throw new Error(T.error.message);if(T.data?.createAction)return F.getFragmentData(E.ACTION_FRAGMENT,T.data.createAction);throw new Error("No action data returned")},[w,j]),S=s.useCallback(async c=>{const r=await k({id:c.id});if(r.error)throw new Error(r.error.message);if(r.data?.convertActionToQuantumOwned)return F.getFragmentData(E.ACTION_FRAGMENT,r.data.convertActionToQuantumOwned);throw new Error("No action data returned")},[k]),P=s.useCallback(async()=>{if(a(!0),!O.length){const c=new Error(`No ${u.pluralLowerCase} selected for ${R==="copy"?"copying":"converting"}`);l?.(c),a(!1);return}try{const c=[];let r=0;const T=R==="copy"?_:S,L=R==="copy"?"copy":"convert";for(const z of O)try{const ee=await T(z);c.push(ee)}catch(ee){console.error(`Failed to ${L} ${u.singularLowerCase} "${z.name}":`,ee),r++}if(c.length>0){const z=c.length,ee=O.length,U=R==="copy"?"copied":"converted",Y=R==="copy"?"copy":"convert";f({title:r>0?`Partial ${Y} completed`:`${u.plural} ${U} successfully`,description:r>0?`${z} of ${ee} ${u.pluralLowerCase} ${U} successfully`:`${z} ${z>1?u.pluralLowerCase:u.singularLowerCase} ${U} successfully`,status:r>0?"warning":"success",duration:3e3,isClosable:!0}),o?.(),A(""),y([])}else throw new Error(`Failed to ${L} any ${u.pluralLowerCase}`)}catch(c){const r=R==="copy"?"copy":"convert",T=c instanceof Error?c.message:`Failed to ${r} ${u.pluralLowerCase}`;f({title:`${R==="copy"?"Copy":"Convert"} failed`,description:T,status:"error",duration:5e3,isClosable:!0}),l?.(c instanceof Error?c:new Error(T))}finally{a(!1)}},[O,R,_,S,f,o,l,u]),M=s.useCallback(()=>{A(""),y([]),N("copy"),n?.()},[n]);s.useEffect(()=>{h&&h({cancelButton:!1,saveButton:O.length===0||p})},[O.length,p,h]),s.useEffect(()=>{d&&d({cancelButton:M,saveButton:P})},[d,M,P]);const B=s.useMemo(()=>Q.map(c=>({value:c.id,label:c.name})),[Q]),V=s.useMemo(()=>W.filter(c=>R==="copy"?!0:!c.quantumOwned).map(c=>({value:c.id,label:c.name,isQuantumOwned:c.quantumOwned})),[W,R]),q=m.fetching,se=C.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[j&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ae,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:R,onChange:c=>{N(c),y([])},children:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:6,children:[e.jsxRuntimeExports.jsx(t.Radio,{value:"copy",colorScheme:"blue",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"medium",children:["Copy ",u.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",u.plural.toLocaleLowerCase()," ","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.jsxs(t.Text,{fontWeight:"medium",children:["Convert to Quantum Owned ",u.singular]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Convert existing"," ",u.plural.toLocaleLowerCase()," to quantum-owned"]})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ae,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(ce.st,{placeholder:"Choose a group...",options:B,value:B.find(c=>c.value===b)||null,onChange:H,isLoading:q,isDisabled:q,isClearable:!0}),m.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: ",m.error.message]})]})]}),b&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsxs(ae,{children:["Select ",u.plural," to"," ",R==="copy"?"Copy":"Convert"]}),se?e.jsxRuntimeExports.jsxs(t.HStack,{children:[e.jsxRuntimeExports.jsx(t.Spinner,{size:"sm"}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Loading ",u.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(ce.st,{placeholder:`Choose ${u.pluralLowerCase} to ${R}...`,options:V,value:V.filter(c=>v.includes(c.value)),onChange:te,isDisabled:V.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(c,{context:r})=>e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",w:"100%",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(t.Text,{children:c.label}),r==="value"&&c.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),c.isQuantumOwned&&r==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),V.length===0&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:["No ",u.pluralLowerCase," found"]})]}),C.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load ",u.pluralLowerCase,":"," ",C.error.message]})]})]}),O.length>0&&e.jsxRuntimeExports.jsxs(t.Box,{p:4,bg:"gray.50",borderRadius:"md",children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"semibold",mb:3,children:O.length===1?`${u.singular} to ${R==="copy"?"Copy":"Convert"}:`:`${O.length} ${u.plural} to ${R==="copy"?"Copy":"Convert"}:`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[O.map((c,r)=>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:[r+1,". ",c.name]}),c.quantumOwned&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,fontSize:"sm",color:"gray.600",children:[c.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",c.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Type:"})," ",c.activityKind]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Laterality:"})," ",c.laterality]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Sensor Locations:"})," ",c.sensorLocations.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Thresholds:"})," ",c.thresholds.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Use Cases:"})," ",c.useCases.map(T=>T.name).join(", ")||"None"]})]})]},c.id)),O.length>1&&e.jsxRuntimeExports.jsx(t.Box,{w:"100%",p:2,bg:"blue.50",borderRadius:"md",border:"1px solid",borderColor:"blue.200",children:e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",fontWeight:"medium",color:"blue.800",children:["Total: ",O.length," ",u.pluralLowerCase," will be"," ",R==="copy"?"copied":"converted"]})})]})]}),!x&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:M,isDisabled:p,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:R==="copy"?"blue":"green",onClick:P,isDisabled:O.length===0||p,isLoading:p,loadingText:`${R==="copy"?"Copying":"Converting"}...`,children:[R==="copy"?"Copy":"Convert"," ",O.length===1?u.singular:`${O.length} ${u.plural}`]})]})]})})},He=({onSave:o,onCancel:n,onError:l,hideButtons:x=!1,setButtonDisabled:h,setButtonOnClick:d,quantumOwned:j})=>{const f=t.useToast(),{getLabel:i}=le.useUiLabelContext(),u=s.useMemo(()=>({singular:i("module"),plural:i("module_plural"),pluralLowerCase:i("module_plural").toLowerCase(),singularLowerCase:i("module").toLowerCase()}),[i]),R=s.useMemo(()=>({singular:i("action"),plural:i("action_plural"),pluralLowerCase:i("action_plural").toLowerCase(),singularLowerCase:i("action").toLowerCase()}),[i]),[N,b]=s.useState(""),[A,v]=s.useState([]),[y,p]=s.useState(!1),[a,m]=s.useState("copy"),[C]=Z.useQuery({query:E.GET_GROUPS}),[w]=Z.useQuery({query:E.GET_MODULES_BY_GROUP,variables:{groupId:N},pause:!N}),[,k]=Z.useMutation(E.CREATE_MODULE),[,Q]=Z.useMutation(E.UPDATE_MODULE),[,W]=Z.useMutation(E.CREATE_ACTION),[,O]=Z.useMutation(E.CONVERT_ACTION_TO_QUANTUM_OWNED),H=s.useMemo(()=>C.data?.groups?C.data.groups.map(r=>F.getFragmentData(E.GROUP_FRAGMENT,r)):[],[C.data]),te=s.useMemo(()=>w.data?.modules?F.getFragmentData(E.ACTION_MODULE_FRAGMENT,w.data?.modules).map(T=>{const L=F.getFragmentData(E.MODULE_ACTION_FRAGMENT,T.moduleActions);return{...T,moduleActions:L.map(z=>({...z,action:F.getFragmentData(E.ACTION_FRAGMENT,z.action)})),categories:F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,T.categories)}}):[],[w.data]),_=s.useMemo(()=>te.filter(r=>A.includes(r.id)),[te,A]),S=s.useCallback(r=>{const T=r?.value||"";b(T),v([])},[]),P=s.useCallback(r=>{const T=r.map(L=>L.value);v(T)},[]),M=s.useCallback(async()=>{if(p(!0),!_.length){p(!1);const r=new Error(`No modules selected for ${a==="convert"?"converting":"copying"}`);l?.(r);return}try{const r=[];let T=0;for(const L of _)try{let z=L.moduleActions.map(ee=>ee.actionId);if(j){const ee=L.moduleActions.map(K=>K.action),U=async K=>{if(a==="copy"){if(K.quantumOwned)return K;const ue=F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,K.categories),Re=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,K.metadataGroups).map(ie=>F.getFragmentData(E.METADATA_ITEM_FRAGMENT,ie.data).map(he=>he.id)).flat(),me=F.getFragmentData(E.REPORT_FRAGMENT,K.reports).map(ie=>({...ie,id:void 0,thresholds:F.getFragmentData(E.THRESHOLD_FRAGMENT,ie.thresholds).map(he=>({...he,id:void 0}))})),pe=F.getFragmentData(E.THRESHOLD_FRAGMENT,K.thresholds).map(ie=>({...ie,id:void 0})),Ee={...K,quantumOwned:!0,thresholds:pe,categories:ue?.map(ie=>ie.id),reports:me,metadataIds:Re,id:void 0},je=await W({fields:Ee});return je.error||!je.data?.createAction?null:F.getFragmentData(E.ACTION_FRAGMENT,je.data.createAction)}if(K.quantumOwned)return K;const xe=await O({id:K.id});return xe.error||!xe.data?.convertActionToQuantumOwned?null:F.getFragmentData(E.ACTION_FRAGMENT,xe.data.convertActionToQuantumOwned)};z=(await Promise.all(ee.map(U))).filter(K=>!!K).map(K=>K.id)}if(a==="convert"){const ee={name:L.name,description:L.description||void 0,actions:z,categories:L.categories.map(Y=>Y.id),quantumOwned:!0},U=await Q({id:L.id,input:ee});if(U.error)throw new Error(U.error.message);if(U.data?.updateModule){const Y=F.getFragmentData(E.ACTION_MODULE_FRAGMENT,U.data.updateModule);r.push(Y)}}else{const ee={name:`${L.name} (Copy)`,description:L.description||void 0,actions:z,categories:L.categories.map(Y=>Y.id),quantumOwned:j},U=await k({input:ee});if(U.error)throw new Error(U.error.message);if(U.data?.createModule){const Y=F.getFragmentData(E.ACTION_MODULE_FRAGMENT,U.data.createModule);r.push(Y)}}}catch(z){console.error(`Failed to ${a==="convert"?"convert":"copy"} module "${L.name}":`,z),T++}if(r.length>0){const L=r.length,z=_.length;f({title:T>0?`Partial ${a==="convert"?"convert":"copy"} completed`:`${u.plural} ${a==="convert"?"converted":"copied"} successfully`,description:T>0?`${L} of ${z} ${u.plural} ${a==="convert"?"converted":"copied"} successfully`:`${L} ${L>1?u.plural:u.singular} ${a==="convert"?"converted":"copied"} successfully`,status:T>0?"warning":"success",duration:3e3,isClosable:!0}),r.length>0&&o?.(),b(""),v([])}else throw new Error(`Failed to ${a==="convert"?"convert":"copy"} any modules`)}catch(r){const T=r instanceof Error?r.message:`Failed to ${a==="convert"?"convert":"copy"} modules`;f({title:a==="convert"?"Convert failed":"Copy failed",description:T,status:"error",duration:5e3,isClosable:!0}),l?.(r instanceof Error?r:new Error(T))}finally{p(!1)}},[_,k,Q,f,o,l,j,W,O,a,u]),B=s.useCallback(()=>{b(""),v([]),m("copy"),n?.()},[n]);s.useEffect(()=>{h&&h({cancelButton:!1,saveButton:_.length===0||y})},[_.length,y,h]),s.useEffect(()=>{d&&d({cancelButton:B,saveButton:M})},[d,B,M]);const V=s.useMemo(()=>H.map(r=>({value:r.id,label:r.name})),[H]),q=s.useMemo(()=>te.filter(r=>a==="copy"?!0:!r.quantumOwned).map(r=>({value:r.id,label:r.name,isQuantumOwned:r.quantumOwned})),[te,a]),se=C.fetching,c=w.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[j&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ae,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:a,onChange:r=>{m(r),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.jsxs(t.Text,{fontWeight:"medium",children:["Copy ",u.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",u.pluralLowerCase," based on selected ones"]})]})}),e.jsxRuntimeExports.jsx(t.Radio,{value:"convert",colorScheme:"green",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"medium",children:"Convert to Quantum Owned"}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Convert existing ",u.pluralLowerCase," to quantum-owned"]})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ae,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(ce.st,{placeholder:"Choose a group...",options:V,value:V.find(r=>r.value===N)||null,onChange:S,isLoading:se,isDisabled:se,isClearable:!0}),C.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",C.error.message]})]})]}),N&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ae,{children:a==="convert"?`Select ${u.plural} to Convert`:`Select ${u.plural} to Copy`}),c?e.jsxRuntimeExports.jsxs(t.HStack,{children:[e.jsxRuntimeExports.jsx(t.Spinner,{size:"sm"}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Loading ",u.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(ce.st,{placeholder:a==="convert"?`Choose ${u.pluralLowerCase} to convert...`:`Choose ${u.pluralLowerCase} to copy...`,options:q,value:q.filter(r=>A.includes(r.value)),onChange:P,isDisabled:q.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(r,{context:T})=>e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",w:"100%",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(t.Text,{children:r.label}),T==="value"&&r.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),r.isQuantumOwned&&T==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),q.length===0&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:["No ",u.pluralLowerCase," found in this group"]})]}),w.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 ",u.pluralLowerCase,":"," ",w.error.message]})]})]}),_.length>0&&e.jsxRuntimeExports.jsxs(t.Box,{p:4,bg:"gray.50",borderRadius:"md",children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"semibold",mb:3,children:_.length===1?`${u.singular} to ${a==="copy"?"Copy":"Convert"}`:`${_.length} ${u.plural} to ${a==="copy"?"Copy":"Convert"}`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[_.map((r,T)=>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:[T+1,". ",r.name]}),r.quantumOwned&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,fontSize:"sm",color:"gray.600",children:[r.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",r.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Activities:"})," ",r.moduleActions.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Categories:"})," ",r.categories.map(L=>L.name).join(", ")||"None"]})]})]},r.id)),_.length>1&&e.jsxRuntimeExports.jsx(t.Box,{w:"100%",p:2,bg:"blue.50",borderRadius:"md",border:"1px solid",borderColor:"blue.200",children:e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",fontWeight:"medium",color:"blue.800",children:["Total: ",_.length," ",u.pluralLowerCase," will be"," ",a==="copy"?"copied":"converted"]})}),j&&_.filter(r=>r.moduleActions.some(T=>!T.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 ${u.plural} will convert non QM-Owned ${R.plural} to QM-Owned ${R.plural}`:`Copying ${u.plural} with Non QM-Owned ${R.plural} will create corresponding QM-Owned ${R.plural}`})})]})]}),!x&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:B,isDisabled:y,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:a==="copy"?"blue":"green",onClick:M,isDisabled:_.length===0||y,isLoading:y,loadingText:`${a==="copy"?"Copying":"Converting"}...`,children:[a==="copy"?"Copy":"Convert"," ",_.length===1?u.singular:`${_.length} ${u.plural}`]})]})]})})},Fe=({name:o,setName:n,actions:l,selectedActionIds:x,setSelectedActionIds:h,availableCategories:d,selectedCategoryIds:j,setSelectedCategoryIds:f,description:i,setDescription:u,...R})=>{const N=t.useDisclosure(),b=s.useMemo(()=>l.map(m=>({...m,selected:x.includes(m.id)})),[l,x]),A=s.useMemo(()=>l.reduce((m,C)=>(m[C.id]=C,m),{}),[l]),v=s.useMemo(()=>x.map(m=>A[m]),[x,A]),y=s.useCallback((m,C)=>{h(C?[...x,m.id]:x.filter(w=>w!==m.id))},[x,h]),p=s.useCallback(m=>{n(m.target.value)},[n]),a=s.useCallback(m=>{u?.(m.target.value)},[u]);return e.jsxRuntimeExports.jsxs(t.Box,{...R,children:[e.jsxRuntimeExports.jsxs(t.HStack,{gap:"2rem",children:[e.jsxRuntimeExports.jsx(Ke,{name:o??"",onInputChange:p}),e.jsxRuntimeExports.jsx(Ye,{availableCategories:d,value:j,onChange:f})]}),e.jsxRuntimeExports.jsx(Je,{description:i??"",onInputChange:a}),e.jsxRuntimeExports.jsx(Xe,{value:v,onChange:h,onAdjustActivities:()=>N.onOpen()}),e.jsxRuntimeExports.jsxs(t.Modal,{isOpen:N.isOpen,onClose:N.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(Le,{actions:b,onSelected:y,disableCreate:!0,disableDelete:!0,tableProps:{height:"28rem",overflowY:"auto"}})}),e.jsxRuntimeExports.jsx(t.ModalFooter,{children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:N.onClose,isDisabled:x.length===0,children:"Done"})})]})]})]})},Ke=s.memo(({name:o,onInputChange:n})=>{const{getLabel:l}=le.useUiLabelContext(),x=l("module");return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(ae,{children:[x," Name"]}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. ACL RTP Test Battery",value:o,onChange:n,isRequired:!0})]})}),Ye=s.memo(({availableCategories:o,value:n,onChange:l})=>{const{getLabel:x}=le.useUiLabelContext(),h=x("module"),d=s.useMemo(()=>[...o,{id:"other",name:"Other"}],[o]),j=s.useMemo(()=>d.map(f=>({value:f.id,label:f.name})),[d]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(ae,{children:[h," Category"]}),e.jsxRuntimeExports.jsx(ce.st,{isDisabled:o.length===0,options:j,value:n.length===0?{value:"other",label:"Other"}:d.filter(f=>n.includes(f.id)).map(f=>({value:f.id,label:f.name}))[0],onChange:f=>l(f?[f.value]:[]),placeholder:"Select category"})]})}),Je=s.memo(({description:o,onInputChange:n})=>{const{getLabel:l}=le.useUiLabelContext(),x=l("module");return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(ae,{children:e.jsxRuntimeExports.jsxs("span",{children:["Description",e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",children:["Briefly describe the objective of this"," ",x.toLocaleLowerCase(),". Max 40 words."]})]})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. Assess readiness to return to play post-ACL reconstruction",value:o,onChange:n})]})}),Xe=s.memo(({value:o,onChange:n,onAdjustActivities:l})=>{const{getLabel:x}=le.useUiLabelContext(),h=s.useMemo(()=>({module:x("module"),moduleLowerCase:x("module").toLocaleLowerCase(),action:x("action"),actionPlural:x("action_plural"),actionPluralLowerCase:x("action_plural").toLocaleLowerCase()}),[x]),d=s.useMemo(()=>o.map(j=>({id:j.id,name:j.name})),[o]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(t.HStack,{justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(ae,{children:e.jsxRuntimeExports.jsxs("span",{children:[h.actionPlural,e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",children:["Drag and drop to reorder the ",h.actionPluralLowerCase," in this ",h.moduleLowerCase,"."]})]})}),e.jsxRuntimeExports.jsxs(t.Button,{size:"sm",variant:"solid",colorScheme:"blue",onClick:l,children:["Add / Remove ",h.actionPlural]})]}),d.length===0?e.jsxRuntimeExports.jsx(t.VStack,{children:e.jsxRuntimeExports.jsxs(t.Text,{color:"gray.500",fontSize:"lg",mb:"4rem",mt:"4rem",children:["No ",h.actionPluralLowerCase," selected for this"," ",h.moduleLowerCase,".",e.jsxRuntimeExports.jsxs(t.Button,{ml:"0.5em",size:"sm",variant:"link",colorScheme:"blue",onClick:l,children:["Add ",h.actionPluralLowerCase,"."]})]})}):e.jsxRuntimeExports.jsx(De,{value:d,onChange:j=>{const f=j(d);n(f.map(i=>i.id))}})]})}),Oe=({value:o,onChange:n,forceKind:l,disableRemove:x,disableKind:h,isDisabled:d,lockRanges:j,...f})=>{const i=s.useMemo(()=>[...o].sort((b,A)=>{const v=de.availablePlanes.indexOf(b.plane),y=de.availablePlanes.indexOf(A.plane);return v-y}),[o]),u=s.useCallback(b=>"segment"in b.id?re.getSegmentNameWithPlane(b.id.segment,b.plane,!0)??"Unknown":re.getJointNameWithPlane(b.id.joint,b.plane,!0)??"Unknown",[]),R=s.useCallback((b,A)=>{const v=i.findIndex(p=>p.id===A.id&&p.plane===A.plane);let y=[...i];l&&(A={...A,kind:l}),y[v]=A,j&&(y=y.map(p=>({...p,min:A.min,max:A.max}))),n(y)},[n,i,l,j]),N=s.useCallback(b=>{const A=i.filter(v=>v.id!==b.id||v.plane!==b.plane);n(A)},[n,i]);return e.jsxRuntimeExports.jsx(t.VStack,{alignItems:"flex-start",overflowY:"auto",...f,children:i.map((b,A)=>e.jsxRuntimeExports.jsx(Ze,{label:u(b),parameter:b,onChange:v=>R(A,v),onRemove:x||d?void 0:()=>N(b),forceKind:l,disableKind:h||d,isDisabled:d},`${JSON.stringify(b.id)}-${b.plane}`))})},Ze=({label:o,parameter:n,onChange:l,onRemove:x,forceKind:h,disableKind:d,isDisabled:j})=>{const f=s.useCallback(R=>"joint"in n.id?re.getJointAngleDirectionName(n.id.joint,n.plane,R<0?-1:1):re.getSegmentAngleDirectionName(n.id.segment,n.plane,R<0?-1:1),[n]),{min:i,max:u}="joint"in n.id?re.getNormativeJointRange(n.id.joint,n.plane):{min:-180,max:180};return e.jsxRuntimeExports.jsxs(t.VStack,{borderRadius:"md",p:2,px:4,bg:"gray.100",w:"100%",overflow:"hidden",flexShrink:"0",children:[e.jsxRuntimeExports.jsxs(t.HStack,{w:"100%",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",flex:1,textTransform:"capitalize",fontWeight:"semibold",children:o}),n.sensorOnly&&e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor Only"}),x&&!j&&e.jsxRuntimeExports.jsx(t.IconButton,{size:"xs",variant:"ghost","aria-label":"delete",icon:e.jsxRuntimeExports.jsx(t.Icon,{as:Te.FaTrash}),onClick:x}),!h&&e.jsxRuntimeExports.jsx(Ge,{selectedItem:n?.kind??I.ThresholdKind.Limit,onChange:({value:R})=>l({...n,kind:R}),isDisabled:d||j,buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:I.ThresholdKind.Limit,label:"limit"},{value:I.ThresholdKind.Target,label:"target"}]})]}),e.jsxRuntimeExports.jsx(Pe,{w:"100%",size:"xs",min:i,max:u,zeroMarker:!0,value:[n.min,n.max],onChange:R=>l({...n,min:R[0],max:R[1]}),formatValue:R=>`${Math.abs(R)}°`,valueLabel:R=>f(R)??"",positiveNegativeLabels:f(0)?[f(-1)??"",f(1)??""]:void 0,isDisabled:j})]})},Ce=(o,n)=>"segment"in o&&"segment"in n&&o.segment===n.segment||"joint"in o&&"joint"in n&&o.joint===n.joint,Me=({options:o,value:n,onChange:l,forceKind:x,singleValue:h,singleValueSideless:d,editOnly:j,disableKind:f,maxParameters:i,...u})=>{const R=d?2:i,N=s.useMemo(()=>{const p=new Map;return o.forEach(a=>{const m="joint"in a.id;let C,w;if(m?(C=re.getJointNameWithPlane(a.id.joint,a.plane,!0)??"Unknown",w=`joint:${a.id.joint}`):(C=re.getSegmentNameWithPlane(a.id.segment,a.plane,!0)??"Unknown",w=`segment:${a.id.segment}`),!p.has(w)){const Q=m?re.getPartName(a.id.joint)??"Unknown Joint":re.getPartName(a.id.segment)??"Unknown Segment";p.set(w,{label:Q,options:[]})}p.get(w).options.push({label:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:2,justify:"space-between",w:"100%",pl:3,children:[e.jsxRuntimeExports.jsx(t.Text,{children:C}),a.sensorOnly&&e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor Only"})]}),value:a.id,plane:a.plane,sensorOnly:a.sensorOnly})}),Array.from(p.values())},[o]),b=s.useMemo(()=>{if(!d||n.length===0)return N;const p=n[0];return N.map(a=>({...a,options:a.options.filter(m=>de.getAnalysisPartIdNoSide(m.value)===de.getAnalysisPartIdNoSide(p.id)&&m.plane===p.plane)})).filter(a=>a.options.length>0)},[N,n,d]),A=s.useMemo(()=>N.flatMap(a=>a.options).filter(a=>n.some(m=>Ce(m.id,a.value)&&m.plane===a.plane)),[N,n]),v=s.useCallback((p,a)=>{if(!a)return!0;const m=a.toLowerCase().split(" ").join(""),C=p.data;if(!C||!C.value)return!1;const w=C.value.joint??C.value.segment;return!w||typeof w!="string"?!1:w.toLowerCase().includes(m)||C.plane&&C.plane.toLowerCase().includes(m)},[]),y=s.useCallback(p=>{const a=p.map(m=>{const C=n.find(O=>Ce(O.id,m.value)&&O.plane===m.plane),w=o.find(O=>Ce(O.id,m.value)&&O.plane===m.plane),k=d?n.find(O=>de.getAnalysisPartIdNoSide(O.id)===de.getAnalysisPartIdNoSide(m.value)&&O.plane===m.plane):void 0,Q=k&&!C?k.min:w&&w.min?w.min:0,W=k&&!C?k.max:w&&w.max?w.max:0;return C??{id:m.value,plane:m.plane,min:Q,max:W,sensorOnly:m.sensorOnly,kind:x??I.ThresholdKind.Limit}});l(a)},[l,n,o,x,d]);return s.useEffect(()=>{const p=n.filter(a=>o.some(m=>Ce(m.id,a.id)&&m.plane===a.plane));p.length!==n.length&&l(p)},[o,l,n]),e.jsxRuntimeExports.jsxs(t.Box,{...u,children:[e.jsxRuntimeExports.jsx(ce.st,{isMulti:!h,placeholder:n.length?`${n.length} selected`:"Search...",value:A,isDisabled:j||A.length>=(R??1/0),onChange:p=>Array.isArray(p)?y([...p]):y(p!==null?[p]:[]),options:b,controlShouldRenderValue:!1,formatOptionLabel:p=>p.label,filterOption:v,isSearchable:!0}),e.jsxRuntimeExports.jsx(Oe,{marginTop:2,maxH:"28rem",value:n,onChange:l,forceKind:x,disableKind:f,isDisabled:j,lockRanges:d})]})},Ae=o=>{switch(o){case I.SensorLocation.Thorax:return"Thorax";case I.SensorLocation.CenterBack:return"Center Back";case I.SensorLocation.Pelvis:return"Pelvis";case I.SensorLocation.LeftThigh:return"Left Thigh";case I.SensorLocation.RightThigh:return"Right Thigh";case I.SensorLocation.LeftShank:return"Left Shank";case I.SensorLocation.RightShank:return"Right Shank";case I.SensorLocation.LeftFoot:return"Left Foot";case I.SensorLocation.RightFoot:return"Right Foot";case I.SensorLocation.LeftUpperArm:return"Left Upper Arm";case I.SensorLocation.RightUpperArm:return"Right Upper Arm";case I.SensorLocation.LeftForearm:return"Left Forearm";case I.SensorLocation.RightForearm:return"Right Forearm";case I.SensorLocation.Head:return"Head"}},Ve=o=>{switch(o){case I.ReportKind.GeneralActivity:return"General Activity";case I.ReportKind.MovementCoordination:return"Movement Coordination";case I.ReportKind.PointOfInterest:return"Point of Interest";case I.ReportKind.Range:return"Range";case I.ReportKind.StabilityBalance:return"Stability Balance"}},et=({id:o,onError:n,onCancel:l,onSave:x,hideButtons:h,setButtonOnClick:d,setButtonDisabled:j,quantumOwned:f,isView:i})=>{const u=Z.useClient(),[{fetching:R},N]=Z.useMutation(E.CREATE_ACTION),[{fetching:b},A]=Z.useMutation(E.UPDATE_ACTION),[{data:v}]=Z.useQuery({query:E.GET_ACTION_BY_ID,variables:{id:o??""},pause:!o}),y=s.useMemo(()=>{const g=F.getFragmentData(E.ACTION_FRAGMENT,v?.getActionById);if(!g)return null;const D=F.getFragmentData(E.REPORT_FRAGMENT,g.reports).map($=>({...$,thresholds:F.getFragmentData(E.THRESHOLD_FRAGMENT,$.thresholds)}));return{...g,thresholds:F.getFragmentData(E.THRESHOLD_FRAGMENT,g.thresholds),reports:D}},[v]),p=R||b,a=!!y&&!!o,{getLabel:m}=le.useUiLabelContext(),C=s.useMemo(()=>({action:m("action")}),[m]),w=s.useMemo(()=>[{key:"module_category",label:"Link Category",multi:!0},{key:"activity_type",label:`${C.action} Type`,multi:!1},{key:"session_type",label:"Session Type",multi:!0},{key:"body_region",label:"Body Region",multi:!0},{key:"sport",label:"Sport",multi:!0}],[C.action]),[k,Q]=s.useState(""),[W,O]=s.useState(""),[H,te]=s.useState(""),[_,S]=s.useState(""),[P,M]=s.useState([]),[B,V]=s.useState({}),[q,se]=s.useState(null),[c,r]=s.useState([]),[T,L]=s.useState([]),[z,ee]=s.useState(""),[U,Y]=s.useState([]),K=le.useAllPartParameters(),xe=s.useMemo(()=>K.filter(g=>g.sensorOnly),[K]),ue=s.useMemo(()=>{const g=[{label:"General Activity",value:I.ReportKind.GeneralActivity},{label:"Movement Coordination",value:I.ReportKind.MovementCoordination},{label:"Point of Interest",value:I.ReportKind.PointOfInterest},{label:"Range",value:I.ReportKind.Range},{label:"Stability Balance",value:I.ReportKind.StabilityBalance}],G=U.map(D=>D.kind);return g.filter(D=>!G.includes(D.value))},[U]),ge=k.length>0,[Re,we]=s.useState({});s.useEffect(()=>{const g=w.map(G=>u.query(E.GET_METADATA_BY_KEY,{key:G.key}));Promise.all(g).then(G=>{const D={};G.forEach($=>{if($.error||!$.data)return;const J=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,$.data.getMetadataByKey),X=F.getFragmentData(E.METADATA_ITEM_FRAGMENT,J.data);D[J.key]=X.map(oe=>({label:oe.label||oe.value,value:oe.value,id:oe.id}))}),V(D)})},[u,w]),s.useEffect(()=>{if(y){const G=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,y.metadataGroups).map(J=>J.data.map(X=>F.getFragmentData(E.METADATA_ITEM_FRAGMENT,X).id)),D=y.reports.map(J=>({id:J.id,instructions:J.instructions??"",kind:J.reportKind,parameters:J.thresholds.map(X=>({id:{[X.partKind]:X.partId},kind:X.kind,min:X.min,max:X.max,plane:X.partDimension,oldId:X.id,sensorOnly:xe.some(oe=>{const ve=oe.id[X.partKind];return ve?ve===X.partId&&oe.plane===X.partDimension:!1})})),sensorLocations:J.sensorLocations})),$={name:y.name,description:y.description||"",cameraPlacement:y.cameraPlacement||"",videoLink:y.videoLink||"",metadataIds:G.flat(),reports:D};Q($.name),O($.description),te($.cameraPlacement),S($.videoLink),M($.metadataIds),Y(D),we($)}},[y]);const me=s.useMemo(()=>JSON.stringify(Re)!==JSON.stringify({name:k,description:W,cameraPlacement:H,videoLink:_,metadataIds:P,reports:U}),[Re,k,W,H,_,P,U]),pe=s.useCallback(()=>{const g={name:k,description:W,cameraPlacement:H,videoLink:_,metadataItemIds:P,laterality:I.ActionLaterality.Either,quantumOwned:f,sessionType:[],thresholds:[],reports:U.map(D=>({id:D.isNew?void 0:D.id,reportKind:D.kind,sensorLocations:D.sensorLocations,instructions:D.instructions,thresholds:D.parameters.map($=>({id:$.oldId,kind:$.kind,min:$.min,max:$.max,partKind:"joint"in $.id?"joint":"segment",partId:"joint"in $.id?$.id.joint:$.id.segment,partDimension:$.plane}))}))};let G;a&&o?G=A({id:o,fields:g}):G=N({fields:g}),G.then(({error:D})=>{D?n(D):x()})},[f,N,A,o,k,W,H,_,P,U,a,x,n]);s.useEffect(()=>{j&&j({cancelButton:p,saveButton:i?!0:p||!ge||!me})},[p,j,ge,me,i]),s.useEffect(()=>{d&&d({cancelButton:l,saveButton:i?()=>{}:pe})},[d,l,pe,i]);const Ee=s.useCallback(g=>{const G=re.getSuggestedSensorLocations(g.map(D=>"joint"in D.id?D.id.joint:D.id.segment));L(G)},[]);s.useEffect(()=>{Ee(c)},[c,Ee]);const je=s.useCallback(()=>{if(!q)return;const g={id:Date.now().toString(),kind:q,parameters:c,sensorLocations:T,instructions:z,isNew:!0};Y(G=>[...G,g]),se(null),r([]),L([]),ee("")},[q,c,T,z]),ie=s.useCallback(g=>{Y(G=>G.filter(D=>D.id!==g))},[]),he=(g,G)=>{const D=w.find(J=>J.key===g);if(!D)return;const $=D.multi?(G??[]).map(J=>J.id):G?[G.id]:[];M(J=>[...J.filter(oe=>Object.values(B).flat().find(fe=>fe.id===oe)&&!Object.keys(B).find(fe=>B[fe]?.some(Ne=>Ne.id===oe&&fe===g))),...$])};return e.jsxRuntimeExports.jsxs(t.VStack,{spacing:4,w:"full",align:"stretch",children:[e.jsxRuntimeExports.jsxs(t.Tabs,{children:[e.jsxRuntimeExports.jsxs(t.TabList,{children:[e.jsxRuntimeExports.jsx(t.Tab,{children:"Basic Information"}),e.jsxRuntimeExports.jsx(t.Tab,{children:"Reports"})]}),e.jsxRuntimeExports.jsxs(t.TabPanels,{children:[e.jsxRuntimeExports.jsx(t.TabPanel,{px:0,children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:k,onChange:g=>Q(g.target.value),type:"text",placeholder:"i.e. Lunge & Return",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Camera Placement"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:H,onChange:g=>te(g.target.value),rows:2,placeholder:"(optional) Describe camera setup, placement, angles",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Video Link"}),e.jsxRuntimeExports.jsx(t.Input,{value:_,onChange:g=>S(g.target.value),type:"url",placeholder:"(optional) https://...",isDisabled:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Description"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:W,onChange:g=>O(g.target.value),rows:2,placeholder:"(optional) Describe how to perform the test or exercise",isDisabled:i})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(ne,{children:"Metadata Tags"}),w.map(g=>e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:g.label}),e.jsxRuntimeExports.jsx(ce.st,{isMulti:g.multi,value:B[g.key]?.filter(G=>P.includes(G.id)),onChange:G=>{he(g.key,G)},options:B[g.key],placeholder:`Select ${g.multi?"one or more":"one"} ${g.label.toLowerCase()}`,isDisabled:i,isClearable:g.multi})]},g.key))]})]})}),e.jsxRuntimeExports.jsx(t.TabPanel,{px:0,children:e.jsxRuntimeExports.jsxs("div",{className:ye.cn("grid grid-cols-1 gap-6",!i&&"md:grid-cols-2"),children:[e.jsxRuntimeExports.jsxs("div",{className:ye.cn("space-y-4",i&&"hidden"),children:[e.jsxRuntimeExports.jsx(ne,{children:"Add New Report"}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Report Kind"}),ue.length===0?e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",p:2,children:"All report kinds have been used. Remove an existing report to add a new one."}):e.jsxRuntimeExports.jsx(ce.st,{value:q?ue.find(g=>g.value===q):null,onChange:g=>se(g?.value||null),options:ue,placeholder:"Select report kind...",isDisabled:i,isClearable:!0})]}),q!==I.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(Me,{options:K,value:c,onChange:r,editOnly:i})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Suggested Sensor Locations"}),e.jsxRuntimeExports.jsx(t.Input,{value:T.map(g=>Ae(g)).join(", "),placeholder:"Auto-filled based on parameters...",isDisabled:!0})]})]}),q===I.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:z,onChange:g=>ee(g.target.value),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:i})]}),e.jsxRuntimeExports.jsx("div",{className:"w-full flex justify-end",children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:je,isDisabled:!q||i||ue.length===0||q!==I.ReportKind.PointOfInterest&&c.length===0,children:"Add Report"})})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(ne,{children:"Configured Reports"}),U.length===0?e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.500",children:"No reports created yet"}):e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:U.map(g=>e.jsxRuntimeExports.jsxs("div",{className:"p-3 border border-gray-200 rounded-md bg-gray-50",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex justify-between items-start mb-2",children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"semibold",children:Ve(g.kind)}),!i&&e.jsxRuntimeExports.jsx(t.Button,{size:"xs",colorScheme:"red",variant:"ghost",onClick:()=>ie(g.id),children:"Remove"})]}),g.kind===I.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:g.instructions,onChange:G=>Y(D=>D.map($=>$.id===g.id?{...$,instructions:G.target.value}:$)),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:i})]}),g.kind!==I.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsx(Me,{options:K,value:g.parameters,onChange:G=>{const D=G.map(J=>J.id.joint??J.id.segment),$=re.getSuggestedSensorLocations(D);Y(J=>J.map(X=>X.id===g.id?{...X,parameters:G,sensorLocations:$}:X))},editOnly:i}),g.kind!==I.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",mt:2,children:["Sensors:"," ",g.sensorLocations.map(G=>Ae(G)).join(", ")]})]},g.id))})]})]})})]})]}),e.jsxRuntimeExports.jsx(t.HStack,{justify:"end",className:ye.cn((h||i)&&"!hidden"),children:e.jsxRuntimeExports.jsxs(t.ButtonGroup,{gap:4,children:[e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:p,onClick:l,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:p||!ge||!me,isLoading:p,onClick:pe,children:"Save changes"})]})})]})},ne=({children:o})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:o}),tt=({id:o,onCancel:n,onSave:l,onError:x,hideButtons:h,quantumOwned:d,setButtonOnClick:j,setButtonDisabled:f})=>{const[{data:i}]=Z.useQuery({query:d?E.GET_QUANTUM_OWNED_ACTIONS:E.GET_ACTIONS}),[{data:u}]=Z.useQuery({query:E.GET_MODULE_BY_ID,variables:{id:o},pause:!o}),[{data:R}]=Z.useQuery({query:E.GET_ALL_MODULE_CATEGORIES}),N=F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,R?.moduleCategories),[{fetching:b},A]=Z.useMutation(E.UPDATE_MODULE),[{fetching:v},y]=Z.useMutation(E.CREATE_MODULE),p=F.getFragmentData(E.ACTION_FRAGMENT,d?i?.quantumOwnedActions:i?.actions)??[],a=F.getFragmentData(E.ACTION_MODULE_FRAGMENT,u?.module),m=F.getFragmentData(E.MODULE_ACTION_FRAGMENT,a?.moduleActions)??[],[C,w]=s.useState([...m.map(S=>S.actionId)??[]]),[k,Q]=s.useState(a?.name??""),[W,O]=s.useState([]),[H,te]=s.useState(a?.description??"");s.useEffect(()=>{a&&(w(m.map(S=>S.actionId)),Q(a.name),te(a.description??""),O(a.categories.map(S=>F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,S).id)??[]))},[a,m]);const _=s.useCallback(()=>{let S;const P={actions:C,name:k,categories:W.filter(M=>M!=="other"),description:H,quantumOwned:d};a?S=A({id:a.id,input:P}):S=y({input:P}),S.then(({error:M})=>{M?x(M):l()})},[y,A,C,k,H,W,a,l,x,d]);return s.useEffect(()=>{f&&f({cancelButton:b||v,saveButton:b||v||!k||H.trim().split(/\s+/).filter(Boolean).length>40})},[f,b,v,C,k,H]),s.useEffect(()=>{j&&j({cancelButton:n,saveButton:_})},[j,n,_]),e.jsxRuntimeExports.jsxs(t.Box,{width:"100%",children:[e.jsxRuntimeExports.jsx(Fe,{name:k,setName:Q,actions:p,selectedActionIds:C,setSelectedActionIds:w,availableCategories:N??[],selectedCategoryIds:W,setSelectedCategoryIds:O,description:H,setDescription:te}),!h&&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:b||v,onClick:n,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:b||v||!k||H.trim().split(/\s+/).filter(Boolean).length>40,isLoading:b||v,onClick:_,children:"Save"})]})})]})};exports.ActivityList=Le;exports.CopyActivityForm=We;exports.CopyModuleForm=He;exports.ModuleForm=Fe;exports.ParameterEditList=Oe;exports.ParameterEditSelect=Me;exports.UpsertActivityForm=et;exports.UpsertModuleForm=tt;
|
package/dist/components.js
CHANGED
|
@@ -186,7 +186,7 @@ const wn = ({
|
|
|
186
186
|
w(([ee, U]) => [z.toString(), U]);
|
|
187
187
|
},
|
|
188
188
|
[w, u]
|
|
189
|
-
),
|
|
189
|
+
), $ = P(
|
|
190
190
|
(L) => {
|
|
191
191
|
const z = L === "" || isNaN(Number(L)) ? L : Ge(Number(L), b);
|
|
192
192
|
w(([ee, U]) => [ee, z.toString()]);
|
|
@@ -342,7 +342,7 @@ const wn = ({
|
|
|
342
342
|
max: b < 0 ? Math.abs(k ?? t) : a,
|
|
343
343
|
precision: 0,
|
|
344
344
|
value: h === "" ? "" : Math.abs(Number(h ?? a)),
|
|
345
|
-
onChange:
|
|
345
|
+
onChange: $,
|
|
346
346
|
onBlur: K,
|
|
347
347
|
borderWidth: 1,
|
|
348
348
|
borderRadius: 3,
|
|
@@ -463,7 +463,7 @@ const wn = ({
|
|
|
463
463
|
return;
|
|
464
464
|
const C = n.filter((E) => E.selected);
|
|
465
465
|
j(C.map((E) => E.id)), m && C.forEach((E) => m(E, !1));
|
|
466
|
-
}, [n, j, m]), K = T(() => n.some((C) => C.selected && !C.quantumOwned), [n]), se = T(() => n.some((C) => C.selected), [n]),
|
|
466
|
+
}, [n, j, m]), K = T(() => n.some((C) => C.selected && !C.quantumOwned), [n]), se = T(() => n.some((C) => C.selected), [n]), $ = T(() => n.some((C) => C.selected && C.quantumOwned), [n]);
|
|
467
467
|
return /* @__PURE__ */ e.jsxs(ne, { ...w, children: [
|
|
468
468
|
/* @__PURE__ */ e.jsxs(ye, { alignContent: "space-between", gap: 4, children: [
|
|
469
469
|
(a || d || j) && /* @__PURE__ */ e.jsxs(Le, { mb: "1rem", gap: 4, children: [
|
|
@@ -483,7 +483,7 @@ const wn = ({
|
|
|
483
483
|
d && !r && /* @__PURE__ */ e.jsx(
|
|
484
484
|
Ve,
|
|
485
485
|
{
|
|
486
|
-
label:
|
|
486
|
+
label: $ ? K ? `Quantum-owned ${k.actionPluralLowerCase} are selected and will be skipped` : `Selected ${k.actionPluralLowerCase} are quantum-owned and cannot be deleted` : void 0,
|
|
487
487
|
shouldWrapChildren: !0,
|
|
488
488
|
children: /* @__PURE__ */ e.jsx(
|
|
489
489
|
V,
|
|
@@ -660,7 +660,7 @@ const wn = ({
|
|
|
660
660
|
y(s);
|
|
661
661
|
},
|
|
662
662
|
[]
|
|
663
|
-
),
|
|
663
|
+
), $ = P(
|
|
664
664
|
async (i) => {
|
|
665
665
|
const s = {
|
|
666
666
|
...i,
|
|
@@ -719,7 +719,7 @@ const wn = ({
|
|
|
719
719
|
try {
|
|
720
720
|
const i = [];
|
|
721
721
|
let s = 0;
|
|
722
|
-
const v = x === "copy" ?
|
|
722
|
+
const v = x === "copy" ? $ : C, O = x === "copy" ? "copy" : "convert";
|
|
723
723
|
for (const B of N)
|
|
724
724
|
try {
|
|
725
725
|
const te = await v(B);
|
|
@@ -758,7 +758,7 @@ const wn = ({
|
|
|
758
758
|
}, [
|
|
759
759
|
N,
|
|
760
760
|
x,
|
|
761
|
-
|
|
761
|
+
$,
|
|
762
762
|
C,
|
|
763
763
|
j,
|
|
764
764
|
n,
|
|
@@ -1067,7 +1067,7 @@ const wn = ({
|
|
|
1067
1067
|
v.categories
|
|
1068
1068
|
)
|
|
1069
1069
|
};
|
|
1070
|
-
}) : [], [M.data]),
|
|
1070
|
+
}) : [], [M.data]), $ = T(() => se.filter(
|
|
1071
1071
|
(s) => I.includes(s.id)
|
|
1072
1072
|
), [se, I]), C = P(
|
|
1073
1073
|
(s) => {
|
|
@@ -1082,7 +1082,7 @@ const wn = ({
|
|
|
1082
1082
|
},
|
|
1083
1083
|
[]
|
|
1084
1084
|
), L = P(async () => {
|
|
1085
|
-
if (h(!0),
|
|
1085
|
+
if (h(!0), !$.length) {
|
|
1086
1086
|
h(!1);
|
|
1087
1087
|
const s = new Error(
|
|
1088
1088
|
`No modules selected for ${o === "convert" ? "converting" : "copying"}`
|
|
@@ -1093,7 +1093,7 @@ const wn = ({
|
|
|
1093
1093
|
try {
|
|
1094
1094
|
const s = [];
|
|
1095
1095
|
let v = 0;
|
|
1096
|
-
for (const O of
|
|
1096
|
+
for (const O of $)
|
|
1097
1097
|
try {
|
|
1098
1098
|
let B = O.moduleActions.map((te) => te.actionId);
|
|
1099
1099
|
if (m) {
|
|
@@ -1198,7 +1198,7 @@ const wn = ({
|
|
|
1198
1198
|
), v++;
|
|
1199
1199
|
}
|
|
1200
1200
|
if (s.length > 0) {
|
|
1201
|
-
const O = s.length, B =
|
|
1201
|
+
const O = s.length, B = $.length;
|
|
1202
1202
|
j({
|
|
1203
1203
|
title: v > 0 ? `Partial ${o === "convert" ? "convert" : "copy"} completed` : `${l.plural} ${o === "convert" ? "converted" : "copied"} successfully`,
|
|
1204
1204
|
description: v > 0 ? `${O} of ${B} ${l.plural} ${o === "convert" ? "converted" : "copied"} successfully` : `${O} ${O > 1 ? l.plural : l.singular} ${o === "convert" ? "converted" : "copied"} successfully`,
|
|
@@ -1223,7 +1223,7 @@ const wn = ({
|
|
|
1223
1223
|
h(!1);
|
|
1224
1224
|
}
|
|
1225
1225
|
}, [
|
|
1226
|
-
|
|
1226
|
+
$,
|
|
1227
1227
|
k,
|
|
1228
1228
|
Q,
|
|
1229
1229
|
j,
|
|
@@ -1240,9 +1240,9 @@ const wn = ({
|
|
|
1240
1240
|
ce(() => {
|
|
1241
1241
|
p && p({
|
|
1242
1242
|
cancelButton: !1,
|
|
1243
|
-
saveButton:
|
|
1243
|
+
saveButton: $.length === 0 || y
|
|
1244
1244
|
});
|
|
1245
|
-
}, [
|
|
1245
|
+
}, [$.length, y, p]), ce(() => {
|
|
1246
1246
|
c && c({
|
|
1247
1247
|
cancelButton: z,
|
|
1248
1248
|
saveButton: L
|
|
@@ -1362,10 +1362,10 @@ const wn = ({
|
|
|
1362
1362
|
] })
|
|
1363
1363
|
] })
|
|
1364
1364
|
] }),
|
|
1365
|
-
|
|
1366
|
-
/* @__PURE__ */ e.jsx(S, { fontWeight: "semibold", mb: 3, children:
|
|
1365
|
+
$.length > 0 && /* @__PURE__ */ e.jsxs(ne, { p: 4, bg: "gray.50", borderRadius: "md", children: [
|
|
1366
|
+
/* @__PURE__ */ e.jsx(S, { fontWeight: "semibold", mb: 3, children: $.length === 1 ? `${l.singular} to ${o === "copy" ? "Copy" : "Convert"}` : `${$.length} ${l.plural} to ${o === "copy" ? "Copy" : "Convert"}` }),
|
|
1367
1367
|
/* @__PURE__ */ e.jsxs(le, { align: "start", spacing: 3, children: [
|
|
1368
|
-
|
|
1368
|
+
$.map((s, v) => /* @__PURE__ */ e.jsxs(
|
|
1369
1369
|
ne,
|
|
1370
1370
|
{
|
|
1371
1371
|
w: "100%",
|
|
@@ -1413,7 +1413,7 @@ const wn = ({
|
|
|
1413
1413
|
},
|
|
1414
1414
|
s.id
|
|
1415
1415
|
)),
|
|
1416
|
-
|
|
1416
|
+
$.length > 1 && /* @__PURE__ */ e.jsx(
|
|
1417
1417
|
ne,
|
|
1418
1418
|
{
|
|
1419
1419
|
w: "100%",
|
|
@@ -1424,7 +1424,7 @@ const wn = ({
|
|
|
1424
1424
|
borderColor: "blue.200",
|
|
1425
1425
|
children: /* @__PURE__ */ e.jsxs(S, { fontSize: "sm", fontWeight: "medium", color: "blue.800", children: [
|
|
1426
1426
|
"Total: ",
|
|
1427
|
-
|
|
1427
|
+
$.length,
|
|
1428
1428
|
" ",
|
|
1429
1429
|
l.pluralLowerCase,
|
|
1430
1430
|
" will be",
|
|
@@ -1433,7 +1433,7 @@ const wn = ({
|
|
|
1433
1433
|
] })
|
|
1434
1434
|
}
|
|
1435
1435
|
),
|
|
1436
|
-
m &&
|
|
1436
|
+
m && $.filter((s) => s.moduleActions.some((v) => !v.action.quantumOwned)).length > 0 && /* @__PURE__ */ e.jsx(
|
|
1437
1437
|
ne,
|
|
1438
1438
|
{
|
|
1439
1439
|
p: 2,
|
|
@@ -1461,13 +1461,13 @@ const wn = ({
|
|
|
1461
1461
|
{
|
|
1462
1462
|
colorScheme: o === "copy" ? "blue" : "green",
|
|
1463
1463
|
onClick: L,
|
|
1464
|
-
isDisabled:
|
|
1464
|
+
isDisabled: $.length === 0 || y,
|
|
1465
1465
|
isLoading: y,
|
|
1466
1466
|
loadingText: `${o === "copy" ? "Copying" : "Converting"}...`,
|
|
1467
1467
|
children: [
|
|
1468
1468
|
o === "copy" ? "Copy" : "Convert",
|
|
1469
1469
|
" ",
|
|
1470
|
-
|
|
1470
|
+
$.length === 1 ? l.singular : `${$.length} ${l.plural}`
|
|
1471
1471
|
]
|
|
1472
1472
|
}
|
|
1473
1473
|
)
|
|
@@ -2055,14 +2055,14 @@ const wn = ({
|
|
|
2055
2055
|
w?.getActionById
|
|
2056
2056
|
);
|
|
2057
2057
|
if (!g) return null;
|
|
2058
|
-
const
|
|
2058
|
+
const F = A(tt, g.reports).map((G) => ({
|
|
2059
2059
|
...G,
|
|
2060
2060
|
thresholds: A(Se, G.thresholds)
|
|
2061
2061
|
}));
|
|
2062
2062
|
return {
|
|
2063
2063
|
...g,
|
|
2064
2064
|
thresholds: A(Se, g.thresholds),
|
|
2065
|
-
reports:
|
|
2065
|
+
reports: F
|
|
2066
2066
|
};
|
|
2067
2067
|
}, [w]), h = x || f, o = !!y && !!n, { getLabel: u } = xe(), b = T(() => ({
|
|
2068
2068
|
action: u("action")
|
|
@@ -2072,7 +2072,7 @@ const wn = ({
|
|
|
2072
2072
|
{ key: "session_type", label: "Session Type", multi: !0 },
|
|
2073
2073
|
{ key: "body_region", label: "Body Region", multi: !0 },
|
|
2074
2074
|
{ key: "sport", label: "Sport", multi: !0 }
|
|
2075
|
-
], [b.action]), [k, Q] = _(""), [q, N] = _(""), [K, se] = _(""), [
|
|
2075
|
+
], [b.action]), [k, Q] = _(""), [q, N] = _(""), [K, se] = _(""), [$, C] = _(""), [E, L] = _([]), [z, ee] = _({}), [U, ae] = _(null), [i, s] = _([]), [v, O] = _([]), [B, te] = _(""), [W, H] = _([]), Y = Vt(), Me = T(() => Y.filter((g) => g.sensorOnly), [Y]), ve = T(() => {
|
|
2076
2076
|
const g = [
|
|
2077
2077
|
{ label: "General Activity", value: re.GeneralActivity },
|
|
2078
2078
|
{
|
|
@@ -2082,18 +2082,18 @@ const wn = ({
|
|
|
2082
2082
|
{ label: "Point of Interest", value: re.PointOfInterest },
|
|
2083
2083
|
{ label: "Range", value: re.Range },
|
|
2084
2084
|
{ label: "Stability Balance", value: re.StabilityBalance }
|
|
2085
|
-
],
|
|
2085
|
+
], D = W.map((F) => F.kind);
|
|
2086
2086
|
return g.filter(
|
|
2087
|
-
(
|
|
2087
|
+
(F) => !D.includes(F.value)
|
|
2088
2088
|
);
|
|
2089
2089
|
}, [W]), ke = k.length > 0, [Fe, nt] = _({});
|
|
2090
2090
|
ce(() => {
|
|
2091
2091
|
const g = M.map(
|
|
2092
|
-
(
|
|
2092
|
+
(D) => l.query(dn, { key: D.key })
|
|
2093
2093
|
);
|
|
2094
|
-
Promise.all(g).then((
|
|
2095
|
-
const
|
|
2096
|
-
|
|
2094
|
+
Promise.all(g).then((D) => {
|
|
2095
|
+
const F = {};
|
|
2096
|
+
D.forEach((G) => {
|
|
2097
2097
|
if (G.error || !G.data) return;
|
|
2098
2098
|
const J = A(
|
|
2099
2099
|
Ye,
|
|
@@ -2102,21 +2102,21 @@ const wn = ({
|
|
|
2102
2102
|
He,
|
|
2103
2103
|
J.data
|
|
2104
2104
|
);
|
|
2105
|
-
|
|
2105
|
+
F[J.key] = Z.map((ue) => ({
|
|
2106
2106
|
label: ue.label || ue.value,
|
|
2107
2107
|
value: ue.value,
|
|
2108
2108
|
id: ue.id
|
|
2109
2109
|
}));
|
|
2110
|
-
}), ee(
|
|
2110
|
+
}), ee(F);
|
|
2111
2111
|
});
|
|
2112
2112
|
}, [l, M]), ce(() => {
|
|
2113
2113
|
if (y) {
|
|
2114
|
-
const
|
|
2114
|
+
const D = A(
|
|
2115
2115
|
Ye,
|
|
2116
2116
|
y.metadataGroups
|
|
2117
2117
|
).map(
|
|
2118
2118
|
(J) => J.data.map((Z) => A(He, Z).id)
|
|
2119
|
-
),
|
|
2119
|
+
), F = y.reports.map((J) => ({
|
|
2120
2120
|
id: J.id,
|
|
2121
2121
|
instructions: J.instructions ?? "",
|
|
2122
2122
|
kind: J.reportKind,
|
|
@@ -2140,10 +2140,10 @@ const wn = ({
|
|
|
2140
2140
|
description: y.description || "",
|
|
2141
2141
|
cameraPlacement: y.cameraPlacement || "",
|
|
2142
2142
|
videoLink: y.videoLink || "",
|
|
2143
|
-
metadataIds:
|
|
2144
|
-
reports:
|
|
2143
|
+
metadataIds: D.flat(),
|
|
2144
|
+
reports: F
|
|
2145
2145
|
};
|
|
2146
|
-
Q(G.name), N(G.description), se(G.cameraPlacement), C(G.videoLink), L(G.metadataIds), H(
|
|
2146
|
+
Q(G.name), N(G.description), se(G.cameraPlacement), C(G.videoLink), L(G.metadataIds), H(F), nt(G);
|
|
2147
2147
|
}
|
|
2148
2148
|
}, [y]);
|
|
2149
2149
|
const Ie = T(
|
|
@@ -2151,7 +2151,7 @@ const wn = ({
|
|
|
2151
2151
|
name: k,
|
|
2152
2152
|
description: q,
|
|
2153
2153
|
cameraPlacement: K,
|
|
2154
|
-
videoLink:
|
|
2154
|
+
videoLink: $,
|
|
2155
2155
|
metadataIds: E,
|
|
2156
2156
|
reports: W
|
|
2157
2157
|
}),
|
|
@@ -2160,7 +2160,7 @@ const wn = ({
|
|
|
2160
2160
|
k,
|
|
2161
2161
|
q,
|
|
2162
2162
|
K,
|
|
2163
|
-
|
|
2163
|
+
$,
|
|
2164
2164
|
E,
|
|
2165
2165
|
W
|
|
2166
2166
|
]
|
|
@@ -2169,7 +2169,7 @@ const wn = ({
|
|
|
2169
2169
|
name: k,
|
|
2170
2170
|
description: q,
|
|
2171
2171
|
cameraPlacement: K,
|
|
2172
|
-
videoLink:
|
|
2172
|
+
videoLink: $,
|
|
2173
2173
|
metadataItemIds: E,
|
|
2174
2174
|
// Backend requires laterality; keep existing default since UI no longer edits it
|
|
2175
2175
|
laterality: bn.Either,
|
|
@@ -2179,12 +2179,12 @@ const wn = ({
|
|
|
2179
2179
|
// Backend requires thresholds; use empty array since reports handle parameters now
|
|
2180
2180
|
thresholds: [],
|
|
2181
2181
|
// Include reports data
|
|
2182
|
-
reports: W.map((
|
|
2183
|
-
id:
|
|
2184
|
-
reportKind:
|
|
2185
|
-
sensorLocations:
|
|
2186
|
-
instructions:
|
|
2187
|
-
thresholds:
|
|
2182
|
+
reports: W.map((F) => ({
|
|
2183
|
+
id: F.isNew ? void 0 : F.id,
|
|
2184
|
+
reportKind: F.kind,
|
|
2185
|
+
sensorLocations: F.sensorLocations,
|
|
2186
|
+
instructions: F.instructions,
|
|
2187
|
+
thresholds: F.parameters.map((G) => ({
|
|
2188
2188
|
id: G.oldId,
|
|
2189
2189
|
kind: G.kind,
|
|
2190
2190
|
min: G.min,
|
|
@@ -2195,14 +2195,14 @@ const wn = ({
|
|
|
2195
2195
|
}))
|
|
2196
2196
|
}))
|
|
2197
2197
|
};
|
|
2198
|
-
let
|
|
2199
|
-
o && n ?
|
|
2198
|
+
let D;
|
|
2199
|
+
o && n ? D = I({
|
|
2200
2200
|
id: n,
|
|
2201
2201
|
fields: g
|
|
2202
|
-
}) :
|
|
2202
|
+
}) : D = R({
|
|
2203
2203
|
fields: g
|
|
2204
|
-
}),
|
|
2205
|
-
|
|
2204
|
+
}), D.then(({ error: F }) => {
|
|
2205
|
+
F ? t(F) : d();
|
|
2206
2206
|
});
|
|
2207
2207
|
}, [
|
|
2208
2208
|
j,
|
|
@@ -2212,7 +2212,7 @@ const wn = ({
|
|
|
2212
2212
|
k,
|
|
2213
2213
|
q,
|
|
2214
2214
|
K,
|
|
2215
|
-
|
|
2215
|
+
$,
|
|
2216
2216
|
E,
|
|
2217
2217
|
W,
|
|
2218
2218
|
o,
|
|
@@ -2233,12 +2233,12 @@ const wn = ({
|
|
|
2233
2233
|
}, [c, a, Oe, r]);
|
|
2234
2234
|
const $e = P(
|
|
2235
2235
|
(g) => {
|
|
2236
|
-
const
|
|
2236
|
+
const D = ut(
|
|
2237
2237
|
g.map(
|
|
2238
|
-
(
|
|
2238
|
+
(F) => "joint" in F.id ? F.id.joint : F.id.segment
|
|
2239
2239
|
)
|
|
2240
2240
|
);
|
|
2241
|
-
O(
|
|
2241
|
+
O(D);
|
|
2242
2242
|
},
|
|
2243
2243
|
[]
|
|
2244
2244
|
);
|
|
@@ -2254,22 +2254,23 @@ const wn = ({
|
|
|
2254
2254
|
kind: U,
|
|
2255
2255
|
parameters: i,
|
|
2256
2256
|
sensorLocations: v,
|
|
2257
|
-
instructions: B
|
|
2257
|
+
instructions: B,
|
|
2258
|
+
isNew: !0
|
|
2258
2259
|
};
|
|
2259
|
-
H((
|
|
2260
|
+
H((D) => [...D, g]), ae(null), s([]), O([]), te("");
|
|
2260
2261
|
}, [
|
|
2261
2262
|
U,
|
|
2262
2263
|
i,
|
|
2263
2264
|
v,
|
|
2264
2265
|
B
|
|
2265
2266
|
]), he = P((g) => {
|
|
2266
|
-
H((
|
|
2267
|
-
}, []), Te = (g,
|
|
2268
|
-
const
|
|
2269
|
-
if (!
|
|
2270
|
-
const G =
|
|
2267
|
+
H((D) => D.filter((F) => F.id !== g));
|
|
2268
|
+
}, []), Te = (g, D) => {
|
|
2269
|
+
const F = M.find((J) => J.key === g);
|
|
2270
|
+
if (!F) return;
|
|
2271
|
+
const G = F.multi ? (D ?? []).map(
|
|
2271
2272
|
(J) => J.id
|
|
2272
|
-
) :
|
|
2273
|
+
) : D ? [D.id] : [];
|
|
2273
2274
|
L((J) => [...J.filter((ue) => Object.values(z).flat().find((De) => De.id === ue) && !Object.keys(z).find(
|
|
2274
2275
|
(De) => z[De]?.some(
|
|
2275
2276
|
(kt) => kt.id === ue && De === g
|
|
@@ -2316,7 +2317,7 @@ const wn = ({
|
|
|
2316
2317
|
/* @__PURE__ */ e.jsx(
|
|
2317
2318
|
we,
|
|
2318
2319
|
{
|
|
2319
|
-
value:
|
|
2320
|
+
value: $,
|
|
2320
2321
|
onChange: (g) => C(g.target.value),
|
|
2321
2322
|
type: "url",
|
|
2322
2323
|
placeholder: "(optional) https://...",
|
|
@@ -2347,10 +2348,10 @@ const wn = ({
|
|
|
2347
2348
|
{
|
|
2348
2349
|
isMulti: g.multi,
|
|
2349
2350
|
value: z[g.key]?.filter(
|
|
2350
|
-
(
|
|
2351
|
+
(D) => E.includes(D.id)
|
|
2351
2352
|
),
|
|
2352
|
-
onChange: (
|
|
2353
|
-
Te(g.key,
|
|
2353
|
+
onChange: (D) => {
|
|
2354
|
+
Te(g.key, D);
|
|
2354
2355
|
},
|
|
2355
2356
|
options: z[g.key],
|
|
2356
2357
|
placeholder: `Select ${g.multi ? "one or more" : "one"} ${g.label.toLowerCase()}`,
|
|
@@ -2463,9 +2464,9 @@ const wn = ({
|
|
|
2463
2464
|
Pe,
|
|
2464
2465
|
{
|
|
2465
2466
|
value: g.instructions,
|
|
2466
|
-
onChange: (
|
|
2467
|
-
(
|
|
2468
|
-
(G) => G.id === g.id ? { ...G, instructions:
|
|
2467
|
+
onChange: (D) => H(
|
|
2468
|
+
(F) => F.map(
|
|
2469
|
+
(G) => G.id === g.id ? { ...G, instructions: D.target.value } : G
|
|
2469
2470
|
)
|
|
2470
2471
|
),
|
|
2471
2472
|
rows: 3,
|
|
@@ -2479,13 +2480,13 @@ const wn = ({
|
|
|
2479
2480
|
{
|
|
2480
2481
|
options: Y,
|
|
2481
2482
|
value: g.parameters,
|
|
2482
|
-
onChange: (
|
|
2483
|
-
const
|
|
2483
|
+
onChange: (D) => {
|
|
2484
|
+
const F = D.map(
|
|
2484
2485
|
(J) => J.id.joint ?? J.id.segment
|
|
2485
|
-
), G = ut(
|
|
2486
|
+
), G = ut(F);
|
|
2486
2487
|
H(
|
|
2487
2488
|
(J) => J.map(
|
|
2488
|
-
(Z) => Z.id === g.id ? { ...Z, parameters:
|
|
2489
|
+
(Z) => Z.id === g.id ? { ...Z, parameters: D, sensorLocations: G } : Z
|
|
2489
2490
|
)
|
|
2490
2491
|
);
|
|
2491
2492
|
},
|
|
@@ -2496,7 +2497,7 @@ const wn = ({
|
|
|
2496
2497
|
"Sensors:",
|
|
2497
2498
|
" ",
|
|
2498
2499
|
g.sensorLocations.map(
|
|
2499
|
-
(
|
|
2500
|
+
(D) => pt(D)
|
|
2500
2501
|
).join(", ")
|
|
2501
2502
|
] })
|
|
2502
2503
|
]
|
|
@@ -2564,7 +2565,7 @@ const wn = ({
|
|
|
2564
2565
|
) ?? []
|
|
2565
2566
|
));
|
|
2566
2567
|
}, [o, u]);
|
|
2567
|
-
const
|
|
2568
|
+
const $ = P(() => {
|
|
2568
2569
|
let C;
|
|
2569
2570
|
const E = {
|
|
2570
2571
|
actions: b,
|
|
@@ -2601,9 +2602,9 @@ const wn = ({
|
|
|
2601
2602
|
}, [j, f, w, b, k, K]), ce(() => {
|
|
2602
2603
|
m && m({
|
|
2603
2604
|
cancelButton: t,
|
|
2604
|
-
saveButton:
|
|
2605
|
+
saveButton: $
|
|
2605
2606
|
});
|
|
2606
|
-
}, [m, t,
|
|
2607
|
+
}, [m, t, $]), /* @__PURE__ */ e.jsxs(ne, { width: "100%", children: [
|
|
2607
2608
|
/* @__PURE__ */ e.jsx(
|
|
2608
2609
|
$n,
|
|
2609
2610
|
{
|
|
@@ -2635,7 +2636,7 @@ const wn = ({
|
|
|
2635
2636
|
colorScheme: "blue",
|
|
2636
2637
|
isDisabled: f || w || !k || K.trim().split(/\s+/).filter(Boolean).length > 40,
|
|
2637
2638
|
isLoading: f || w,
|
|
2638
|
-
onClick:
|
|
2639
|
+
onClick: $,
|
|
2639
2640
|
children: "Save"
|
|
2640
2641
|
}
|
|
2641
2642
|
)
|