quantum-component-library 1.4.50-dev.2 → 1.4.50-dev.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,10 +5,11 @@ export type Item = {
5
5
  export type Props = {
6
6
  value: Item[];
7
7
  onChange: (cb: (prev: Item[]) => Item[]) => void;
8
+ disabled?: boolean;
8
9
  };
9
10
  /**
10
11
  * A component that allows adjusting the order of a list of items.
11
12
  * It provides a drag-and-drop interface to reorder the items.
12
13
  * This uses the react-dnd library to handle drag-and-drop functionality.
13
14
  */
14
- export declare const ListOrderInput: ({ value, onChange }: Props) => import("react/jsx-runtime").JSX.Element;
15
+ export declare const ListOrderInput: ({ value, onChange, disabled }: Props) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,5 @@
1
+ export type UpsertModuleFormContextType = {
2
+ isView?: boolean;
3
+ };
4
+ export declare const UpsertModuleFormContext: import('react').Context<UpsertModuleFormContextType | undefined>;
5
+ export declare const useUpsertModuleFormContext: () => UpsertModuleFormContextType;
@@ -13,5 +13,6 @@ export type UpsertModuleFormProps = {
13
13
  cancelButton: () => void;
14
14
  saveButton: () => void;
15
15
  }) => void;
16
+ isView?: boolean;
16
17
  };
