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