@australiangreens/ag-internal-components 0.3.1 → 0.3.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.
@@ -1,2 +1,2 @@
1
- "use strict";var Be=Object.defineProperty,Pe=Object.defineProperties;var Ne=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var te=Object.prototype.hasOwnProperty,oe=Object.prototype.propertyIsEnumerable;var z=(e,t,n)=>t in e?Be(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,p=(e,t)=>{for(var n in t||(t={}))te.call(t,n)&&z(e,n,t[n]);if(O)for(var n of O(t))oe.call(t,n)&&z(e,n,t[n]);return e},_=(e,t)=>Pe(e,Ne(t));var ne=(e,t)=>{var n={};for(var i in e)te.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(e!=null&&O)for(var i of O(e))t.indexOf(i)<0&&oe.call(e,i)&&(n[i]=e[i]);return n};var ie=(e,t,n)=>z(e,typeof t!="symbol"?t+"":t,n);var I=(e,t,n)=>new Promise((i,s)=>{var l=c=>{try{a(n.next(c))}catch(u){s(u)}},d=c=>{try{a(n.throw(c))}catch(u){s(u)}},a=c=>c.done?i(c.value):Promise.resolve(c.value).then(l,d);a((n=n.apply(e,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),D=require("react"),r=require("@mui/material"),G=require("@mui/icons-material"),Me=require("autosuggest-highlight/match"),Le=require("autosuggest-highlight/parse"),ge=require("@tanstack/react-query"),X=require("@auth0/auth0-react"),$e=require("buffer"),Re=require("@mui/material/Skeleton"),w=require("jotai"),qe=require("souvlaki"),Oe=require("@mui/material/CssBaseline"),Ue=require("@mui/material/Box"),He=require("jotai/utils"),B=require("@mui/material/styles"),We=require("react-avatar"),L=e=>e&&e.__esModule?e:{default:e},ze=L(Me),Ge=L(Le),Ve=L(Re),Xe=L(Oe),re=L(Ue),se=L(We);function Ke({text:e}){const[t,n]=D.useState(0);return o.jsxs(o.Fragment,{children:[o.jsx(r.Typography,{variant:"h6",color:"inherit",component:"div",sx:{fontSize:"22px"},children:"Hello world"}),o.jsx(r.Typography,{variant:"caption",display:"block",children:o.jsx("span",{children:"Just ensuring MUI is working as planned as a peer dependency. v0.0.11"})}),o.jsx(r.Button,{variant:"outlined",onClick:()=>n(i=>i+1),"aria-label":"Increment",children:"Hello I am a button"}),o.jsxs("p",{children:["This is some text: ",o.jsx("span",{children:e})]}),o.jsxs(r.Paper,{children:["This number will incremember when button pressed: ",t]})]})}const K=({isOpen:e,dialogTitle:t,children:n,maxWidth:i,primaryButton:s,secondaryButton:l,additionalButtons:d,onClose:a,sx:c,"data-testid":u,disableCloseOnBackdropOrEscape:x=!1,isLoading:k=!1})=>{var y,F;const[v,g]=D.useState(!1);return o.jsxs(r.Dialog,{open:e,onClose:(h,j)=>I(null,null,function*(){x&&(j==="backdropClick"||j==="escapeKeyDown")||v||(l!=null&&l.onClick?yield l.onClick():a())}),fullWidth:!0,maxWidth:i!=null?i:"xs","data-testid":u,sx:c,children:[k&&o.jsx(r.LinearProgress,{sx:{height:"4px",marginBottom:"-4px"}}),o.jsx(r.DialogTitle,{children:t}),o.jsx(r.DialogContent,{sx:{"& > :last-child":{marginBottom:0}},children:n}),o.jsxs(r.DialogActions,{children:[o.jsx(r.Button,{onClick:(y=l==null?void 0:l.onClick)!=null?y:a,"data-testid":l==null?void 0:l.testId,disabled:(l==null?void 0:l.disabled)||v,color:l==null?void 0:l.buttonColor,children:(F=l==null?void 0:l.text)!=null?F:"Cancel"}),d&&d.map((h,j)=>{var b;return o.jsx(r.Button,{onClick:h==null?void 0:h.onClick,"data-testid":h==null?void 0:h.testId,disabled:(h==null?void 0:h.disabled)||v,color:h==null?void 0:h.buttonColor,children:(b=h.text)!=null?b:`Button ${j}`},j)}),s&&o.jsx(r.Button,{onClick:()=>I(null,null,function*(){var h;g(!0),yield(h=s.onClick)==null?void 0:h.call(s),g(!1)}),"data-testid":s.testId,disabled:s.disabled||v,color:s==null?void 0:s.buttonColor,children:s.text})]})]})},Q=({minLength:e,preLoadedOptions:t,lookup:n,label:i,inputValue:s})=>ge.useQuery({queryFn:()=>e&&s.length<e?t!=null?t:[]:t?t.filter(l=>l.label.toLowerCase().includes(s.toLowerCase())):n(s),queryKey:["autocomplete",i,s]});function Qe({lookup:e=()=>I(null,null,function*(){}),enableHighlighting:t=!0,onChange:n,minLength:i=0,label:s,value:l,"data-testid":d,sx:a,boxSx:c,textFieldColor:u,textFieldVariant:x="filled",loadingText:k="Loading...",noOptionsText:v="No options",popupIcon:g=o.jsx(G.ArrowDropDown,{}),error:y=!1,helperText:F="",preLoadedOptions:h=void 0,disablePortal:j=!1,disableIconFlip:b=!1}){const[T,$]=D.useState(""),P=(m,A)=>{const C=l.filter(S=>S.id!==A);n(C,"delete",m)},{data:f,isLoading:E}=Q({inputValue:T,label:s,lookup:e,minLength:i,preLoadedOptions:h}),N=T.length>=i;return o.jsxs("div",{"data-testid":d,children:[o.jsx(r.Autocomplete,{sx:p(p({},a),b?{".MuiAutocomplete-popupIndicatorOpen":{transform:"rotate(0deg)"}}:{}),"data-testid":d?`${d}:Autocomplete`:void 0,disablePortal:j,multiple:!0,getOptionLabel:m=>typeof m=="string"?m:m.label,loading:N?E:!1,options:[...l,...f!=null?f:[]],filterSelectedOptions:!0,includeInputInList:!0,value:l,onChange:(m,A,C)=>{n(A,C,m)},onInputChange:(m,A)=>$(A),noOptionsText:N?v:"Start typing to search",loadingText:k,popupIcon:g,renderInput:m=>o.jsx(r.TextField,_(p({},m),{label:s,fullWidth:!0,variant:x,error:y,helperText:F,InputProps:_(p({},m.InputProps),{endAdornment:o.jsxs(o.Fragment,{children:[E?o.jsx(r.CircularProgress,{color:"inherit",size:20}):null,m.InputProps.endAdornment]})}),"data-testid":d?`${d}:Autocomplete:TextField`:void 0,onKeyDown:A=>{(A.key==="Backspace"||A.key==="Delete")&&A.stopPropagation()},color:u})),renderTags:()=>null,isOptionEqualToValue:(m,A)=>m.id===A.id,renderOption:(m,A,C)=>{if(t){const S=ze.default(A.label,C.inputValue,{insideWords:!0,findAllOccurrences:!0}),W=Ge.default(A.label,S);return D.createElement("li",_(p({},m),{key:A.id,"data-testid":d?`${d}:Autocomplete:option(${A.id.toString()})`:void 0}),o.jsx("div",{children:W.map((ee,Ie)=>o.jsx("span",{style:{fontWeight:ee.highlight?700:400},children:ee.text},Ie))}))}else return D.createElement("li",_(p({},m),{key:A.id,"data-testid":d?`${d}:option(${A.id.toString()})`:void 0}),A.label)}}),l.length>0&&o.jsx(r.Box,{sx:c,children:l.map(m=>o.jsx(r.Chip,{sx:{marginTop:1,marginRight:1,height:"auto"},label:o.jsx(r.Tooltip,{title:m.tooltipContent||"",placement:"bottom-start",PopperProps:{modifiers:[{name:"offset",options:{offset:[115,-15]}}]},children:o.jsx(r.Typography,{style:{whiteSpace:"normal"},children:m.chipLabel?m.chipLabel:m.label})}),"data-testid":d?`${d}:Chip(${m.id.toString()})`:void 0,onDelete:A=>P(A,m.id),deleteIcon:o.jsx(G.Cancel,{"data-testid":d?`${d}:Chip(${m.id.toString()}):deleteIcon`:void 0})},m.id))})]})}const Ye=/MUI: The value provided to.*is invalid/i,Je=({lookup:e=()=>I(null,null,function*(){}),onChange:t,label:n,value:i,sx:s,textFieldColor:l,textFieldVariant:d="filled",error:a=!1,"data-testid":c,noOptionsText:u="No options",minLength:x=3,disablePortal:k=!1,preLoadedOptions:v,helperText:g="",disabled:y,popupIcon:F,disableIconFlip:h})=>{const[j,b]=D.useState(""),{data:T,isLoading:$}=Q({inputValue:j,label:n,lookup:e,minLength:x!=null?x:0,preLoadedOptions:v}),P=j.length>=x;return o.jsx("div",{"data-testid":c,children:o.jsx(r.Stack,{direction:"row",spacing:1,children:o.jsx(r.Autocomplete,{sx:p(p({},s),h?{".MuiAutocomplete-popupIndicatorOpen":{transform:"rotate(0deg)"}}:{}),"data-testid":c?`${c}:Autocomplete`:void 0,loading:P?$:!1,options:T!=null?T:[],onChange:(f,E,N)=>{t(f,E,N)},disablePortal:k,filterOptions:f=>f,value:i,noOptionsText:P?u:"Start typing to search",getOptionLabel:f=>f.label,popupIcon:F,renderInput:f=>o.jsx(r.TextField,_(p({"data-testid":c?`${c}:Autocomplete:TextField`:void 0},f),{variant:d,label:n,color:l,error:a,helperText:g})),isOptionEqualToValue:(f,E)=>f.id===E.id,onInputChange:(f,E)=>{b(E)},renderOption:(f,E)=>D.createElement("li",_(p({},f),{key:E.id,"data-testid":c?`${c}:Autocomplete:option(${E.id.toString()})`:void 0}),E.label),disabled:y})})})},fe=e=>{if(!e)return-1;try{const n=e.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"),i=decodeURIComponent($e.Buffer.from(n,"base64").toString("utf8").split("").map(function(l){return"%"+("00"+l.charCodeAt(0).toString(16)).slice(-2)}).join("")),s=JSON.parse(i);return s!=null&&s.exp?s.exp:-1}catch(t){return-1}},Ze=({open:e=!1,closeHandler:t,setAuth0ExpiryTime:n})=>{const{logout:i,getAccessTokenSilently:s}=X.useAuth0(),l=()=>I(null,null,function*(){i({logoutParams:{returnTo:`${window.location.origin}`}})}),a={text:"Continue",onClick:()=>I(null,null,function*(){const u=yield s({cacheMode:"off"}),x=fe(u)*1e3;n(x),t()}),disabled:!1,testId:"PreferencesDialog",buttonColor:"secondary"},c={text:"Log out",onClick:l,disabled:!1,testId:"PreferencesDialog",buttonColor:"secondary"};return o.jsx(K,{isOpen:e,primaryButton:a,secondaryButton:c,onClose:t,dialogTitle:"Session expiry",disableCloseOnBackdropOrEscape:!0,children:o.jsx("p",{style:{marginBottom:0},children:"Your session is about to time out due to inactivity. Do you want to continue?"})})};function et(e){return"error"in e}function tt(e){var i;const t=e.error,n=(i=e==null?void 0:e.error_description)!=null?i:"";return t==="access_denied"&&n.startsWith("You do not have the required authorization")}function ot(e){var i;const t=e.error,n=(i=e==null?void 0:e.error_description)!=null?i:"";return t==="access_denied"&&n.startsWith("User did not authorize the request")}function nt(e){var i;const t=e.error,n=(i=e==null?void 0:e.error_description)!=null?i:"";return t==="access_denied"&&n.match(/Script.*time.*exceeded/)}function it({children:e,appName:t="the app",throwErrors:n="none",disableConsoleLogging:i=!1,onError:s=()=>{}}){var k,v;const{isAuthenticated:l,isLoading:d,error:a,loginWithRedirect:c,logout:u}=X.useAuth0();D.useEffect(()=>{a&&s(a)},[a,s]);const x=D.useMemo(()=>({appState:{returnTo:`${window.location.pathname}${window.location.search}`}}),[]);if(D.useEffect(()=>{d||l||a||c(x)},[d,l,a,c,s,x]),a){if(i||console.error(`Error detected in AuthGuard [isAuthenticated=${l},isLoading=${d}]`,a),n==="all")throw a;if(et(a)){let g="Auth error",y="An unknown Auth0 error occurred.";if(tt(a))g="Unauthorised",y=`You are not authorised to access ${t}.`;else if(ot(a))g="App not authorised",y=`You have not authorised ${t} to access your user profile. This is necessary to use ${t}.`;else if(nt(a))g="Auth0 script execution time exceeded",y="The Auth0 login flow exceeded the time limit (20s). Try again in a minute by clicking the RELOAD button below.";else if(a.message==="Invalid state"){const F=localStorage.getItem("auth0_redirect_count");F?F&&parseInt(F)<2&&(localStorage.setItem("auth0_redirect_count",String(parseInt(F)+1)),c(x)):(localStorage.setItem("auth0_redirect_count","1"),c(x))}else if(n==="unknown")throw a;return o.jsxs(r.Dialog,{open:!0,children:[o.jsx(r.DialogTitle,{children:g}),o.jsxs(r.DialogContent,{children:[o.jsx(r.Typography,{children:y}),o.jsx("br",{}),o.jsx(r.Typography,{variant:"subtitle2",children:"Details from Auth0"}),o.jsxs(r.Typography,{variant:"body2",children:["error: ",(k=a==null?void 0:a.error)!=null?k:"N/A"]}),o.jsxs(r.Typography,{variant:"body2",children:["description: ",(v=a==null?void 0:a.error_description)!=null?v:"N/A"]})]}),o.jsxs(r.DialogActions,{children:[g==="Auth0 script execution time exceeded"&&o.jsx(r.Button,{href:window.location.origin+window.location.pathname,children:"Reload"}),o.jsx(r.Button,{onClick:()=>u({logoutParams:{returnTo:window.location.origin}}),children:"Logout"})]})]})}else if(n==="unknown")throw a}return l?(localStorage.removeItem("auth0_redirect_count"),o.jsx(o.Fragment,{children:e})):o.jsx(Ve.default,{variant:"rectangular",animation:"pulse",height:"100vh",width:"100vw"})}const rt={autoHideDuration:6e3,anchorOrigin:{vertical:"top",horizontal:"center"},disableWindowBlurListener:!1},st={shouldClose:(e,t)=>t!=="clickaway"},ae={message:"",severity:"info",variant:"standard",progressIndicator:void 0},le=100,ce=2e3,at=2e3,lt=(()=>{let e=0;return()=>(e+=1,e)})(),ct={borderBottomLeftRadius:"0px",borderBottomRightRadius:"0px"},dt={},ut={},Y=D.createContext(null);function Ae(l){var d=l,{overrideState:e=dt,overrideActions:t=ut,shouldClose:n=st.shouldClose,children:i}=d,s=ne(d,["overrideState","overrideActions","shouldClose","children"]);var A;const[{open:a},c]=D.useState({open:!1}),u=D.useRef([]),x=D.useRef(Date.now()),k=D.useRef(0),v=D.useCallback(C=>{c({open:C})},[]),g=D.useCallback((C={})=>{k.current+=1,u.current.length>=le&&Date.now()-x.current>=ce&&(x.current=Date.now(),console.error(`SaladBarProvider: MAX_QUEUE_LENGTH (${le}) hit ${k.current} times in last ${ce}ms)`),k.current=0);const S=p(_(p({},ae),{key:lt()}),C);return u.current.push(S),u.current.length===1&&c({open:!0}),S.key},[]),y=(C="",S={})=>g(p({message:C,severity:"success"},S)),F=(C="",S={})=>g(p({message:C,severity:"info"},S)),h=(C="",S={})=>g(p({message:C,severity:"warning"},S)),j=(C="",S={})=>g(p({message:C,severity:"error"},S)),b=C=>{const S=u.current.findIndex(W=>W.key===C);if(S!==-1)return S===0?(c({open:!1}),u.current[0]):u.current.splice(S,1)},T=(C,S)=>{n(C,S)&&c({open:!1})},$=()=>{},P=()=>{u.current.shift(),u.current.length>0&&c({open:!0})},f=(A=u.current[0])!=null?A:p({},ae),E={};"autoHideDuration"in f&&(E.autoHideDuration=f.autoHideDuration);const N=p(p({},rt),s),m=p(p({open:a,setOpen:v,enqueueNotification:g,enqueueSuccessNotification:y,enqueueInfoNotification:F,enqueueWarningNotification:h,enqueueErrorNotification:j,removeNotification:b},e),t);return o.jsxs(Y.Provider,{value:m,children:[i,o.jsx(r.Snackbar,_(p(p({},N),E),{open:a,onClose:T,TransitionProps:{onExited:P,onExit:$},sx:{zIndex:at},children:o.jsxs("div",{children:[o.jsx(r.Alert,{onClose:C=>T(C,"closeAlert"),severity:f.severity,variant:"filled",icon:f.progressIndicator==="circular"?o.jsx(r.CircularProgress,{size:"1em"}):void 0,style:f.progressIndicator==="linear"?ct:void 0,children:f.message}),f.progressIndicator==="linear"&&o.jsx(r.LinearProgress,{color:"primary"})]})}))]})}class J extends Error{}ie(J,"errorName","ContextError");function Ce(){const e=D.useContext(Y);if(e===null)throw new J("Error: Tried to useSaladBar outside of a <SaladBarProvider>");return e}const pt=qe.createHelper((e={autoHideDuration:1},t={},n={})=>({children:i})=>o.jsx(Ae,_(p({},e),{overrideState:t,overrideActions:n,children:o.jsx(o.Fragment,{children:i})}))),ve="domainCode";var xe;const de=w.atom(JSON.parse((xe=localStorage.getItem(ve))!=null?xe:'{"domainCode": ""}').domainCode),Se=w.atom(e=>e(de),(e,t,n)=>{t(de,n),localStorage.setItem(ve,JSON.stringify({domainCode:n}))}),ye={act:"ACT",nsw:"NSW",nt:"NT",qld:"QLD",sa:"SA",tas:"TAS",vic:"VIC",wa:"WA",ag:"AG",fedmps:"FedMPs","":""},Z=e=>{var t;return e===null?"N/A":(t=ye[e])!=null?t:""},ht=({isLoading:e,isOpen:t,onClose:n,onDomainChange:i,domainOptions:s,applicationName:l,handleLogout:d})=>{const[a,c]=w.useAtom(Se),[u,x]=D.useState(a),{enqueueSuccessNotification:k}=Ce(),v=s.length===0,g=!!a&&!s.includes(a)&&!s.includes(u),y=!a||v||g,F=()=>I(null,null,function*(){u?(c(u),i==null||i(u),k(`Set organisation to ${u}`),n()):(c(""),i==null||i(""))}),h=()=>I(null,null,function*(){a&&!v&&!g?(x(a),n()):y&&d()});let j;return v?j="Unable to retrieve your active organisations. Try logging in again.":g&&(j="You no longer have any roles in your chosen organisation. Please choose another."),o.jsxs(K,{isOpen:t,dialogTitle:"Select an organisation",primaryButton:{text:"Confirm",onClick:F,disabled:!u||v||g,buttonColor:"primary"},secondaryButton:{text:y?"Logout":"Cancel",onClick:h},onClose:y?()=>{}:n,children:[o.jsxs(r.Typography,{marginBottom:2,children:["Select the default organisation that you want to use with the ",l,"."]}),o.jsx(r.Autocomplete,{loading:e,multiple:!1,disableClearable:!1,value:u!==""?u:null,onChange:(b,T)=>x(T!=null?T:""),getOptionLabel:Z,options:[...s.toSorted()],renderInput:b=>o.jsx(r.TextField,_(p({},b),{variant:"filled",label:"Select organisation",InputProps:_(p({},b.InputProps),{endAdornment:o.jsxs(o.Fragment,{children:[e?o.jsx(r.CircularProgress,{color:"inherit",size:20,sx:{marginTop:"-20px"}}):null,b.InputProps.endAdornment]})})}))}),j&&o.jsx(r.FormHelperText,{error:!0,children:j})]})},je=()=>{const e=r.useTheme();return r.useMediaQuery(e.breakpoints.down("sm"))},mt=64,xt=72,gt=256,q=w.atom(!0),we=w.atom(gt),De=w.atom(xt),V=w.atom(""),ke=w.atom(void 0),Fe=w.atom(mt),be=w.atom(void 0);function ft({links:e}){return o.jsx("div",{children:"LinksMenu not implemented yet"})}const U="Navbar",R={root:`${U}-root`,menuButton:`${U}-menuButton`,hide:`${U}-hide`,content:`${U}-content`},At=B.styled(r.Box,{name:"NavBar"})(({theme:e})=>({[`&.${R.root}`]:{display:"flex"},[`& .${R.menuButton}`]:{marginRight:36},[`& .${R.hide}`]:{display:"none"},[`& .${R.content}`]:{flexGrow:1,padding:e.spacing(3)}})),M=(e,t,n)=>e.transitions.create(t,{easing:e.transitions.easing.sharp,duration:n==="leaving"?e.transitions.duration.leavingScreen:e.transitions.duration.enteringScreen}),Ct=e=>{const t=r.useTheme();return o.jsx(r.Collapse,p({easing:t.transitions.easing.sharp,timeout:{enter:t.transitions.duration.enteringScreen,exit:t.transitions.duration.leavingScreen}},e))},Ee=e=>{var t,n;return{overflowX:"hidden",color:"inherit",backgroundColor:(n=(t=e==null?void 0:e.navBar)==null?void 0:t.backgroundColor)!=null?n:"white"}},ue=(e,t)=>p({width:t,transition:M(e,"width","entering")},Ee(e)),pe=(e,t)=>p({width:t,transition:M(e,"width","leaving")},Ee(e)),vt=B.styled(r.Drawer,{shouldForwardProp:e=>!["widthOpen","widthClosed","isSmallScreen"].includes(e)})(({theme:e,open:t,widthOpen:n,widthClosed:i,isSmallScreen:s})=>p(p({flexShrink:0,whiteSpace:"nowrap",boxSizing:"border-box",display:"flex",flexDirection:"column"},t&&_(p({},ue(e,n)),{backgroundColor:"","& .MuiDrawer-paper":ue(e,n)})),!t&&_(p({},pe(e,s?n:i)),{backgroundColor:"","& .MuiDrawer-paper":pe(e,s?n:i)})));function _e(e){return e.replace(/(^|-)([a-z])/g,(t,n,i)=>n==="-"?" "+i.toUpperCase():i.toUpperCase())}function St(e,t,n,i){var d;if(!e)return"None";const l=Object.entries(e).filter(([a,c])=>a.startsWith("https://greens.org.au/roles/")&&c.includes(t)).map(([a])=>{var c;return _e((c=a.split("/").at(-1))!=null?c:"")});return(d=i.find(a=>n[a].some(c=>l.includes(c))))!=null?d:"None"}const yt=e=>{const{getIdTokenClaims:t,user:n}=X.useAuth0();return ge.useQuery({queryKey:["availableDomains",n==null?void 0:n.sub],queryFn:()=>I(null,null,function*(){const i=yield t();return i?Object.entries(i).reduce((s,[l,d])=>{var u;const a=_e((u=l.split("/").at(-1))!=null?u:""),c=l.startsWith("https://greens.org.au/roles/")&&e.includes(a)?d:[];return[...new Set([...s,...c])]},[]):[]})})},jt=e=>Object.values(e).reduce((t,n)=>[...new Set([...t,...n])],[]),H={log:console.warn.bind(console),error:console.error.bind(console),warn:console.warn.bind(console),info:console.info.bind(console),debug:console.debug.bind(console)};function wt(e,t){console[e]=(...n)=>{for(const i of t)if(typeof i=="function"){if(i(...n))return}else if(i instanceof RegExp&&n.length>0){for(const s of n)if(typeof s=="string"&&i.test(s))return}H[e](n)}}function Dt(e){if(e)console[e]=H[e];else for(const t of Object.keys(H))console[t]=H[t]}function Te(e){let t=0;for(let n=0,i=e.length;n<i;n++){const s=e.charCodeAt(n);t=(t<<5)-t+s,t|=0}return t}const he=["#A62A21","#7e3794","#0B51C1","#3A6024","#A81563","#B3003C"],me=e=>e.split(/\s/).map(t=>t.substring(0,1).toUpperCase()).filter(t=>!!t).slice(0,2).join("").toUpperCase();function kt({user:e,domainCode:t,open:n,useNewAvatar:i=!1}){const s=r.useTheme();return o.jsxs(r.Box,{sx:{paddingTop:3,display:"flex",alignItems:"center",flexDirection:"column",gap:"0.5rem"},children:[!i&&o.jsx(r.Box,{sx:{width:n?"5rem":"2rem",transition:n?M(s,["width","height"],"entering"):M(s,["width","height"],"leaving"),aspectRatio:1},children:e!=null&&e.name?o.jsx(o.Fragment,{children:o.jsx(r.Avatar,{src:e==null?void 0:e.picture,sx:{width:"100%",height:"100%",bgcolor:he[Math.abs(Te(e==null?void 0:e.name))%he.length]},children:me(e==null?void 0:e.name)})}):o.jsx(r.Avatar,{sx:{width:"100%",height:"100%"}})}),i&&o.jsx(r.Box,{sx:{width:n?"5rem":"2rem",transition:n?M(s,["width","height"],"entering"):M(s,["width","height"],"leaving"),aspectRatio:1},children:e!=null&&e.name?o.jsx(o.Fragment,{children:o.jsxs(se.default,{src:e==null?void 0:e.picture,name:e==null?void 0:e.name,round:!0,size:n?"80":"32",children:[" ",me(e==null?void 0:e.name)," ","ab"]})}):o.jsx(se.default,{})}),o.jsx(Ct,{sx:{width:"100%"},in:n,children:o.jsx(r.Fade,{in:n,children:o.jsxs(r.Box,{width:"100%",display:"flex",flexDirection:"column",alignItems:"center",children:[e!=null&&e.name?o.jsx(r.Typography,{children:e==null?void 0:e.name}):o.jsx(r.Skeleton,{animation:!1,width:"50%"}),t?o.jsx(r.Typography,{children:Z(t)}):o.jsx(r.Skeleton,{animation:!1,width:"25%"})]})})})]})}function Ft({open:e,widthClosed:t,widthOpen:n,"data-testid":i,top:s,middle:l,bottom:d,user:a,domainCode:c,useNewAvatar:u=!1}){const x=je(),k=w.useSetAtom(q);return o.jsx(At,{className:R.root,"data-testid":i,children:o.jsxs(vt,{open:e,widthOpen:n,widthClosed:t,anchor:"left",variant:x?"temporary":"permanent",PaperProps:{component:"nav"},onClose:()=>{k(!1)},isSmallScreen:x,children:[!x&&o.jsx(r.Toolbar,{}),s&&o.jsxs(r.Box,{flexGrow:"0",children:[s,o.jsx(r.Divider,{variant:"middle",sx:{marginY:"0.5rem"}})]}),o.jsx(r.Box,{flexGrow:"1",children:Array.isArray(l)?o.jsx(ft,{links:l}):l}),o.jsxs(r.Box,{flexGrow:"0",children:[o.jsx(r.Divider,{variant:"middle",sx:{marginY:"0.5rem"}}),o.jsx(kt,{user:a,domainCode:c,open:e,useNewAvatar:u}),d&&o.jsx(o.Fragment,{children:d})]})]})})}function bt({children:e,topBarHeight:t,maxWidth:n=!1,noPadding:i}){return o.jsx(r.Box,{sx:{overflow:"auto",height:`calc(100vh - ${t}px)`,flexGrow:1},children:i?o.jsx(r.Box,{component:"main",id:"main-content",height:"inherit",children:e}):o.jsx(r.Container,{component:"main",id:"main-content",maxWidth:n,sx:{paddingTop:3,paddingBottom:3,flexGrow:1},children:e})})}const Et="TopBar",_t={titleText:`${Et}-titleText`};function Tt({titleText:e="",height:t,"data-testid":n,middle:i}){const s=w.useSetAtom(q),l=()=>s(c=>!c),d=r.useTheme(),a=je();return o.jsx("header",{"data-testid":n,children:o.jsxs(r.Paper,{square:!0,elevation:0,sx:{width:"100%",position:"sticky",color:"primary.contrastText",backgroundColor:"primary.main",display:"flex",alignItems:"center",gap:2,flexShrink:0,height:t,zIndex:a?0:d.zIndex.drawer+101},children:[o.jsx(r.IconButton,{size:"medium",color:"inherit",sx:{padding:1.5,marginLeft:"12px"},onClick:l,children:o.jsx(G.ViewHeadline,{fontSize:"medium"})}),o.jsx(r.Typography,{className:_t.titleText,variant:"h6",component:"h1",children:e}),i]})})}function It({children:e,initialTitleText:t,initialNavBarOpen:n,pageContainerProps:i,pageContentDataTestId:s,topBarDataTestId:l,navBarDataTestId:d,navBarMiddle:a,navBarBottom:c,user:u,domainCode:x,useNewAvatar:k=!1}){He.useHydrateAtoms([[q,n!=null?n:!0],[V,t!=null?t:""]]);const v=w.useAtomValue(q),[g]=w.useAtom(we),[y]=w.useAtom(De),F=w.useAtomValue(V),[h]=w.useAtom(Fe),[j]=w.useAtom(ke),[b]=w.useAtom(be);return o.jsxs(re.default,{children:[o.jsx(Xe.default,{}),o.jsx(Tt,{titleText:F,"data-testid":l,height:h,middle:j}),o.jsxs(re.default,{sx:{display:"flex"},children:[o.jsx(Ft,{open:v,top:b,middle:a,bottom:c,user:u,domainCode:x,widthOpen:g,widthClosed:y,offsetTop:h,"data-testid":d,useNewAvatar:k}),o.jsx(bt,_(p({"data-testid":s,topBarHeight:h},i),{children:e}))]})]})}const Bt=B.createTheme({palette:{primary:{dark:"#00A651",light:"#A3D39C",main:"#007236",contrastText:"#FFF"},warning:{main:"#F5871F",light:"#FCC589",dark:"#A2590A",contrastText:"#FFF"},secondary:{main:"#662D91",light:"#BD8CBF",dark:"#440E62",contrastText:"#FFF"},error:{main:"#D43C95",light:"#8F2064",dark:"#F9CDE0",contrastText:"#FFF"},info:{main:"#00A88D",light:"#ADDCCF",dark:"#005243",contrastText:"#FFF"},success:{main:"#00A651",light:"#A3D39C",dark:"#007236",contrastText:"#FFF"}},typography:{explainer:{fontSize:"14px",marginBlockStart:"1em"}},navBar:{backgroundColor:"#E8E8E8"}}),Pt=B.createTheme({palette:{primary:{main:"#007236",dark:"#005221",light:"#00A04E",contrastText:"#FFFFFF"},secondary:{main:"#662D91",dark:"#440E62",light:"#93268F",contrastText:"#FFFFFF"},error:{main:"#D32F2F",dark:"#C62828",light:"#EF5350"},info:{main:"#0288D1",dark:"#01579B",light:"#03A9F4"},success:{main:"#0288D1",dark:"#01579B",light:"#03A9F4"}},components:{MuiTextField:{defaultProps:{color:"secondary"}},MuiToggleButtonGroup:{defaultProps:{color:"secondary"}},MuiCheckbox:{defaultProps:{color:"secondary"}},MuiSelect:{defaultProps:{color:"secondary"}},MuiSwitch:{defaultProps:{color:"secondary"}},MuiFormControl:{defaultProps:{color:"secondary"}},MuiMenuItem:{styleOverrides:{root:({theme:e})=>({"&.Mui-selected":{backgroundColor:B.alpha(e.palette.secondary.main,e.palette.action.selectedOpacity),"&:hover":{backgroundColor:B.alpha(e.palette.secondary.main,e.palette.action.selectedOpacity)},"&.Mui-focusVisible":{backgroundColor:B.alpha(e.palette.secondary.main,e.palette.action.focusOpacity)}}})}}},typography:{h4:{fontSize:"1.88rem",fontWeight:500},h5:{fontWeight:500},explainer:{fontSize:"14px",marginBlockStart:"1em"}},navBar:{backgroundColor:"#E8E8E8"}});exports.AgDialog=K;exports.AppLayout=It;exports.AuthGuard=it;exports.Context=Y;exports.ContextError=J;exports.DOMAIN_CODE_LABELS=ye;exports.DomainCodeDialog=ht;exports.ExampleComponent=Ke;exports.FetchAutocomplete=Qe;exports.MUI_AUTOCOMPLETE_VALUE_WARNING_REGEX=Ye;exports.SaladBarProvider=Ae;exports.SessionExpiryDialog=Ze;exports.SingleAutocomplete=Je;exports.determineUserLevelFromClaims=St;exports.domainCodeAtom=Se;exports.fed21Theme=Bt;exports.getAuth0Expiry=fe;exports.getDomainOptionLabel=Z;exports.getValidBusinessRoles=jt;exports.internalAgSystemsTheme=Pt;exports.navBarOpenAtom=q;exports.navBarTopAtom=be;exports.navBarWidthClosedAtom=De;exports.navBarWidthOpenAtom=we;exports.simpleHashCode=Te;exports.suppressConsole=wt;exports.titleTextAtom=V;exports.topBarHeightAtom=Fe;exports.topBarMiddleAtom=ke;exports.unsuppressConsole=Dt;exports.useAutocompleteOptions=Q;exports.useSaladBar=Ce;exports.useValidDomains=yt;exports.withSaladBarProvider=pt;
1
+ "use strict";var Re=Object.defineProperty,qe=Object.defineProperties;var Ue=Object.getOwnPropertyDescriptors;var V=Object.getOwnPropertySymbols;var re=Object.prototype.hasOwnProperty,se=Object.prototype.propertyIsEnumerable;var K=(e,t,n)=>t in e?Re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,h=(e,t)=>{for(var n in t||(t={}))re.call(t,n)&&K(e,n,t[n]);if(V)for(var n of V(t))se.call(t,n)&&K(e,n,t[n]);return e},_=(e,t)=>qe(e,Ue(t));var ae=(e,t)=>{var n={};for(var i in e)re.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(e!=null&&V)for(var i of V(e))t.indexOf(i)<0&&se.call(e,i)&&(n[i]=e[i]);return n};var le=(e,t,n)=>K(e,typeof t!="symbol"?t+"":t,n);var T=(e,t,n)=>new Promise((i,s)=>{var l=c=>{try{a(n.next(c))}catch(p){s(p)}},d=c=>{try{a(n.throw(c))}catch(p){s(p)}},a=c=>c.done?i(c.value):Promise.resolve(c.value).then(l,d);a((n=n.apply(e,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),j=require("react"),r=require("@mui/material"),Q=require("@mui/icons-material"),He=require("autosuggest-highlight/match"),We=require("autosuggest-highlight/parse"),Se=require("@tanstack/react-query"),J=require("@auth0/auth0-react"),Ve=require("buffer"),ze=require("@mui/material/Skeleton"),y=require("jotai"),Ge=require("souvlaki"),Xe=require("@mui/material/CssBaseline"),Ke=require("@mui/material/Box"),Qe=require("jotai/utils"),M=require("@mui/material/styles"),Ye=require("react-avatar"),U=e=>e&&e.__esModule?e:{default:e},Je=U(He),Ze=U(We),et=U(ze),tt=U(Xe),ce=U(Ke),de=U(Ye);function ot({text:e}){const[t,n]=j.useState(0);return o.jsxs(o.Fragment,{children:[o.jsx(r.Typography,{variant:"h6",color:"inherit",component:"div",sx:{fontSize:"22px"},children:"Hello world"}),o.jsx(r.Typography,{variant:"caption",display:"block",children:o.jsx("span",{children:"Just ensuring MUI is working as planned as a peer dependency. v0.0.11"})}),o.jsx(r.Button,{variant:"outlined",onClick:()=>n(i=>i+1),"aria-label":"Increment",children:"Hello I am a button"}),o.jsxs("p",{children:["This is some text: ",o.jsx("span",{children:e})]}),o.jsxs(r.Paper,{children:["This number will incremember when button pressed: ",t]})]})}const Z=({isOpen:e,dialogTitle:t,children:n,maxWidth:i,primaryButton:s,secondaryButton:l,additionalButtons:d,onClose:a,sx:c,"data-testid":p,disableCloseOnBackdropOrEscape:g=!1,isLoading:w=!1})=>{var v,F;const[S,A]=j.useState(!1);return o.jsxs(r.Dialog,{open:e,onClose:(f,D)=>T(null,null,function*(){g&&(D==="backdropClick"||D==="escapeKeyDown")||S||(l!=null&&l.onClick?yield l.onClick():a())}),fullWidth:!0,maxWidth:i!=null?i:"xs","data-testid":p,sx:c,children:[w&&o.jsx(r.LinearProgress,{sx:{height:"4px",marginBottom:"-4px"}}),o.jsx(r.DialogTitle,{children:t}),o.jsx(r.DialogContent,{sx:{"& > :last-child":{marginBottom:0}},children:n}),o.jsxs(r.DialogActions,{children:[o.jsx(r.Button,{onClick:(v=l==null?void 0:l.onClick)!=null?v:a,"data-testid":l==null?void 0:l.testId,disabled:(l==null?void 0:l.disabled)||S,color:l==null?void 0:l.buttonColor,children:(F=l==null?void 0:l.text)!=null?F:"Cancel"}),d&&d.map((f,D)=>{var k;return o.jsx(r.Button,{onClick:f==null?void 0:f.onClick,"data-testid":f==null?void 0:f.testId,disabled:(f==null?void 0:f.disabled)||S,color:f==null?void 0:f.buttonColor,children:(k=f.text)!=null?k:`Button ${D}`},D)}),s&&o.jsx(r.Button,{onClick:()=>T(null,null,function*(){var f;A(!0),yield(f=s.onClick)==null?void 0:f.call(s),A(!1)}),"data-testid":s.testId,disabled:s.disabled||S,color:s==null?void 0:s.buttonColor,children:s.text})]})]})},nt={popper:{modifiers:[{name:"offset",options:{offset:[115,-15]}}]}},ve={right:2},ee=({minLength:e,preLoadedOptions:t,lookup:n,label:i,inputValue:s})=>Se.useQuery({queryFn:()=>e&&s.length<e?t!=null?t:[]:t?t.filter(l=>l.label.toLowerCase().includes(s.toLowerCase())):n(s),queryKey:["autocomplete",i,s]});function it({lookup:e=()=>T(null,null,function*(){}),enableHighlighting:t=!0,onChange:n,minLength:i=0,label:s,value:l,"data-testid":d,sx:a,boxSx:c,textFieldColor:p,textFieldVariant:g="filled",loadingText:w="Loading...",noOptionsText:S="No options",popupIcon:A=o.jsx(Q.ArrowDropDown,{}),error:v=!1,helperText:F="",preLoadedOptions:f=void 0,disablePortal:D=!1,disableIconFlip:k=!1,chipToolTipSlotProps:E=nt,isPlaceholder:B=!1,placeHolderText:N=void 0,onRightClick:b=()=>{},disableDefaultRightClickBehaviour:I=!1}){const[L,O]=j.useState(""),$=(m,C)=>{const P=l.filter(X=>X.id!==C);n(P,"delete",m)},{data:u,isLoading:x}=ee({inputValue:L,label:s,lookup:e,minLength:i,preLoadedOptions:f}),R=L.length>=i,Le=B?{sx:{"& .MuiFilledInput-root.Mui-focused":{backgroundColor:"hsla(201, 98%, 41%, 0.08)"}},focused:!0}:{};return o.jsxs("div",{"data-testid":d,children:[o.jsx(r.Autocomplete,{sx:h(h({},a),k?{".MuiAutocomplete-popupIndicatorOpen":{transform:"rotate(0deg)"}}:{}),"data-testid":d?`${d}:Autocomplete`:void 0,disablePortal:D,multiple:!0,getOptionLabel:m=>typeof m=="string"?m:m.label,loading:R?x:!1,options:[...l,...u!=null?u:[]],filterSelectedOptions:!0,includeInputInList:!0,value:l,onChange:(m,C,P)=>{n(C,P,m)},onInputChange:(m,C)=>O(C),noOptionsText:R?S:"Start typing to search",loadingText:w,popupIcon:A,renderInput:m=>o.jsx(r.TextField,h(_(h({},m),{label:s,fullWidth:!0,variant:g,error:v,helperText:F,slotProps:{input:_(h({},m.InputProps),{endAdornment:o.jsxs(o.Fragment,{children:[x?o.jsx(r.CircularProgress,{color:"inherit",size:20}):null,m.InputProps.endAdornment]})})},"data-testid":d?`${d}:Autocomplete:TextField`:void 0,onKeyDown:C=>{(C.key==="Backspace"||C.key==="Delete")&&C.stopPropagation()},color:p,placeholder:N}),Le)),renderValue:()=>null,isOptionEqualToValue:(m,C)=>m.id===C.id,renderOption:(m,C,P)=>{if(t){const X=Je.default(C.label,P.inputValue,{insideWords:!0,findAllOccurrences:!0}),Oe=Ze.default(C.label,X);return j.createElement("li",_(h({},m),{key:C.id,"data-testid":d?`${d}:Autocomplete:option(${C.id.toString()})`:void 0}),o.jsx("div",{children:Oe.map((ie,$e)=>o.jsx("span",{style:{fontWeight:ie.highlight?700:400},children:ie.text},$e))}))}else return j.createElement("li",_(h({},m),{key:C.id,"data-testid":d?`${d}:option(${C.id.toString()})`:void 0}),C.label)},onContextMenu:b,onMouseDownCapture:m=>{m.button===ve.right&&I&&(m.preventDefault(),m.stopPropagation())},onContextMenuCapture:m=>{I&&(m.preventDefault(),m.stopPropagation())}}),l.length>0&&o.jsx(r.Box,{sx:c,children:l.map(m=>{var C;return o.jsx(r.Chip,{sx:{marginTop:1,marginRight:1,height:"auto"},label:o.jsx(r.Tooltip,{title:(C=m.tooltipContent)!=null?C:"",placement:"bottom-start",slotProps:E,children:o.jsx(r.Typography,{style:{whiteSpace:"normal"},children:m.chipLabel?m.chipLabel:m.label})}),"data-testid":d?`${d}:Chip(${m.id.toString()})`:void 0,onDelete:P=>$(P,m.id),deleteIcon:o.jsx(Q.Cancel,{"data-testid":d?`${d}:Chip(${m.id.toString()}):deleteIcon`:void 0})},m.id)})})]})}const rt=/MUI: The value provided to.*is invalid/i,st=({lookup:e=()=>T(null,null,function*(){}),onChange:t,label:n,value:i,sx:s,textFieldColor:l,textFieldVariant:d="filled",error:a=!1,"data-testid":c,noOptionsText:p="No options",minLength:g=3,disablePortal:w=!1,preLoadedOptions:S,helperText:A="",disabled:v,popupIcon:F,disableIconFlip:f,isPlaceholder:D=!1,placeHolderText:k=void 0,onRightClick:E=()=>{},disableDefaultRightClickBehaviour:B=!1})=>{const[N,b]=j.useState(""),{data:I,isLoading:L}=ee({inputValue:N,label:n,lookup:e,minLength:g!=null?g:0,preLoadedOptions:S}),O=N.length>=g,$=D?{sx:{"& .MuiFilledInput-root.Mui-focused":{backgroundColor:"hsla(201, 98%, 41%, 0.08)"}},focused:!0}:{};return o.jsx("div",{"data-testid":c,children:o.jsx(r.Stack,{direction:"row",spacing:1,onContextMenu:E,onMouseDownCapture:u=>{u.button===ve.right&&B&&(u.preventDefault(),u.stopPropagation())},onContextMenuCapture:u=>{B&&(u.preventDefault(),u.stopPropagation())},children:o.jsx(r.Autocomplete,{sx:h(h({},s),f?{".MuiAutocomplete-popupIndicatorOpen":{transform:"rotate(0deg)"}}:{}),"data-testid":c?`${c}:Autocomplete`:void 0,loading:O?L:!1,options:I!=null?I:[],onChange:(u,x,R)=>{t(u,x,R)},disablePortal:w,filterOptions:u=>u,value:i,noOptionsText:O?p:"Start typing to search",getOptionLabel:u=>u.label,popupIcon:F,renderInput:u=>o.jsx(r.TextField,h(_(h({"data-testid":c?`${c}:Autocomplete:TextField`:void 0},u),{variant:d,label:n,color:l,error:a,helperText:A,placeholder:k}),$)),isOptionEqualToValue:(u,x)=>u.id===x.id,onInputChange:(u,x)=>{b(x)},renderOption:(u,x)=>j.createElement("li",_(h({},u),{key:x.id,"data-testid":c?`${c}:Autocomplete:option(${x.id.toString()})`:void 0}),x.label),disabled:v})})})},ye=e=>{if(!e)return-1;try{const n=e.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"),i=decodeURIComponent(Ve.Buffer.from(n,"base64").toString("utf8").split("").map(function(l){return"%"+("00"+l.charCodeAt(0).toString(16)).slice(-2)}).join("")),s=JSON.parse(i);return s!=null&&s.exp?s.exp:-1}catch(t){return-1}},at=({open:e=!1,closeHandler:t,setAuth0ExpiryTime:n})=>{const{logout:i,getAccessTokenSilently:s}=J.useAuth0(),l=()=>T(null,null,function*(){i({logoutParams:{returnTo:`${window.location.origin}`}})}),a={text:"Continue",onClick:()=>T(null,null,function*(){const p=yield s({cacheMode:"off"}),g=ye(p)*1e3;n(g),t()}),disabled:!1,testId:"PreferencesDialog",buttonColor:"secondary"},c={text:"Log out",onClick:l,disabled:!1,testId:"PreferencesDialog",buttonColor:"secondary"};return o.jsx(Z,{isOpen:e,primaryButton:a,secondaryButton:c,onClose:t,dialogTitle:"Session expiry",disableCloseOnBackdropOrEscape:!0,children:o.jsx("p",{style:{marginBottom:0},children:"Your session is about to time out due to inactivity. Do you want to continue?"})})};function lt(e){return"error"in e}function ct(e){var i;const t=e.error,n=(i=e==null?void 0:e.error_description)!=null?i:"";return t==="access_denied"&&n.startsWith("You do not have the required authorization")}function dt(e){var i;const t=e.error,n=(i=e==null?void 0:e.error_description)!=null?i:"";return t==="access_denied"&&n.startsWith("User did not authorize the request")}function ut(e){var i;const t=e.error,n=(i=e==null?void 0:e.error_description)!=null?i:"";return t==="access_denied"&&n.match(/Script.*time.*exceeded/)}function pt({children:e,appName:t="the app",throwErrors:n="none",disableConsoleLogging:i=!1,onError:s=()=>{}}){var w,S;const{isAuthenticated:l,isLoading:d,error:a,loginWithRedirect:c,logout:p}=J.useAuth0();j.useEffect(()=>{a&&s(a)},[a,s]);const g=j.useMemo(()=>({appState:{returnTo:`${window.location.pathname}${window.location.search}`}}),[]);if(j.useEffect(()=>{d||l||a||c(g)},[d,l,a,c,s,g]),a){if(i||console.error(`Error detected in AuthGuard [isAuthenticated=${l},isLoading=${d}]`,a),n==="all")throw a;if(lt(a)){let A="Auth error",v="An unknown Auth0 error occurred.";if(ct(a))A="Unauthorised",v=`You are not authorised to access ${t}.`;else if(dt(a))A="App not authorised",v=`You have not authorised ${t} to access your user profile. This is necessary to use ${t}.`;else if(ut(a))A="Auth0 script execution time exceeded",v="The Auth0 login flow exceeded the time limit (20s). Try again in a minute by clicking the RELOAD button below.";else if(a.message==="Invalid state"){const F=localStorage.getItem("auth0_redirect_count");F?F&&parseInt(F)<2&&(localStorage.setItem("auth0_redirect_count",String(parseInt(F)+1)),c(g)):(localStorage.setItem("auth0_redirect_count","1"),c(g))}else if(n==="unknown")throw a;return o.jsxs(r.Dialog,{open:!0,children:[o.jsx(r.DialogTitle,{children:A}),o.jsxs(r.DialogContent,{children:[o.jsx(r.Typography,{children:v}),o.jsx("br",{}),o.jsx(r.Typography,{variant:"subtitle2",children:"Details from Auth0"}),o.jsxs(r.Typography,{variant:"body2",children:["error: ",(w=a==null?void 0:a.error)!=null?w:"N/A"]}),o.jsxs(r.Typography,{variant:"body2",children:["description: ",(S=a==null?void 0:a.error_description)!=null?S:"N/A"]})]}),o.jsxs(r.DialogActions,{children:[A==="Auth0 script execution time exceeded"&&o.jsx(r.Button,{href:window.location.origin+window.location.pathname,children:"Reload"}),o.jsx(r.Button,{onClick:()=>p({logoutParams:{returnTo:window.location.origin}}),children:"Logout"})]})]})}else if(n==="unknown")throw a}return l?(localStorage.removeItem("auth0_redirect_count"),o.jsx(o.Fragment,{children:e})):o.jsx(et.default,{variant:"rectangular",animation:"pulse",height:"100vh",width:"100vw"})}const ht={autoHideDuration:6e3,anchorOrigin:{vertical:"top",horizontal:"center"},disableWindowBlurListener:!1},mt={shouldClose:(e,t)=>t!=="clickaway"},ue={message:"",severity:"info",variant:"standard",progressIndicator:void 0},pe=100,he=2e3,ft=2e3,xt=(()=>{let e=0;return()=>(e+=1,e)})(),gt={borderBottomLeftRadius:"0px",borderBottomRightRadius:"0px"},At={},Ct={},te=j.createContext(null);function je(l){var d=l,{overrideState:e=At,overrideActions:t=Ct,shouldClose:n=mt.shouldClose,children:i}=d,s=ae(d,["overrideState","overrideActions","shouldClose","children"]);var $;const[{open:a},c]=j.useState({open:!1}),p=j.useRef([]),g=j.useRef(Date.now()),w=j.useRef(0),S=j.useCallback(u=>{c({open:u})},[]),A=j.useCallback((u={})=>{w.current+=1,p.current.length>=pe&&Date.now()-g.current>=he&&(g.current=Date.now(),console.error(`SaladBarProvider: MAX_QUEUE_LENGTH (${pe}) hit ${w.current} times in last ${he}ms)`),w.current=0);const x=h(_(h({},ue),{key:xt()}),u);return p.current.push(x),p.current.length===1&&c({open:!0}),x.key},[]),v=(u="",x={})=>A(h({message:u,severity:"success"},x)),F=(u="",x={})=>A(h({message:u,severity:"info"},x)),f=(u="",x={})=>A(h({message:u,severity:"warning"},x)),D=(u="",x={})=>A(h({message:u,severity:"error"},x)),k=u=>{const x=p.current.findIndex(R=>R.key===u);if(x!==-1)return x===0?(c({open:!1}),p.current[0]):p.current.splice(x,1)},E=(u,x)=>{n(u,x)&&c({open:!1})},B=()=>{},N=()=>{p.current.shift(),p.current.length>0&&c({open:!0})},b=($=p.current[0])!=null?$:h({},ue),I={};"autoHideDuration"in b&&(I.autoHideDuration=b.autoHideDuration);const L=h(h({},ht),s),O=h(h({open:a,setOpen:S,enqueueNotification:A,enqueueSuccessNotification:v,enqueueInfoNotification:F,enqueueWarningNotification:f,enqueueErrorNotification:D,removeNotification:k},e),t);return o.jsxs(te.Provider,{value:O,children:[i,o.jsx(r.Snackbar,_(h(h({},L),I),{open:a,onClose:E,TransitionProps:{onExited:N,onExit:B},sx:{zIndex:ft},children:o.jsxs("div",{children:[o.jsx(r.Alert,{onClose:u=>E(u,"closeAlert"),severity:b.severity,variant:"filled",icon:b.progressIndicator==="circular"?o.jsx(r.CircularProgress,{size:"1em"}):void 0,style:b.progressIndicator==="linear"?gt:void 0,children:b.message}),b.progressIndicator==="linear"&&o.jsx(r.LinearProgress,{color:"primary"})]})}))]})}class oe extends Error{}le(oe,"errorName","ContextError");function we(){const e=j.useContext(te);if(e===null)throw new oe("Error: Tried to useSaladBar outside of a <SaladBarProvider>");return e}const St=Ge.createHelper((e={autoHideDuration:1},t={},n={})=>({children:i})=>o.jsx(je,_(h({},e),{overrideState:t,overrideActions:n,children:o.jsx(o.Fragment,{children:i})}))),De="domainCode";var Ce;const me=y.atom(JSON.parse((Ce=localStorage.getItem(De))!=null?Ce:'{"domainCode": ""}').domainCode),Fe=y.atom(e=>e(me),(e,t,n)=>{t(me,n),localStorage.setItem(De,JSON.stringify({domainCode:n}))}),ke={act:"ACT",nsw:"NSW",nt:"NT",qld:"QLD",sa:"SA",tas:"TAS",vic:"VIC",wa:"WA",ag:"AG",fedmps:"FedMPs","":""},ne=e=>{var t;return e===null?"N/A":(t=ke[e])!=null?t:""},vt=({isLoading:e,isOpen:t,onClose:n,onDomainChange:i,domainOptions:s,applicationName:l,handleLogout:d})=>{const[a,c]=y.useAtom(Fe),[p,g]=j.useState(a),{enqueueSuccessNotification:w}=we(),S=s.length===0,A=!!a&&!s.includes(a)&&!s.includes(p),v=!a||S||A,F=()=>T(null,null,function*(){p?(c(p),i==null||i(p),w(`Set organisation to ${p}`),n()):(c(""),i==null||i(""))}),f=()=>T(null,null,function*(){a&&!S&&!A?(g(a),n()):v&&d()});let D;return S?D="Unable to retrieve your active organisations. Try logging in again.":A&&(D="You no longer have any roles in your chosen organisation. Please choose another."),o.jsxs(Z,{isOpen:t,dialogTitle:"Select an organisation",primaryButton:{text:"Confirm",onClick:F,disabled:!p||S||A,buttonColor:"primary"},secondaryButton:{text:v?"Logout":"Cancel",onClick:f},onClose:v?()=>{}:n,children:[o.jsxs(r.Typography,{marginBottom:2,children:["Select the default organisation that you want to use with the ",l,"."]}),o.jsx(r.Autocomplete,{loading:e,multiple:!1,disableClearable:!1,value:p!==""?p:null,onChange:(k,E)=>g(E!=null?E:""),getOptionLabel:ne,options:[...s.toSorted()],renderInput:k=>o.jsx(r.TextField,_(h({},k),{variant:"filled",label:"Select organisation",InputProps:_(h({},k.InputProps),{endAdornment:o.jsxs(o.Fragment,{children:[e?o.jsx(r.CircularProgress,{color:"inherit",size:20,sx:{marginTop:"-20px"}}):null,k.InputProps.endAdornment]})})}))}),D&&o.jsx(r.FormHelperText,{error:!0,children:D})]})},_e=()=>{const e=r.useTheme();return r.useMediaQuery(e.breakpoints.down("sm"))},yt=64,jt=72,wt=256,W=y.atom(!0),be=y.atom(wt),Ee=y.atom(jt),Y=y.atom(""),Te=y.atom(void 0),Ie=y.atom(yt),Pe=y.atom(void 0);function Dt({links:e}){return o.jsx("div",{children:"LinksMenu not implemented yet"})}const z="Navbar",H={root:`${z}-root`,menuButton:`${z}-menuButton`,hide:`${z}-hide`,content:`${z}-content`},Ft=M.styled(r.Box,{name:"NavBar"})(({theme:e})=>({[`&.${H.root}`]:{display:"flex"},[`& .${H.menuButton}`]:{marginRight:36},[`& .${H.hide}`]:{display:"none"},[`& .${H.content}`]:{flexGrow:1,padding:e.spacing(3)}})),q=(e,t,n)=>e.transitions.create(t,{easing:e.transitions.easing.sharp,duration:n==="leaving"?e.transitions.duration.leavingScreen:e.transitions.duration.enteringScreen}),kt=e=>{const t=r.useTheme();return o.jsx(r.Collapse,h({easing:t.transitions.easing.sharp,timeout:{enter:t.transitions.duration.enteringScreen,exit:t.transitions.duration.leavingScreen}},e))},Me=e=>{var t,n;return{overflowX:"hidden",color:"inherit",backgroundColor:(n=(t=e==null?void 0:e.navBar)==null?void 0:t.backgroundColor)!=null?n:"white"}},fe=(e,t)=>h({width:t,transition:q(e,"width","entering")},Me(e)),xe=(e,t)=>h({width:t,transition:q(e,"width","leaving")},Me(e)),_t=M.styled(r.Drawer,{shouldForwardProp:e=>!["widthOpen","widthClosed","isSmallScreen"].includes(e)})(({theme:e,open:t,widthOpen:n,widthClosed:i,isSmallScreen:s})=>h(h({flexShrink:0,whiteSpace:"nowrap",boxSizing:"border-box",display:"flex",flexDirection:"column"},t&&_(h({},fe(e,n)),{backgroundColor:"","& .MuiDrawer-paper":fe(e,n)})),!t&&_(h({},xe(e,s?n:i)),{backgroundColor:"","& .MuiDrawer-paper":xe(e,s?n:i)})));function Be(e){return e.replace(/(^|-)([a-z])/g,(t,n,i)=>n==="-"?" "+i.toUpperCase():i.toUpperCase())}function bt(e,t,n,i){var d;if(!e)return"None";const l=Object.entries(e).filter(([a,c])=>a.startsWith("https://greens.org.au/roles/")&&c.includes(t)).map(([a])=>{var c;return Be((c=a.split("/").at(-1))!=null?c:"")});return(d=i.find(a=>n[a].some(c=>l.includes(c))))!=null?d:"None"}const Et=e=>{const{getIdTokenClaims:t,user:n}=J.useAuth0();return Se.useQuery({queryKey:["availableDomains",n==null?void 0:n.sub],queryFn:()=>T(null,null,function*(){const i=yield t();return i?Object.entries(i).reduce((s,[l,d])=>{var p;const a=Be((p=l.split("/").at(-1))!=null?p:""),c=l.startsWith("https://greens.org.au/roles/")&&e.includes(a)?d:[];return[...new Set([...s,...c])]},[]):[]})})},Tt=e=>Object.values(e).reduce((t,n)=>[...new Set([...t,...n])],[]),G={log:console.warn.bind(console),error:console.error.bind(console),warn:console.warn.bind(console),info:console.info.bind(console),debug:console.debug.bind(console)};function It(e,t){console[e]=(...n)=>{for(const i of t)if(typeof i=="function"){if(i(...n))return}else if(i instanceof RegExp&&n.length>0){for(const s of n)if(typeof s=="string"&&i.test(s))return}G[e](n)}}function Pt(e){if(e)console[e]=G[e];else for(const t of Object.keys(G))console[t]=G[t]}function Ne(e){let t=0;for(let n=0,i=e.length;n<i;n++){const s=e.charCodeAt(n);t=(t<<5)-t+s,t|=0}return t}const ge=["#A62A21","#7e3794","#0B51C1","#3A6024","#A81563","#B3003C"],Ae=e=>e.split(/\s/).map(t=>t.substring(0,1).toUpperCase()).filter(t=>!!t).slice(0,2).join("").toUpperCase();function Mt({user:e,domainCode:t,open:n,useNewAvatar:i=!1}){const s=r.useTheme();return o.jsxs(r.Box,{sx:{paddingTop:3,display:"flex",alignItems:"center",flexDirection:"column",gap:"0.5rem"},children:[!i&&o.jsx(r.Box,{sx:{width:n?"5rem":"2rem",transition:n?q(s,["width","height"],"entering"):q(s,["width","height"],"leaving"),aspectRatio:1},children:e!=null&&e.name?o.jsx(o.Fragment,{children:o.jsx(r.Avatar,{src:e==null?void 0:e.picture,sx:{width:"100%",height:"100%",bgcolor:ge[Math.abs(Ne(e==null?void 0:e.name))%ge.length]},children:Ae(e==null?void 0:e.name)})}):o.jsx(r.Avatar,{sx:{width:"100%",height:"100%"}})}),i&&o.jsx(r.Box,{sx:{width:n?"5rem":"2rem",transition:n?q(s,["width","height"],"entering"):q(s,["width","height"],"leaving"),aspectRatio:1},children:e!=null&&e.name?o.jsx(o.Fragment,{children:o.jsxs(de.default,{src:e==null?void 0:e.picture,name:e==null?void 0:e.name,round:!0,size:n?"80":"32",children:[" ",Ae(e==null?void 0:e.name)," ","ab"]})}):o.jsx(de.default,{})}),o.jsx(kt,{sx:{width:"100%"},in:n,children:o.jsx(r.Fade,{in:n,children:o.jsxs(r.Box,{width:"100%",display:"flex",flexDirection:"column",alignItems:"center",children:[e!=null&&e.name?o.jsx(r.Typography,{children:e==null?void 0:e.name}):o.jsx(r.Skeleton,{animation:!1,width:"50%"}),t?o.jsx(r.Typography,{children:ne(t)}):o.jsx(r.Skeleton,{animation:!1,width:"25%"})]})})})]})}function Bt({open:e,widthClosed:t,widthOpen:n,"data-testid":i,top:s,middle:l,bottom:d,user:a,domainCode:c,useNewAvatar:p=!1}){const g=_e(),w=y.useSetAtom(W);return o.jsx(Ft,{className:H.root,"data-testid":i,children:o.jsxs(_t,{open:e,widthOpen:n,widthClosed:t,anchor:"left",variant:g?"temporary":"permanent",PaperProps:{component:"nav"},onClose:()=>{w(!1)},isSmallScreen:g,children:[!g&&o.jsx(r.Toolbar,{}),s&&o.jsxs(r.Box,{flexGrow:"0",children:[s,o.jsx(r.Divider,{variant:"middle",sx:{marginY:"0.5rem"}})]}),o.jsx(r.Box,{flexGrow:"1",children:Array.isArray(l)?o.jsx(Dt,{links:l}):l}),o.jsxs(r.Box,{flexGrow:"0",children:[o.jsx(r.Divider,{variant:"middle",sx:{marginY:"0.5rem"}}),o.jsx(Mt,{user:a,domainCode:c,open:e,useNewAvatar:p}),d&&o.jsx(o.Fragment,{children:d})]})]})})}function Nt({children:e,topBarHeight:t,maxWidth:n=!1,noPadding:i}){return o.jsx(r.Box,{sx:{overflow:"auto",height:`calc(100vh - ${t}px)`,flexGrow:1},children:i?o.jsx(r.Box,{component:"main",id:"main-content",height:"inherit",children:e}):o.jsx(r.Container,{component:"main",id:"main-content",maxWidth:n,sx:{paddingTop:3,paddingBottom:3,flexGrow:1},children:e})})}const Lt="TopBar",Ot={titleText:`${Lt}-titleText`};function $t({titleText:e="",height:t,"data-testid":n,middle:i}){const s=y.useSetAtom(W),l=()=>s(c=>!c),d=r.useTheme(),a=_e();return o.jsx("header",{"data-testid":n,children:o.jsxs(r.Paper,{square:!0,elevation:0,sx:{width:"100%",position:"sticky",color:"primary.contrastText",backgroundColor:"primary.main",display:"flex",alignItems:"center",gap:2,flexShrink:0,height:t,zIndex:a?0:d.zIndex.drawer+101},children:[o.jsx(r.IconButton,{size:"medium",color:"inherit",sx:{padding:1.5,marginLeft:"12px"},onClick:l,children:o.jsx(Q.ViewHeadline,{fontSize:"medium"})}),o.jsx(r.Typography,{className:Ot.titleText,variant:"h6",component:"h1",children:e}),i]})})}function Rt({children:e,initialTitleText:t,initialNavBarOpen:n,pageContainerProps:i,pageContentDataTestId:s,topBarDataTestId:l,navBarDataTestId:d,navBarMiddle:a,navBarBottom:c,user:p,domainCode:g,useNewAvatar:w=!1}){Qe.useHydrateAtoms([[W,n!=null?n:!0],[Y,t!=null?t:""]]);const S=y.useAtomValue(W),[A]=y.useAtom(be),[v]=y.useAtom(Ee),F=y.useAtomValue(Y),[f]=y.useAtom(Ie),[D]=y.useAtom(Te),[k]=y.useAtom(Pe);return o.jsxs(ce.default,{children:[o.jsx(tt.default,{}),o.jsx($t,{titleText:F,"data-testid":l,height:f,middle:D}),o.jsxs(ce.default,{sx:{display:"flex"},children:[o.jsx(Bt,{open:S,top:k,middle:a,bottom:c,user:p,domainCode:g,widthOpen:A,widthClosed:v,offsetTop:f,"data-testid":d,useNewAvatar:w}),o.jsx(Nt,_(h({"data-testid":s,topBarHeight:f},i),{children:e}))]})]})}const qt=M.createTheme({palette:{primary:{dark:"#00A651",light:"#A3D39C",main:"#007236",contrastText:"#FFF"},warning:{main:"#F5871F",light:"#FCC589",dark:"#A2590A",contrastText:"#FFF"},secondary:{main:"#662D91",light:"#BD8CBF",dark:"#440E62",contrastText:"#FFF"},error:{main:"#D43C95",light:"#8F2064",dark:"#F9CDE0",contrastText:"#FFF"},info:{main:"#00A88D",light:"#ADDCCF",dark:"#005243",contrastText:"#FFF"},success:{main:"#00A651",light:"#A3D39C",dark:"#007236",contrastText:"#FFF"}},typography:{explainer:{fontSize:"14px",marginBlockStart:"1em"}},navBar:{backgroundColor:"#E8E8E8"}}),Ut=M.createTheme({palette:{primary:{main:"#007236",dark:"#005221",light:"#00A04E",contrastText:"#FFFFFF"},secondary:{main:"#662D91",dark:"#440E62",light:"#93268F",contrastText:"#FFFFFF"},error:{main:"#D32F2F",dark:"#C62828",light:"#EF5350"},info:{main:"#0288D1",dark:"#01579B",light:"#03A9F4"},success:{main:"#0288D1",dark:"#01579B",light:"#03A9F4"}},components:{MuiTextField:{defaultProps:{color:"secondary"}},MuiToggleButtonGroup:{defaultProps:{color:"secondary"}},MuiCheckbox:{defaultProps:{color:"secondary"}},MuiSelect:{defaultProps:{color:"secondary"}},MuiSwitch:{defaultProps:{color:"secondary"}},MuiFormControl:{defaultProps:{color:"secondary"}},MuiMenuItem:{styleOverrides:{root:({theme:e})=>({"&.Mui-selected":{backgroundColor:M.alpha(e.palette.secondary.main,e.palette.action.selectedOpacity),"&:hover":{backgroundColor:M.alpha(e.palette.secondary.main,e.palette.action.selectedOpacity)},"&.Mui-focusVisible":{backgroundColor:M.alpha(e.palette.secondary.main,e.palette.action.focusOpacity)}}})}}},typography:{h4:{fontSize:"1.88rem",fontWeight:500},h5:{fontWeight:500},explainer:{fontSize:"14px",marginBlockStart:"1em"}},navBar:{backgroundColor:"#E8E8E8"}});exports.AgDialog=Z;exports.AppLayout=Rt;exports.AuthGuard=pt;exports.Context=te;exports.ContextError=oe;exports.DOMAIN_CODE_LABELS=ke;exports.DomainCodeDialog=vt;exports.ExampleComponent=ot;exports.FetchAutocomplete=it;exports.MUI_AUTOCOMPLETE_VALUE_WARNING_REGEX=rt;exports.SaladBarProvider=je;exports.SessionExpiryDialog=at;exports.SingleAutocomplete=st;exports.determineUserLevelFromClaims=bt;exports.domainCodeAtom=Fe;exports.fed21Theme=qt;exports.getAuth0Expiry=ye;exports.getDomainOptionLabel=ne;exports.getValidBusinessRoles=Tt;exports.internalAgSystemsTheme=Ut;exports.navBarOpenAtom=W;exports.navBarTopAtom=Pe;exports.navBarWidthClosedAtom=Ee;exports.navBarWidthOpenAtom=be;exports.simpleHashCode=Ne;exports.suppressConsole=It;exports.titleTextAtom=Y;exports.topBarHeightAtom=Ie;exports.topBarMiddleAtom=Te;exports.unsuppressConsole=Pt;exports.useAutocompleteOptions=ee;exports.useSaladBar=we;exports.useValidDomains=Et;exports.withSaladBarProvider=St;
2
2
  //# sourceMappingURL=index.cjs.map