17
- export declare const UpsertModuleForm: ({ id, onCancel, onSave, onError, hideButtons, quantumOwned, setButtonOnClick, setButtonDisabled, }: UpsertModuleFormProps) => import("react/jsx-runtime").JSX.Element;
18
+ export declare const UpsertModuleForm: ({ id, onCancel, onSave, onError, hideButtons, quantumOwned, setButtonOnClick, setButtonDisabled, isView, }: UpsertModuleFormProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,4 @@
1
+ export declare const UpsertModuleFormProvider: ({ children, isView, }: {
2
+ children: React.ReactNode;
3
+ isView?: boolean;
4
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -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"),Te=require("./utils-cn-FIKrq5Mb.cjs");require("./moment-vendor-1cRqq0AH.cjs");require("./lodash-vendor-CWf2psR2.cjs");const Z=require("urql"),le=require("./hooks.cjs"),Ie=require("./ufuzzy-vendor-7qHa_k39.cjs"),ye=require("./react-icons-vendor-BF_sZq07.cjs"),ce=require("./react-select-vendor-sW1B_api.cjs"),F=require("./generated.cjs"),E=require("./graphql-BhVmuiCG.cjs"),Se=require("./react-dnd-vendor-BqsnzPKT.cjs"),I=require("./generated-graphql.cjs"),re=require("./services-human-B4_65njx.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(a=>a.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:ye.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],[a]=f.splice(h,1);return f.splice(d,0,a),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,C=n;if(v===C)return;const p=d.current?.getBoundingClientRect(),r=(p.bottom-p.top)/2,T=A.getClientOffset().y-p.top;v<C&&T<r||v>C&&T>r||(h(v,C),b.index=C)}}),[{isDragging:a},u]=Se.useDrag({type:o,item:()=>({id:l,index:n}),collect:b=>({isDragging:b.isDragging()})}),R=a?.6:1,k=a?"grabbing":"grab";return u(f(d)),e.jsxRuntimeExports.jsxs(t.Tr,{ref:d,style:{opacity:R,cursor:k},"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=a=>a===l||a.value===l,f=a=>j(a)?{...d,...h}:d;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:x,children:o.map((a,u)=>e.jsxRuntimeExports.jsx(t.Tooltip,{label:a.tooltip,openDelay:50,closeDelay:200,placement:"top",visibility:a.tooltip?"visible":"hidden",hasArrow:!0,children:e.jsxRuntimeExports.jsx(t.Button,{onClick:()=>j(a)?null:n(a,u),isDisabled:a.disabled,...f(a),children:a.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:a,valueLabel:u,positiveNegativeLabels:R,isDisabled:k,...b})=>{const[A,v]=s.useState([void 0,void 0]),C=A[0],p=A[1],r=f&&n<-5&&l>5,m=Number(x?.[0]??p??n)>0?1:-1,T=Number(x?.[1]??p??l)<0?-1:1,w=R?.[0]===R?.[1],D=x?.[0],W=x?.[1];s.useEffect(()=>{D!==void 0&&W!==void 0&&v([D.toFixed(0),W.toFixed(0)])},[D,W,v]);const B=s.useCallback(([M,z])=>{M<z&&v([M.toFixed(0),z.toFixed(0)])},[v]),O=s.useCallback(([M,z])=>{M<z&&h([M,z])},[h]),H=s.useCallback(()=>{v(([M,z])=>{const V=isNaN(Number(M))?n:Number(M),q=isNaN(Number(z))?l:Number(z),se=be(Number(V),m),c=be(Number(q),T),i=m<0?Math.max(se,n):Math.min(se,l),y=T<0?Math.max(c,n):Math.min(c,l);return i>y?(h([y,i]),[y.toFixed(0),i.toFixed(0)]):(h([i,y]),[i.toFixed(0),y.toFixed(0)])})},[h,v,m,T,n,l]),te=s.useCallback(M=>{const z=M===""||isNaN(Number(M))?M:be(Number(M),m);v(([V,q])=>[z.toString(),q])},[v,m]),_=s.useCallback(M=>{const z=M===""||isNaN(Number(M))?M:be(Number(M),T);v(([V,q])=>[V,z.toString()])},[v,T]),S=s.useMemo(()=>j==="xs"?"0.75rem":void 0,[j]),P=s.useCallback((M,z)=>{const V=Number(z.target.value);if(!C||!p||![-1,1].includes(V))return;const q=i=>V<0?-1*Math.abs(i):Math.abs(i),se=M?q(Number(C)):Number(C),c=M?Number(p):q(Number(p));se>c?h([c,se]):h([se,c])},[C,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(C??n),Number(p??l)],max:l,min:n,minStepsBetweenThumbs:3,step:1,onChange:B,onChangeEnd:O,isDisabled:k,children:[e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:n,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:j??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:a?a?.(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:a?a(l):l})}),r&&e.jsxRuntimeExports.jsxs(t.RangeSliderMark,{value:0,top:"-1em",pos:"relative",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:j,fontWeight:"semibold",children:a?.(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||k,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):W??l,value:C===""?"":Math.abs(Number(C??n)),onChange:te,onBlur:H,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:k,...d,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),e.jsxRuntimeExports.jsx(t.NumberInput,{size:j??"sm",min:0,max:T<0?Math.abs(D??n):l,precision:0,value:p===""?"":Math.abs(Number(p??l)),onChange:_,onBlur:H,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:k,...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:T,onChange:M=>P(!1,M),isDisabled:w||k,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:a,disableDelete:u,disableEdit:R,disableCreate:k,hideUseCase:b=!0,tableProps:A,containerProps:v,quantumIconSrc:C="/favicon.ico"})=>{const[p,r]=s.useState(""),[m,T]=s.useState(),{getLabel:w}=le.useUiLabelContext(),D=s.useMemo(()=>({action:w("action"),actionPlural:w("action_plural"),actionLowerCase:w("action").toLocaleLowerCase(),actionPluralLowerCase:w("action_plural").toLocaleLowerCase()}),[w]),W=s.useMemo(()=>{if(!o)return;const S=Ue(o,p);return b?S:Qe(S,m)},[o,p,m,b]),B=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||k,colorScheme:"blackAlpha",backgroundColor:"gray.700",onClick:l,children:["Create New ",D.action]}),x&&!a&&e.jsxRuntimeExports.jsx(t.Tooltip,{label:_?H?`Quantum-owned ${D.actionPluralLowerCase} are selected and will be skipped`:`Selected ${D.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:B,children:"Delete Selected"})}),f&&!a&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!te,onClick:O,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx(ke,{setSearch:r,actions:o,updateUseCases:T,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 ",W?.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:W?.map(S=>e.jsxRuntimeExports.jsxs(t.Tr,{className:Te.cn("hover:bg-[#f7f7f7]",!a&&"cursor-pointer",S.selected&&"bg-gray-200"),onClick:()=>{a||j?.(S,!S.selected)},children:[e.jsxRuntimeExports.jsx(t.Td,{children:e.jsxRuntimeExports.jsxs(t.Flex,{children:[!a&&e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:S.selected?e.jsxRuntimeExports.jsx(ye.FaCheckSquare,{className:"text-blue-500"}):e.jsxRuntimeExports.jsx(ye.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:C}),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:a}=le.useUiLabelContext(),u=s.useMemo(()=>({singular:a("action"),plural:a("action_plural"),pluralLowerCase:a("action_plural").toLowerCase(),singularLowerCase:a("action").toLowerCase()}),[a]),[R,k]=s.useState("copy"),[b,A]=s.useState(""),[v,C]=s.useState([]),[p,r]=s.useState(!1),[m]=Z.useQuery({query:E.GET_GROUPS}),[T]=Z.useQuery({query:E.GET_ACTIONS_BY_GROUP,variables:{groupId:b},pause:!b}),[,w]=Z.useMutation(E.CREATE_ACTION),[,D]=Z.useMutation(E.CONVERT_ACTION_TO_QUANTUM_OWNED),W=s.useMemo(()=>m.data?.groups?m.data.groups.map(c=>F.getFragmentData(E.GROUP_FRAGMENT,c)):[],[m.data]),B=s.useMemo(()=>T.data?T.data.actions.map(i=>{const y=F.getFragmentData(E.ACTION_FRAGMENT,i),L=F.getFragmentData(E.REPORT_FRAGMENT,y.reports),U=F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,y.categories),Q=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,y.metadataGroups).map(Y=>({...Y,data:Y.data.map(K=>F.getFragmentData(E.METADATA_ITEM_FRAGMENT,K))}));return{...y,thresholds:F.getFragmentData(E.THRESHOLD_FRAGMENT,y.thresholds),reports:L.map(Y=>({...Y,thresholds:F.getFragmentData(E.THRESHOLD_FRAGMENT,Y.thresholds)})),categories:U,metadataGroups:Q}}):[],[T.data]),O=s.useMemo(()=>B.filter(c=>v.includes(c.id)),[B,v]),H=s.useCallback(c=>{const i=c?.value||"";A(i),C([])},[]),te=s.useCallback(c=>{const i=c.map(y=>y.value);C(i)},[]),_=s.useCallback(async c=>{const i={...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(U=>U.id)).filter(L=>L!==void 0),reports:c.reports.map(L=>({...L,id:void 0,thresholds:L.thresholds.map(U=>({...U,id:void 0}))})),id:void 0},y=await w({fields:i});if(y.error)throw new Error(y.error.message);if(y.data?.createAction)return F.getFragmentData(E.ACTION_FRAGMENT,y.data.createAction);throw new Error("No action data returned")},[w,j]),S=s.useCallback(async c=>{const i=await D({id:c.id});if(i.error)throw new Error(i.error.message);if(i.data?.convertActionToQuantumOwned)return F.getFragmentData(E.ACTION_FRAGMENT,i.data.convertActionToQuantumOwned);throw new Error("No action data returned")},[D]),P=s.useCallback(async()=>{if(r(!0),!O.length){const c=new Error(`No ${u.pluralLowerCase} selected for ${R==="copy"?"copying":"converting"}`);l?.(c),r(!1);return}try{const c=[];let i=0;const y=R==="copy"?_:S,L=R==="copy"?"copy":"convert";for(const U of O)try{const ee=await y(U);c.push(ee)}catch(ee){console.error(`Failed to ${L} ${u.singularLowerCase} "${U.name}":`,ee),i++}if(c.length>0){const U=c.length,ee=O.length,Q=R==="copy"?"copied":"converted",Y=R==="copy"?"copy":"convert";f({title:i>0?`Partial ${Y} completed`:`${u.plural} ${Q} successfully`,description:i>0?`${U} of ${ee} ${u.pluralLowerCase} ${Q} successfully`:`${U} ${U>1?u.pluralLowerCase:u.singularLowerCase} ${Q} successfully`,status:i>0?"warning":"success",duration:3e3,isClosable:!0}),o?.(),A(""),C([])}else throw new Error(`Failed to ${L} any ${u.pluralLowerCase}`)}catch(c){const i=R==="copy"?"copy":"convert",y=c instanceof Error?c.message:`Failed to ${i} ${u.pluralLowerCase}`;f({title:`${R==="copy"?"Copy":"Convert"} failed`,description:y,status:"error",duration:5e3,isClosable:!0}),l?.(c instanceof Error?c:new Error(y))}finally{r(!1)}},[O,R,_,S,f,o,l,u]),M=s.useCallback(()=>{A(""),C([]),k("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 z=s.useMemo(()=>W.map(c=>({value:c.id,label:c.name})),[W]),V=s.useMemo(()=>B.filter(c=>R==="copy"?!0:!c.quantumOwned).map(c=>({value:c.id,label:c.name,isQuantumOwned:c.quantumOwned})),[B,R]),q=m.fetching,se=T.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=>{k(c),C([])},children:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:6,children:[e.jsxRuntimeExports.jsx(t.Radio,{value:"copy",colorScheme:"blue",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.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:z,value:z.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:i})=>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}),i==="value"&&c.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),c.isQuantumOwned&&i==="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"]})]}),T.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,":"," ",T.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,i)=>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:[i+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(y=>y.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:a}=le.useUiLabelContext(),u=s.useMemo(()=>({singular:a("module"),plural:a("module_plural"),pluralLowerCase:a("module_plural").toLowerCase(),singularLowerCase:a("module").toLowerCase()}),[a]),R=s.useMemo(()=>({singular:a("action"),plural:a("action_plural"),pluralLowerCase:a("action_plural").toLowerCase(),singularLowerCase:a("action").toLowerCase()}),[a]),[k,b]=s.useState(""),[A,v]=s.useState([]),[C,p]=s.useState(!1),[r,m]=s.useState("copy"),[T]=Z.useQuery({query:E.GET_GROUPS}),[w]=Z.useQuery({query:E.GET_MODULES_BY_GROUP,variables:{groupId:k},pause:!k}),[,D]=Z.useMutation(E.CREATE_MODULE),[,W]=Z.useMutation(E.UPDATE_MODULE),[,B]=Z.useMutation(E.CREATE_ACTION),[,O]=Z.useMutation(E.CONVERT_ACTION_TO_QUANTUM_OWNED),H=s.useMemo(()=>T.data?.groups?T.data.groups.map(i=>F.getFragmentData(E.GROUP_FRAGMENT,i)):[],[T.data]),te=s.useMemo(()=>w.data?.modules?F.getFragmentData(E.ACTION_MODULE_FRAGMENT,w.data?.modules).map(y=>{const L=F.getFragmentData(E.MODULE_ACTION_FRAGMENT,y.moduleActions);return{...y,moduleActions:L.map(U=>({...U,action:F.getFragmentData(E.ACTION_FRAGMENT,U.action)})),categories:F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,y.categories)}}):[],[w.data]),_=s.useMemo(()=>te.filter(i=>A.includes(i.id)),[te,A]),S=s.useCallback(i=>{const y=i?.value||"";b(y),v([])},[]),P=s.useCallback(i=>{const y=i.map(L=>L.value);v(y)},[]),M=s.useCallback(async()=>{if(p(!0),!_.length){p(!1);const i=new Error(`No modules selected for ${r==="convert"?"converting":"copying"}`);l?.(i);return}try{const i=[];let y=0;for(const L of _)try{let U=L.moduleActions.map(ee=>ee.actionId);if(j){const ee=L.moduleActions.map(K=>K.action),Q=async K=>{if(r==="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 B({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)};U=(await Promise.all(ee.map(Q))).filter(K=>!!K).map(K=>K.id)}if(r==="convert"){const ee={name:L.name,description:L.description||void 0,actions:U,categories:L.categories.map(Y=>Y.id),quantumOwned:!0},Q=await W({id:L.id,input:ee});if(Q.error)throw new Error(Q.error.message);if(Q.data?.updateModule){const Y=F.getFragmentData(E.ACTION_MODULE_FRAGMENT,Q.data.updateModule);i.push(Y)}}else{const ee={name:`${L.name} (Copy)`,description:L.description||void 0,actions:U,categories:L.categories.map(Y=>Y.id),quantumOwned:j},Q=await D({input:ee});if(Q.error)throw new Error(Q.error.message);if(Q.data?.createModule){const Y=F.getFragmentData(E.ACTION_MODULE_FRAGMENT,Q.data.createModule);i.push(Y)}}}catch(U){console.error(`Failed to ${r==="convert"?"convert":"copy"} module "${L.name}":`,U),y++}if(i.length>0){const L=i.length,U=_.length;f({title:y>0?`Partial ${r==="convert"?"convert":"copy"} completed`:`${u.plural} ${r==="convert"?"converted":"copied"} successfully`,description:y>0?`${L} of ${U} ${u.plural} ${r==="convert"?"converted":"copied"} successfully`:`${L} ${L>1?u.plural:u.singular} ${r==="convert"?"converted":"copied"} successfully`,status:y>0?"warning":"success",duration:3e3,isClosable:!0}),i.length>0&&o?.(),b(""),v([])}else throw new Error(`Failed to ${r==="convert"?"convert":"copy"} any modules`)}catch(i){const y=i instanceof Error?i.message:`Failed to ${r==="convert"?"convert":"copy"} modules`;f({title:r==="convert"?"Convert failed":"Copy failed",description:y,status:"error",duration:5e3,isClosable:!0}),l?.(i instanceof Error?i:new Error(y))}finally{p(!1)}},[_,D,W,f,o,l,j,B,O,r,u]),z=s.useCallback(()=>{b(""),v([]),m("copy"),n?.()},[n]);s.useEffect(()=>{h&&h({cancelButton:!1,saveButton:_.length===0||C})},[_.length,C,h]),s.useEffect(()=>{d&&d({cancelButton:z,saveButton:M})},[d,z,M]);const V=s.useMemo(()=>H.map(i=>({value:i.id,label:i.name})),[H]),q=s.useMemo(()=>te.filter(i=>r==="copy"?!0:!i.quantumOwned).map(i=>({value:i.id,label:i.name,isQuantumOwned:i.quantumOwned})),[te,r]),se=T.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:r,onChange:i=>{m(i),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(i=>i.value===k)||null,onChange:S,isLoading:se,isDisabled:se,isClearable:!0}),T.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: ",T.error.message]})]})]}),k&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ae,{children:r==="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:r==="convert"?`Choose ${u.pluralLowerCase} to convert...`:`Choose ${u.pluralLowerCase} to copy...`,options:q,value:q.filter(i=>A.includes(i.value)),onChange:P,isDisabled:q.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(i,{context:y})=>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:i.label}),y==="value"&&i.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),i.isQuantumOwned&&y==="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 ${r==="copy"?"Copy":"Convert"}`:`${_.length} ${u.plural} to ${r==="copy"?"Copy":"Convert"}`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[_.map((i,y)=>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:[y+1,". ",i.name]}),i.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:[i.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",i.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Activities:"})," ",i.moduleActions.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Categories:"})," ",i.categories.map(L=>L.name).join(", ")||"None"]})]})]},i.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"," ",r==="copy"?"copied":"converted"]})}),j&&_.filter(i=>i.moduleActions.some(y=>!y.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:r==="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:z,isDisabled:C,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:r==="copy"?"blue":"green",onClick:M,isDisabled:_.length===0||C,isLoading:C,loadingText:`${r==="copy"?"Copying":"Converting"}...`,children:[r==="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:a,setDescription:u,...R})=>{const k=t.useDisclosure(),b=s.useMemo(()=>l.map(m=>({...m,selected:x.includes(m.id)})),[l,x]),A=s.useMemo(()=>l.reduce((m,T)=>(m[T.id]=T,m),{}),[l]),v=s.useMemo(()=>x.map(m=>A[m]),[x,A]),C=s.useCallback((m,T)=>{h(T?[...x,m.id]:x.filter(w=>w!==m.id))},[x,h]),p=s.useCallback(m=>{n(m.target.value)},[n]),r=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:a??"",onInputChange:r}),e.jsxRuntimeExports.jsx(Xe,{value:v,onChange:h,onAdjustActivities:()=>k.onOpen()}),e.jsxRuntimeExports.jsxs(t.Modal,{isOpen:k.isOpen,onClose:k.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:C,disableCreate:!0,disableDelete:!0,tableProps:{height:"28rem",overflowY:"auto"}})}),e.jsxRuntimeExports.jsx(t.ModalFooter,{children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:k.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(a=>a.id))}})]})}),Oe=({value:o,onChange:n,forceKind:l,disableRemove:x,disableKind:h,isDisabled:d,lockRanges:j,...f})=>{const a=s.useMemo(()=>[...o].sort((b,A)=>{const v=de.availablePlanes.indexOf(b.plane),C=de.availablePlanes.indexOf(A.plane);return v-C}),[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=a.findIndex(p=>p.id===A.id&&p.plane===A.plane);let C=[...a];l&&(A={...A,kind:l}),C[v]=A,j&&(C=C.map(p=>({...p,min:A.min,max:A.max}))),n(C)},[n,a,l,j]),k=s.useCallback(b=>{const A=a.filter(v=>v.id!==b.id||v.plane!==b.plane);n(A)},[n,a]);return e.jsxRuntimeExports.jsx(t.VStack,{alignItems:"flex-start",overflowY:"auto",...f,children:a.map((b,A)=>e.jsxRuntimeExports.jsx(Ze,{label:u(b),parameter:b,onChange:v=>R(A,v),onRemove:x||d?void 0:()=>k(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:a,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:ye.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:a,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:a,...u})=>{const R=d?2:a,k=s.useMemo(()=>{const p=new Map;return o.forEach(r=>{const m="joint"in r.id;let T,w;if(m?(T=re.getJointNameWithPlane(r.id.joint,r.plane,!0)??"Unknown",w=`joint:${r.id.joint}`):(T=re.getSegmentNameWithPlane(r.id.segment,r.plane,!0)??"Unknown",w=`segment:${r.id.segment}`),!p.has(w)){const B=m?re.getPartName(r.id.joint)??"Unknown Joint":re.getPartName(r.id.segment)??"Unknown Segment";p.set(w,{label:B,options:[]})}const D=p.get(w),W=[T,m?r.id.joint:r.id.segment,r.plane].filter(Boolean).map(B=>String(B).toLowerCase().replace(/\s+|_/g,""));D.options.push({label:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:2,justify:"space-between",w:"100%",pl:3,children:[e.jsxRuntimeExports.jsx(t.Text,{children:T}),r.sensorOnly&&e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor Only"})]}),value:r.id,plane:r.plane,sensorOnly:r.sensorOnly,searchTokens:W})}),Array.from(p.values())},[o]),b=s.useMemo(()=>{if(!d||n.length===0)return k;const p=n[0];return k.map(r=>({...r,options:r.options.filter(m=>de.getAnalysisPartIdNoSide(m.value)===de.getAnalysisPartIdNoSide(p.id)&&m.plane===p.plane)})).filter(r=>r.options.length>0)},[k,n,d]),A=s.useMemo(()=>k.flatMap(r=>r.options).filter(r=>n.some(m=>Ce(m.id,r.value)&&m.plane===r.plane)),[k,n]),v=s.useCallback((p,r)=>{if(!r)return!0;const m=r.toLowerCase().replace(/\s+|_/g,""),T=p.data;return!T||!T.searchTokens?!1:T.searchTokens.some(w=>w.includes(m))},[]),C=s.useCallback(p=>{const r=p.map(m=>{const T=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),D=d?n.find(O=>de.getAnalysisPartIdNoSide(O.id)===de.getAnalysisPartIdNoSide(m.value)&&O.plane===m.plane):void 0,W=D&&!T?D.min:w&&w.min?w.min:0,B=D&&!T?D.max:w&&w.max?w.max:0;return T??{id:m.value,plane:m.plane,min:W,max:B,sensorOnly:m.sensorOnly,kind:x??I.ThresholdKind.Limit}});l(r)},[l,n,o,x,d]);return s.useEffect(()=>{const p=n.filter(r=>o.some(m=>Ce(m.id,r.id)&&m.plane===r.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)?C([...p]):C(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:a})=>{const u=Z.useClient(),[{fetching:R},k]=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}),C=s.useMemo(()=>{const g=F.getFragmentData(E.ACTION_FRAGMENT,v?.getActionById);if(!g)return null;const N=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:N}},[v]),p=R||b,r=!!C&&!!o,{getLabel:m}=le.useUiLabelContext(),T=s.useMemo(()=>({action:m("action")}),[m]),w=s.useMemo(()=>[{key:"module_category",label:"Link Category",multi:!0},{key:"activity_type",label:`${T.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}],[T.action]),[D,W]=s.useState(""),[B,O]=s.useState(""),[H,te]=s.useState(""),[_,S]=s.useState(""),[P,M]=s.useState([]),[z,V]=s.useState({}),[q,se]=s.useState(null),[c,i]=s.useState([]),[y,L]=s.useState([]),[U,ee]=s.useState(""),[Q,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=Q.map(N=>N.kind);return g.filter(N=>!G.includes(N.value))},[Q]),ge=D.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 N={};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);N[J.key]=X.map(oe=>({label:oe.label||oe.value,value:oe.value,id:oe.id}))}),V(N)})},[u,w]),s.useEffect(()=>{if(C){const G=F.getFragmentData(E.METADATA_GROUP_FRAGMENT,C.metadataGroups).map(J=>J.data.map(X=>F.getFragmentData(E.METADATA_ITEM_FRAGMENT,X).id)),N=C.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:C.name,description:C.description||"",cameraPlacement:C.cameraPlacement||"",videoLink:C.videoLink||"",metadataIds:G.flat(),reports:N};W($.name),O($.description),te($.cameraPlacement),S($.videoLink),M($.metadataIds),Y(N),we($)}},[C]);const me=s.useMemo(()=>JSON.stringify(Re)!==JSON.stringify({name:D,description:B,cameraPlacement:H,videoLink:_,metadataIds:P,reports:Q}),[Re,D,B,H,_,P,Q]),pe=s.useCallback(()=>{const g={name:D,description:B,cameraPlacement:H,videoLink:_,metadataItemIds:P,laterality:I.ActionLaterality.Either,quantumOwned:f,sessionType:[],thresholds:[],reports:Q.map(N=>({id:N.isNew?void 0:N.id,reportKind:N.kind,sensorLocations:N.sensorLocations,instructions:N.instructions,thresholds:N.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;r&&o?G=A({id:o,fields:g}):G=k({fields:g}),G.then(({error:N})=>{N?n(N):x()})},[f,k,A,o,D,B,H,_,P,Q,r,x,n]);s.useEffect(()=>{j&&j({cancelButton:p,saveButton:a?!0:p||!ge||!me})},[p,j,ge,me,a]),s.useEffect(()=>{d&&d({cancelButton:l,saveButton:a?()=>{}:pe})},[d,l,pe,a]);const Ee=s.useCallback(g=>{const G=re.getSuggestedSensorLocations(g.map(N=>"joint"in N.id?N.id.joint:N.id.segment));L(G)},[]);s.useEffect(()=>{Ee(c)},[c,Ee]);const je=s.useCallback(()=>{if(!q)return;const g=q===I.ReportKind.PointOfInterest,G={id:Date.now().toString(),kind:q,parameters:g?[]:c,sensorLocations:g?[]:y,instructions:g?U:"",isNew:!0};Y(N=>[...N,G]),se(null),i([]),L([]),ee("")},[q,c,y,U]),ie=s.useCallback(g=>{Y(G=>G.filter(N=>N.id!==g))},[]),he=(g,G)=>{const N=w.find(J=>J.key===g);if(!N)return;const $=N.multi?(G??[]).map(J=>J.id):G?[G.id]:[];M(J=>[...J.filter(oe=>Object.values(z).flat().find(fe=>fe.id===oe)&&!Object.keys(z).find(fe=>z[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:D,onChange:g=>W(g.target.value),type:"text",placeholder:"i.e. Lunge & Return",isDisabled:a})]}),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:a})]}),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:a})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Description"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:B,onChange:g=>O(g.target.value),rows:2,placeholder:"(optional) Describe how to perform the test or exercise",isDisabled:a})]})]}),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:z[g.key]?.filter(G=>P.includes(G.id)),onChange:G=>{he(g.key,G)},options:z[g.key],placeholder:`Select ${g.multi?"one or more":"one"} ${g.label.toLowerCase()}`,isDisabled:a,isClearable:g.multi})]},g.key))]})]})}),e.jsxRuntimeExports.jsx(t.TabPanel,{px:0,children:e.jsxRuntimeExports.jsxs("div",{className:Te.cn("grid grid-cols-1 gap-6",!a&&"md:grid-cols-2"),children:[e.jsxRuntimeExports.jsxs("div",{className:Te.cn("space-y-4",a&&"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:a,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:i,editOnly:a})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Suggested Sensor Locations"}),e.jsxRuntimeExports.jsx(t.Input,{value:y.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:U,onChange:g=>ee(g.target.value),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:a})]}),e.jsxRuntimeExports.jsx("div",{className:"w-full flex justify-end",children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:je,isDisabled:!q||a||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"}),Q.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:Q.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)}),!a&&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(N=>N.map($=>$.id===g.id?{...$,instructions:G.target.value}:$)),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:a})]}),g.kind!==I.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsx(Me,{options:K,value:g.parameters,onChange:G=>{const N=G.map(J=>J.id.joint??J.id.segment),$=re.getSuggestedSensorLocations(N);Y(J=>J.map(X=>X.id===g.id?{...X,parameters:G,sensorLocations:$}:X))},editOnly:a}),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:Te.cn((h||a)&&"!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:a}]=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}),k=F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,R?.moduleCategories),[{fetching:b},A]=Z.useMutation(E.UPDATE_MODULE),[{fetching:v},C]=Z.useMutation(E.CREATE_MODULE),p=F.getFragmentData(E.ACTION_FRAGMENT,d?a?.quantumOwnedActions:a?.actions)??[],r=F.getFragmentData(E.ACTION_MODULE_FRAGMENT,u?.module),m=F.getFragmentData(E.MODULE_ACTION_FRAGMENT,r?.moduleActions)??[],[T,w]=s.useState([...m.map(S=>S.actionId)??[]]),[D,W]=s.useState(r?.name??""),[B,O]=s.useState([]),[H,te]=s.useState(r?.description??"");s.useEffect(()=>{r&&(w(m.map(S=>S.actionId)),W(r.name),te(r.description??""),O(r.categories.map(S=>F.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,S).id)??[]))},[r,m]);const _=s.useCallback(()=>{let S;const P={actions:T,name:D,categories:B.filter(M=>M!=="other"),description:H,quantumOwned:d};r?S=A({id:r.id,input:P}):S=C({input:P}),S.then(({error:M})=>{M?x(M):l()})},[C,A,T,D,H,B,r,l,x,d]);return s.useEffect(()=>{f&&f({cancelButton:b||v,saveButton:b||v||!D||H.trim().split(/\s+/).filter(Boolean).length>40})},[f,b,v,T,D,H]),s.useEffect(()=>{j&&j({cancelButton:n,saveButton:_})},[j,n,_]),e.jsxRuntimeExports.jsxs(t.Box,{width:"100%",children:[e.jsxRuntimeExports.jsx(Fe,{name:D,setName:W,actions:p,selectedActionIds:T,setSelectedActionIds:w,availableCategories:k??[],selectedCategoryIds:B,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||!D||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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./react-jsx-runtime-vendor-Dszzpdy0.cjs"),t=require("@chakra-ui/react");require("./moment-vendor-1cRqq0AH.cjs");const s=require("react"),ge=require("./utils-cn-FIKrq5Mb.cjs");require("./lodash-vendor-CWf2psR2.cjs");const Z=require("urql"),le=require("./hooks.cjs"),De=require("./ufuzzy-vendor-7qHa_k39.cjs"),ye=require("./react-icons-vendor-BF_sZq07.cjs"),ce=require("./react-select-vendor-sW1B_api.cjs"),N=require("./generated.cjs"),E=require("./graphql-BhVmuiCG.cjs"),Se=require("./react-dnd-vendor-BqsnzPKT.cjs"),re=require("./services-human-B4_65njx.cjs"),k=require("./generated-graphql.cjs"),de=require("./types.cjs"),_e=({setSearch:o,actions:n,updateUseCases:a,hideUseCaseFilter:p=!1})=>{const g=s.useMemo(()=>n?.flatMap(x=>x.useCases).filter((x,m,y)=>y.findIndex(r=>r.id===x.id)===m).map(x=>({label:x.name,value:x.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:ye.FaSearch,color:"gray.300"})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"Search by name...",width:"100%",maxW:p?void 0:"30rem",onChange:x=>o(x.target.value)})]}),!p&&e.jsxRuntimeExports.jsx(t.InputGroup,{size:"md",children:e.jsxRuntimeExports.jsx(ce.st,{size:"md",chakraStyles:{container:x=>({...x,width:"100%"})},menuPortalTarget:document.body,placeholder:"Filter use case",isMulti:!0,options:g,onChange:x=>a(x.map(m=>m.value))})})]})},ae=({children:o})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:o}),Ge=({value:o,onChange:n,disabled:a})=>{const p=s.useState(()=>Math.random().toString(36).substring(2,15))[0],g=s.useCallback((x,m)=>{a||n(y=>{const r=[...y],[d]=r.splice(x,1);return r.splice(m,0,d),r})},[n,a]);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((x,m)=>e.jsxRuntimeExports.jsx(Pe,{listKey:p,index:m,id:x.id,name:x.name,move:g,className:ge.cn(a&&"!cursor-default")},x.id))})]})})})})},Pe=({listKey:o,index:n,id:a,name:p,move:g,className:x})=>{const m=s.useRef(null),[{handlerId:y},r]=Se.useDrop({accept:o,collect:C=>({handlerId:C.getHandlerId()?.toString()??""}),hover:(C,A)=>{if(!m.current)return;const f=C.index,j=n;if(f===j)return;const u=m.current?.getBoundingClientRect(),c=(u.bottom-u.top)/2,S=A.getClientOffset().y-u.top;f<j&&S<c||f>j&&S>c||(g(f,j),C.index=j)}}),[{isDragging:d},R]=Se.useDrag({type:o,item:()=>({id:a,index:n}),collect:C=>({isDragging:C.isDragging()})}),D=d?.6:1,M=d?"grabbing":"grab";return R(r(m)),e.jsxRuntimeExports.jsxs(t.Tr,{ref:m,style:{opacity:D,cursor:M},"data-handler-id":y,className:x,children:[e.jsxRuntimeExports.jsx(t.Td,{children:n+1}),e.jsxRuntimeExports.jsx(t.Td,{children:p})]})},$e=({items:o,onChange:n,selectedItem:a,isDisabled:p,selectedProps:g,buttonProps:x})=>{const m=r=>r===a||r.value===a,y=r=>m(r)?{...x,...g}:x;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:p,children:o.map((r,d)=>e.jsxRuntimeExports.jsx(t.Tooltip,{label:r.tooltip,openDelay:50,closeDelay:200,placement:"top",visibility:r.tooltip?"visible":"hidden",hasArrow:!0,children:e.jsxRuntimeExports.jsx(t.Button,{onClick:()=>m(r)?null:n(r,d),isDisabled:r.disabled,...y(r),children:r.label})},d))})},Ce=(o,n)=>n<0?-1*Math.abs(o):Math.abs(o),Be=({isReversed:o,min:n,max:a,value:p,onChange:g,inputProps:x,size:m,zeroMarker:y,formatValue:r,valueLabel:d,positiveNegativeLabels:R,isDisabled:D,...M})=>{const[C,A]=s.useState([void 0,void 0]),f=C[0],j=C[1],u=y&&n<-5&&a>5,c=Number(p?.[0]??j??n)>0?1:-1,T=Number(p?.[1]??j??a)<0?-1:1,S=R?.[0]===R?.[1],$=p?.[0],U=p?.[1];s.useEffect(()=>{$!==void 0&&U!==void 0&&A([$.toFixed(0),U.toFixed(0)])},[$,U,A]);const q=s.useCallback(([w,P])=>{w<P&&A([w.toFixed(0),P.toFixed(0)])},[A]),O=s.useCallback(([w,P])=>{w<P&&g([w,P])},[g]),V=s.useCallback(()=>{A(([w,P])=>{const ee=isNaN(Number(w))?n:Number(w),Q=isNaN(Number(P))?a:Number(P),se=Ce(Number(ee),c),l=Ce(Number(Q),T),i=c<0?Math.max(se,n):Math.min(se,a),b=T<0?Math.max(l,n):Math.min(l,a);return i>b?(g([b,i]),[b.toFixed(0),i.toFixed(0)]):(g([i,b]),[i.toFixed(0),b.toFixed(0)])})},[g,A,c,T,n,a]),J=s.useCallback(w=>{const P=w===""||isNaN(Number(w))?w:Ce(Number(w),c);A(([ee,Q])=>[P.toString(),Q])},[A,c]),G=s.useCallback(w=>{const P=w===""||isNaN(Number(w))?w:Ce(Number(w),T);A(([ee,Q])=>[ee,P.toString()])},[A,T]),v=s.useMemo(()=>m==="xs"?"0.75rem":void 0,[m]),L=s.useCallback((w,P)=>{const ee=Number(P.target.value);if(!f||!j||![-1,1].includes(ee))return;const Q=i=>ee<0?-1*Math.abs(i):Math.abs(i),se=w?Q(Number(f)):Number(f),l=w?Number(j):Q(Number(j));se>l?g([l,se]):g([se,l])},[f,j,g]);return e.jsxRuntimeExports.jsxs(t.Flex,{direction:"column",...M,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(f??n),Number(j??a)],max:a,min:n,minStepsBetweenThumbs:3,step:1,onChange:q,onChangeEnd:O,isDisabled:D,children:[e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:n,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:m??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:r?r?.(n):n})}),e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:a,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:m??"sm",fontWeight:"semibold",style:{transform:"translateX(-100%)"},whiteSpace:"nowrap",children:r?r(a):a})}),u&&e.jsxRuntimeExports.jsxs(t.RangeSliderMark,{value:0,top:"-1em",pos:"relative",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:m,fontWeight:"semibold",children:r?.(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:v,h:v}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:1,w:v,h:v})]})}),d&&e.jsxRuntimeExports.jsxs(t.Flex,{direction:o?"row-reverse":"row",justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:m??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:d(n)}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:m??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:d(a)})]}),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:m,fontWeight:"bold",value:c,onChange:w=>L(!0,w),isDisabled:S||D,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:m??"sm",min:0,max:c<0?Math.abs(n):U??a,value:f===""?"":Math.abs(Number(f??n)),onChange:J,onBlur:V,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:D,...x,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),e.jsxRuntimeExports.jsx(t.NumberInput,{size:m??"sm",min:0,max:T<0?Math.abs($??n):a,precision:0,value:j===""?"":Math.abs(Number(j??a)),onChange:G,onBlur:V,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:D,...x,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),R&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:m,fontWeight:"bold",value:T,onChange:w=>L(!1,w),isDisabled:S||D,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:R[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:R[1]})]})]})]})},Ue=({tags:o,containerProps:n,...a})=>e.jsxRuntimeExports.jsx(t.HStack,{...n,children:o.map((p,g)=>e.jsxRuntimeExports.jsx(t.Tag,{...a,children:p},g))}),ze=new De.uFuzzy({}),qe=({action:o,quantumIconSrc:n})=>{const{getLabel:a}=le.useUiLabelContext(),p=s.useMemo(()=>({actionLowerCase:a("action").toLocaleLowerCase()}),[a]);return o.quantumOwned?e.jsxRuntimeExports.jsx(t.Tooltip,{label:`This ${p.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 ${p.actionLowerCase}`})})}):null},Qe=(o,n)=>{if(!n||!n.trim().length)return o;const a=o.map(g=>g.name??"");return ze.filter(a,n)?.map(g=>o[g])??[]},We=o=>!o||o.length===0?"None":o.map(n=>n.replace(/([A-Z])/g," $1").trim()).join(", "),He=(o,n)=>!n||n.length==0?o:o.filter(a=>a.useCases?.some(p=>n.includes(p.id))??!1),Fe=({actions:o,totalActions:n,onCreate:a,onDelete:p,onEdit:g,onView:x,onSelected:m,onDuplicate:y,disableMultiSelect:r,disableDelete:d,disableEdit:R,disableCreate:D,hideUseCase:M=!0,tableProps:C,containerProps:A,quantumIconSrc:f="/favicon.ico"})=>{const[j,u]=s.useState(""),[c,T]=s.useState(),{getLabel:S}=le.useUiLabelContext(),$=s.useMemo(()=>({action:S("action"),actionPlural:S("action_plural"),actionLowerCase:S("action").toLocaleLowerCase(),actionPluralLowerCase:S("action_plural").toLocaleLowerCase()}),[S]),U=s.useMemo(()=>{if(!o)return;const v=Qe(o,j);return M?v:He(v,c)},[o,j,c,M]),q=s.useCallback(()=>{if(!p)return;const L=o.filter(w=>w.selected&&!w.quantumOwned).map(w=>w.id);p(L)},[o,p]),O=s.useCallback(()=>{if(!y)return;const v=o.filter(L=>L.selected);y(v.map(L=>L.id)),m&&v.forEach(L=>m(L,!1))},[o,y,m]),V=s.useMemo(()=>o.some(v=>v.selected&&!v.quantumOwned),[o]),J=s.useMemo(()=>o.some(v=>v.selected),[o]),G=s.useMemo(()=>o.some(v=>v.selected&&v.quantumOwned),[o]);return e.jsxRuntimeExports.jsxs(t.Box,{...A,children:[e.jsxRuntimeExports.jsxs(t.Flex,{alignContent:"space-between",gap:4,children:[(a||p||y)&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mb:"1rem",gap:4,children:[a&&e.jsxRuntimeExports.jsxs(t.Button,{isDisabled:!a||D,colorScheme:"blackAlpha",backgroundColor:"gray.700",onClick:a,children:["Create New ",$.action]}),p&&!r&&e.jsxRuntimeExports.jsx(t.Tooltip,{label:G?V?`Quantum-owned ${$.actionPluralLowerCase} are selected and will be skipped`:`Selected ${$.actionPluralLowerCase} are quantum-owned and cannot be deleted`:void 0,shouldWrapChildren:!0,children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!V||!p||d,onClick:q,children:"Delete Selected"})}),y&&!r&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!J,onClick:O,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx(_e,{setSearch:u,actions:o,updateUseCases:T,hideUseCaseFilter:M})]}),e.jsxRuntimeExports.jsx(t.TableContainer,{mr:"2rem",overflowX:"hidden",...C,children:e.jsxRuntimeExports.jsxs(t.Table,{size:"md",variant:"simple",children:[e.jsxRuntimeExports.jsx(t.Thead,{position:"sticky",top:0,bg:"white",zIndex:1,children:e.jsxRuntimeExports.jsxs(t.Tr,{children:[e.jsxRuntimeExports.jsxs(t.Th,{fontWeight:"normal",children:["(showing ",U?.length??0," of"," ",n??o.length,")"]}),e.jsxRuntimeExports.jsx(t.Th,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Th,{children:"Sensor Locations"}),!M&&e.jsxRuntimeExports.jsx(t.Th,{children:"Use Case"}),e.jsxRuntimeExports.jsx(t.Th,{})]})}),e.jsxRuntimeExports.jsx(t.Tbody,{children:U?.map(v=>e.jsxRuntimeExports.jsxs(t.Tr,{className:ge.cn("hover:bg-[#f7f7f7]",!r&&"cursor-pointer",v.selected&&"bg-gray-200"),onClick:()=>{r||m?.(v,!v.selected)},children:[e.jsxRuntimeExports.jsx(t.Td,{children:e.jsxRuntimeExports.jsxs(t.Flex,{children:[!r&&e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:v.selected?e.jsxRuntimeExports.jsx(ye.FaCheckSquare,{className:"text-blue-500"}):e.jsxRuntimeExports.jsx(ye.FaSquare,{className:"text-gray-400"})}),(v.quantumOwned||!g)&&x&&e.jsxRuntimeExports.jsx(t.Button,{ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:L=>{L.stopPropagation(),x(v.id)},children:"View"}),!v.quantumOwned&&g&&e.jsxRuntimeExports.jsx(t.Button,{isDisabled:R,ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:L=>{L.stopPropagation(),g(v.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(qe,{action:v,quantumIconSrc:f}),v.name]})}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",whiteSpace:"break-spaces",children:We(v.sensorLocations)}),!M&&e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:e.jsxRuntimeExports.jsx(Ue,{containerProps:{flexWrap:"wrap"},tags:v.useCases?.map(L=>L.name)??[]})})]},v.id))})]})})]})},Ke=({onSave:o,onCancel:n,onError:a,hideButtons:p=!1,setButtonDisabled:g,setButtonOnClick:x,quantumOwned:m})=>{const y=t.useToast(),{getLabel:r}=le.useUiLabelContext(),d=s.useMemo(()=>({singular:r("action"),plural:r("action_plural"),pluralLowerCase:r("action_plural").toLowerCase(),singularLowerCase:r("action").toLowerCase()}),[r]),[R,D]=s.useState("copy"),[M,C]=s.useState(""),[A,f]=s.useState([]),[j,u]=s.useState(!1),[c]=Z.useQuery({query:E.GET_GROUPS}),[T]=Z.useQuery({query:E.GET_ACTIONS_BY_GROUP,variables:{groupId:M},pause:!M}),[,S]=Z.useMutation(E.CREATE_ACTION),[,$]=Z.useMutation(E.CONVERT_ACTION_TO_QUANTUM_OWNED),U=s.useMemo(()=>c.data?.groups?c.data.groups.map(l=>N.getFragmentData(E.GROUP_FRAGMENT,l)):[],[c.data]),q=s.useMemo(()=>T.data?T.data.actions.map(i=>{const b=N.getFragmentData(E.ACTION_FRAGMENT,i),F=N.getFragmentData(E.REPORT_FRAGMENT,b.reports),z=N.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,b.categories),W=N.getFragmentData(E.METADATA_GROUP_FRAGMENT,b.metadataGroups).map(K=>({...K,data:K.data.map(H=>N.getFragmentData(E.METADATA_ITEM_FRAGMENT,H))}));return{...b,thresholds:N.getFragmentData(E.THRESHOLD_FRAGMENT,b.thresholds),reports:F.map(K=>({...K,thresholds:N.getFragmentData(E.THRESHOLD_FRAGMENT,K.thresholds)})),categories:z,metadataGroups:W}}):[],[T.data]),O=s.useMemo(()=>q.filter(l=>A.includes(l.id)),[q,A]),V=s.useCallback(l=>{const i=l?.value||"";C(i),f([])},[]),J=s.useCallback(l=>{const i=l.map(b=>b.value);f(i)},[]),G=s.useCallback(async l=>{const i={...l,name:`${l.name} (Copy)`,description:l.description||void 0,instructionsPointOfInterest:l.instructionsPointOfInterest||void 0,instructionsMovementReport:l.instructionsMovementReport||void 0,laterality:l.laterality,activityKind:l.activityKind,sensorLocations:l.sensorLocations,thresholds:l.thresholds.map(F=>({...F,id:void 0})),categories:l.categories.map(F=>F.id),quantumOwned:m,metadataItemIds:l.metadataGroups.flatMap(F=>F.data.map(z=>z.id)).filter(F=>F!==void 0),reports:l.reports.map(F=>({...F,id:void 0,thresholds:F.thresholds.map(z=>({...z,id:void 0}))})),id:void 0},b=await S({fields:i});if(b.error)throw new Error(b.error.message);if(b.data?.createAction)return N.getFragmentData(E.ACTION_FRAGMENT,b.data.createAction);throw new Error("No action data returned")},[S,m]),v=s.useCallback(async l=>{const i=await $({id:l.id});if(i.error)throw new Error(i.error.message);if(i.data?.convertActionToQuantumOwned)return N.getFragmentData(E.ACTION_FRAGMENT,i.data.convertActionToQuantumOwned);throw new Error("No action data returned")},[$]),L=s.useCallback(async()=>{if(u(!0),!O.length){const l=new Error(`No ${d.pluralLowerCase} selected for ${R==="copy"?"copying":"converting"}`);a?.(l),u(!1);return}try{const l=[];let i=0;const b=R==="copy"?G:v,F=R==="copy"?"copy":"convert";for(const z of O)try{const te=await b(z);l.push(te)}catch(te){console.error(`Failed to ${F} ${d.singularLowerCase} "${z.name}":`,te),i++}if(l.length>0){const z=l.length,te=O.length,W=R==="copy"?"copied":"converted",K=R==="copy"?"copy":"convert";y({title:i>0?`Partial ${K} completed`:`${d.plural} ${W} successfully`,description:i>0?`${z} of ${te} ${d.pluralLowerCase} ${W} successfully`:`${z} ${z>1?d.pluralLowerCase:d.singularLowerCase} ${W} successfully`,status:i>0?"warning":"success",duration:3e3,isClosable:!0}),o?.(),C(""),f([])}else throw new Error(`Failed to ${F} any ${d.pluralLowerCase}`)}catch(l){const i=R==="copy"?"copy":"convert",b=l instanceof Error?l.message:`Failed to ${i} ${d.pluralLowerCase}`;y({title:`${R==="copy"?"Copy":"Convert"} failed`,description:b,status:"error",duration:5e3,isClosable:!0}),a?.(l instanceof Error?l:new Error(b))}finally{u(!1)}},[O,R,G,v,y,o,a,d]),w=s.useCallback(()=>{C(""),f([]),D("copy"),n?.()},[n]);s.useEffect(()=>{g&&g({cancelButton:!1,saveButton:O.length===0||j})},[O.length,j,g]),s.useEffect(()=>{x&&x({cancelButton:w,saveButton:L})},[x,w,L]);const P=s.useMemo(()=>U.map(l=>({value:l.id,label:l.name})),[U]),ee=s.useMemo(()=>q.filter(l=>R==="copy"?!0:!l.quantumOwned).map(l=>({value:l.id,label:l.name,isQuantumOwned:l.quantumOwned})),[q,R]),Q=c.fetching,se=T.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[m&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ae,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:R,onChange:l=>{D(l),f([])},children:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:6,children:[e.jsxRuntimeExports.jsx(t.Radio,{value:"copy",colorScheme:"blue",children:e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:1,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"medium",children:["Copy ",d.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",d.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 ",d.singular]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Convert existing"," ",d.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:P,value:P.find(l=>l.value===M)||null,onChange:V,isLoading:Q,isDisabled:Q,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]})]})]}),M&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsxs(ae,{children:["Select ",d.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 ",d.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(ce.st,{placeholder:`Choose ${d.pluralLowerCase} to ${R}...`,options:ee,value:ee.filter(l=>A.includes(l.value)),onChange:J,isDisabled:ee.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(l,{context:i})=>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:l.label}),i==="value"&&l.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),l.isQuantumOwned&&i==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),ee.length===0&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:["No ",d.pluralLowerCase," found"]})]}),T.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 ",d.pluralLowerCase,":"," ",T.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?`${d.singular} to ${R==="copy"?"Copy":"Convert"}:`:`${O.length} ${d.plural} to ${R==="copy"?"Copy":"Convert"}:`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[O.map((l,i)=>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:[i+1,". ",l.name]}),l.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:[l.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",l.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Type:"})," ",l.activityKind]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Laterality:"})," ",l.laterality]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Sensor Locations:"})," ",l.sensorLocations.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Thresholds:"})," ",l.thresholds.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Use Cases:"})," ",l.useCases.map(b=>b.name).join(", ")||"None"]})]})]},l.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," ",d.pluralLowerCase," will be"," ",R==="copy"?"copied":"converted"]})})]})]}),!p&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:w,isDisabled:j,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:R==="copy"?"blue":"green",onClick:L,isDisabled:O.length===0||j,isLoading:j,loadingText:`${R==="copy"?"Copying":"Converting"}...`,children:[R==="copy"?"Copy":"Convert"," ",O.length===1?d.singular:`${O.length} ${d.plural}`]})]})]})})},Ye=({onSave:o,onCancel:n,onError:a,hideButtons:p=!1,setButtonDisabled:g,setButtonOnClick:x,quantumOwned:m})=>{const y=t.useToast(),{getLabel:r}=le.useUiLabelContext(),d=s.useMemo(()=>({singular:r("module"),plural:r("module_plural"),pluralLowerCase:r("module_plural").toLowerCase(),singularLowerCase:r("module").toLowerCase()}),[r]),R=s.useMemo(()=>({singular:r("action"),plural:r("action_plural"),pluralLowerCase:r("action_plural").toLowerCase(),singularLowerCase:r("action").toLowerCase()}),[r]),[D,M]=s.useState(""),[C,A]=s.useState([]),[f,j]=s.useState(!1),[u,c]=s.useState("copy"),[T]=Z.useQuery({query:E.GET_GROUPS}),[S]=Z.useQuery({query:E.GET_MODULES_BY_GROUP,variables:{groupId:D},pause:!D}),[,$]=Z.useMutation(E.CREATE_MODULE),[,U]=Z.useMutation(E.UPDATE_MODULE),[,q]=Z.useMutation(E.CREATE_ACTION),[,O]=Z.useMutation(E.CONVERT_ACTION_TO_QUANTUM_OWNED),V=s.useMemo(()=>T.data?.groups?T.data.groups.map(i=>N.getFragmentData(E.GROUP_FRAGMENT,i)):[],[T.data]),J=s.useMemo(()=>S.data?.modules?N.getFragmentData(E.ACTION_MODULE_FRAGMENT,S.data?.modules).map(b=>{const F=N.getFragmentData(E.MODULE_ACTION_FRAGMENT,b.moduleActions);return{...b,moduleActions:F.map(z=>({...z,action:N.getFragmentData(E.ACTION_FRAGMENT,z.action)})),categories:N.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,b.categories)}}):[],[S.data]),G=s.useMemo(()=>J.filter(i=>C.includes(i.id)),[J,C]),v=s.useCallback(i=>{const b=i?.value||"";M(b),A([])},[]),L=s.useCallback(i=>{const b=i.map(F=>F.value);A(b)},[]),w=s.useCallback(async()=>{if(j(!0),!G.length){j(!1);const i=new Error(`No modules selected for ${u==="convert"?"converting":"copying"}`);a?.(i);return}try{const i=[];let b=0;for(const F of G)try{let z=F.moduleActions.map(te=>te.actionId);if(m){const te=F.moduleActions.map(H=>H.action),W=async H=>{if(u==="copy"){if(H.quantumOwned)return H;const ue=N.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,H.categories),Ee=N.getFragmentData(E.METADATA_GROUP_FRAGMENT,H.metadataGroups).map(ie=>N.getFragmentData(E.METADATA_ITEM_FRAGMENT,ie.data).map(he=>he.id)).flat(),me=N.getFragmentData(E.REPORT_FRAGMENT,H.reports).map(ie=>({...ie,id:void 0,thresholds:N.getFragmentData(E.THRESHOLD_FRAGMENT,ie.thresholds).map(he=>({...he,id:void 0}))})),pe=N.getFragmentData(E.THRESHOLD_FRAGMENT,H.thresholds).map(ie=>({...ie,id:void 0})),fe={...H,quantumOwned:!0,thresholds:pe,categories:ue?.map(ie=>ie.id),reports:me,metadataIds:Ee,id:void 0},je=await q({fields:fe});return je.error||!je.data?.createAction?null:N.getFragmentData(E.ACTION_FRAGMENT,je.data.createAction)}if(H.quantumOwned)return H;const xe=await O({id:H.id});return xe.error||!xe.data?.convertActionToQuantumOwned?null:N.getFragmentData(E.ACTION_FRAGMENT,xe.data.convertActionToQuantumOwned)};z=(await Promise.all(te.map(W))).filter(H=>!!H).map(H=>H.id)}if(u==="convert"){const te={name:F.name,description:F.description||void 0,actions:z,categories:F.categories.map(K=>K.id),quantumOwned:!0},W=await U({id:F.id,input:te});if(W.error)throw new Error(W.error.message);if(W.data?.updateModule){const K=N.getFragmentData(E.ACTION_MODULE_FRAGMENT,W.data.updateModule);i.push(K)}}else{const te={name:`${F.name} (Copy)`,description:F.description||void 0,actions:z,categories:F.categories.map(K=>K.id),quantumOwned:m},W=await $({input:te});if(W.error)throw new Error(W.error.message);if(W.data?.createModule){const K=N.getFragmentData(E.ACTION_MODULE_FRAGMENT,W.data.createModule);i.push(K)}}}catch(z){console.error(`Failed to ${u==="convert"?"convert":"copy"} module "${F.name}":`,z),b++}if(i.length>0){const F=i.length,z=G.length;y({title:b>0?`Partial ${u==="convert"?"convert":"copy"} completed`:`${d.plural} ${u==="convert"?"converted":"copied"} successfully`,description:b>0?`${F} of ${z} ${d.plural} ${u==="convert"?"converted":"copied"} successfully`:`${F} ${F>1?d.plural:d.singular} ${u==="convert"?"converted":"copied"} successfully`,status:b>0?"warning":"success",duration:3e3,isClosable:!0}),i.length>0&&o?.(),M(""),A([])}else throw new Error(`Failed to ${u==="convert"?"convert":"copy"} any modules`)}catch(i){const b=i instanceof Error?i.message:`Failed to ${u==="convert"?"convert":"copy"} modules`;y({title:u==="convert"?"Convert failed":"Copy failed",description:b,status:"error",duration:5e3,isClosable:!0}),a?.(i instanceof Error?i:new Error(b))}finally{j(!1)}},[G,$,U,y,o,a,m,q,O,u,d]),P=s.useCallback(()=>{M(""),A([]),c("copy"),n?.()},[n]);s.useEffect(()=>{g&&g({cancelButton:!1,saveButton:G.length===0||f})},[G.length,f,g]),s.useEffect(()=>{x&&x({cancelButton:P,saveButton:w})},[x,P,w]);const ee=s.useMemo(()=>V.map(i=>({value:i.id,label:i.name})),[V]),Q=s.useMemo(()=>J.filter(i=>u==="copy"?!0:!i.quantumOwned).map(i=>({value:i.id,label:i.name,isQuantumOwned:i.quantumOwned})),[J,u]),se=T.fetching,l=S.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[m&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ae,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:u,onChange:i=>{c(i),A([])},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 ",d.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",d.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 ",d.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:ee,value:ee.find(i=>i.value===D)||null,onChange:v,isLoading:se,isDisabled:se,isClearable:!0}),T.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: ",T.error.message]})]})]}),D&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ae,{children:u==="convert"?`Select ${d.plural} to Convert`:`Select ${d.plural} to Copy`}),l?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 ",d.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(ce.st,{placeholder:u==="convert"?`Choose ${d.pluralLowerCase} to convert...`:`Choose ${d.pluralLowerCase} to copy...`,options:Q,value:Q.filter(i=>C.includes(i.value)),onChange:L,isDisabled:Q.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(i,{context:b})=>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:i.label}),b==="value"&&i.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),i.isQuantumOwned&&b==="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 ",d.pluralLowerCase," found in this group"]})]}),S.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load ",d.pluralLowerCase,":"," ",S.error.message]})]})]}),G.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:G.length===1?`${d.singular} to ${u==="copy"?"Copy":"Convert"}`:`${G.length} ${d.plural} to ${u==="copy"?"Copy":"Convert"}`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[G.map((i,b)=>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:[b+1,". ",i.name]}),i.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:[i.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",i.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Activities:"})," ",i.moduleActions.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Categories:"})," ",i.categories.map(F=>F.name).join(", ")||"None"]})]})]},i.id)),G.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: ",G.length," ",d.pluralLowerCase," will be"," ",u==="copy"?"copied":"converted"]})}),m&&G.filter(i=>i.moduleActions.some(b=>!b.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:u==="convert"?`Converting ${d.plural} will convert non QM-Owned ${R.plural} to QM-Owned ${R.plural}`:`Copying ${d.plural} with Non QM-Owned ${R.plural} will create corresponding QM-Owned ${R.plural}`})})]})]}),!p&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:P,isDisabled:f,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:u==="copy"?"blue":"green",onClick:w,isDisabled:G.length===0||f,isLoading:f,loadingText:`${u==="copy"?"Copying":"Converting"}...`,children:[u==="copy"?"Copy":"Convert"," ",G.length===1?d.singular:`${G.length} ${d.plural}`]})]})]})})},Oe=s.createContext(void 0),ve=()=>{const o=s.useContext(Oe);if(!o)throw new Error("useUpsertModuleFormContext must be used within a UpsertModuleFormProvider");return o},Ne=({name:o,setName:n,actions:a,selectedActionIds:p,setSelectedActionIds:g,availableCategories:x,selectedCategoryIds:m,setSelectedCategoryIds:y,description:r,setDescription:d,...R})=>{const D=t.useDisclosure(),M=s.useMemo(()=>a.map(c=>({...c,selected:p.includes(c.id)})),[a,p]),C=s.useMemo(()=>a.reduce((c,T)=>(c[T.id]=T,c),{}),[a]),A=s.useMemo(()=>p.map(c=>C[c]),[p,C]),f=s.useCallback((c,T)=>{g(T?[...p,c.id]:p.filter(S=>S!==c.id))},[p,g]),j=s.useCallback(c=>{n(c.target.value)},[n]),u=s.useCallback(c=>{d?.(c.target.value)},[d]);return e.jsxRuntimeExports.jsxs(t.Box,{...R,children:[e.jsxRuntimeExports.jsxs(t.HStack,{gap:"2rem",children:[e.jsxRuntimeExports.jsx(Je,{name:o??"",onInputChange:j}),e.jsxRuntimeExports.jsx(Ve,{availableCategories:x,value:m,onChange:y})]}),e.jsxRuntimeExports.jsx(Xe,{description:r??"",onInputChange:u}),e.jsxRuntimeExports.jsx(Ze,{value:A,onChange:g,onAdjustActivities:()=>D.onOpen()}),e.jsxRuntimeExports.jsxs(t.Modal,{isOpen:D.isOpen,onClose:D.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(Fe,{actions:M,onSelected:f,disableCreate:!0,disableDelete:!0,tableProps:{height:"28rem",overflowY:"auto"}})}),e.jsxRuntimeExports.jsx(t.ModalFooter,{children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:D.onClose,isDisabled:p.length===0,children:"Done"})})]})]})]})},Je=s.memo(({name:o,onInputChange:n})=>{const{getLabel:a}=le.useUiLabelContext(),p=a("module"),{isView:g}=ve();return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(ae,{children:[p," Name"]}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. ACL RTP Test Battery",value:o,onChange:n,isRequired:!0,isDisabled:g})]})}),Ve=s.memo(({availableCategories:o,value:n,onChange:a})=>{const{getLabel:p}=le.useUiLabelContext(),g=p("module"),{isView:x}=ve(),m=s.useMemo(()=>[...o,{id:"other",name:"Other"}],[o]),y=s.useMemo(()=>m.map(r=>({value:r.id,label:r.name})),[m]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(ae,{children:[g," Category"]}),e.jsxRuntimeExports.jsx(ce.st,{isDisabled:o.length===0||x,options:y,value:n.length===0?{value:"other",label:"Other"}:m.filter(r=>n.includes(r.id)).map(r=>({value:r.id,label:r.name}))[0],onChange:r=>a(r?[r.value]:[]),placeholder:"Select category"})]})}),Xe=s.memo(({description:o,onInputChange:n})=>{const{getLabel:a}=le.useUiLabelContext(),p=a("module"),{isView:g}=ve();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"," ",p.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,isDisabled:g})]})}),Ze=s.memo(({value:o,onChange:n,onAdjustActivities:a})=>{const{getLabel:p}=le.useUiLabelContext(),{isView:g}=ve(),x=s.useMemo(()=>({module:p("module"),moduleLowerCase:p("module").toLocaleLowerCase(),action:p("action"),actionPlural:p("action_plural"),actionPluralLowerCase:p("action_plural").toLocaleLowerCase()}),[p]),m=s.useMemo(()=>o.map(y=>({id:y.id,name:y.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:[x.actionPlural,e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",children:["Drag and drop to reorder the ",x.actionPluralLowerCase," in this ",x.moduleLowerCase,"."]})]})}),!g&&e.jsxRuntimeExports.jsxs(t.Button,{size:"sm",variant:"solid",colorScheme:"blue",onClick:a,children:["Add / Remove ",x.actionPlural]})]}),m.length===0?e.jsxRuntimeExports.jsx(t.VStack,{children:e.jsxRuntimeExports.jsxs(t.Text,{color:"gray.500",fontSize:"lg",mb:"4rem",mt:"4rem",children:["No ",x.actionPluralLowerCase," selected for this"," ",x.moduleLowerCase,".",!g&&e.jsxRuntimeExports.jsxs(t.Button,{ml:"0.5em",size:"sm",variant:"link",colorScheme:"blue",onClick:a,children:["Add ",x.actionPluralLowerCase,"."]})]})}):e.jsxRuntimeExports.jsx(Ge,{value:m,onChange:y=>{const r=y(m);n(r.map(d=>d.id))},disabled:g})]})}),Ie=({value:o,onChange:n,forceKind:a,disableRemove:p,disableKind:g,isDisabled:x,lockRanges:m,...y})=>{const r=s.useMemo(()=>[...o].sort((M,C)=>{const A=de.availablePlanes.indexOf(M.plane),f=de.availablePlanes.indexOf(C.plane);return A-f}),[o]),d=s.useCallback(M=>"segment"in M.id?re.getSegmentNameWithPlane(M.id.segment,M.plane,!0)??"Unknown":re.getJointNameWithPlane(M.id.joint,M.plane,!0)??"Unknown",[]),R=s.useCallback((M,C)=>{const A=r.findIndex(j=>j.id===C.id&&j.plane===C.plane);let f=[...r];a&&(C={...C,kind:a}),f[A]=C,m&&(f=f.map(j=>({...j,min:C.min,max:C.max}))),n(f)},[n,r,a,m]),D=s.useCallback(M=>{const C=r.filter(A=>A.id!==M.id||A.plane!==M.plane);n(C)},[n,r]);return e.jsxRuntimeExports.jsx(t.VStack,{alignItems:"flex-start",overflowY:"auto",...y,children:r.map((M,C)=>e.jsxRuntimeExports.jsx(et,{label:d(M),parameter:M,onChange:A=>R(C,A),onRemove:p||x?void 0:()=>D(M),forceKind:a,disableKind:g||x,isDisabled:x},`${JSON.stringify(M.id)}-${M.plane}`))})},et=({label:o,parameter:n,onChange:a,onRemove:p,forceKind:g,disableKind:x,isDisabled:m})=>{const y=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:r,max:d}="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"}),p&&!m&&e.jsxRuntimeExports.jsx(t.IconButton,{size:"xs",variant:"ghost","aria-label":"delete",icon:e.jsxRuntimeExports.jsx(t.Icon,{as:ye.FaTrash}),onClick:p}),!g&&e.jsxRuntimeExports.jsx($e,{selectedItem:n?.kind??k.ThresholdKind.Limit,onChange:({value:R})=>a({...n,kind:R}),isDisabled:x||m,buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:k.ThresholdKind.Limit,label:"limit"},{value:k.ThresholdKind.Target,label:"target"}]})]}),e.jsxRuntimeExports.jsx(Be,{w:"100%",size:"xs",min:r,max:d,zeroMarker:!0,value:[n.min,n.max],onChange:R=>a({...n,min:R[0],max:R[1]}),formatValue:R=>`${Math.abs(R)}°`,valueLabel:R=>y(R)??"",positiveNegativeLabels:y(0)?[y(-1)??"",y(1)??""]:void 0,isDisabled:m})]})},Te=(o,n)=>"segment"in o&&"segment"in n&&o.segment===n.segment||"joint"in o&&"joint"in n&&o.joint===n.joint,we=({options:o,value:n,onChange:a,forceKind:p,singleValue:g,singleValueSideless:x,editOnly:m,disableKind:y,maxParameters:r,...d})=>{const R=x?2:r,D=s.useMemo(()=>{const j=new Map;return o.forEach(u=>{const c="joint"in u.id;let T,S;if(c?(T=re.getJointNameWithPlane(u.id.joint,u.plane,!0)??"Unknown",S=`joint:${u.id.joint}`):(T=re.getSegmentNameWithPlane(u.id.segment,u.plane,!0)??"Unknown",S=`segment:${u.id.segment}`),!j.has(S)){const q=c?re.getPartName(u.id.joint)??"Unknown Joint":re.getPartName(u.id.segment)??"Unknown Segment";j.set(S,{label:q,options:[]})}const $=j.get(S),U=[T,c?u.id.joint:u.id.segment,u.plane].filter(Boolean).map(q=>String(q).toLowerCase().replace(/\s+|_/g,""));$.options.push({label:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:2,justify:"space-between",w:"100%",pl:3,children:[e.jsxRuntimeExports.jsx(t.Text,{children:T}),u.sensorOnly&&e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor Only"})]}),value:u.id,plane:u.plane,sensorOnly:u.sensorOnly,searchTokens:U})}),Array.from(j.values())},[o]),M=s.useMemo(()=>{if(!x||n.length===0)return D;const j=n[0];return D.map(u=>({...u,options:u.options.filter(c=>de.getAnalysisPartIdNoSide(c.value)===de.getAnalysisPartIdNoSide(j.id)&&c.plane===j.plane)})).filter(u=>u.options.length>0)},[D,n,x]),C=s.useMemo(()=>D.flatMap(u=>u.options).filter(u=>n.some(c=>Te(c.id,u.value)&&c.plane===u.plane)),[D,n]),A=s.useCallback((j,u)=>{if(!u)return!0;const c=u.toLowerCase().replace(/\s+|_/g,""),T=j.data;return!T||!T.searchTokens?!1:T.searchTokens.some(S=>S.includes(c))},[]),f=s.useCallback(j=>{const u=j.map(c=>{const T=n.find(O=>Te(O.id,c.value)&&O.plane===c.plane),S=o.find(O=>Te(O.id,c.value)&&O.plane===c.plane),$=x?n.find(O=>de.getAnalysisPartIdNoSide(O.id)===de.getAnalysisPartIdNoSide(c.value)&&O.plane===c.plane):void 0,U=$&&!T?$.min:S&&S.min?S.min:0,q=$&&!T?$.max:S&&S.max?S.max:0;return T??{id:c.value,plane:c.plane,min:U,max:q,sensorOnly:c.sensorOnly,kind:p??k.ThresholdKind.Limit}});a(u)},[a,n,o,p,x]);return s.useEffect(()=>{const j=n.filter(u=>o.some(c=>Te(c.id,u.id)&&c.plane===u.plane));j.length!==n.length&&a(j)},[o,a,n]),e.jsxRuntimeExports.jsxs(t.Box,{...d,children:[e.jsxRuntimeExports.jsx(ce.st,{isMulti:!g,placeholder:n.length?`${n.length} selected`:"Search...",value:C,isDisabled:m||C.length>=(R??1/0),onChange:j=>Array.isArray(j)?f([...j]):f(j!==null?[j]:[]),options:M,controlShouldRenderValue:!1,formatOptionLabel:j=>j.label,filterOption:A,isSearchable:!0}),e.jsxRuntimeExports.jsx(Ie,{marginTop:2,maxH:"28rem",value:n,onChange:a,forceKind:p,disableKind:y,isDisabled:m,lockRanges:x})]})},Le=o=>{switch(o){case k.SensorLocation.Thorax:return"Thorax";case k.SensorLocation.CenterBack:return"Center Back";case k.SensorLocation.Pelvis:return"Pelvis";case k.SensorLocation.LeftThigh:return"Left Thigh";case k.SensorLocation.RightThigh:return"Right Thigh";case k.SensorLocation.LeftShank:return"Left Shank";case k.SensorLocation.RightShank:return"Right Shank";case k.SensorLocation.LeftFoot:return"Left Foot";case k.SensorLocation.RightFoot:return"Right Foot";case k.SensorLocation.LeftUpperArm:return"Left Upper Arm";case k.SensorLocation.RightUpperArm:return"Right Upper Arm";case k.SensorLocation.LeftForearm:return"Left Forearm";case k.SensorLocation.RightForearm:return"Right Forearm";case k.SensorLocation.Head:return"Head"}},tt=o=>{switch(o){case k.ReportKind.GeneralActivity:return"General Activity";case k.ReportKind.MovementCoordination:return"Movement Coordination";case k.ReportKind.PointOfInterest:return"Point of Interest";case k.ReportKind.Range:return"Range";case k.ReportKind.StabilityBalance:return"Stability Balance"}},st=({id:o,onError:n,onCancel:a,onSave:p,hideButtons:g,setButtonOnClick:x,setButtonDisabled:m,quantumOwned:y,isView:r})=>{const d=Z.useClient(),[{fetching:R},D]=Z.useMutation(E.CREATE_ACTION),[{fetching:M},C]=Z.useMutation(E.UPDATE_ACTION),[{data:A}]=Z.useQuery({query:E.GET_ACTION_BY_ID,variables:{id:o??""},pause:!o}),f=s.useMemo(()=>{const h=N.getFragmentData(E.ACTION_FRAGMENT,A?.getActionById);if(!h)return null;const I=N.getFragmentData(E.REPORT_FRAGMENT,h.reports).map(B=>({...B,thresholds:N.getFragmentData(E.THRESHOLD_FRAGMENT,B.thresholds)}));return{...h,thresholds:N.getFragmentData(E.THRESHOLD_FRAGMENT,h.thresholds),reports:I}},[A]),j=R||M,u=!!f&&!!o,{getLabel:c}=le.useUiLabelContext(),T=s.useMemo(()=>({action:c("action")}),[c]),S=s.useMemo(()=>[{key:"module_category",label:"Link Category",multi:!0},{key:"activity_type",label:`${T.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}],[T.action]),[$,U]=s.useState(""),[q,O]=s.useState(""),[V,J]=s.useState(""),[G,v]=s.useState(""),[L,w]=s.useState([]),[P,ee]=s.useState({}),[Q,se]=s.useState(null),[l,i]=s.useState([]),[b,F]=s.useState([]),[z,te]=s.useState(""),[W,K]=s.useState([]),H=le.useAllPartParameters(),xe=s.useMemo(()=>H.filter(h=>h.sensorOnly),[H]),ue=s.useMemo(()=>{const h=[{label:"General Activity",value:k.ReportKind.GeneralActivity},{label:"Movement Coordination",value:k.ReportKind.MovementCoordination},{label:"Point of Interest",value:k.ReportKind.PointOfInterest},{label:"Range",value:k.ReportKind.Range},{label:"Stability Balance",value:k.ReportKind.StabilityBalance}],_=W.map(I=>I.kind);return h.filter(I=>!_.includes(I.value))},[W]),Re=$.length>0,[Ee,Ae]=s.useState({});s.useEffect(()=>{const h=S.map(_=>d.query(E.GET_METADATA_BY_KEY,{key:_.key}));Promise.all(h).then(_=>{const I={};_.forEach(B=>{if(B.error||!B.data)return;const Y=N.getFragmentData(E.METADATA_GROUP_FRAGMENT,B.data.getMetadataByKey),X=N.getFragmentData(E.METADATA_ITEM_FRAGMENT,Y.data);I[Y.key]=X.map(oe=>({label:oe.label||oe.value,value:oe.value,id:oe.id}))}),ee(I)})},[d,S]),s.useEffect(()=>{if(f){const _=N.getFragmentData(E.METADATA_GROUP_FRAGMENT,f.metadataGroups).map(Y=>Y.data.map(X=>N.getFragmentData(E.METADATA_ITEM_FRAGMENT,X).id)),I=f.reports.map(Y=>({id:Y.id,instructions:Y.instructions??"",kind:Y.reportKind,parameters:Y.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 Me=oe.id[X.partKind];return Me?Me===X.partId&&oe.plane===X.partDimension:!1})})),sensorLocations:Y.sensorLocations})),B={name:f.name,description:f.description||"",cameraPlacement:f.cameraPlacement||"",videoLink:f.videoLink||"",metadataIds:_.flat(),reports:I};U(B.name),O(B.description),J(B.cameraPlacement),v(B.videoLink),w(B.metadataIds),K(I),Ae(B)}},[f]);const me=s.useMemo(()=>JSON.stringify(Ee)!==JSON.stringify({name:$,description:q,cameraPlacement:V,videoLink:G,metadataIds:L,reports:W}),[Ee,$,q,V,G,L,W]),pe=s.useCallback(()=>{const h={name:$,description:q,cameraPlacement:V,videoLink:G,metadataItemIds:L,laterality:k.ActionLaterality.Either,quantumOwned:y,sessionType:[],thresholds:[],reports:W.map(I=>({id:I.isNew?void 0:I.id,reportKind:I.kind,sensorLocations:I.sensorLocations,instructions:I.instructions,thresholds:I.parameters.map(B=>({id:B.oldId,kind:B.kind,min:B.min,max:B.max,partKind:"joint"in B.id?"joint":"segment",partId:"joint"in B.id?B.id.joint:B.id.segment,partDimension:B.plane}))}))};let _;u&&o?_=C({id:o,fields:h}):_=D({fields:h}),_.then(({error:I})=>{I?n(I):p()})},[y,D,C,o,$,q,V,G,L,W,u,p,n]);s.useEffect(()=>{m&&m({cancelButton:j,saveButton:r?!0:j||!Re||!me})},[j,m,Re,me,r]),s.useEffect(()=>{x&&x({cancelButton:a,saveButton:r?()=>{}:pe})},[x,a,pe,r]);const fe=s.useCallback(h=>{const _=re.getSuggestedSensorLocations(h.map(I=>"joint"in I.id?I.id.joint:I.id.segment));F(_)},[]);s.useEffect(()=>{fe(l)},[l,fe]);const je=s.useCallback(()=>{if(!Q)return;const h=Q===k.ReportKind.PointOfInterest,_={id:Date.now().toString(),kind:Q,parameters:h?[]:l,sensorLocations:h?[]:b,instructions:h?z:"",isNew:!0};K(I=>[...I,_]),se(null),i([]),F([]),te("")},[Q,l,b,z]),ie=s.useCallback(h=>{K(_=>_.filter(I=>I.id!==h))},[]),he=(h,_)=>{const I=S.find(Y=>Y.key===h);if(!I)return;const B=I.multi?(_??[]).map(Y=>Y.id):_?[_.id]:[];w(Y=>[...Y.filter(oe=>Object.values(P).flat().find(be=>be.id===oe)&&!Object.keys(P).find(be=>P[be]?.some(ke=>ke.id===oe&&be===h))),...B])};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:$,onChange:h=>U(h.target.value),type:"text",placeholder:"i.e. Lunge & Return",isDisabled:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Camera Placement"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:V,onChange:h=>J(h.target.value),rows:2,placeholder:"(optional) Describe camera setup, placement, angles",isDisabled:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Video Link"}),e.jsxRuntimeExports.jsx(t.Input,{value:G,onChange:h=>v(h.target.value),type:"url",placeholder:"(optional) https://...",isDisabled:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Description"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:q,onChange:h=>O(h.target.value),rows:2,placeholder:"(optional) Describe how to perform the test or exercise",isDisabled:r})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(ne,{children:"Metadata Tags"}),S.map(h=>e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:h.label}),e.jsxRuntimeExports.jsx(ce.st,{isMulti:h.multi,value:P[h.key]?.filter(_=>L.includes(_.id)),onChange:_=>{he(h.key,_)},options:P[h.key],placeholder:`Select ${h.multi?"one or more":"one"} ${h.label.toLowerCase()}`,isDisabled:r,isClearable:h.multi})]},h.key))]})]})}),e.jsxRuntimeExports.jsx(t.TabPanel,{px:0,children:e.jsxRuntimeExports.jsxs("div",{className:ge.cn("grid grid-cols-1 gap-6",!r&&"md:grid-cols-2"),children:[e.jsxRuntimeExports.jsxs("div",{className:ge.cn("space-y-4",r&&"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(h=>h.value===Q):null,onChange:h=>se(h?.value||null),options:ue,placeholder:"Select report kind...",isDisabled:r,isClearable:!0})]}),Q!==k.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(we,{options:H,value:l,onChange:i,editOnly:r})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Suggested Sensor Locations"}),e.jsxRuntimeExports.jsx(t.Input,{value:b.map(h=>Le(h)).join(", "),placeholder:"Auto-filled based on parameters...",isDisabled:!0})]})]}),Q===k.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:z,onChange:h=>te(h.target.value),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:r})]}),e.jsxRuntimeExports.jsx("div",{className:"w-full flex justify-end",children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:je,isDisabled:!Q||r||ue.length===0||Q!==k.ReportKind.PointOfInterest&&l.length===0,children:"Add Report"})})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(ne,{children:"Configured Reports"}),W.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:W.map(h=>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:tt(h.kind)}),!r&&e.jsxRuntimeExports.jsx(t.Button,{size:"xs",colorScheme:"red",variant:"ghost",onClick:()=>ie(h.id),children:"Remove"})]}),h.kind===k.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ne,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:h.instructions,onChange:_=>K(I=>I.map(B=>B.id===h.id?{...B,instructions:_.target.value}:B)),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:r})]}),h.kind!==k.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsx(we,{options:H,value:h.parameters,onChange:_=>{const I=_.map(Y=>Y.id.joint??Y.id.segment),B=re.getSuggestedSensorLocations(I);K(Y=>Y.map(X=>X.id===h.id?{...X,parameters:_,sensorLocations:B}:X))},editOnly:r}),h.kind!==k.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",mt:2,children:["Sensors:"," ",h.sensorLocations.map(_=>Le(_)).join(", ")]})]},h.id))})]})]})})]})]}),e.jsxRuntimeExports.jsx(t.HStack,{justify:"end",className:ge.cn((g||r)&&"!hidden"),children:e.jsxRuntimeExports.jsxs(t.ButtonGroup,{gap:4,children:[e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:j,onClick:a,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:j||!Re||!me,isLoading:j,onClick:pe,children:"Save changes"})]})})]})},ne=({children:o})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:o}),nt=({children:o,isView:n})=>e.jsxRuntimeExports.jsx(Oe.Provider,{value:{isView:n},children:o}),ot=({id:o,onCancel:n,onSave:a,onError:p,hideButtons:g,quantumOwned:x,setButtonOnClick:m,setButtonDisabled:y,isView:r})=>{const[{data:d}]=Z.useQuery({query:x?E.GET_QUANTUM_OWNED_ACTIONS:E.GET_ACTIONS}),[{data:R}]=Z.useQuery({query:E.GET_MODULE_BY_ID,variables:{id:o},pause:!o}),[{data:D}]=Z.useQuery({query:E.GET_ALL_MODULE_CATEGORIES}),M=N.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,D?.moduleCategories),[{fetching:C},A]=Z.useMutation(E.UPDATE_MODULE),[{fetching:f},j]=Z.useMutation(E.CREATE_MODULE),u=N.getFragmentData(E.ACTION_FRAGMENT,x?d?.quantumOwnedActions:d?.actions)??[],c=N.getFragmentData(E.ACTION_MODULE_FRAGMENT,R?.module),T=s.useMemo(()=>N.getFragmentData(E.MODULE_ACTION_FRAGMENT,c?.moduleActions)??[],[c?.moduleActions]),[S,$]=s.useState([...T.map(L=>L.actionId)??[]]),[U,q]=s.useState(c?.name??""),[O,V]=s.useState([]),[J,G]=s.useState(c?.description??"");s.useEffect(()=>{c&&($(T.map(L=>L.actionId)),q(c.name),G(c.description??""),V(c.categories.map(L=>N.getFragmentData(E.MODULE_CATEGORY_FRAGMENT,L).id)??[]))},[c,T]);const v=s.useCallback(()=>{let L;const w={actions:S,name:U,categories:O.filter(P=>P!=="other"),description:J,quantumOwned:x};c?L=A({id:c.id,input:w}):L=j({input:w}),L.then(({error:P})=>{P?p(P):a()})},[j,A,S,U,J,O,c,a,p,x]);return s.useEffect(()=>{y&&y({cancelButton:C||f,saveButton:C||f||!U||J.trim().split(/\s+/).filter(Boolean).length>40})},[y,C,f,S,U,J]),s.useEffect(()=>{m&&m({cancelButton:n,saveButton:v})},[m,n,v]),e.jsxRuntimeExports.jsx(t.Box,{width:"100%",children:e.jsxRuntimeExports.jsxs(nt,{isView:r,children:[e.jsxRuntimeExports.jsx(Ne,{name:U,setName:q,actions:u,selectedActionIds:S,setSelectedActionIds:$,availableCategories:M??[],selectedCategoryIds:O,setSelectedCategoryIds:V,description:J,setDescription:G}),!g&&!r&&e.jsxRuntimeExports.jsx(t.HStack,{justifyContent:"flex-start",children:e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mt:16,gap:4,children:[e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:C||f,onClick:n,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:C||f||!U||J.trim().split(/\s+/).filter(Boolean).length>40,isLoading:C||f,onClick:v,children:"Save"})]})})]})})};exports.ActivityList=Fe;exports.CopyActivityForm=Ke;exports.CopyModuleForm=Ye;exports.ModuleForm=Ne;exports.ParameterEditList=Ie;exports.ParameterEditSelect=we;exports.UpsertActivityForm=st;exports.UpsertModuleForm=ot;