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