quantum-component-library 1.4.65 → 1.4.67

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.
@@ -43,5 +43,14 @@ export type ActivityListProps = {
43
43
  containerProps?: BoxProps;
44
44
  /** Source for the quantum icon default is /favicon.ico*/
45
45
  quantumIconSrc?: string;
46
+ /**
47
+ * When true, each row shows a +/- counter instead of a single checkbox and
48
+ * allows selecting the same activity multiple times. `onSelected(action, true)`
49
+ * is called for each `+` click (add one instance); `onSelected(action, false)`
50
+ * for each `-` click (remove the most-recent instance).
51
+ */
52
+ allowDuplicateSelection?: boolean;
53
+ /** Required when allowDuplicateSelection is true. Returns the number of times the given action is currently selected. */
54
+ getSelectedCount?: (actionId: string) => number;
46
55
  };
47
- export declare const ActivityList: ({ actions, totalActions, onCreate, onDelete, onEdit, onView, onSelected, onDuplicate, disableMultiSelect, disableDelete, disableEdit, disableCreate, hideUseCase, showMetadataFilters, tableProps, containerProps, quantumIconSrc, }: ActivityListProps) => import("react/jsx-runtime").JSX.Element;
56
+ export declare const ActivityList: ({ actions, totalActions, onCreate, onDelete, onEdit, onView, onSelected, onDuplicate, disableMultiSelect, disableDelete, disableEdit, disableCreate, hideUseCase, showMetadataFilters, tableProps, containerProps, quantumIconSrc, allowDuplicateSelection, getSelectedCount, }: ActivityListProps) => 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");require("./moment-vendor-1cRqq0AH.cjs");const t=require("@chakra-ui/react"),s=require("react"),w=require("./generated.cjs"),R=require("./graphql-kPu5QxaL.cjs"),Te=require("./utils-cn-FIKrq5Mb.cjs");require("./lodash-vendor-CfNg9qwP.cjs");const ee=require("urql"),ae=require("./hooks.cjs"),Pe=require("./ufuzzy-vendor-7qHa_k39.cjs"),ie=require("./react-select-vendor-BLLqfZvd.cjs"),Se=require("./react-icons-vendor-BF_sZq07.cjs"),me=require("./services.cjs"),ve=require("./react-dnd-vendor-DvbjNa5U.cjs"),ce=require("./services-human-DFPelsei.cjs"),G=require("./generated-graphql.cjs"),pe=require("./types.cjs"),Be=({setSearch:a,actions:r,updateUseCases:l,hideUseCaseFilter:h=!1})=>{const p=s.useMemo(()=>r?.flatMap(j=>j.useCases).filter((j,d,C)=>C.findIndex(o=>o.id===j.id)===d).map(j=>({label:j.name,value:j.id}))||[],[r]);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:Se.FaSearch,color:"gray.300"})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"Search by name...",width:"100%",maxW:h?void 0:"30rem",onChange:j=>a(j.target.value)})]}),!h&&e.jsxRuntimeExports.jsx(t.InputGroup,{size:"md",children:e.jsxRuntimeExports.jsx(ie.st,{size:"md",chakraStyles:{container:j=>({...j,width:"100%"})},menuPortalTarget:document.body,placeholder:"Filter use case",isMulti:!0,options:p,onChange:j=>l(j.map(d=>d.value))})})]})},ue=({children:a})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:a}),$e=({items:a,onChange:r,selectedItem:l,isDisabled:h,selectedProps:p,buttonProps:j})=>{const d=o=>o===l||o.value===l,C=o=>d(o)?{...j,...p}:j;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:h,children:a.map((o,i)=>e.jsxRuntimeExports.jsx(t.Tooltip,{label:o.tooltip,openDelay:50,closeDelay:200,placement:"top",visibility:o.tooltip?"visible":"hidden",hasArrow:!0,children:e.jsxRuntimeExports.jsx(t.Button,{onClick:()=>d(o)?null:r(o,i),isDisabled:o.disabled,...C(o),children:o.label})},i))})},Ce=(a,r)=>r<0?-1*Math.abs(a):Math.abs(a),Ue=({isReversed:a,min:r,max:l,value:h,onChange:p,inputProps:j,size:d,zeroMarker:C,formatValue:o,valueLabel:i,positiveNegativeLabels:x,isDisabled:y,...b})=>{const[T,S]=s.useState([void 0,void 0]),M=T[0],E=T[1],m=C&&r<-5&&l>5,A=Number(h?.[0]??E??r)>0?1:-1,g=Number(h?.[1]??E??l)<0?-1:1,v=x?.[0]===x?.[1],F=h?.[0],U=h?.[1];s.useEffect(()=>{F!==void 0&&U!==void 0&&S([F.toFixed(0),U.toFixed(0)])},[F,U,S]);const k=s.useCallback(([L,$])=>{L<$&&S([L.toFixed(0),$.toFixed(0)])},[S]),N=s.useCallback(([L,$])=>{L<$&&p([L,$])},[p]),J=s.useCallback(()=>{S(([L,$])=>{const Q=isNaN(Number(L))?r:Number(L),B=isNaN(Number($))?l:Number($),K=Ce(Number(Q),A),c=Ce(Number(B),g),n=A<0?Math.max(K,r):Math.min(K,l),u=g<0?Math.max(c,r):Math.min(c,l);return n>u?(p([u,n]),[u.toFixed(0),n.toFixed(0)]):(p([n,u]),[n.toFixed(0),u.toFixed(0)])})},[p,S,A,g,r,l]),te=s.useCallback(L=>{const $=L===""||isNaN(Number(L))?L:Ce(Number(L),A);S(([Q,B])=>[$.toString(),B])},[S,A]),D=s.useCallback(L=>{const $=L===""||isNaN(Number(L))?L:Ce(Number(L),g);S(([Q,B])=>[Q,$.toString()])},[S,g]),V=s.useMemo(()=>d==="xs"?"0.75rem":void 0,[d]),X=s.useCallback((L,$)=>{const Q=Number($.target.value);if(!M||!E||![-1,1].includes(Q))return;const B=n=>Q<0?-1*Math.abs(n):Math.abs(n),K=L?B(Number(M)):Number(M),c=L?Number(E):B(Number(E));K>c?p([c,K]):p([K,c])},[M,E,p]);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:a,value:[Number(M??r),Number(E??l)],max:l,min:r,minStepsBetweenThumbs:3,step:1,onChange:k,onChangeEnd:N,isDisabled:y,children:[e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:r,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:d??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:o?o?.(r):r})}),e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:l,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:d??"sm",fontWeight:"semibold",style:{transform:"translateX(-100%)"},whiteSpace:"nowrap",children:o?o(l):l})}),m&&e.jsxRuntimeExports.jsxs(t.RangeSliderMark,{value:0,top:"-1em",pos:"relative",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:d,fontWeight:"semibold",children:o?.(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})]})}),i&&e.jsxRuntimeExports.jsxs(t.Flex,{direction:a?"row-reverse":"row",justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:d??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:i(r)}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:d??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:i(l)})]}),e.jsxRuntimeExports.jsxs(t.Flex,{direction:a?"row-reverse":"row",justifyContent:"center",alignItems:"center",gap:"0.125em",children:[x&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:d,fontWeight:"bold",value:A,onChange:L=>X(!0,L),isDisabled:v||y,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:x[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:x[1]})]}),e.jsxRuntimeExports.jsx(t.NumberInput,{precision:0,size:d??"sm",min:0,max:A<0?Math.abs(r):U??l,value:M===""?"":Math.abs(Number(M??r)),onChange:te,onBlur:J,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:y,...j,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),e.jsxRuntimeExports.jsx(t.NumberInput,{size:d??"sm",min:0,max:g<0?Math.abs(F??r):l,precision:0,value:E===""?"":Math.abs(Number(E??l)),onChange:D,onBlur:J,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:y,...j,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),x&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:d,fontWeight:"bold",value:g,onChange:L=>X(!1,L),isDisabled:v||y,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:x[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:x[1]})]})]})]})},ze=({tags:a,containerProps:r,...l})=>e.jsxRuntimeExports.jsx(t.HStack,{...r,children:a.map((h,p)=>e.jsxRuntimeExports.jsx(t.Tag,{...l,children:h},p))}),qe=new Pe.uFuzzy({}),We=({action:a,quantumIconSrc:r})=>{const{getLabel:l}=ae.useUiLabelContext(),h=s.useMemo(()=>({actionLowerCase:l("action").toLocaleLowerCase()}),[l]);return a.quantumOwned?e.jsxRuntimeExports.jsx(t.Tooltip,{label:`This ${h.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:r,boxSize:"1em",alt:`Quantum-owned ${h.actionLowerCase}`})})}):null},Ke=(a,r)=>{if(!r||!r.trim().length)return a;const l=a.map(p=>p.name??"");return qe.filter(l,r)?.map(p=>a[p])??[]},He=a=>!a||a.length===0?"None":a.map(r=>r.replace(/([A-Z])/g," $1").trim()).join(", "),Qe=(a,r)=>!r||r.length==0?a:a.filter(l=>l.useCases?.some(h=>r.includes(h.id))??!1),Ye=(a,r,l)=>!r||r.length===0?a:a.filter(h=>{const p={};return r.forEach(j=>{for(const[d,C]of Object.entries(l||{}))if(C.some(o=>o.id===j)){p[d]||(p[d]=[]),p[d].push(j);break}}),Object.entries(p).every(([j,d])=>{const C=h.metadataGroups?.find(y=>w.getFragmentData(R.METADATA_GROUP_FRAGMENT,y).key===j);if(!C)return!1;const o=w.getFragmentData(R.METADATA_GROUP_FRAGMENT,C),x=w.getFragmentData(R.METADATA_ITEM_FRAGMENT,o.data).map(y=>y.id);return d.some(y=>x.includes(y))})}),ke=({actions:a,totalActions:r,onCreate:l,onDelete:h,onEdit:p,onView:j,onSelected:d,onDuplicate:C,disableMultiSelect:o,disableDelete:i,disableEdit:x,disableCreate:y,hideUseCase:b=!0,showMetadataFilters:T=!0,tableProps:S,containerProps:M,quantumIconSrc:E="/favicon.ico"})=>{const[m,A]=s.useState(""),[g,v]=s.useState(),[F,U]=s.useState([]),[k,N]=s.useState({}),{getLabel:J}=ae.useUiLabelContext(),te=ee.useClient(),D=s.useMemo(()=>({action:J("action"),actionPlural:J("action_plural"),actionLowerCase:J("action").toLocaleLowerCase(),actionPluralLowerCase:J("action_plural").toLocaleLowerCase()}),[J]),V=s.useMemo(()=>[{key:"module_category",label:"Link Category",multi:!0},{key:"activity_type",label:`${D.action} Type`,multi:!0},{key:"session_type",label:"Session Type",multi:!0},{key:"body_region",label:"Body Region",multi:!0},{key:"sport",label:"Sport",multi:!0}],[D.action]);s.useEffect(()=>{if(!T)return;const n=V.map(u=>te.query(R.GET_METADATA_BY_KEY,{key:u.key}));Promise.all(n).then(u=>{const I={};u.forEach(q=>{if(q.error||!q.data)return;const H=w.getFragmentData(R.METADATA_GROUP_FRAGMENT,q.data.getMetadataByKey),W=w.getFragmentData(R.METADATA_ITEM_FRAGMENT,H.data);I[H.key]=W.map(z=>({label:z.label||z.value,value:z.value,id:z.id}))}),N(I)})},[te,V,T]);const X=s.useMemo(()=>{if(!a)return;const n=Ke(a,m),u=b?n:Qe(n,g);return T?Ye(u,F,k):u},[a,m,g,b,T,F,k]),L=s.useCallback(()=>{if(!h)return;const u=a.filter(I=>I.selected&&!I.quantumOwned).map(I=>I.id);h(u)},[a,h]),$=s.useCallback(()=>{if(!C)return;const n=a.filter(u=>u.selected);C(n.map(u=>u.id)),d&&n.forEach(u=>d(u,!1))},[a,C,d]),Q=s.useMemo(()=>a.some(n=>n.selected&&!n.quantumOwned),[a]),B=s.useMemo(()=>a.some(n=>n.selected),[a]),K=s.useMemo(()=>a.some(n=>n.selected&&n.quantumOwned),[a]),c=s.useCallback((n,u)=>{const I=V.find(H=>H.key===n);if(!I)return;const q=I.multi?(u??[]).map(H=>H.id):u?[u.id]:[];U(H=>[...H.filter(z=>Object.values(k).flat().find(ne=>ne.id===z)&&!Object.keys(k).find(ne=>k[ne]?.some(de=>de.id===z&&ne===n))),...q])},[V,k]);return e.jsxRuntimeExports.jsxs(t.Box,{...M,children:[e.jsxRuntimeExports.jsxs(t.Flex,{alignContent:"space-between",gap:4,children:[(l||h||C)&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mb:"1rem",gap:4,children:[l&&e.jsxRuntimeExports.jsxs(t.Button,{isDisabled:!l||y,colorScheme:"blackAlpha",backgroundColor:"gray.700",onClick:l,children:["Create New ",D.action]}),h&&!o&&e.jsxRuntimeExports.jsx(t.Tooltip,{label:K?Q?`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:!Q||!h||i,onClick:L,children:"Delete Selected"})}),C&&!o&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!B,onClick:$,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx(Be,{setSearch:A,actions:a,updateUseCases:v,hideUseCaseFilter:b})]}),T&&k&&e.jsxRuntimeExports.jsx(t.Box,{my:4,children:e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4",children:V.map(n=>e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(t.FormLabel,{fontSize:"sm",children:n.label}),e.jsxRuntimeExports.jsx(ie.st,{chakraStyles:{menu:u=>({...u,zIndex:2})},isMulti:n.multi,value:k[n.key]?.filter(u=>F.includes(u.id)),onChange:u=>{c(n.key,u)},options:k[n.key],placeholder:`Select ${n.multi?"one or more":"one"} ${n.label.toLowerCase()}`,isClearable:n.multi})]},n.key))})}),e.jsxRuntimeExports.jsx(t.TableContainer,{mr:"2rem",overflowX:"hidden",...S,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 ",X?.length??0," of"," ",r??a.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:X?.map(n=>e.jsxRuntimeExports.jsxs(t.Tr,{className:Te.cn("hover:bg-[#f7f7f7]",!o&&"cursor-pointer",n.selected&&"bg-gray-200"),onClick:()=>{o||d?.(n,!n.selected)},children:[e.jsxRuntimeExports.jsx(t.Td,{children:e.jsxRuntimeExports.jsxs(t.Flex,{children:[!o&&e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:n.selected?e.jsxRuntimeExports.jsx(Se.FaCheckSquare,{className:"text-blue-500"}):e.jsxRuntimeExports.jsx(Se.FaSquare,{className:"text-gray-400"})}),(n.quantumOwned||!p)&&j&&e.jsxRuntimeExports.jsx(t.Button,{ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:u=>{u.stopPropagation(),j(n.id)},children:"View"}),!n.quantumOwned&&p&&e.jsxRuntimeExports.jsx(t.Button,{isDisabled:x,ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:u=>{u.stopPropagation(),p(n.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(We,{action:n,quantumIconSrc:E}),n.name]})}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",whiteSpace:"break-spaces",children:He(n.sensorLocations)}),!b&&e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:e.jsxRuntimeExports.jsx(ze,{containerProps:{flexWrap:"wrap"},tags:n.useCases?.map(u=>u.name)??[]})})]},n.id))})]})})]})},Je=({onSave:a,onCancel:r,onError:l,hideButtons:h=!1,setButtonDisabled:p,setButtonOnClick:j,quantumOwned:d})=>{const C=t.useToast(),{getLabel:o}=ae.useUiLabelContext(),i=s.useMemo(()=>({singular:o("action"),plural:o("action_plural"),pluralLowerCase:o("action_plural").toLowerCase(),singularLowerCase:o("action").toLowerCase()}),[o]),[x,y]=s.useState("copy"),[b,T]=s.useState(""),[S,M]=s.useState([]),[E,m]=s.useState(!1),[A]=ee.useQuery({query:R.GET_GROUPS}),[g]=ee.useQuery({query:R.GET_ACTIONS_BY_GROUP,variables:{groupId:b},pause:!b}),[,v]=ee.useMutation(R.CREATE_ACTION),[,F]=ee.useMutation(R.CONVERT_ACTION_TO_QUANTUM_OWNED),U=s.useMemo(()=>A.data?.groups?A.data.groups.map(c=>w.getFragmentData(R.GROUP_FRAGMENT,c)):[],[A.data]),k=s.useMemo(()=>g.data?g.data.actions.map(n=>{const u=w.getFragmentData(R.ACTION_FRAGMENT,n),I=w.getFragmentData(R.REPORT_FRAGMENT,u.reports),q=w.getFragmentData(R.MODULE_CATEGORY_FRAGMENT,u.categories),W=w.getFragmentData(R.METADATA_GROUP_FRAGMENT,u.metadataGroups).map(z=>({...z,data:z.data.map(Y=>w.getFragmentData(R.METADATA_ITEM_FRAGMENT,Y))}));return{...u,thresholds:w.getFragmentData(R.THRESHOLD_FRAGMENT,u.thresholds),reports:I.map(z=>({...z,thresholds:w.getFragmentData(R.THRESHOLD_FRAGMENT,z.thresholds)})),categories:q,metadataGroups:W}}):[],[g.data]),N=s.useMemo(()=>k.filter(c=>S.includes(c.id)),[k,S]),J=s.useCallback(c=>{const n=c?.value||"";T(n),M([])},[]),te=s.useCallback(c=>{const n=c.map(u=>u.value);M(n)},[]),D=s.useCallback(async c=>{const n={...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(I=>({...I,id:void 0})),categories:c.categories.map(I=>I.id),quantumOwned:d,metadataItemIds:c.metadataGroups.flatMap(I=>I.data.map(q=>q.id)).filter(I=>I!==void 0),reports:c.reports.map(I=>({...I,id:void 0,thresholds:I.thresholds.map(q=>({...q,id:void 0}))})),id:void 0},u=await v({fields:n});if(u.error)throw new Error(u.error.message);if(u.data?.createAction)return w.getFragmentData(R.ACTION_FRAGMENT,u.data.createAction);throw new Error("No action data returned")},[v,d]),V=s.useCallback(async c=>{const n=await F({id:c.id});if(n.error)throw new Error(n.error.message);if(n.data?.convertActionToQuantumOwned)return w.getFragmentData(R.ACTION_FRAGMENT,n.data.convertActionToQuantumOwned);throw new Error("No action data returned")},[F]),X=s.useCallback(async()=>{if(m(!0),!N.length){const c=new Error(`No ${i.pluralLowerCase} selected for ${x==="copy"?"copying":"converting"}`);l?.(c),m(!1);return}try{const c=[];let n=0;const u=x==="copy"?D:V,I=x==="copy"?"copy":"convert";for(const q of N)try{const H=await u(q);c.push(H)}catch(H){console.error(`Failed to ${I} ${i.singularLowerCase} "${q.name}":`,H),n++}if(c.length>0){const q=c.length,H=N.length,W=x==="copy"?"copied":"converted",z=x==="copy"?"copy":"convert";C({title:n>0?`Partial ${z} completed`:`${i.plural} ${W} successfully`,description:n>0?`${q} of ${H} ${i.pluralLowerCase} ${W} successfully`:`${q} ${q>1?i.pluralLowerCase:i.singularLowerCase} ${W} successfully`,status:n>0?"warning":"success",duration:3e3,isClosable:!0}),a?.(),T(""),M([])}else throw new Error(`Failed to ${I} any ${i.pluralLowerCase}`)}catch(c){const n=x==="copy"?"copy":"convert",u=c instanceof Error?c.message:`Failed to ${n} ${i.pluralLowerCase}`;C({title:`${x==="copy"?"Copy":"Convert"} failed`,description:u,status:"error",duration:5e3,isClosable:!0}),l?.(c instanceof Error?c:new Error(u))}finally{m(!1)}},[N,x,D,V,C,a,l,i]),L=s.useCallback(()=>{T(""),M([]),y("copy"),r?.()},[r]);s.useEffect(()=>{p&&p({cancelButton:!1,saveButton:N.length===0||E})},[N.length,E,p]),s.useEffect(()=>{j&&j({cancelButton:L,saveButton:X})},[j,L,X]);const $=s.useMemo(()=>U.map(c=>({value:c.id,label:c.name})),[U]),Q=s.useMemo(()=>k.filter(c=>x==="copy"?!0:!c.quantumOwned).map(c=>({value:c.id,label:c.name,isQuantumOwned:c.quantumOwned})),[k,x]),B=A.fetching,K=g.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[d&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:x,onChange:c=>{y(c),M([])},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 ",i.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",i.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 ",i.singular]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Convert existing"," ",i.plural.toLocaleLowerCase()," to quantum-owned"]})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(ie.st,{placeholder:"Choose a group...",options:$,value:$.find(c=>c.value===b)||null,onChange:J,isLoading:B,isDisabled:B,isClearable:!0}),A.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: ",A.error.message]})]})]}),b&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsxs(ue,{children:["Select ",i.plural," to"," ",x==="copy"?"Copy":"Convert"]}),K?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 ",i.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(ie.st,{placeholder:`Choose ${i.pluralLowerCase} to ${x}...`,options:Q,value:Q.filter(c=>S.includes(c.value)),onChange:te,isDisabled:Q.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(c,{context:n})=>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}),n==="value"&&c.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),c.isQuantumOwned&&n==="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 ",i.pluralLowerCase," found"]})]}),g.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load ",i.pluralLowerCase,":"," ",g.error.message]})]})]}),N.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:N.length===1?`${i.singular} to ${x==="copy"?"Copy":"Convert"}:`:`${N.length} ${i.plural} to ${x==="copy"?"Copy":"Convert"}:`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[N.map((c,n)=>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:[n+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(u=>u.name).join(", ")||"None"]})]})]},c.id)),N.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: ",N.length," ",i.pluralLowerCase," will be"," ",x==="copy"?"copied":"converted"]})})]})]}),!h&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:L,isDisabled:E,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:x==="copy"?"blue":"green",onClick:X,isDisabled:N.length===0||E,isLoading:E,loadingText:`${x==="copy"?"Copying":"Converting"}...`,children:[x==="copy"?"Copy":"Convert"," ",N.length===1?i.singular:`${N.length} ${i.plural}`]})]})]})})},Ve=({onSave:a,onCancel:r,onError:l,hideButtons:h=!1,setButtonDisabled:p,setButtonOnClick:j,quantumOwned:d})=>{const C=t.useToast(),{getLabel:o}=ae.useUiLabelContext(),i=s.useMemo(()=>({singular:o("module"),plural:o("module_plural"),pluralLowerCase:o("module_plural").toLowerCase(),singularLowerCase:o("module").toLowerCase()}),[o]),x=s.useMemo(()=>({singular:o("action"),plural:o("action_plural"),pluralLowerCase:o("action_plural").toLowerCase(),singularLowerCase:o("action").toLowerCase()}),[o]),[y,b]=s.useState(""),[T,S]=s.useState([]),[M,E]=s.useState(!1),[m,A]=s.useState("copy"),[g]=ee.useQuery({query:R.GET_GROUPS}),[v]=ee.useQuery({query:R.GET_MODULES_BY_GROUP,variables:{groupId:y},pause:!y}),[,F]=ee.useMutation(R.CREATE_MODULE),[,U]=ee.useMutation(R.UPDATE_MODULE),[,k]=ee.useMutation(R.CREATE_ACTION),[,N]=ee.useMutation(R.CONVERT_ACTION_TO_QUANTUM_OWNED),J=s.useMemo(()=>g.data?.groups?g.data.groups.map(n=>w.getFragmentData(R.GROUP_FRAGMENT,n)):[],[g.data]),te=s.useMemo(()=>v.data?.modules?w.getFragmentData(R.ACTION_MODULE_FRAGMENT,v.data?.modules).map(u=>{const I=w.getFragmentData(R.MODULE_ACTION_FRAGMENT,u.moduleActions),H=w.getFragmentData(R.METADATA_GROUP_FRAGMENT,u.metadataGroups).map(W=>w.getFragmentData(R.METADATA_ITEM_FRAGMENT,W.data)).flat();return{...u,moduleActions:I.map(W=>({...W,action:w.getFragmentData(R.ACTION_FRAGMENT,W.action)})),categories:w.getFragmentData(R.MODULE_CATEGORY_FRAGMENT,u.categories),metadataItems:H}}):[],[v.data]),D=s.useMemo(()=>te.filter(n=>T.includes(n.id)),[te,T]),V=s.useCallback(n=>{const u=n?.value||"";b(u),S([])},[]),X=s.useCallback(n=>{const u=n.map(I=>I.value);S(u)},[]),L=s.useCallback(async()=>{if(E(!0),!D.length){E(!1);const n=new Error(`No modules selected for ${m==="convert"?"converting":"copying"}`);l?.(n);return}try{const n=[];let u=0;for(const I of D)try{let q=I.moduleActions.map(H=>H.actionId);if(d){const H=I.moduleActions.map(Y=>Y.action),W=async Y=>{if(m==="copy"){if(Y.quantumOwned)return Y;const de=w.getFragmentData(R.MODULE_CATEGORY_FRAGMENT,Y.categories),je=w.getFragmentData(R.METADATA_GROUP_FRAGMENT,Y.metadataGroups).map(le=>w.getFragmentData(R.METADATA_ITEM_FRAGMENT,le.data).map(ge=>ge.id)).flat(),fe=w.getFragmentData(R.REPORT_FRAGMENT,Y.reports).map(le=>({...le,id:void 0,thresholds:w.getFragmentData(R.THRESHOLD_FRAGMENT,le.thresholds).map(ge=>({...ge,id:void 0}))})),Me=w.getFragmentData(R.THRESHOLD_FRAGMENT,Y.thresholds).map(le=>({...le,id:void 0})),he={...Y,quantumOwned:!0,thresholds:Me,categories:de?.map(le=>le.id),reports:fe,metadataIds:je,id:void 0},xe=await k({fields:he});return xe.error||!xe.data?.createAction?null:w.getFragmentData(R.ACTION_FRAGMENT,xe.data.createAction)}if(Y.quantumOwned)return Y;const ne=await N({id:Y.id});return ne.error||!ne.data?.convertActionToQuantumOwned?null:w.getFragmentData(R.ACTION_FRAGMENT,ne.data.convertActionToQuantumOwned)};q=(await Promise.all(H.map(W))).filter(Y=>!!Y?.id).map(Y=>Y.id)}if(m==="convert"){const H={name:I.name,description:I.description||void 0,actions:q,categories:I.categories.map(z=>z.id),quantumOwned:!0},W=await U({id:I.id,input:H});if(W.error)throw new Error(W.error.message);if(W.data?.updateModule){const z=w.getFragmentData(R.ACTION_MODULE_FRAGMENT,W.data.updateModule);n.push(z)}}else{const H={name:`${I.name} (Copy)`,description:I.description||void 0,moduleActions:I.moduleActions.map(z=>({actionId:z.actionId,reportId:z.reportId??void 0})),categories:I.categories.map(z=>z.id),quantumOwned:d,metadataItemIds:I.metadataItems.map(z=>z.id)},W=await F({input:H});if(W.error)throw new Error(W.error.message);if(W.data?.createModule){const z=w.getFragmentData(R.ACTION_MODULE_FRAGMENT,W.data.createModule);n.push(z)}}}catch(q){console.error(`Failed to ${m==="convert"?"convert":"copy"} module "${I.name}":`,q),u++}if(n.length>0){const I=n.length,q=D.length;C({title:u>0?`Partial ${m==="convert"?"convert":"copy"} completed`:`${i.plural} ${m==="convert"?"converted":"copied"} successfully`,description:u>0?`${I} of ${q} ${i.plural} ${m==="convert"?"converted":"copied"} successfully`:`${I} ${I>1?i.plural:i.singular} ${m==="convert"?"converted":"copied"} successfully`,status:u>0?"warning":"success",duration:3e3,isClosable:!0}),n.length>0&&a?.(),b(""),S([])}else throw new Error(`Failed to ${m==="convert"?"convert":"copy"} any modules`)}catch(n){const u=n instanceof Error?n.message:`Failed to ${m==="convert"?"convert":"copy"} modules`;C({title:m==="convert"?"Convert failed":"Copy failed",description:u,status:"error",duration:5e3,isClosable:!0}),l?.(n instanceof Error?n:new Error(u))}finally{E(!1)}},[D,F,U,C,a,l,d,k,N,m,i]),$=s.useCallback(()=>{b(""),S([]),A("copy"),r?.()},[r]);s.useEffect(()=>{p&&p({cancelButton:!1,saveButton:D.length===0||M})},[D.length,M,p]),s.useEffect(()=>{j&&j({cancelButton:$,saveButton:L})},[j,$,L]);const Q=s.useMemo(()=>J.map(n=>({value:n.id,label:n.name})),[J]),B=s.useMemo(()=>te.filter(n=>m==="copy"?!0:!n.quantumOwned).map(n=>({value:n.id,label:n.name,isQuantumOwned:n.quantumOwned})),[te,m]),K=g.fetching,c=v.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[d&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:m,onChange:n=>{A(n),S([])},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 ",i.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",i.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 ",i.pluralLowerCase," to quantum-owned"]})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(ie.st,{placeholder:"Choose a group...",options:Q,value:Q.find(n=>n.value===y)||null,onChange:V,isLoading:K,isDisabled:K,isClearable:!0}),g.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",g.error.message]})]})]}),y&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:m==="convert"?`Select ${i.plural} to Convert`:`Select ${i.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 ",i.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(ie.st,{placeholder:m==="convert"?`Choose ${i.pluralLowerCase} to convert...`:`Choose ${i.pluralLowerCase} to copy...`,options:B,value:B.filter(n=>T.includes(n.value)),onChange:X,isDisabled:B.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(n,{context:u})=>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:n.label}),u==="value"&&n.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),n.isQuantumOwned&&u==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),B.length===0&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:["No ",i.pluralLowerCase," found in this group"]})]}),v.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 ",i.pluralLowerCase,":"," ",v.error.message]})]})]}),D.length>0&&e.jsxRuntimeExports.jsxs(t.Box,{p:4,bg:"gray.50",borderRadius:"md",children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"semibold",mb:3,children:D.length===1?`${i.singular} to ${m==="copy"?"Copy":"Convert"}`:`${D.length} ${i.plural} to ${m==="copy"?"Copy":"Convert"}`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[D.map((n,u)=>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:[u+1,". ",n.name]}),n.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:[n.description&&e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Description:"})," ",n.description]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Activities:"})," ",n.moduleActions.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Categories:"})," ",n.categories.map(I=>I.name).join(", ")||"None"]})]})]},n.id)),D.length>1&&e.jsxRuntimeExports.jsx(t.Box,{w:"100%",p:2,bg:"blue.50",borderRadius:"md",border:"1px solid",borderColor:"blue.200",children:e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",fontWeight:"medium",color:"blue.800",children:["Total: ",D.length," ",i.pluralLowerCase," will be"," ",m==="copy"?"copied":"converted"]})}),d&&D.filter(n=>n.moduleActions.some(u=>!u.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:m==="convert"?`Converting ${i.plural} will convert non QM-Owned ${x.plural} to QM-Owned ${x.plural}`:`Copying ${i.plural} with Non QM-Owned ${x.plural} will create corresponding QM-Owned ${x.plural}`})})]})]}),!h&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:$,isDisabled:M,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:m==="copy"?"blue":"green",onClick:L,isDisabled:D.length===0||M,isLoading:M,loadingText:`${m==="copy"?"Copying":"Converting"}...`,children:[m==="copy"?"Copy":"Convert"," ",D.length===1?i.singular:`${D.length} ${i.plural}`]})]})]})})},Le=s.createContext(void 0),Re=()=>{const a=s.useContext(Le);if(!a)throw new Error("useUpsertModuleFormContext must be used within a UpsertModuleFormProvider");return a},Ne=({name:a,setName:r,actions:l,moduleActionEntries:h,setModuleActionEntries:p,availableCategories:j,selectedCategoryIds:d,setSelectedCategoryIds:C,description:o,setDescription:i,selectedMetadataIds:x,setSelectedMetadataIds:y,...b})=>{const T=t.useDisclosure(),S=s.useMemo(()=>[...new Set(h.map(v=>v.actionId))],[h]),M=s.useMemo(()=>l.map(v=>({...v,selected:S.includes(v.id)})),[l,S]),E=s.useMemo(()=>l.reduce((v,F)=>(v[F.id]=F,v),{}),[l]),m=s.useCallback((v,F)=>{if(F){const U={key:crypto.randomUUID(),actionId:v.id,reportId:null};p(k=>[...k,U])}else p(U=>U.filter(k=>k.actionId!==v.id))},[p]),A=s.useCallback(v=>{r(v.target.value)},[r]),g=s.useCallback(v=>{i?.(v.target.value)},[i]);return e.jsxRuntimeExports.jsxs(t.Box,{...b,children:[e.jsxRuntimeExports.jsxs(t.HStack,{gap:"2rem",children:[e.jsxRuntimeExports.jsx(Xe,{name:a??"",onInputChange:A}),e.jsxRuntimeExports.jsx(Ze,{availableCategories:j,value:d,onChange:C})]}),e.jsxRuntimeExports.jsx(et,{description:o??"",onInputChange:g}),e.jsxRuntimeExports.jsx(ot,{selectedMetadataIds:x,setSelectedMetadataIds:y}),e.jsxRuntimeExports.jsx(tt,{moduleActionEntries:h,setModuleActionEntries:p,actionsById:E,onAdjustActivities:()=>T.onOpen()}),e.jsxRuntimeExports.jsxs(t.Modal,{isOpen:T.isOpen,onClose:T.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(ke,{actions:M,onSelected:m,disableCreate:!0,disableDelete:!0,tableProps:{height:"28rem",overflowY:"auto"}})}),e.jsxRuntimeExports.jsx(t.ModalFooter,{children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:T.onClose,isDisabled:h.length===0,children:"Done"})})]})]})]})},Xe=s.memo(({name:a,onInputChange:r})=>{const{getLabel:l}=ae.useUiLabelContext(),h=l("module"),{isView:p}=Re();return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(ue,{children:[h," Name"]}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. ACL RTP Test Battery",value:a,onChange:r,isRequired:!0,isDisabled:p})]})}),Ze=s.memo(({availableCategories:a,value:r,onChange:l})=>{const{getLabel:h}=ae.useUiLabelContext(),p=h("module"),{isView:j}=Re(),d=s.useMemo(()=>[...a,{id:"other",name:"Other"}],[a]),C=s.useMemo(()=>d.map(o=>({value:o.id,label:o.name})),[d]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(ue,{children:[p," Category"]}),e.jsxRuntimeExports.jsx(ie.st,{isDisabled:a.length===0||j,options:C,value:r.length===0?{value:"other",label:"Other"}:d.filter(o=>r.includes(o.id)).map(o=>({value:o.id,label:o.name}))[0],onChange:o=>l(o?[o.value]:[]),placeholder:"Select category"})]})}),et=s.memo(({description:a,onInputChange:r})=>{const{getLabel:l}=ae.useUiLabelContext(),h=l("module"),{isView:p}=Re();return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(ue,{children:e.jsxRuntimeExports.jsxs("span",{children:["Description",e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",children:["Briefly describe the objective of this"," ",h.toLocaleLowerCase(),". Max 40 words."]})]})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. Assess readiness to return to play post-ACL reconstruction",value:a,onChange:r,isDisabled:p})]})}),tt=s.memo(({moduleActionEntries:a,setModuleActionEntries:r,actionsById:l,onAdjustActivities:h})=>{const{getLabel:p}=ae.useUiLabelContext(),{isView:j}=Re(),d=s.useMemo(()=>({module:p("module"),moduleLowerCase:p("module").toLocaleLowerCase(),action:p("action"),actionPlural:p("action_plural"),actionPluralLowerCase:p("action_plural").toLocaleLowerCase()}),[p]),C=s.useMemo(()=>a.map(o=>{const i=l[o.actionId];return i?{key:o.key,actionId:o.actionId,name:i.name,reports:w.getFragmentData(R.REPORT_FRAGMENT,i.reports)||[],selectedReportId:o.reportId}:null}).filter(Boolean),[a,l]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(t.HStack,{justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(ue,{children:e.jsxRuntimeExports.jsxs("span",{children:[d.actionPlural,!j&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",children:["Drag and drop to reorder the ",d.actionPluralLowerCase," ","in this ",d.moduleLowerCase,"."]})]})}),!j&&e.jsxRuntimeExports.jsxs(t.Button,{size:"sm",variant:"solid",colorScheme:"blue",onClick:h,children:["Add / Remove ",d.actionPlural]})]}),C.length===0?e.jsxRuntimeExports.jsx(t.VStack,{children:e.jsxRuntimeExports.jsxs(t.Text,{color:"gray.500",fontSize:"lg",mb:"4rem",mt:"4rem",children:["No ",d.actionPluralLowerCase," selected for this"," ",d.moduleLowerCase,".",!j&&e.jsxRuntimeExports.jsxs(t.Button,{ml:"0.5em",size:"sm",variant:"link",colorScheme:"blue",onClick:h,children:["Add ",d.actionPluralLowerCase,"."]})]})}):e.jsxRuntimeExports.jsx(st,{value:C,onChange:o=>{r(i=>{const x=i.map(b=>{const T=l[b.actionId];return T?{key:b.key,actionId:b.actionId,name:T.name,reports:w.getFragmentData(R.REPORT_FRAGMENT,T.reports)||[],selectedReportId:b.reportId}:null}).filter(Boolean);return o(x).map(b=>({key:b.key,actionId:b.actionId,reportId:b.selectedReportId}))})},disabled:j,setModuleActionEntries:r})]})}),st=s.memo(({value:a,onChange:r,disabled:l,setModuleActionEntries:h})=>{const[p]=s.useState(()=>Math.random().toString(36).substring(2,15)),j=s.useCallback((o,i)=>{l||r(x=>{const y=[...x],[b]=y.splice(o,1);return y.splice(i,0,b),y})},[r,l]),d=s.useCallback(o=>{h(i=>{const x=i.findIndex(S=>S.key===o);if(x===-1)return i;const y=i[x],b={key:crypto.randomUUID(),actionId:y.actionId,reportId:null},T=[...i];return T.splice(x+1,0,b),T})},[h]),C=s.useCallback(o=>{h(i=>i.filter(x=>x.key!==o))},[h]);return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsx(ve.DndProvider,{backend:ve.HTML5Backend,children:e.jsxRuntimeExports.jsx(t.VStack,{spacing:3,align:"stretch",children:a.map((o,i)=>e.jsxRuntimeExports.jsx(nt,{listKey:p,item:o,index:i,disabled:!!l,move:j,onReportChange:x=>{h(y=>y.map(b=>b.key===o.key?{...b,reportId:x}:b))},onDuplicate:()=>d(o.key),onRemove:()=>C(o.key)},o.key))})})})}),nt=s.memo(({listKey:a,item:r,index:l,disabled:h,move:p,onReportChange:j,onDuplicate:d,onRemove:C})=>{const o=s.useRef(null),{getLabel:i}=ae.useUiLabelContext(),x=i("action"),[{handlerId:y},b]=ve.useDrop({accept:a,collect:g=>({handlerId:g.getHandlerId()?.toString()??""}),hover:(g,v)=>{if(!o.current)return;const F=g.index,U=l;if(F===U)return;const k=o.current?.getBoundingClientRect(),N=(k.bottom-k.top)/2,te=v.getClientOffset().y-k.top;F<U&&te<N||F>U&&te>N||(p(F,U),g.index=U)}}),[{isDragging:T},S]=ve.useDrag({type:a,item:()=>({id:r.key,index:l}),collect:g=>({isDragging:g.isDragging()}),canDrag:!h}),M=s.useMemo(()=>`action-report-label-${r.key}`,[r.key]),E=s.useMemo(()=>[{value:null,label:"No Report"},...r.reports.map(g=>{const v=g.name&&g.name.length>0?g.name:"No Name",F=me.reportKindName(g.reportKind);return{value:g.id,label:`${v} (${F})`}})],[r.reports]),m=T?.6:1,A=h?"default":T?"grabbing":"grab";return S(b(o)),e.jsxRuntimeExports.jsx(t.Box,{ref:o,p:3,border:"1px solid",borderColor:"gray.200",borderRadius:"md",bg:"gray.50",style:{opacity:m,cursor:A},"data-handler-id":y,children:e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",align:"center",children:[e.jsxRuntimeExports.jsxs(t.HStack,{spacing:3,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"semibold",minW:"2rem",children:[l+1,"."]}),e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"medium",children:r.name})]}),e.jsxRuntimeExports.jsxs(t.HStack,{spacing:3,align:"center",children:[e.jsxRuntimeExports.jsxs(t.Text,{id:M,fontSize:"sm",color:"gray.600",children:[x," Report:"]}),e.jsxRuntimeExports.jsx(t.Box,{width:{base:"100%",md:"350px"},children:e.jsxRuntimeExports.jsx(ie.st,{"aria-labelledby":M,value:E.find(g=>g.value===r.selectedReportId),onChange:g=>{j(g?.value||null)},options:E,placeholder:"Select report...",isDisabled:h})}),!h&&e.jsxRuntimeExports.jsxs(t.HStack,{spacing:1,children:[e.jsxRuntimeExports.jsx(t.Button,{size:"xs",variant:"ghost",colorScheme:"blue",onClick:d,title:"Add another instance with a different report",children:"+ Duplicate"}),e.jsxRuntimeExports.jsx(t.Button,{size:"xs",variant:"ghost",colorScheme:"red",onClick:C,title:"Remove this entry",children:"Remove"})]})]})]})})}),ot=s.memo(({selectedMetadataIds:a,setSelectedMetadataIds:r})=>{const{getLabel:l}=ae.useUiLabelContext(),{isView:h,metadataOptions:p}=Re(),j=s.useMemo(()=>[{key:"activity_type",label:`${l("action")} Type`,multi:!0},{key:"session_type",label:"Session Type",multi:!0},{key:"body_region",label:"Body Region",multi:!0},{key:"sport",label:"Sport",multi:!0}],[l]),d=s.useCallback((C,o)=>{const i=j.find(y=>y.key===C);if(!i)return;const x=i.multi?(o??[]).map(y=>y.id):o?[o.id]:[];r(y=>[...y.filter(T=>Object.values(p||{}).flat().find(M=>M.id===T)&&!Object.keys(p||{}).find(M=>p?.[M]?.some(E=>E.id===T&&M===C))),...x])},[j,p,r]);return p?e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(ue,{children:"Metadata Tags"}),e.jsxRuntimeExports.jsx(t.HStack,{gap:"1rem",align:"start",children:j.map(C=>e.jsxRuntimeExports.jsxs(t.FormControl,{flex:"1",children:[e.jsxRuntimeExports.jsx(t.FormLabel,{fontSize:"sm",children:C.label}),e.jsxRuntimeExports.jsx(ie.st,{isMulti:C.multi,value:p[C.key]?.filter(o=>a.includes(o.id)),onChange:o=>{d(C.key,o)},options:p[C.key],placeholder:`Select ${C.multi?"one or more":"one"} ${C.label.toLowerCase()}`,isDisabled:h,isClearable:C.multi})]},C.key))})]}):null}),De=({value:a,onChange:r,forceKind:l,disableRemove:h,disableKind:p,isDisabled:j,lockRanges:d,...C})=>{const o=s.useMemo(()=>[...a].sort((b,T)=>{const S=pe.availablePlanes.indexOf(b.plane),M=pe.availablePlanes.indexOf(T.plane);return S-M}),[a]),i=s.useCallback(b=>"segment"in b.id?ce.getSegmentNameWithPlane(b.id.segment,b.plane,!0)??"Unknown":ce.getJointNameWithPlane(b.id.joint,b.plane,!0)??"Unknown",[]),x=s.useCallback((b,T)=>{const S=o.findIndex(E=>E.id===T.id&&E.plane===T.plane);let M=[...o];l&&(T={...T,kind:l}),M[S]=T,d&&(M=M.map(E=>({...E,min:T.min,max:T.max}))),r(M)},[r,o,l,d]),y=s.useCallback(b=>{const T=o.filter(S=>S.id!==b.id||S.plane!==b.plane);r(T)},[r,o]);return e.jsxRuntimeExports.jsx(t.VStack,{alignItems:"flex-start",overflowY:"auto",...C,children:o.map((b,T)=>e.jsxRuntimeExports.jsx(rt,{label:i(b),parameter:b,onChange:S=>x(T,S),onRemove:h||j?void 0:()=>y(b),forceKind:l,disableKind:p||j,isDisabled:j},`${JSON.stringify(b.id)}-${b.plane}`))})},rt=({label:a,parameter:r,onChange:l,onRemove:h,forceKind:p,disableKind:j,isDisabled:d})=>{const C=s.useCallback(x=>"joint"in r.id?ce.getJointAngleDirectionName(r.id.joint,r.plane,x<0?-1:1):ce.getSegmentAngleDirectionName(r.id.segment,r.plane,x<0?-1:1),[r]),{min:o,max:i}="joint"in r.id?ce.getNormativeJointRange(r.id.joint,r.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%",alignItems:"center",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",flex:1,textTransform:"capitalize",fontWeight:"semibold",children:a}),r.sensorOnly?e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor"}):e.jsxRuntimeExports.jsxs(t.HStack,{spacing:1,children:[e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"blue",variant:"subtle",children:"Pose"}),e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor"})]}),h&&!d&&e.jsxRuntimeExports.jsx(t.IconButton,{size:"xs",variant:"ghost","aria-label":"delete",icon:e.jsxRuntimeExports.jsx(t.Icon,{as:Se.FaTrash}),onClick:h}),!p&&e.jsxRuntimeExports.jsx($e,{selectedItem:r?.kind??G.ThresholdKind.Limit,onChange:({value:x})=>l({...r,kind:x}),isDisabled:j||d,buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:G.ThresholdKind.Limit,label:"limit"},{value:G.ThresholdKind.Target,label:"target"}]})]}),e.jsxRuntimeExports.jsx(Ue,{w:"100%",size:"xs",min:o,max:i,zeroMarker:!0,value:[r.min,r.max],onChange:x=>l({...r,min:x[0],max:x[1]}),formatValue:x=>`${Math.abs(x)}°`,valueLabel:x=>C(x)??"",positiveNegativeLabels:C(0)?[C(-1)??"",C(1)??""]:void 0,isDisabled:d})]})},ye=(a,r)=>"segment"in a&&"segment"in r&&a.segment===r.segment||"joint"in a&&"joint"in r&&a.joint===r.joint,Ie=({options:a,value:r,onChange:l,forceKind:h,singleValue:p,singleValueSideless:j,editOnly:d,disableKind:C,maxParameters:o,...i})=>{const x=j?2:o,y=s.useMemo(()=>{const E=new Map;return a.forEach(m=>{const A="joint"in m.id;let g,v;if(A?(g=ce.getJointNameWithPlane(m.id.joint,m.plane,!0)??"Unknown",v=`joint:${m.id.joint}`):(g=ce.getSegmentNameWithPlane(m.id.segment,m.plane,!0)??"Unknown",v=`segment:${m.id.segment}`),!E.has(v)){const k=A?ce.getPartName(m.id.joint)??"Unknown Joint":ce.getPartName(m.id.segment)??"Unknown Segment";E.set(v,{label:k,options:[]})}const F=E.get(v),U=[g,A?m.id.joint:m.id.segment,m.plane].filter(Boolean).map(k=>String(k).toLowerCase().replace(/\s+|_/g,""));F.options.push({label:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:2,justify:"space-between",alignItems:"center",w:"100%",pl:3,children:[e.jsxRuntimeExports.jsx(t.Text,{children:g}),m.sensorOnly?e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor"}):e.jsxRuntimeExports.jsxs(t.HStack,{spacing:1,children:[e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"blue",variant:"subtle",children:"Pose"}),e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor"})]})]}),value:m.id,plane:m.plane,sensorOnly:m.sensorOnly,searchTokens:U})}),Array.from(E.values())},[a]),b=s.useMemo(()=>{if(!j||r.length===0)return y;const E=r[0];return y.map(m=>({...m,options:m.options.filter(A=>pe.getAnalysisPartIdNoSide(A.value)===pe.getAnalysisPartIdNoSide(E.id)&&A.plane===E.plane)})).filter(m=>m.options.length>0)},[y,r,j]),T=s.useMemo(()=>y.flatMap(m=>m.options).filter(m=>r.some(A=>ye(A.id,m.value)&&A.plane===m.plane)),[y,r]),S=s.useCallback((E,m)=>{if(!m)return!0;const A=m.toLowerCase().replace(/\s+|_/g,""),g=E.data;return!g||!g.searchTokens?!1:g.searchTokens.some(v=>v.includes(A))},[]),M=s.useCallback(E=>{const m=E.map(A=>{const g=r.find(N=>ye(N.id,A.value)&&N.plane===A.plane),v=a.find(N=>ye(N.id,A.value)&&N.plane===A.plane),F=j?r.find(N=>pe.getAnalysisPartIdNoSide(N.id)===pe.getAnalysisPartIdNoSide(A.value)&&N.plane===A.plane):void 0,U=F&&!g?F.min:v&&v.min?v.min:0,k=F&&!g?F.max:v&&v.max?v.max:0;return g??{id:A.value,plane:A.plane,min:U,max:k,sensorOnly:A.sensorOnly,kind:h??G.ThresholdKind.Limit}});l(m)},[l,r,a,h,j]);return s.useEffect(()=>{const E=r.filter(m=>a.some(A=>ye(A.id,m.id)&&A.plane===m.plane));E.length!==r.length&&l(E)},[a,l,r]),e.jsxRuntimeExports.jsxs(t.Box,{...i,children:[e.jsxRuntimeExports.jsx(ie.st,{isMulti:!p,placeholder:r.length?`${r.length} selected`:"Search...",value:T,isDisabled:d||T.length>=(x??1/0),onChange:E=>Array.isArray(E)?M([...E]):M(E!==null?[E]:[]),options:b,controlShouldRenderValue:!1,formatOptionLabel:E=>E.label,filterOption:S,isSearchable:!0}),e.jsxRuntimeExports.jsx(De,{marginTop:2,maxH:"28rem",value:r,onChange:l,forceKind:h,disableKind:C,isDisabled:d,lockRanges:j})]})},Fe=a=>{switch(a){case G.SensorLocation.Thorax:return"Thorax";case G.SensorLocation.CenterBack:return"Center Back";case G.SensorLocation.Pelvis:return"Pelvis";case G.SensorLocation.LeftThigh:return"Left Thigh";case G.SensorLocation.RightThigh:return"Right Thigh";case G.SensorLocation.LeftShank:return"Left Shank";case G.SensorLocation.RightShank:return"Right Shank";case G.SensorLocation.LeftFoot:return"Left Foot";case G.SensorLocation.RightFoot:return"Right Foot";case G.SensorLocation.LeftUpperArm:return"Left Upper Arm";case G.SensorLocation.RightUpperArm:return"Right Upper Arm";case G.SensorLocation.LeftForearm:return"Left Forearm";case G.SensorLocation.RightForearm:return"Right Forearm";case G.SensorLocation.Head:return"Head"}},at=({id:a,onError:r,onCancel:l,onSave:h,hideButtons:p,setButtonOnClick:j,setButtonDisabled:d,quantumOwned:C,isView:o})=>{const i=ee.useClient(),[{fetching:x},y]=ee.useMutation(R.CREATE_ACTION),[{fetching:b},T]=ee.useMutation(R.UPDATE_ACTION),[{data:S}]=ee.useQuery({query:R.GET_ACTION_BY_ID,variables:{id:a??""},pause:!a}),M=s.useMemo(()=>{const f=w.getFragmentData(R.ACTION_FRAGMENT,S?.getActionById);if(!f)return null;const _=(w.getFragmentData(R.REPORT_FRAGMENT,f.reports)||[]).map(O=>({...O,thresholds:w.getFragmentData(R.THRESHOLD_FRAGMENT,O.thresholds)}));return{...f,thresholds:w.getFragmentData(R.THRESHOLD_FRAGMENT,f.thresholds),reports:_}},[S]),E=x||b,m=!!M&&!!a,{getLabel:A}=ae.useUiLabelContext(),g=s.useMemo(()=>({action:A("action")}),[A]),v=s.useMemo(()=>[{key:"module_category",label:"Link Category",multi:!0},{key:"activity_type",label:`${g.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},{key:"activity_motion_direction",label:"Activity Motion Direction",multi:!0}],[g.action]),[F,U]=s.useState(""),[k,N]=s.useState(""),[J,te]=s.useState(""),[D,V]=s.useState(""),[X,L]=s.useState([]),[$,Q]=s.useState({}),[B,K]=s.useState(null),[c,n]=s.useState(""),[u,I]=s.useState([]),[q,H]=s.useState([]),[W,z]=s.useState(""),[Y,ne]=s.useState([]),de=ae.useAllPartParameters(),we=s.useMemo(()=>de.filter(f=>f.sensorOnly),[de]),je=[{label:me.reportKindName(G.ReportKind.GeneralActivity),value:G.ReportKind.GeneralActivity},{label:me.reportKindName(G.ReportKind.MovementCoordination),value:G.ReportKind.MovementCoordination},{label:me.reportKindName(G.ReportKind.Range),value:G.ReportKind.Range},{label:me.reportKindName(G.ReportKind.StabilityBalance),value:G.ReportKind.StabilityBalance},{label:me.reportKindName(G.ReportKind.PointOfInterest),value:G.ReportKind.PointOfInterest}],Ee=s.useMemo(()=>F.trim().length>0,[F]),[fe,Me]=s.useState({});s.useEffect(()=>{const f=v.map(P=>i.query(R.GET_METADATA_BY_KEY,{key:P.key}));Promise.all(f).then(P=>{const _={};P.forEach(O=>{if(O.error||!O.data)return;const se=w.getFragmentData(R.METADATA_GROUP_FRAGMENT,O.data.getMetadataByKey),Z=w.getFragmentData(R.METADATA_ITEM_FRAGMENT,se.data);_[se.key]=Z.map(re=>({label:re.label||re.value,value:re.value,id:re.id}))}),Q(_)})},[i,v]),s.useEffect(()=>{if(M){const P=w.getFragmentData(R.METADATA_GROUP_FRAGMENT,M.metadataGroups).map(se=>se.data.map(Z=>w.getFragmentData(R.METADATA_ITEM_FRAGMENT,Z).id)),_=M.reports.map(se=>({id:se.id,name:se.name??"",instructions:se.instructions??"",kind:se.reportKind,autoGenerate:se.autoGenerate??!1,parameters:se.thresholds.map(Z=>({id:{[Z.partKind]:Z.partId},kind:Z.kind,min:Z.min,max:Z.max,plane:Z.partDimension,oldId:Z.id,sensorOnly:we.some(re=>{const Ae=re.id[Z.partKind];return Ae?Ae===Z.partId&&re.plane===Z.partDimension:!1})})),sensorLocations:se.sensorLocations})),O={name:M.name,description:M.description||"",cameraPlacement:M.cameraPlacement||"",videoLink:M.videoLink||"",metadataIds:P.flat(),reports:_};U(O.name),N(O.description),te(O.cameraPlacement),V(O.videoLink),L(O.metadataIds),ne(_),Me(O)}},[M]);const he=s.useMemo(()=>JSON.stringify(fe)!==JSON.stringify({name:F,description:k,cameraPlacement:J,videoLink:D,metadataIds:X,reports:Y}),[fe,F,k,J,D,X,Y]),xe=s.useCallback(()=>{const f={name:F,description:k,cameraPlacement:J,videoLink:D,metadataItemIds:X,laterality:G.ActionLaterality.Either,quantumOwned:C,sessionType:[],thresholds:[],reports:Y.map(_=>({id:_.isNew?void 0:_.id,name:_.name,reportKind:_.kind,sensorLocations:_.sensorLocations,instructions:_.instructions,autoGenerate:_.autoGenerate??!1,thresholds:_.parameters.map(O=>({id:O.oldId,kind:O.kind,min:O.min,max:O.max,partKind:"joint"in O.id?"joint":"segment",partId:"joint"in O.id?O.id.joint:O.id.segment,partDimension:O.plane}))}))};let P;m&&a?P=T({id:a,fields:f}):P=y({fields:f}),P.then(({error:_})=>{_?r(_):h()})},[C,y,T,a,F,k,J,D,X,Y,m,h,r]);s.useEffect(()=>{d&&d({cancelButton:E,saveButton:o?!0:E||!Ee||!he})},[E,d,Ee,he,o]),s.useEffect(()=>{j&&j({cancelButton:l,saveButton:o?()=>{}:xe})},[j,l,xe,o]);const le=s.useCallback(f=>{const P=ce.getSuggestedSensorLocations(f.map(_=>"joint"in _.id?_.id.joint:_.id.segment));H(P)},[]);s.useEffect(()=>{le(u)},[u,le]);const ge=s.useCallback(()=>{if(!B||!c.trim())return;const f=B===G.ReportKind.PointOfInterest,P={id:Date.now().toString(),name:c.trim(),kind:B,parameters:f?[]:u,sensorLocations:f?[]:q,instructions:f?W:"",autoGenerate:!1,isNew:!0};ne(_=>[..._,P]),K(null),n(""),I([]),H([]),z("")},[B,c,u,q,W]),Oe=s.useCallback(f=>{ne(P=>P.filter(_=>_.id!==f))},[]),_e=(f,P)=>{const _=v.find(se=>se.key===f);if(!_)return;const O=_.multi?(P??[]).map(se=>se.id):P?[P.id]:[];L(se=>[...se.filter(re=>Object.values($).flat().find(be=>be.id===re)&&!Object.keys($).find(be=>$[be]?.some(Ge=>Ge.id===re&&be===f))),...O])};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:"Activity Configuration"}),e.jsxRuntimeExports.jsx(t.Tab,{children:"Reports Configuration"})]}),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(oe,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:F,onChange:f=>U(f.target.value),type:"text",placeholder:"i.e. Lunge & Return",isDisabled:o})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Camera Placement"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:J,onChange:f=>te(f.target.value),rows:2,placeholder:"(optional) Describe camera setup, placement, angles",isDisabled:o})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Video Link"}),e.jsxRuntimeExports.jsx(t.Input,{value:D,onChange:f=>V(f.target.value),type:"url",placeholder:"(optional) https://...",isDisabled:o})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Description"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:k,onChange:f=>N(f.target.value),rows:2,placeholder:"(optional) Describe how to perform the test or exercise",isDisabled:o})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(oe,{children:"Metadata Tags"}),v.map(f=>e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:f.label}),e.jsxRuntimeExports.jsx(ie.st,{isMulti:f.multi,value:$[f.key]?.filter(P=>X.includes(P.id)),onChange:P=>{_e(f.key,P)},options:$[f.key],placeholder:`Select ${f.multi?"one or more":"one"} ${f.label.toLowerCase()}`,isDisabled:o,isClearable:f.multi})]},f.key))]})]})}),e.jsxRuntimeExports.jsx(t.TabPanel,{px:0,children:e.jsxRuntimeExports.jsxs("div",{className:Te.cn("grid grid-cols-1 gap-6",!o&&"md:grid-cols-2"),children:[e.jsxRuntimeExports.jsxs("div",{className:Te.cn("space-y-4",o&&"hidden"),children:[e.jsxRuntimeExports.jsx(oe,{children:"Add New Report"}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Report Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:c,onChange:f=>n(f.target.value),maxLength:120,type:"text",placeholder:"Enter report name...",isDisabled:o})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Report Type"}),e.jsxRuntimeExports.jsx(ie.st,{value:B?je.find(f=>f.value===B):null,onChange:f=>K(f?.value||null),options:je,placeholder:"Select report type...",isDisabled:o,isClearable:!0})]}),B!==G.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(Ie,{options:de,value:u,onChange:I,editOnly:o})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Sensor Locations"}),e.jsxRuntimeExports.jsx(t.Input,{value:q.map(f=>Fe(f)).join(", "),placeholder:"Auto-filled based on parameters...",isDisabled:!0})]})]}),B===G.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:W,onChange:f=>z(f.target.value),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:o})]}),e.jsxRuntimeExports.jsx("div",{className:"w-full flex justify-end",children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:ge,isDisabled:!B||!c.trim()||o||je.length===0||B!==G.ReportKind.PointOfInterest&&u.length===0,children:"Add Report"})})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(oe,{children:"Configured Reports"}),Y.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:Y.map(f=>e.jsxRuntimeExports.jsxs("div",{className:"p-3 border border-gray-200 rounded-md bg-gray-50 flex flex-col gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.600",children:me.reportKindName(f.kind)}),!o&&e.jsxRuntimeExports.jsx(t.Button,{size:"xs",colorScheme:"red",variant:"ghost",onClick:()=>Oe(f.id),children:"Remove"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Report Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:f.name,onChange:P=>ne(_=>_.map(O=>O.id===f.id?{...O,name:P.target.value}:O)),placeholder:"Enter report name...",isDisabled:o})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{display:"flex",alignItems:"center",children:[e.jsxRuntimeExports.jsx(t.FormLabel,{htmlFor:`auto-generate-${f.id}`,mb:"0",children:"Auto Generate"}),e.jsxRuntimeExports.jsx(t.Switch,{id:`auto-generate-${f.id}`,isChecked:f.autoGenerate??!1,onChange:P=>ne(_=>_.map(O=>O.id===f.id?{...O,autoGenerate:P.target.checked}:O)),isDisabled:o})]}),f.kind===G.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:f.instructions,onChange:P=>ne(_=>_.map(O=>O.id===f.id?{...O,instructions:P.target.value}:O)),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:o})]}),f.kind!==G.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs("div",{className:"flex flex-col",children:[e.jsxRuntimeExports.jsx(oe,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(Ie,{options:de,value:f.parameters,onChange:P=>{const _=Z=>"joint"in Z.id?Z.id.joint:Z.id.segment,O=P.map(_),se=ce.getSuggestedSensorLocations(O);ne(Z=>Z.map(re=>re.id===f.id?{...re,parameters:P,sensorLocations:se}:re))},editOnly:o})]}),f.kind!==G.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Sensors:"," ",f.sensorLocations.map(P=>Fe(P)).join(", ")]})]},f.id))})]})]})})]})]}),e.jsxRuntimeExports.jsx(t.HStack,{justify:"end",className:Te.cn((p||o)&&"!hidden"),children:e.jsxRuntimeExports.jsxs(t.ButtonGroup,{gap:4,children:[e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:E,onClick:l,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:E||!Ee||!he,isLoading:E,onClick:xe,children:"Save changes"})]})})]})},oe=({children:a})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:a}),it=({children:a,isView:r,metadataKeys:l})=>{const[h,p]=s.useState({}),j=ee.useClient();return s.useEffect(()=>{let d=!1;return(async()=>{const o=(l??[]).map(y=>j.query(R.GET_METADATA_BY_KEY,{key:y}).toPromise()),i=await Promise.all(o),x={};for(const y of i){if(y.error||!y.data?.getMetadataByKey)continue;const b=w.getFragmentData(R.METADATA_GROUP_FRAGMENT,y.data.getMetadataByKey);if(!b)continue;const T=w.getFragmentData(R.METADATA_ITEM_FRAGMENT,b.data)??[];x[b.key]=T.map(S=>({label:S.label||S.value,value:S.value,id:S.id}))}d||p(x)})(),()=>{d=!0}},[j,l]),e.jsxRuntimeExports.jsx(Le.Provider,{value:{isView:r,metadataOptions:h},children:a})},lt=({id:a,onCancel:r,onSave:l,onError:h,hideButtons:p,quantumOwned:j,setButtonOnClick:d,setButtonDisabled:C,isView:o})=>{const[{data:i,fetching:x}]=ee.useQuery({query:j?R.GET_QUANTUM_OWNED_ACTIONS:R.GET_ACTIONS}),[{data:y}]=ee.useQuery({query:R.GET_MODULE_BY_ID,variables:{id:a},pause:!a}),[{data:b}]=ee.useQuery({query:R.GET_ALL_MODULE_CATEGORIES}),T=w.getFragmentData(R.MODULE_CATEGORY_FRAGMENT,b?.moduleCategories),[{fetching:S},M]=ee.useMutation(R.UPDATE_MODULE),[{fetching:E},m]=ee.useMutation(R.CREATE_MODULE),A=s.useMemo(()=>!i||x?[]:w.getFragmentData(R.ACTION_FRAGMENT,j?i?.quantumOwnedActions??[]:i?.actions??[]).filter(B=>!!B?.id),[i,j,x]),g=w.getFragmentData(R.ACTION_MODULE_FRAGMENT,y?.module),v=s.useMemo(()=>w.getFragmentData(R.MODULE_ACTION_FRAGMENT,g?.moduleActions)??[],[g?.moduleActions]),[F,U]=s.useState([]),[k,N]=s.useState(g?.name??""),[J,te]=s.useState([]),[D,V]=s.useState(g?.description??""),[X,L]=s.useState([]);s.useEffect(()=>{if(g){const Q=v.map((c,n)=>({key:c.id??`${c.actionId}-${n}`,actionId:c.actionId,reportId:c.reportId||null}));U(Q),N(g.name),V(g.description??""),te(g.categories.map(c=>w.getFragmentData(R.MODULE_CATEGORY_FRAGMENT,c).id)??[]);const K=w.getFragmentData(R.METADATA_GROUP_FRAGMENT,g.metadataGroups).map(c=>c.data.map(n=>w.getFragmentData(R.METADATA_ITEM_FRAGMENT,n).id));L(K.flat())}},[g,v]);const $=s.useCallback(()=>{let Q;const B={moduleActions:F.map(K=>({actionId:K.actionId,reportId:K.reportId??void 0})),name:k,categories:J.filter(K=>K!=="other"),description:D,quantumOwned:j,metadataItemIds:X};g?Q=M({id:g.id,input:B}):Q=m({input:B}),Q.then(({error:K})=>{K?h(K instanceof Error?K:new Error(String(K))):l()})},[m,M,F,k,D,J,X,g,l,h,j]);return s.useEffect(()=>{C&&C({cancelButton:S||E,saveButton:S||E||!k||D.trim().split(/\s+/).filter(Boolean).length>40})},[C,S,E,F,k,D]),s.useEffect(()=>{d&&d({cancelButton:r,saveButton:$})},[d,r,$]),e.jsxRuntimeExports.jsx(t.Box,{width:"100%",children:e.jsxRuntimeExports.jsxs(it,{isView:o,metadataKeys:["activity_type","session_type","body_region","sport"],children:[e.jsxRuntimeExports.jsx(Ne,{name:k,setName:N,actions:A,moduleActionEntries:F,setModuleActionEntries:U,availableCategories:T??[],selectedCategoryIds:J,setSelectedCategoryIds:te,description:D,setDescription:V,selectedMetadataIds:X,setSelectedMetadataIds:L}),!p&&!o&&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:S||E,onClick:r,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:S||E||!k||D.trim().split(/\s+/).filter(Boolean).length>40,isLoading:S||E,onClick:$,children:"Save"})]})})]})})};exports.ActivityList=ke;exports.CopyActivityForm=Je;exports.CopyModuleForm=Ve;exports.ModuleForm=Ne;exports.ParameterEditList=De;exports.ParameterEditSelect=Ie;exports.UpsertActivityForm=at;exports.UpsertModuleForm=lt;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./react-jsx-runtime-vendor-Dszzpdy0.cjs");require("./moment-vendor-1cRqq0AH.cjs");const t=require("@chakra-ui/react"),s=require("react"),F=require("./generated.cjs"),R=require("./graphql-kPu5QxaL.cjs"),ve=require("./utils-cn-FIKrq5Mb.cjs");require("./lodash-vendor-CfNg9qwP.cjs");const Z=require("urql"),ae=require("./hooks.cjs"),Pe=require("./ufuzzy-vendor-7qHa_k39.cjs"),ie=require("./react-select-vendor-BLLqfZvd.cjs"),he=require("./react-icons-vendor-c4NUuwCE.cjs"),je=require("./services.cjs"),Me=require("./react-dnd-vendor-DvbjNa5U.cjs"),ce=require("./services-human-DFPelsei.cjs"),$=require("./generated-graphql.cjs"),ge=require("./types.cjs"),Be=({setSearch:r,actions:o,updateUseCases:i,hideUseCaseFilter:h=!1})=>{const p=s.useMemo(()=>o?.flatMap(j=>j.useCases).filter((j,d,C)=>C.findIndex(n=>n.id===j.id)===d).map(j=>({label:j.name,value:j.id}))||[],[o]);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:he.FaSearch,color:"gray.300"})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"Search by name...",width:"100%",maxW:h?void 0:"30rem",onChange:j=>r(j.target.value)})]}),!h&&e.jsxRuntimeExports.jsx(t.InputGroup,{size:"md",children:e.jsxRuntimeExports.jsx(ie.st,{size:"md",chakraStyles:{container:j=>({...j,width:"100%"})},menuPortalTarget:document.body,placeholder:"Filter use case",isMulti:!0,options:p,onChange:j=>i(j.map(d=>d.value))})})]})},ue=({children:r})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:r}),$e=({items:r,onChange:o,selectedItem:i,isDisabled:h,selectedProps:p,buttonProps:j})=>{const d=n=>n===i||n.value===i,C=n=>d(n)?{...j,...p}:j;return e.jsxRuntimeExports.jsx(t.ButtonGroup,{isAttached:!0,isDisabled:h,children:r.map((n,a)=>e.jsxRuntimeExports.jsx(t.Tooltip,{label:n.tooltip,openDelay:50,closeDelay:200,placement:"top",visibility:n.tooltip?"visible":"hidden",hasArrow:!0,children:e.jsxRuntimeExports.jsx(t.Button,{onClick:()=>d(n)?null:o(n,a),isDisabled:n.disabled,...C(n),children:n.label})},a))})},Te=(r,o)=>o<0?-1*Math.abs(r):Math.abs(r),Ue=({isReversed:r,min:o,max:i,value:h,onChange:p,inputProps:j,size:d,zeroMarker:C,formatValue:n,valueLabel:a,positiveNegativeLabels:m,isDisabled:y,...b})=>{const[v,M]=s.useState([void 0,void 0]),I=v[0],E=v[1],x=C&&o<-5&&i>5,k=Number(h?.[0]??E??o)>0?1:-1,g=Number(h?.[1]??E??i)<0?-1:1,N=m?.[0]===m?.[1],T=h?.[0],B=h?.[1];s.useEffect(()=>{T!==void 0&&B!==void 0&&M([T.toFixed(0),B.toFixed(0)])},[T,B,M]);const O=s.useCallback(([L,z])=>{L<z&&M([L.toFixed(0),z.toFixed(0)])},[M]),w=s.useCallback(([L,z])=>{L<z&&p([L,z])},[p]),K=s.useCallback(()=>{M(([L,z])=>{const J=isNaN(Number(L))?o:Number(L),q=isNaN(Number(z))?i:Number(z),Q=Te(Number(J),k),c=Te(Number(q),g),l=k<0?Math.max(Q,o):Math.min(Q,i),S=g<0?Math.max(c,o):Math.min(c,i);return l>S?(p([S,l]),[S.toFixed(0),l.toFixed(0)]):(p([l,S]),[l.toFixed(0),S.toFixed(0)])})},[p,M,k,g,o,i]),te=s.useCallback(L=>{const z=L===""||isNaN(Number(L))?L:Te(Number(L),k);M(([J,q])=>[z.toString(),q])},[M,k]),D=s.useCallback(L=>{const z=L===""||isNaN(Number(L))?L:Te(Number(L),g);M(([J,q])=>[J,z.toString()])},[M,g]),ne=s.useMemo(()=>d==="xs"?"0.75rem":void 0,[d]),V=s.useCallback((L,z)=>{const J=Number(z.target.value);if(!I||!E||![-1,1].includes(J))return;const q=l=>J<0?-1*Math.abs(l):Math.abs(l),Q=L?q(Number(I)):Number(I),c=L?Number(E):q(Number(E));Q>c?p([c,Q]):p([Q,c])},[I,E,p]);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:r,value:[Number(I??o),Number(E??i)],max:i,min:o,minStepsBetweenThumbs:3,step:1,onChange:O,onChangeEnd:w,isDisabled:y,children:[e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:o,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:d??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:n?n?.(o):o})}),e.jsxRuntimeExports.jsx(t.RangeSliderMark,{value:i,top:"-1em",children:e.jsxRuntimeExports.jsx(t.Text,{fontSize:d??"sm",fontWeight:"semibold",style:{transform:"translateX(-100%)"},whiteSpace:"nowrap",children:n?n(i):i})}),x&&e.jsxRuntimeExports.jsxs(t.RangeSliderMark,{value:0,top:"-1em",pos:"relative",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:d,fontWeight:"semibold",children:n?.(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:ne,h:ne}),e.jsxRuntimeExports.jsx(t.RangeSliderThumb,{index:1,w:ne,h:ne})]})}),a&&e.jsxRuntimeExports.jsxs(t.Flex,{direction:r?"row-reverse":"row",justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:d??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:a(o)}),e.jsxRuntimeExports.jsx(t.Text,{fontSize:d??"sm",fontWeight:"semibold",whiteSpace:"nowrap",children:a(i)})]}),e.jsxRuntimeExports.jsxs(t.Flex,{direction:r?"row-reverse":"row",justifyContent:"center",alignItems:"center",gap:"0.125em",children:[m&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:d,fontWeight:"bold",value:k,onChange:L=>V(!0,L),isDisabled:N||y,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:m[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:m[1]})]}),e.jsxRuntimeExports.jsx(t.NumberInput,{precision:0,size:d??"sm",min:0,max:k<0?Math.abs(o):B??i,value:I===""?"":Math.abs(Number(I??o)),onChange:te,onBlur:K,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:y,...j,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),e.jsxRuntimeExports.jsx(t.NumberInput,{size:d??"sm",min:0,max:g<0?Math.abs(T??o):i,precision:0,value:E===""?"":Math.abs(Number(E??i)),onChange:D,onBlur:K,borderWidth:1,borderRadius:3,borderColor:"#ccc",isDisabled:y,...j,children:e.jsxRuntimeExports.jsx(t.NumberInputField,{backgroundColor:"#fff",paddingRight:0,width:"4em"})}),m&&e.jsxRuntimeExports.jsxs(t.Select,{width:"auto",size:d,fontWeight:"bold",value:g,onChange:L=>V(!1,L),isDisabled:N||y,children:[e.jsxRuntimeExports.jsx("option",{value:-1,children:m[0]}),e.jsxRuntimeExports.jsx("option",{value:1,children:m[1]})]})]})]})},ze=({tags:r,containerProps:o,...i})=>e.jsxRuntimeExports.jsx(t.HStack,{...o,children:r.map((h,p)=>e.jsxRuntimeExports.jsx(t.Tag,{...i,children:h},p))}),qe=new Pe.uFuzzy({}),We=({action:r,quantumIconSrc:o})=>{const{getLabel:i}=ae.useUiLabelContext(),h=s.useMemo(()=>({actionLowerCase:i("action").toLocaleLowerCase()}),[i]);return r.quantumOwned?e.jsxRuntimeExports.jsx(t.Tooltip,{label:`This ${h.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:o,boxSize:"1em",alt:`Quantum-owned ${h.actionLowerCase}`})})}):null},He=(r,o)=>{if(!o||!o.trim().length)return r;const i=r.map(p=>p.name??"");return qe.filter(i,o)?.map(p=>r[p])??[]},Ke=r=>!r||r.length===0?"None":r.map(o=>o.replace(/([A-Z])/g," $1").trim()).join(", "),Qe=(r,o)=>!o||o.length==0?r:r.filter(i=>i.useCases?.some(h=>o.includes(h.id))??!1),Ye=(r,o,i)=>!o||o.length===0?r:r.filter(h=>{const p={};return o.forEach(j=>{for(const[d,C]of Object.entries(i||{}))if(C.some(n=>n.id===j)){p[d]||(p[d]=[]),p[d].push(j);break}}),Object.entries(p).every(([j,d])=>{const C=h.metadataGroups?.find(y=>F.getFragmentData(R.METADATA_GROUP_FRAGMENT,y).key===j);if(!C)return!1;const n=F.getFragmentData(R.METADATA_GROUP_FRAGMENT,C),m=F.getFragmentData(R.METADATA_ITEM_FRAGMENT,n.data).map(y=>y.id);return d.some(y=>m.includes(y))})}),we=({actions:r,totalActions:o,onCreate:i,onDelete:h,onEdit:p,onView:j,onSelected:d,onDuplicate:C,disableMultiSelect:n,disableDelete:a,disableEdit:m,disableCreate:y,hideUseCase:b=!0,showMetadataFilters:v=!0,tableProps:M,containerProps:I,quantumIconSrc:E="/favicon.ico",allowDuplicateSelection:x=!1,getSelectedCount:k})=>{const[g,N]=s.useState(""),[T,B]=s.useState(),[O,w]=s.useState([]),[K,te]=s.useState({}),{getLabel:D}=ae.useUiLabelContext(),ne=Z.useClient(),V=s.useMemo(()=>({action:D("action"),actionPlural:D("action_plural"),actionLowerCase:D("action").toLocaleLowerCase(),actionPluralLowerCase:D("action_plural").toLocaleLowerCase()}),[D]),L=s.useMemo(()=>[{key:"module_category",label:"Link Category",multi:!0},{key:"activity_type",label:`${V.action} Type`,multi:!0},{key:"session_type",label:"Session Type",multi:!0},{key:"body_region",label:"Body Region",multi:!0},{key:"sport",label:"Sport",multi:!0}],[V.action]);s.useEffect(()=>{if(!v)return;const u=L.map(A=>ne.query(R.GET_METADATA_BY_KEY,{key:A.key}));Promise.all(u).then(A=>{const W={};A.forEach(_=>{if(_.error||!_.data)return;const H=F.getFragmentData(R.METADATA_GROUP_FRAGMENT,_.data.getMetadataByKey),Y=F.getFragmentData(R.METADATA_ITEM_FRAGMENT,H.data);W[H.key]=Y.map(se=>({label:se.label||se.value,value:se.value,id:se.id}))}),te(W)})},[ne,L,v]);const z=s.useMemo(()=>{if(!r)return;const u=He(r,g),A=b?u:Qe(u,T);return v?Ye(A,O,K):A},[r,g,T,b,v,O,K]),J=s.useCallback(()=>{if(!h)return;const A=r.filter(W=>W.selected&&!W.quantumOwned).map(W=>W.id);h(A)},[r,h]),q=s.useCallback(()=>{if(!C)return;const u=r.filter(A=>A.selected);C(u.map(A=>A.id)),d&&u.forEach(A=>d(A,!1))},[r,C,d]),Q=s.useMemo(()=>r.some(u=>u.selected&&!u.quantumOwned),[r]),c=s.useMemo(()=>r.some(u=>u.selected),[r]),l=s.useMemo(()=>r.some(u=>u.selected&&u.quantumOwned),[r]),S=s.useCallback((u,A)=>{const W=L.find(H=>H.key===u);if(!W)return;const _=W.multi?(A??[]).map(H=>H.id):A?[A.id]:[];w(H=>[...H.filter(se=>Object.values(K).flat().find(xe=>xe.id===se)&&!Object.keys(K).find(xe=>K[xe]?.some(me=>me.id===se&&xe===u))),..._])},[L,K]);return e.jsxRuntimeExports.jsxs(t.Box,{...I,children:[e.jsxRuntimeExports.jsxs(t.Flex,{alignContent:"space-between",gap:4,children:[(i||h||C)&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{mb:"1rem",gap:4,children:[i&&e.jsxRuntimeExports.jsxs(t.Button,{isDisabled:!i||y,colorScheme:"blackAlpha",backgroundColor:"gray.700",onClick:i,children:["Create New ",V.action]}),h&&!n&&e.jsxRuntimeExports.jsx(t.Tooltip,{label:l?Q?`Quantum-owned ${V.actionPluralLowerCase} are selected and will be skipped`:`Selected ${V.actionPluralLowerCase} are quantum-owned and cannot be deleted`:void 0,shouldWrapChildren:!0,children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!Q||!h||a,onClick:J,children:"Delete Selected"})}),C&&!n&&e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:!c,onClick:q,children:"Duplicate Selected"})]}),e.jsxRuntimeExports.jsx(Be,{setSearch:N,actions:r,updateUseCases:B,hideUseCaseFilter:b})]}),v&&K&&e.jsxRuntimeExports.jsx(t.Box,{my:4,children:e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4",children:L.map(u=>e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(t.FormLabel,{fontSize:"sm",children:u.label}),e.jsxRuntimeExports.jsx(ie.st,{chakraStyles:{menu:A=>({...A,zIndex:2})},isMulti:u.multi,value:K[u.key]?.filter(A=>O.includes(A.id)),onChange:A=>{S(u.key,A)},options:K[u.key],placeholder:`Select ${u.multi?"one or more":"one"} ${u.label.toLowerCase()}`,isClearable:u.multi})]},u.key))})}),e.jsxRuntimeExports.jsx(t.TableContainer,{mr:"2rem",overflowX:"hidden",...M,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 ",z?.length??0," of"," ",o??r.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:z?.map(u=>{const A=x?k?.(u.id)??0:0,W=x?A>0:!!u.selected;return e.jsxRuntimeExports.jsxs(t.Tr,{className:ve.cn("hover:bg-[#f7f7f7]",!n&&!x&&"cursor-pointer",W&&"bg-gray-200"),onClick:()=>{n||x||d?.(u,!u.selected)},children:[e.jsxRuntimeExports.jsx(t.Td,{children:e.jsxRuntimeExports.jsxs(t.Flex,{alignItems:"center",children:[!n&&x?e.jsxRuntimeExports.jsxs(t.HStack,{spacing:1,onClick:_=>_.stopPropagation(),children:[e.jsxRuntimeExports.jsx(t.IconButton,{"aria-label":"Remove one instance",icon:e.jsxRuntimeExports.jsx(he.FaMinus,{}),size:"xs",variant:"outline",isDisabled:A===0,onClick:()=>d?.(u,!1)}),e.jsxRuntimeExports.jsx(t.Text,{minW:"1.5rem",textAlign:"center",fontWeight:A>0?"semibold":"normal",color:A>0?"blue.600":"gray.500",children:A}),e.jsxRuntimeExports.jsx(t.IconButton,{"aria-label":"Add one instance",icon:e.jsxRuntimeExports.jsx(he.FaPlus,{}),size:"xs",variant:"outline",colorScheme:"blue",onClick:()=>d?.(u,!0)})]}):n?null:e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:u.selected?e.jsxRuntimeExports.jsx(he.FaCheckSquare,{className:"text-blue-500"}):e.jsxRuntimeExports.jsx(he.FaSquare,{className:"text-gray-400"})}),(u.quantumOwned||!p)&&j&&e.jsxRuntimeExports.jsx(t.Button,{ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:_=>{_.stopPropagation(),j(u.id)},children:"View"}),!u.quantumOwned&&p&&e.jsxRuntimeExports.jsx(t.Button,{isDisabled:m,ml:"1em",size:"sm",variant:"link",colorScheme:"blue",onClick:_=>{_.stopPropagation(),p(u.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(We,{action:u,quantumIconSrc:E}),u.name]})}),e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",whiteSpace:"break-spaces",children:Ke(u.sensorLocations)}),!b&&e.jsxRuntimeExports.jsx(t.Td,{maxW:"20rem",children:e.jsxRuntimeExports.jsx(ze,{containerProps:{flexWrap:"wrap"},tags:u.useCases?.map(_=>_.name)??[]})})]},u.id)})})]})})]})},Je=({onSave:r,onCancel:o,onError:i,hideButtons:h=!1,setButtonDisabled:p,setButtonOnClick:j,quantumOwned:d})=>{const C=t.useToast(),{getLabel:n}=ae.useUiLabelContext(),a=s.useMemo(()=>({singular:n("action"),plural:n("action_plural"),pluralLowerCase:n("action_plural").toLowerCase(),singularLowerCase:n("action").toLowerCase()}),[n]),[m,y]=s.useState("copy"),[b,v]=s.useState(""),[M,I]=s.useState([]),[E,x]=s.useState(!1),[k]=Z.useQuery({query:R.GET_GROUPS}),[g]=Z.useQuery({query:R.GET_ACTIONS_BY_GROUP,variables:{groupId:b},pause:!b}),[,N]=Z.useMutation(R.CREATE_ACTION),[,T]=Z.useMutation(R.CONVERT_ACTION_TO_QUANTUM_OWNED),B=s.useMemo(()=>k.data?.groups?k.data.groups.map(c=>F.getFragmentData(R.GROUP_FRAGMENT,c)):[],[k.data]),O=s.useMemo(()=>g.data?g.data.actions.map(l=>{const S=F.getFragmentData(R.ACTION_FRAGMENT,l),u=F.getFragmentData(R.REPORT_FRAGMENT,S.reports),A=F.getFragmentData(R.MODULE_CATEGORY_FRAGMENT,S.categories),_=F.getFragmentData(R.METADATA_GROUP_FRAGMENT,S.metadataGroups).map(H=>({...H,data:H.data.map(Y=>F.getFragmentData(R.METADATA_ITEM_FRAGMENT,Y))}));return{...S,thresholds:F.getFragmentData(R.THRESHOLD_FRAGMENT,S.thresholds),reports:u.map(H=>({...H,thresholds:F.getFragmentData(R.THRESHOLD_FRAGMENT,H.thresholds)})),categories:A,metadataGroups:_}}):[],[g.data]),w=s.useMemo(()=>O.filter(c=>M.includes(c.id)),[O,M]),K=s.useCallback(c=>{const l=c?.value||"";v(l),I([])},[]),te=s.useCallback(c=>{const l=c.map(S=>S.value);I(l)},[]),D=s.useCallback(async c=>{const l={...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(u=>({...u,id:void 0})),categories:c.categories.map(u=>u.id),quantumOwned:d,metadataItemIds:c.metadataGroups.flatMap(u=>u.data.map(A=>A.id)).filter(u=>u!==void 0),reports:c.reports.map(u=>({...u,id:void 0,thresholds:u.thresholds.map(A=>({...A,id:void 0}))})),id:void 0},S=await N({fields:l});if(S.error)throw new Error(S.error.message);if(S.data?.createAction)return F.getFragmentData(R.ACTION_FRAGMENT,S.data.createAction);throw new Error("No action data returned")},[N,d]),ne=s.useCallback(async c=>{const l=await T({id:c.id});if(l.error)throw new Error(l.error.message);if(l.data?.convertActionToQuantumOwned)return F.getFragmentData(R.ACTION_FRAGMENT,l.data.convertActionToQuantumOwned);throw new Error("No action data returned")},[T]),V=s.useCallback(async()=>{if(x(!0),!w.length){const c=new Error(`No ${a.pluralLowerCase} selected for ${m==="copy"?"copying":"converting"}`);i?.(c),x(!1);return}try{const c=[];let l=0;const S=m==="copy"?D:ne,u=m==="copy"?"copy":"convert";for(const A of w)try{const W=await S(A);c.push(W)}catch(W){console.error(`Failed to ${u} ${a.singularLowerCase} "${A.name}":`,W),l++}if(c.length>0){const A=c.length,W=w.length,_=m==="copy"?"copied":"converted",H=m==="copy"?"copy":"convert";C({title:l>0?`Partial ${H} completed`:`${a.plural} ${_} successfully`,description:l>0?`${A} of ${W} ${a.pluralLowerCase} ${_} successfully`:`${A} ${A>1?a.pluralLowerCase:a.singularLowerCase} ${_} successfully`,status:l>0?"warning":"success",duration:3e3,isClosable:!0}),r?.(),v(""),I([])}else throw new Error(`Failed to ${u} any ${a.pluralLowerCase}`)}catch(c){const l=m==="copy"?"copy":"convert",S=c instanceof Error?c.message:`Failed to ${l} ${a.pluralLowerCase}`;C({title:`${m==="copy"?"Copy":"Convert"} failed`,description:S,status:"error",duration:5e3,isClosable:!0}),i?.(c instanceof Error?c:new Error(S))}finally{x(!1)}},[w,m,D,ne,C,r,i,a]),L=s.useCallback(()=>{v(""),I([]),y("copy"),o?.()},[o]);s.useEffect(()=>{p&&p({cancelButton:!1,saveButton:w.length===0||E})},[w.length,E,p]),s.useEffect(()=>{j&&j({cancelButton:L,saveButton:V})},[j,L,V]);const z=s.useMemo(()=>B.map(c=>({value:c.id,label:c.name})),[B]),J=s.useMemo(()=>O.filter(c=>m==="copy"?!0:!c.quantumOwned).map(c=>({value:c.id,label:c.name,isQuantumOwned:c.quantumOwned})),[O,m]),q=k.fetching,Q=g.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[d&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:m,onChange:c=>{y(c),I([])},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 ",a.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",a.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 ",a.singular]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Convert existing"," ",a.plural.toLocaleLowerCase()," to quantum-owned"]})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(ie.st,{placeholder:"Choose a group...",options:z,value:z.find(c=>c.value===b)||null,onChange:K,isLoading:q,isDisabled:q,isClearable:!0}),k.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: ",k.error.message]})]})]}),b&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsxs(ue,{children:["Select ",a.plural," to"," ",m==="copy"?"Copy":"Convert"]}),Q?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 ",a.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(ie.st,{placeholder:`Choose ${a.pluralLowerCase} to ${m}...`,options:J,value:J.filter(c=>M.includes(c.value)),onChange:te,isDisabled:J.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(c,{context:l})=>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}),l==="value"&&c.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),c.isQuantumOwned&&l==="menu"&&e.jsxRuntimeExports.jsx(t.Tag,{size:"sm",colorScheme:"blue",variant:"solid",children:"Quantum Owned"})]})}),J.length===0&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",mt:2,children:["No ",a.pluralLowerCase," found"]})]}),g.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load ",a.pluralLowerCase,":"," ",g.error.message]})]})]}),w.length>0&&e.jsxRuntimeExports.jsxs(t.Box,{p:4,bg:"gray.50",borderRadius:"md",children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"semibold",mb:3,children:w.length===1?`${a.singular} to ${m==="copy"?"Copy":"Convert"}:`:`${w.length} ${a.plural} to ${m==="copy"?"Copy":"Convert"}:`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[w.map((c,l)=>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:[l+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(S=>S.name).join(", ")||"None"]})]})]},c.id)),w.length>1&&e.jsxRuntimeExports.jsx(t.Box,{w:"100%",p:2,bg:"blue.50",borderRadius:"md",border:"1px solid",borderColor:"blue.200",children:e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",fontWeight:"medium",color:"blue.800",children:["Total: ",w.length," ",a.pluralLowerCase," will be"," ",m==="copy"?"copied":"converted"]})})]})]}),!h&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:L,isDisabled:E,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:m==="copy"?"blue":"green",onClick:V,isDisabled:w.length===0||E,isLoading:E,loadingText:`${m==="copy"?"Copying":"Converting"}...`,children:[m==="copy"?"Copy":"Convert"," ",w.length===1?a.singular:`${w.length} ${a.plural}`]})]})]})})},Ve=({onSave:r,onCancel:o,onError:i,hideButtons:h=!1,setButtonDisabled:p,setButtonOnClick:j,quantumOwned:d})=>{const C=t.useToast(),{getLabel:n}=ae.useUiLabelContext(),a=s.useMemo(()=>({singular:n("module"),plural:n("module_plural"),pluralLowerCase:n("module_plural").toLowerCase(),singularLowerCase:n("module").toLowerCase()}),[n]),m=s.useMemo(()=>({singular:n("action"),plural:n("action_plural"),pluralLowerCase:n("action_plural").toLowerCase(),singularLowerCase:n("action").toLowerCase()}),[n]),[y,b]=s.useState(""),[v,M]=s.useState([]),[I,E]=s.useState(!1),[x,k]=s.useState("copy"),[g]=Z.useQuery({query:R.GET_GROUPS}),[N]=Z.useQuery({query:R.GET_MODULES_BY_GROUP,variables:{groupId:y},pause:!y}),[,T]=Z.useMutation(R.CREATE_MODULE),[,B]=Z.useMutation(R.UPDATE_MODULE),[,O]=Z.useMutation(R.CREATE_ACTION),[,w]=Z.useMutation(R.CONVERT_ACTION_TO_QUANTUM_OWNED),K=s.useMemo(()=>g.data?.groups?g.data.groups.map(l=>F.getFragmentData(R.GROUP_FRAGMENT,l)):[],[g.data]),te=s.useMemo(()=>N.data?.modules?F.getFragmentData(R.ACTION_MODULE_FRAGMENT,N.data?.modules).map(S=>{const u=F.getFragmentData(R.MODULE_ACTION_FRAGMENT,S.moduleActions),W=F.getFragmentData(R.METADATA_GROUP_FRAGMENT,S.metadataGroups).map(_=>F.getFragmentData(R.METADATA_ITEM_FRAGMENT,_.data)).flat();return{...S,moduleActions:u.map(_=>({..._,action:F.getFragmentData(R.ACTION_FRAGMENT,_.action)})),categories:F.getFragmentData(R.MODULE_CATEGORY_FRAGMENT,S.categories),metadataItems:W}}):[],[N.data]),D=s.useMemo(()=>te.filter(l=>v.includes(l.id)),[te,v]),ne=s.useCallback(l=>{const S=l?.value||"";b(S),M([])},[]),V=s.useCallback(l=>{const S=l.map(u=>u.value);M(S)},[]),L=s.useCallback(async()=>{if(E(!0),!D.length){E(!1);const l=new Error(`No modules selected for ${x==="convert"?"converting":"copying"}`);i?.(l);return}try{const l=[];let S=0;for(const u of D)try{let A=u.moduleActions.map(W=>W.actionId);if(d){const W=u.moduleActions.map(Y=>Y.action),_=async Y=>{if(x==="copy"){if(Y.quantumOwned)return Y;const de=F.getFragmentData(R.MODULE_CATEGORY_FRAGMENT,Y.categories),me=F.getFragmentData(R.METADATA_GROUP_FRAGMENT,Y.metadataGroups).map(le=>F.getFragmentData(R.METADATA_ITEM_FRAGMENT,le.data).map(Ee=>Ee.id)).flat(),Ce=F.getFragmentData(R.REPORT_FRAGMENT,Y.reports).map(le=>({...le,id:void 0,thresholds:F.getFragmentData(R.THRESHOLD_FRAGMENT,le.thresholds).map(Ee=>({...Ee,id:void 0}))})),Ae=F.getFragmentData(R.THRESHOLD_FRAGMENT,Y.thresholds).map(le=>({...le,id:void 0})),Re={...Y,quantumOwned:!0,thresholds:Ae,categories:de?.map(le=>le.id),reports:Ce,metadataIds:me,id:void 0},pe=await O({fields:Re});return pe.error||!pe.data?.createAction?null:F.getFragmentData(R.ACTION_FRAGMENT,pe.data.createAction)}if(Y.quantumOwned)return Y;const se=await w({id:Y.id});return se.error||!se.data?.convertActionToQuantumOwned?null:F.getFragmentData(R.ACTION_FRAGMENT,se.data.convertActionToQuantumOwned)};A=(await Promise.all(W.map(_))).filter(Y=>!!Y?.id).map(Y=>Y.id)}if(x==="convert"){const W={name:u.name,description:u.description||void 0,actions:A,categories:u.categories.map(H=>H.id),quantumOwned:!0},_=await B({id:u.id,input:W});if(_.error)throw new Error(_.error.message);if(_.data?.updateModule){const H=F.getFragmentData(R.ACTION_MODULE_FRAGMENT,_.data.updateModule);l.push(H)}}else{const W={name:`${u.name} (Copy)`,description:u.description||void 0,moduleActions:u.moduleActions.map(H=>({actionId:H.actionId,reportId:H.reportId??void 0})),categories:u.categories.map(H=>H.id),quantumOwned:d,metadataItemIds:u.metadataItems.map(H=>H.id)},_=await T({input:W});if(_.error)throw new Error(_.error.message);if(_.data?.createModule){const H=F.getFragmentData(R.ACTION_MODULE_FRAGMENT,_.data.createModule);l.push(H)}}}catch(A){console.error(`Failed to ${x==="convert"?"convert":"copy"} module "${u.name}":`,A),S++}if(l.length>0){const u=l.length,A=D.length;C({title:S>0?`Partial ${x==="convert"?"convert":"copy"} completed`:`${a.plural} ${x==="convert"?"converted":"copied"} successfully`,description:S>0?`${u} of ${A} ${a.plural} ${x==="convert"?"converted":"copied"} successfully`:`${u} ${u>1?a.plural:a.singular} ${x==="convert"?"converted":"copied"} successfully`,status:S>0?"warning":"success",duration:3e3,isClosable:!0}),l.length>0&&r?.(),b(""),M([])}else throw new Error(`Failed to ${x==="convert"?"convert":"copy"} any modules`)}catch(l){const S=l instanceof Error?l.message:`Failed to ${x==="convert"?"convert":"copy"} modules`;C({title:x==="convert"?"Convert failed":"Copy failed",description:S,status:"error",duration:5e3,isClosable:!0}),i?.(l instanceof Error?l:new Error(S))}finally{E(!1)}},[D,T,B,C,r,i,d,O,w,x,a]),z=s.useCallback(()=>{b(""),M([]),k("copy"),o?.()},[o]);s.useEffect(()=>{p&&p({cancelButton:!1,saveButton:D.length===0||I})},[D.length,I,p]),s.useEffect(()=>{j&&j({cancelButton:z,saveButton:L})},[j,z,L]);const J=s.useMemo(()=>K.map(l=>({value:l.id,label:l.name})),[K]),q=s.useMemo(()=>te.filter(l=>x==="copy"?!0:!l.quantumOwned).map(l=>({value:l.id,label:l.name,isQuantumOwned:l.quantumOwned})),[te,x]),Q=g.fetching,c=N.fetching;return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsxs(t.VStack,{spacing:6,align:"stretch",children:[d&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:"Operation Mode"}),e.jsxRuntimeExports.jsx(t.RadioGroup,{value:x,onChange:l=>{k(l),M([])},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 ",a.plural]}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Create new ",a.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 ",a.pluralLowerCase," to quantum-owned"]})]})})]})})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:"Select Source Group"}),e.jsxRuntimeExports.jsx(ie.st,{placeholder:"Choose a group...",options:J,value:J.find(l=>l.value===y)||null,onChange:ne,isLoading:Q,isDisabled:Q,isClearable:!0}),g.error&&e.jsxRuntimeExports.jsxs(t.Alert,{status:"error",mt:2,children:[e.jsxRuntimeExports.jsx(t.AlertIcon,{}),e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",children:["Failed to load groups: ",g.error.message]})]})]}),y&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(ue,{children:x==="convert"?`Select ${a.plural} to Convert`:`Select ${a.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 ",a.pluralLowerCase,"..."]})]}):e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(ie.st,{placeholder:x==="convert"?`Choose ${a.pluralLowerCase} to convert...`:`Choose ${a.pluralLowerCase} to copy...`,options:q,value:q.filter(l=>v.includes(l.value)),onChange:V,isDisabled:q.length===0,isClearable:!0,isMulti:!0,closeMenuOnSelect:!1,formatOptionLabel:(l,{context:S})=>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}),S==="value"&&l.isQuantumOwned&&e.jsxRuntimeExports.jsx(t.Text,{color:"blue",fontSize:"xs",children:"(Quantum Owned)"})]}),l.isQuantumOwned&&S==="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 ",a.pluralLowerCase," found in this group"]})]}),N.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 ",a.pluralLowerCase,":"," ",N.error.message]})]})]}),D.length>0&&e.jsxRuntimeExports.jsxs(t.Box,{p:4,bg:"gray.50",borderRadius:"md",children:[e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"semibold",mb:3,children:D.length===1?`${a.singular} to ${x==="copy"?"Copy":"Convert"}`:`${D.length} ${a.plural} to ${x==="copy"?"Copy":"Convert"}`}),e.jsxRuntimeExports.jsxs(t.VStack,{align:"start",spacing:3,children:[D.map((l,S)=>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:[S+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:"Activities:"})," ",l.moduleActions.length]}),e.jsxRuntimeExports.jsxs(t.Text,{children:[e.jsxRuntimeExports.jsx("strong",{children:"Categories:"})," ",l.categories.map(u=>u.name).join(", ")||"None"]})]})]},l.id)),D.length>1&&e.jsxRuntimeExports.jsx(t.Box,{w:"100%",p:2,bg:"blue.50",borderRadius:"md",border:"1px solid",borderColor:"blue.200",children:e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",fontWeight:"medium",color:"blue.800",children:["Total: ",D.length," ",a.pluralLowerCase," will be"," ",x==="copy"?"copied":"converted"]})}),d&&D.filter(l=>l.moduleActions.some(S=>!S.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:x==="convert"?`Converting ${a.plural} will convert non QM-Owned ${m.plural} to QM-Owned ${m.plural}`:`Copying ${a.plural} with Non QM-Owned ${m.plural} will create corresponding QM-Owned ${m.plural}`})})]})]}),!h&&e.jsxRuntimeExports.jsxs(t.ButtonGroup,{spacing:4,justifyContent:"flex-end",children:[e.jsxRuntimeExports.jsx(t.Button,{variant:"outline",onClick:z,isDisabled:I,children:"Cancel"}),e.jsxRuntimeExports.jsxs(t.Button,{colorScheme:x==="copy"?"blue":"green",onClick:L,isDisabled:D.length===0||I,isLoading:I,loadingText:`${x==="copy"?"Copying":"Converting"}...`,children:[x==="copy"?"Copy":"Convert"," ",D.length===1?a.singular:`${D.length} ${a.plural}`]})]})]})})},Le=s.createContext(void 0),fe=()=>{const r=s.useContext(Le);if(!r)throw new Error("useUpsertModuleFormContext must be used within a UpsertModuleFormProvider");return r},Ne=({name:r,setName:o,actions:i,moduleActionEntries:h,setModuleActionEntries:p,availableCategories:j,selectedCategoryIds:d,setSelectedCategoryIds:C,description:n,setDescription:a,selectedMetadataIds:m,setSelectedMetadataIds:y,...b})=>{const v=t.useDisclosure(),M=s.useMemo(()=>{const T={};return h.forEach(B=>{T[B.actionId]=(T[B.actionId]??0)+1}),T},[h]),I=s.useCallback(T=>M[T]??0,[M]),E=s.useMemo(()=>i.map(T=>({...T,selected:(M[T.id]??0)>0})),[i,M]),x=s.useMemo(()=>i.reduce((T,B)=>(T[B.id]=B,T),{}),[i]),k=s.useCallback((T,B)=>{if(B){const O={key:crypto.randomUUID(),actionId:T.id,reportId:null};p(w=>[...w,O])}else p(O=>{for(let w=O.length-1;w>=0;w--)if(O[w].actionId===T.id){const K=[...O];return K.splice(w,1),K}return O})},[p]),g=s.useCallback(T=>{o(T.target.value)},[o]),N=s.useCallback(T=>{a?.(T.target.value)},[a]);return e.jsxRuntimeExports.jsxs(t.Box,{...b,children:[e.jsxRuntimeExports.jsxs(t.HStack,{gap:"2rem",children:[e.jsxRuntimeExports.jsx(Xe,{name:r??"",onInputChange:g}),e.jsxRuntimeExports.jsx(Ze,{availableCategories:j,value:d,onChange:C})]}),e.jsxRuntimeExports.jsx(et,{description:n??"",onInputChange:N}),e.jsxRuntimeExports.jsx(ot,{selectedMetadataIds:m,setSelectedMetadataIds:y}),e.jsxRuntimeExports.jsx(tt,{moduleActionEntries:h,setModuleActionEntries:p,actionsById:x,onAdjustActivities:()=>v.onOpen()}),e.jsxRuntimeExports.jsxs(t.Modal,{isOpen:v.isOpen,onClose:v.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(we,{actions:E,onSelected:k,allowDuplicateSelection:!0,getSelectedCount:I,disableCreate:!0,disableDelete:!0,tableProps:{height:"28rem",overflowY:"auto"}})}),e.jsxRuntimeExports.jsx(t.ModalFooter,{children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:v.onClose,isDisabled:h.length===0,children:"Done"})})]})]})]})},Xe=s.memo(({name:r,onInputChange:o})=>{const{getLabel:i}=ae.useUiLabelContext(),h=i("module"),{isView:p}=fe();return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(ue,{children:[h," Name"]}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. ACL RTP Test Battery",value:r,onChange:o,isRequired:!0,isDisabled:p})]})}),Ze=s.memo(({availableCategories:r,value:o,onChange:i})=>{const{getLabel:h}=ae.useUiLabelContext(),p=h("module"),{isView:j}=fe(),d=s.useMemo(()=>[...r,{id:"other",name:"Other"}],[r]),C=s.useMemo(()=>d.map(n=>({value:n.id,label:n.name})),[d]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(ue,{children:[p," Category"]}),e.jsxRuntimeExports.jsx(ie.st,{isDisabled:r.length===0||j,options:C,value:o.length===0?{value:"other",label:"Other"}:d.filter(n=>o.includes(n.id)).map(n=>({value:n.id,label:n.name}))[0],onChange:n=>i(n?[n.value]:[]),placeholder:"Select category"})]})}),et=s.memo(({description:r,onInputChange:o})=>{const{getLabel:i}=ae.useUiLabelContext(),h=i("module"),{isView:p}=fe();return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(ue,{children:e.jsxRuntimeExports.jsxs("span",{children:["Description",e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",children:["Briefly describe the objective of this"," ",h.toLocaleLowerCase(),". Max 40 words."]})]})}),e.jsxRuntimeExports.jsx(t.Input,{placeholder:"i.e. Assess readiness to return to play post-ACL reconstruction",value:r,onChange:o,isDisabled:p})]})}),tt=s.memo(({moduleActionEntries:r,setModuleActionEntries:o,actionsById:i,onAdjustActivities:h})=>{const{getLabel:p}=ae.useUiLabelContext(),{isView:j}=fe(),d=s.useMemo(()=>({module:p("module"),moduleLowerCase:p("module").toLocaleLowerCase(),action:p("action"),actionPlural:p("action_plural"),actionPluralLowerCase:p("action_plural").toLocaleLowerCase()}),[p]),C=s.useMemo(()=>r.map(n=>{const a=i[n.actionId];return a?{key:n.key,actionId:n.actionId,name:a.name,reports:F.getFragmentData(R.REPORT_FRAGMENT,a.reports)||[],selectedReportId:n.reportId}:null}).filter(Boolean),[r,i]);return e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsxs(t.HStack,{justifyContent:"space-between",children:[e.jsxRuntimeExports.jsx(ue,{children:e.jsxRuntimeExports.jsxs("span",{children:[d.actionPlural,!j&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.500",children:["Drag and drop to reorder the ",d.actionPluralLowerCase," ","in this ",d.moduleLowerCase,"."]})]})}),!j&&e.jsxRuntimeExports.jsxs(t.Button,{size:"sm",variant:"solid",colorScheme:"blue",onClick:h,children:["Add / Remove ",d.actionPlural]})]}),C.length===0?e.jsxRuntimeExports.jsx(t.VStack,{children:e.jsxRuntimeExports.jsxs(t.Text,{color:"gray.500",fontSize:"lg",mb:"4rem",mt:"4rem",children:["No ",d.actionPluralLowerCase," selected for this"," ",d.moduleLowerCase,".",!j&&e.jsxRuntimeExports.jsxs(t.Button,{ml:"0.5em",size:"sm",variant:"link",colorScheme:"blue",onClick:h,children:["Add ",d.actionPluralLowerCase,"."]})]})}):e.jsxRuntimeExports.jsx(st,{value:C,onChange:n=>{o(a=>{const m=a.map(b=>{const v=i[b.actionId];return v?{key:b.key,actionId:b.actionId,name:v.name,reports:F.getFragmentData(R.REPORT_FRAGMENT,v.reports)||[],selectedReportId:b.reportId}:null}).filter(Boolean);return n(m).map(b=>({key:b.key,actionId:b.actionId,reportId:b.selectedReportId}))})},disabled:j,setModuleActionEntries:o})]})}),st=s.memo(({value:r,onChange:o,disabled:i,setModuleActionEntries:h})=>{const[p]=s.useState(()=>Math.random().toString(36).substring(2,15)),j=s.useCallback((n,a)=>{i||o(m=>{const y=[...m],[b]=y.splice(n,1);return y.splice(a,0,b),y})},[o,i]),d=s.useCallback(n=>{h(a=>{const m=a.findIndex(M=>M.key===n);if(m===-1)return a;const y=a[m],b={key:crypto.randomUUID(),actionId:y.actionId,reportId:null},v=[...a];return v.splice(m+1,0,b),v})},[h]),C=s.useCallback(n=>{h(a=>a.filter(m=>m.key!==n))},[h]);return e.jsxRuntimeExports.jsx(t.Box,{children:e.jsxRuntimeExports.jsx(Me.DndProvider,{backend:Me.HTML5Backend,children:e.jsxRuntimeExports.jsx(t.VStack,{spacing:3,align:"stretch",children:r.map((n,a)=>e.jsxRuntimeExports.jsx(nt,{listKey:p,item:n,index:a,disabled:!!i,move:j,onReportChange:m=>{h(y=>y.map(b=>b.key===n.key?{...b,reportId:m}:b))},onDuplicate:()=>d(n.key),onRemove:()=>C(n.key)},n.key))})})})}),nt=s.memo(({listKey:r,item:o,index:i,disabled:h,move:p,onReportChange:j,onDuplicate:d,onRemove:C})=>{const n=s.useRef(null),{getLabel:a}=ae.useUiLabelContext(),m=a("action"),[{handlerId:y},b]=Me.useDrop({accept:r,collect:g=>({handlerId:g.getHandlerId()?.toString()??""}),hover:(g,N)=>{if(!n.current)return;const T=g.index,B=i;if(T===B)return;const O=n.current?.getBoundingClientRect(),w=(O.bottom-O.top)/2,te=N.getClientOffset().y-O.top;T<B&&te<w||T>B&&te>w||(p(T,B),g.index=B)}}),[{isDragging:v},M]=Me.useDrag({type:r,item:()=>({id:o.key,index:i}),collect:g=>({isDragging:g.isDragging()}),canDrag:!h}),I=s.useMemo(()=>`action-report-label-${o.key}`,[o.key]),E=s.useMemo(()=>[{value:null,label:"No Report"},...o.reports.map(g=>{const N=g.name&&g.name.length>0?g.name:"No Name",T=je.reportKindName(g.reportKind);return{value:g.id,label:`${N} (${T})`}})],[o.reports]),x=v?.6:1,k=h?"default":v?"grabbing":"grab";return M(b(n)),e.jsxRuntimeExports.jsx(t.Box,{ref:n,p:3,border:"1px solid",borderColor:"gray.200",borderRadius:"md",bg:"gray.50",style:{opacity:x,cursor:k},"data-handler-id":y,children:e.jsxRuntimeExports.jsxs(t.HStack,{justify:"space-between",align:"center",children:[e.jsxRuntimeExports.jsxs(t.HStack,{spacing:3,children:[e.jsxRuntimeExports.jsxs(t.Text,{fontWeight:"semibold",minW:"2rem",children:[i+1,"."]}),e.jsxRuntimeExports.jsx(t.Text,{fontWeight:"medium",children:o.name})]}),e.jsxRuntimeExports.jsxs(t.HStack,{spacing:3,align:"center",children:[e.jsxRuntimeExports.jsxs(t.Text,{id:I,fontSize:"sm",color:"gray.600",children:[m," Report:"]}),e.jsxRuntimeExports.jsx(t.Box,{width:{base:"100%",md:"350px"},children:e.jsxRuntimeExports.jsx(ie.st,{"aria-labelledby":I,value:E.find(g=>g.value===o.selectedReportId),onChange:g=>{j(g?.value||null)},options:E,placeholder:"Select report...",isDisabled:h})}),!h&&e.jsxRuntimeExports.jsxs(t.HStack,{spacing:1,children:[e.jsxRuntimeExports.jsx(t.Button,{size:"xs",variant:"ghost",colorScheme:"blue",onClick:d,title:"Add another instance with a different report",children:"+ Duplicate"}),e.jsxRuntimeExports.jsx(t.Button,{size:"xs",variant:"ghost",colorScheme:"red",onClick:C,title:"Remove this entry",children:"Remove"})]})]})]})})}),ot=s.memo(({selectedMetadataIds:r,setSelectedMetadataIds:o})=>{const{getLabel:i}=ae.useUiLabelContext(),{isView:h,metadataOptions:p}=fe(),j=s.useMemo(()=>[{key:"activity_type",label:`${i("action")} Type`,multi:!0},{key:"session_type",label:"Session Type",multi:!0},{key:"body_region",label:"Body Region",multi:!0},{key:"sport",label:"Sport",multi:!0}],[i]),d=s.useCallback((C,n)=>{const a=j.find(y=>y.key===C);if(!a)return;const m=a.multi?(n??[]).map(y=>y.id):n?[n.id]:[];o(y=>[...y.filter(v=>Object.values(p||{}).flat().find(I=>I.id===v)&&!Object.keys(p||{}).find(I=>p?.[I]?.some(E=>E.id===v&&I===C))),...m])},[j,p,o]);return p?e.jsxRuntimeExports.jsxs(t.FormControl,{mb:4,children:[e.jsxRuntimeExports.jsx(ue,{children:"Metadata Tags"}),e.jsxRuntimeExports.jsx(t.HStack,{gap:"1rem",align:"start",children:j.map(C=>e.jsxRuntimeExports.jsxs(t.FormControl,{flex:"1",children:[e.jsxRuntimeExports.jsx(t.FormLabel,{fontSize:"sm",children:C.label}),e.jsxRuntimeExports.jsx(ie.st,{isMulti:C.multi,value:p[C.key]?.filter(n=>r.includes(n.id)),onChange:n=>{d(C.key,n)},options:p[C.key],placeholder:`Select ${C.multi?"one or more":"one"} ${C.label.toLowerCase()}`,isDisabled:h,isClearable:C.multi})]},C.key))})]}):null}),Oe=({value:r,onChange:o,forceKind:i,disableRemove:h,disableKind:p,isDisabled:j,lockRanges:d,...C})=>{const n=s.useMemo(()=>[...r].sort((b,v)=>{const M=ge.availablePlanes.indexOf(b.plane),I=ge.availablePlanes.indexOf(v.plane);return M-I}),[r]),a=s.useCallback(b=>"segment"in b.id?ce.getSegmentNameWithPlane(b.id.segment,b.plane,!0)??"Unknown":ce.getJointNameWithPlane(b.id.joint,b.plane,!0)??"Unknown",[]),m=s.useCallback((b,v)=>{const M=n.findIndex(E=>E.id===v.id&&E.plane===v.plane);let I=[...n];i&&(v={...v,kind:i}),I[M]=v,d&&(I=I.map(E=>({...E,min:v.min,max:v.max}))),o(I)},[o,n,i,d]),y=s.useCallback(b=>{const v=n.filter(M=>M.id!==b.id||M.plane!==b.plane);o(v)},[o,n]);return e.jsxRuntimeExports.jsx(t.VStack,{alignItems:"flex-start",overflowY:"auto",...C,children:n.map((b,v)=>e.jsxRuntimeExports.jsx(rt,{label:a(b),parameter:b,onChange:M=>m(v,M),onRemove:h||j?void 0:()=>y(b),forceKind:i,disableKind:p||j,isDisabled:j},`${JSON.stringify(b.id)}-${b.plane}`))})},rt=({label:r,parameter:o,onChange:i,onRemove:h,forceKind:p,disableKind:j,isDisabled:d})=>{const C=s.useCallback(m=>"joint"in o.id?ce.getJointAngleDirectionName(o.id.joint,o.plane,m<0?-1:1):ce.getSegmentAngleDirectionName(o.id.segment,o.plane,m<0?-1:1),[o]),{min:n,max:a}="joint"in o.id?ce.getNormativeJointRange(o.id.joint,o.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%",alignItems:"center",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",flex:1,textTransform:"capitalize",fontWeight:"semibold",children:r}),o.sensorOnly?e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor"}):e.jsxRuntimeExports.jsxs(t.HStack,{spacing:1,children:[e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"blue",variant:"subtle",children:"Pose"}),e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor"})]}),h&&!d&&e.jsxRuntimeExports.jsx(t.IconButton,{size:"xs",variant:"ghost","aria-label":"delete",icon:e.jsxRuntimeExports.jsx(t.Icon,{as:he.FaTrash}),onClick:h}),!p&&e.jsxRuntimeExports.jsx($e,{selectedItem:o?.kind??$.ThresholdKind.Limit,onChange:({value:m})=>i({...o,kind:m}),isDisabled:j||d,buttonProps:{size:"sm",variant:"outline",colorScheme:"gray"},selectedProps:{variant:"solid",colorScheme:"teal"},items:[{value:$.ThresholdKind.Limit,label:"limit"},{value:$.ThresholdKind.Target,label:"target"}]})]}),e.jsxRuntimeExports.jsx(Ue,{w:"100%",size:"xs",min:n,max:a,zeroMarker:!0,value:[o.min,o.max],onChange:m=>i({...o,min:m[0],max:m[1]}),formatValue:m=>`${Math.abs(m)}°`,valueLabel:m=>C(m)??"",positiveNegativeLabels:C(0)?[C(-1)??"",C(1)??""]:void 0,isDisabled:d})]})},Se=(r,o)=>"segment"in r&&"segment"in o&&r.segment===o.segment||"joint"in r&&"joint"in o&&r.joint===o.joint,ke=({options:r,value:o,onChange:i,forceKind:h,singleValue:p,singleValueSideless:j,editOnly:d,disableKind:C,maxParameters:n,...a})=>{const m=j?2:n,y=s.useMemo(()=>{const E=new Map;return r.forEach(x=>{const k="joint"in x.id;let g,N;if(k?(g=ce.getJointNameWithPlane(x.id.joint,x.plane,!0)??"Unknown",N=`joint:${x.id.joint}`):(g=ce.getSegmentNameWithPlane(x.id.segment,x.plane,!0)??"Unknown",N=`segment:${x.id.segment}`),!E.has(N)){const O=k?ce.getPartName(x.id.joint)??"Unknown Joint":ce.getPartName(x.id.segment)??"Unknown Segment";E.set(N,{label:O,options:[]})}const T=E.get(N),B=[g,k?x.id.joint:x.id.segment,x.plane].filter(Boolean).map(O=>String(O).toLowerCase().replace(/\s+|_/g,""));T.options.push({label:e.jsxRuntimeExports.jsxs(t.HStack,{spacing:2,justify:"space-between",alignItems:"center",w:"100%",pl:3,children:[e.jsxRuntimeExports.jsx(t.Text,{children:g}),x.sensorOnly?e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor"}):e.jsxRuntimeExports.jsxs(t.HStack,{spacing:1,children:[e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"blue",variant:"subtle",children:"Pose"}),e.jsxRuntimeExports.jsx(t.Badge,{size:"sm",colorScheme:"orange",variant:"subtle",children:"Sensor"})]})]}),value:x.id,plane:x.plane,sensorOnly:x.sensorOnly,searchTokens:B})}),Array.from(E.values())},[r]),b=s.useMemo(()=>{if(!j||o.length===0)return y;const E=o[0];return y.map(x=>({...x,options:x.options.filter(k=>ge.getAnalysisPartIdNoSide(k.value)===ge.getAnalysisPartIdNoSide(E.id)&&k.plane===E.plane)})).filter(x=>x.options.length>0)},[y,o,j]),v=s.useMemo(()=>y.flatMap(x=>x.options).filter(x=>o.some(k=>Se(k.id,x.value)&&k.plane===x.plane)),[y,o]),M=s.useCallback((E,x)=>{if(!x)return!0;const k=x.toLowerCase().replace(/\s+|_/g,""),g=E.data;return!g||!g.searchTokens?!1:g.searchTokens.some(N=>N.includes(k))},[]),I=s.useCallback(E=>{const x=E.map(k=>{const g=o.find(w=>Se(w.id,k.value)&&w.plane===k.plane),N=r.find(w=>Se(w.id,k.value)&&w.plane===k.plane),T=j?o.find(w=>ge.getAnalysisPartIdNoSide(w.id)===ge.getAnalysisPartIdNoSide(k.value)&&w.plane===k.plane):void 0,B=T&&!g?T.min:N&&N.min?N.min:0,O=T&&!g?T.max:N&&N.max?N.max:0;return g??{id:k.value,plane:k.plane,min:B,max:O,sensorOnly:k.sensorOnly,kind:h??$.ThresholdKind.Limit}});i(x)},[i,o,r,h,j]);return s.useEffect(()=>{const E=o.filter(x=>r.some(k=>Se(k.id,x.id)&&k.plane===x.plane));E.length!==o.length&&i(E)},[r,i,o]),e.jsxRuntimeExports.jsxs(t.Box,{...a,children:[e.jsxRuntimeExports.jsx(ie.st,{isMulti:!p,placeholder:o.length?`${o.length} selected`:"Search...",value:v,isDisabled:d||v.length>=(m??1/0),onChange:E=>Array.isArray(E)?I([...E]):I(E!==null?[E]:[]),options:b,controlShouldRenderValue:!1,formatOptionLabel:E=>E.label,filterOption:M,isSearchable:!0}),e.jsxRuntimeExports.jsx(Oe,{marginTop:2,maxH:"28rem",value:o,onChange:i,forceKind:h,disableKind:C,isDisabled:d,lockRanges:j})]})},Fe=r=>{switch(r){case $.SensorLocation.Thorax:return"Thorax";case $.SensorLocation.CenterBack:return"Center Back";case $.SensorLocation.Pelvis:return"Pelvis";case $.SensorLocation.LeftThigh:return"Left Thigh";case $.SensorLocation.RightThigh:return"Right Thigh";case $.SensorLocation.LeftShank:return"Left Shank";case $.SensorLocation.RightShank:return"Right Shank";case $.SensorLocation.LeftFoot:return"Left Foot";case $.SensorLocation.RightFoot:return"Right Foot";case $.SensorLocation.LeftUpperArm:return"Left Upper Arm";case $.SensorLocation.RightUpperArm:return"Right Upper Arm";case $.SensorLocation.LeftForearm:return"Left Forearm";case $.SensorLocation.RightForearm:return"Right Forearm";case $.SensorLocation.Head:return"Head"}},at=({id:r,onError:o,onCancel:i,onSave:h,hideButtons:p,setButtonOnClick:j,setButtonDisabled:d,quantumOwned:C,isView:n})=>{const a=Z.useClient(),[{fetching:m},y]=Z.useMutation(R.CREATE_ACTION),[{fetching:b},v]=Z.useMutation(R.UPDATE_ACTION),[{data:M}]=Z.useQuery({query:R.GET_ACTION_BY_ID,variables:{id:r??""},pause:!r}),I=s.useMemo(()=>{const f=F.getFragmentData(R.ACTION_FRAGMENT,M?.getActionById);if(!f)return null;const P=(F.getFragmentData(R.REPORT_FRAGMENT,f.reports)||[]).map(G=>({...G,thresholds:F.getFragmentData(R.THRESHOLD_FRAGMENT,G.thresholds)}));return{...f,thresholds:F.getFragmentData(R.THRESHOLD_FRAGMENT,f.thresholds),reports:P}},[M]),E=m||b,x=!!I&&!!r,{getLabel:k}=ae.useUiLabelContext(),g=s.useMemo(()=>({action:k("action")}),[k]),N=s.useMemo(()=>[{key:"module_category",label:"Link Category",multi:!0},{key:"activity_type",label:`${g.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},{key:"activity_motion_direction",label:"Activity Motion Direction",multi:!0}],[g.action]),[T,B]=s.useState(""),[O,w]=s.useState(""),[K,te]=s.useState(""),[D,ne]=s.useState(""),[V,L]=s.useState([]),[z,J]=s.useState({}),[q,Q]=s.useState(null),[c,l]=s.useState(""),[S,u]=s.useState([]),[A,W]=s.useState([]),[_,H]=s.useState(""),[Y,se]=s.useState([]),de=ae.useAllPartParameters(),xe=s.useMemo(()=>de.filter(f=>f.sensorOnly),[de]),me=[{label:je.reportKindName($.ReportKind.GeneralActivity),value:$.ReportKind.GeneralActivity},{label:je.reportKindName($.ReportKind.MovementCoordination),value:$.ReportKind.MovementCoordination},{label:je.reportKindName($.ReportKind.Range),value:$.ReportKind.Range},{label:je.reportKindName($.ReportKind.StabilityBalance),value:$.ReportKind.StabilityBalance},{label:je.reportKindName($.ReportKind.PointOfInterest),value:$.ReportKind.PointOfInterest}],be=s.useMemo(()=>T.trim().length>0,[T]),[Ce,Ae]=s.useState({});s.useEffect(()=>{const f=N.map(U=>a.query(R.GET_METADATA_BY_KEY,{key:U.key}));Promise.all(f).then(U=>{const P={};U.forEach(G=>{if(G.error||!G.data)return;const ee=F.getFragmentData(R.METADATA_GROUP_FRAGMENT,G.data.getMetadataByKey),X=F.getFragmentData(R.METADATA_ITEM_FRAGMENT,ee.data);P[ee.key]=X.map(re=>({label:re.label||re.value,value:re.value,id:re.id}))}),J(P)})},[a,N]),s.useEffect(()=>{if(I){const U=F.getFragmentData(R.METADATA_GROUP_FRAGMENT,I.metadataGroups).map(ee=>ee.data.map(X=>F.getFragmentData(R.METADATA_ITEM_FRAGMENT,X).id)),P=I.reports.map(ee=>({id:ee.id,name:ee.name??"",instructions:ee.instructions??"",kind:ee.reportKind,autoGenerate:ee.autoGenerate??!1,parameters:ee.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(re=>{const Ie=re.id[X.partKind];return Ie?Ie===X.partId&&re.plane===X.partDimension:!1})})),sensorLocations:ee.sensorLocations})),G={name:I.name,description:I.description||"",cameraPlacement:I.cameraPlacement||"",videoLink:I.videoLink||"",metadataIds:U.flat(),reports:P};B(G.name),w(G.description),te(G.cameraPlacement),ne(G.videoLink),L(G.metadataIds),se(P),Ae(G)}},[I]);const Re=s.useMemo(()=>JSON.stringify(Ce)!==JSON.stringify({name:T,description:O,cameraPlacement:K,videoLink:D,metadataIds:V,reports:Y}),[Ce,T,O,K,D,V,Y]),pe=s.useCallback(()=>{const f={name:T,description:O,cameraPlacement:K,videoLink:D,metadataItemIds:V,laterality:$.ActionLaterality.Either,quantumOwned:C,sessionType:[],thresholds:[],reports:Y.map(P=>({id:P.isNew?void 0:P.id,name:P.name,reportKind:P.kind,sensorLocations:P.sensorLocations,instructions:P.instructions,autoGenerate:P.autoGenerate??!1,thresholds:P.parameters.map(G=>({id:G.oldId,kind:G.kind,min:G.min,max:G.max,partKind:"joint"in G.id?"joint":"segment",partId:"joint"in G.id?G.id.joint:G.id.segment,partDimension:G.plane}))}))};let U;x&&r?U=v({id:r,fields:f}):U=y({fields:f}),U.then(({error:P})=>{P?o(P):h()})},[C,y,v,r,T,O,K,D,V,Y,x,h,o]);s.useEffect(()=>{d&&d({cancelButton:E,saveButton:n?!0:E||!be||!Re})},[E,d,be,Re,n]),s.useEffect(()=>{j&&j({cancelButton:i,saveButton:n?()=>{}:pe})},[j,i,pe,n]);const le=s.useCallback(f=>{const U=ce.getSuggestedSensorLocations(f.map(P=>"joint"in P.id?P.id.joint:P.id.segment));W(U)},[]);s.useEffect(()=>{le(S)},[S,le]);const Ee=s.useCallback(()=>{if(!q||!c.trim())return;const f=q===$.ReportKind.PointOfInterest,U={id:Date.now().toString(),name:c.trim(),kind:q,parameters:f?[]:S,sensorLocations:f?[]:A,instructions:f?_:"",autoGenerate:!1,isNew:!0};se(P=>[...P,U]),Q(null),l(""),u([]),W([]),H("")},[q,c,S,A,_]),De=s.useCallback(f=>{se(U=>U.filter(P=>P.id!==f))},[]),_e=(f,U)=>{const P=N.find(ee=>ee.key===f);if(!P)return;const G=P.multi?(U??[]).map(ee=>ee.id):U?[U.id]:[];L(ee=>[...ee.filter(re=>Object.values(z).flat().find(ye=>ye.id===re)&&!Object.keys(z).find(ye=>z[ye]?.some(Ge=>Ge.id===re&&ye===f))),...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:"Activity Configuration"}),e.jsxRuntimeExports.jsx(t.Tab,{children:"Reports Configuration"})]}),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(oe,{children:"Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:T,onChange:f=>B(f.target.value),type:"text",placeholder:"i.e. Lunge & Return",isDisabled:n})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Camera Placement"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:K,onChange:f=>te(f.target.value),rows:2,placeholder:"(optional) Describe camera setup, placement, angles",isDisabled:n})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Video Link"}),e.jsxRuntimeExports.jsx(t.Input,{value:D,onChange:f=>ne(f.target.value),type:"url",placeholder:"(optional) https://...",isDisabled:n})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Description"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:O,onChange:f=>w(f.target.value),rows:2,placeholder:"(optional) Describe how to perform the test or exercise",isDisabled:n})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(oe,{children:"Metadata Tags"}),N.map(f=>e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:f.label}),e.jsxRuntimeExports.jsx(ie.st,{isMulti:f.multi,value:z[f.key]?.filter(U=>V.includes(U.id)),onChange:U=>{_e(f.key,U)},options:z[f.key],placeholder:`Select ${f.multi?"one or more":"one"} ${f.label.toLowerCase()}`,isDisabled:n,isClearable:f.multi})]},f.key))]})]})}),e.jsxRuntimeExports.jsx(t.TabPanel,{px:0,children:e.jsxRuntimeExports.jsxs("div",{className:ve.cn("grid grid-cols-1 gap-6",!n&&"md:grid-cols-2"),children:[e.jsxRuntimeExports.jsxs("div",{className:ve.cn("space-y-4",n&&"hidden"),children:[e.jsxRuntimeExports.jsx(oe,{children:"Add New Report"}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Report Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:c,onChange:f=>l(f.target.value),maxLength:120,type:"text",placeholder:"Enter report name...",isDisabled:n})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Report Type"}),e.jsxRuntimeExports.jsx(ie.st,{value:q?me.find(f=>f.value===q):null,onChange:f=>Q(f?.value||null),options:me,placeholder:"Select report type...",isDisabled:n,isClearable:!0})]}),q!==$.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(ke,{options:de,value:S,onChange:u,editOnly:n})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Sensor Locations"}),e.jsxRuntimeExports.jsx(t.Input,{value:A.map(f=>Fe(f)).join(", "),placeholder:"Auto-filled based on parameters...",isDisabled:!0})]})]}),q===$.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:_,onChange:f=>H(f.target.value),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:n})]}),e.jsxRuntimeExports.jsx("div",{className:"w-full flex justify-end",children:e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",onClick:Ee,isDisabled:!q||!c.trim()||n||me.length===0||q!==$.ReportKind.PointOfInterest&&S.length===0,children:"Add Report"})})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(oe,{children:"Configured Reports"}),Y.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:Y.map(f=>e.jsxRuntimeExports.jsxs("div",{className:"p-3 border border-gray-200 rounded-md bg-gray-50 flex flex-col gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxRuntimeExports.jsx(t.Text,{fontSize:"sm",color:"gray.600",children:je.reportKindName(f.kind)}),!n&&e.jsxRuntimeExports.jsx(t.Button,{size:"xs",colorScheme:"red",variant:"ghost",onClick:()=>De(f.id),children:"Remove"})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Report Name"}),e.jsxRuntimeExports.jsx(t.Input,{value:f.name,onChange:U=>se(P=>P.map(G=>G.id===f.id?{...G,name:U.target.value}:G)),placeholder:"Enter report name...",isDisabled:n})]}),e.jsxRuntimeExports.jsxs(t.FormControl,{display:"flex",alignItems:"center",children:[e.jsxRuntimeExports.jsx(t.FormLabel,{htmlFor:`auto-generate-${f.id}`,mb:"0",children:"Auto Generate"}),e.jsxRuntimeExports.jsx(t.Switch,{id:`auto-generate-${f.id}`,isChecked:f.autoGenerate??!1,onChange:U=>se(P=>P.map(G=>G.id===f.id?{...G,autoGenerate:U.target.checked}:G)),isDisabled:n})]}),f.kind===$.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.FormControl,{children:[e.jsxRuntimeExports.jsx(oe,{children:"Instructions"}),e.jsxRuntimeExports.jsx(t.Textarea,{value:f.instructions,onChange:U=>se(P=>P.map(G=>G.id===f.id?{...G,instructions:U.target.value}:G)),rows:3,placeholder:"Enter specific instructions for this report...",isDisabled:n})]}),f.kind!==$.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs("div",{className:"flex flex-col",children:[e.jsxRuntimeExports.jsx(oe,{children:"Default Parameters"}),e.jsxRuntimeExports.jsx(ke,{options:de,value:f.parameters,onChange:U=>{const P=X=>"joint"in X.id?X.id.joint:X.id.segment,G=U.map(P),ee=ce.getSuggestedSensorLocations(G);se(X=>X.map(re=>re.id===f.id?{...re,parameters:U,sensorLocations:ee}:re))},editOnly:n})]}),f.kind!==$.ReportKind.PointOfInterest&&e.jsxRuntimeExports.jsxs(t.Text,{fontSize:"sm",color:"gray.600",children:["Sensors:"," ",f.sensorLocations.map(U=>Fe(U)).join(", ")]})]},f.id))})]})]})})]})]}),e.jsxRuntimeExports.jsx(t.HStack,{justify:"end",className:ve.cn((p||n)&&"!hidden"),children:e.jsxRuntimeExports.jsxs(t.ButtonGroup,{gap:4,children:[e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"gray",isDisabled:E,onClick:i,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:E||!be||!Re,isLoading:E,onClick:pe,children:"Save changes"})]})})]})},oe=({children:r})=>e.jsxRuntimeExports.jsx(t.FormLabel,{fontWeight:"bold",fontFamily:"sans-serif",fontSize:"large",children:r}),it=({children:r,isView:o,metadataKeys:i})=>{const[h,p]=s.useState({}),j=Z.useClient();return s.useEffect(()=>{let d=!1;return(async()=>{const n=(i??[]).map(y=>j.query(R.GET_METADATA_BY_KEY,{key:y}).toPromise()),a=await Promise.all(n),m={};for(const y of a){if(y.error||!y.data?.getMetadataByKey)continue;const b=F.getFragmentData(R.METADATA_GROUP_FRAGMENT,y.data.getMetadataByKey);if(!b)continue;const v=F.getFragmentData(R.METADATA_ITEM_FRAGMENT,b.data)??[];m[b.key]=v.map(M=>({label:M.label||M.value,value:M.value,id:M.id}))}d||p(m)})(),()=>{d=!0}},[j,i]),e.jsxRuntimeExports.jsx(Le.Provider,{value:{isView:o,metadataOptions:h},children:r})},lt=({id:r,onCancel:o,onSave:i,onError:h,hideButtons:p,quantumOwned:j,setButtonOnClick:d,setButtonDisabled:C,isView:n})=>{const[{data:a,fetching:m}]=Z.useQuery({query:j?R.GET_QUANTUM_OWNED_ACTIONS:R.GET_ACTIONS}),[{data:y}]=Z.useQuery({query:R.GET_MODULE_BY_ID,variables:{id:r},pause:!r}),[{data:b}]=Z.useQuery({query:R.GET_ALL_MODULE_CATEGORIES}),v=F.getFragmentData(R.MODULE_CATEGORY_FRAGMENT,b?.moduleCategories),[{fetching:M},I]=Z.useMutation(R.UPDATE_MODULE),[{fetching:E},x]=Z.useMutation(R.CREATE_MODULE),k=s.useMemo(()=>!a||m?[]:F.getFragmentData(R.ACTION_FRAGMENT,j?a?.quantumOwnedActions??[]:a?.actions??[]).filter(q=>!!q?.id),[a,j,m]),g=F.getFragmentData(R.ACTION_MODULE_FRAGMENT,y?.module),N=s.useMemo(()=>F.getFragmentData(R.MODULE_ACTION_FRAGMENT,g?.moduleActions)??[],[g?.moduleActions]),[T,B]=s.useState([]),[O,w]=s.useState(g?.name??""),[K,te]=s.useState([]),[D,ne]=s.useState(g?.description??""),[V,L]=s.useState([]);s.useEffect(()=>{if(g){const J=N.map((c,l)=>({key:c.id??`${c.actionId}-${l}`,actionId:c.actionId,reportId:c.reportId||null}));B(J),w(g.name),ne(g.description??""),te(g.categories.map(c=>F.getFragmentData(R.MODULE_CATEGORY_FRAGMENT,c).id)??[]);const Q=F.getFragmentData(R.METADATA_GROUP_FRAGMENT,g.metadataGroups).map(c=>c.data.map(l=>F.getFragmentData(R.METADATA_ITEM_FRAGMENT,l).id));L(Q.flat())}},[g,N]);const z=s.useCallback(()=>{let J;const q={moduleActions:T.map(Q=>({actionId:Q.actionId,reportId:Q.reportId??void 0})),name:O,categories:K.filter(Q=>Q!=="other"),description:D,quantumOwned:j,metadataItemIds:V};g?J=I({id:g.id,input:q}):J=x({input:q}),J.then(({error:Q})=>{Q?h(Q instanceof Error?Q:new Error(String(Q))):i()})},[x,I,T,O,D,K,V,g,i,h,j]);return s.useEffect(()=>{C&&C({cancelButton:M||E,saveButton:M||E||!O||D.trim().split(/\s+/).filter(Boolean).length>40})},[C,M,E,T,O,D]),s.useEffect(()=>{d&&d({cancelButton:o,saveButton:z})},[d,o,z]),e.jsxRuntimeExports.jsx(t.Box,{width:"100%",children:e.jsxRuntimeExports.jsxs(it,{isView:n,metadataKeys:["activity_type","session_type","body_region","sport"],children:[e.jsxRuntimeExports.jsx(Ne,{name:O,setName:w,actions:k,moduleActionEntries:T,setModuleActionEntries:B,availableCategories:v??[],selectedCategoryIds:K,setSelectedCategoryIds:te,description:D,setDescription:ne,selectedMetadataIds:V,setSelectedMetadataIds:L}),!p&&!n&&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:M||E,onClick:o,children:"Cancel"}),e.jsxRuntimeExports.jsx(t.Button,{colorScheme:"blue",isDisabled:M||E||!O||D.trim().split(/\s+/).filter(Boolean).length>40,isLoading:M||E,onClick:z,children:"Save"})]})})]})})};exports.ActivityList=we;exports.CopyActivityForm=Je;exports.CopyModuleForm=Ve;exports.ModuleForm=Ne;exports.ParameterEditList=Oe;exports.ParameterEditSelect=ke;exports.UpsertActivityForm=at;exports.UpsertModuleForm=lt;