@australiangreens/ag-internal-components 0.3.2 → 0.3.3

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 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;
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},b=(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"),P=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,k;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:(k=l==null?void 0:l.text)!=null?k:"Cancel"}),d&&d.map((f,D)=>{var F;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:(F=f.text)!=null?F:`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:k="",preLoadedOptions:f=void 0,disablePortal:D=!1,disableIconFlip:F=!1,chipToolTipSlotProps:E=nt,isPlaceholder:B=!1,placeHolderText:N=void 0,onRightClick:_=()=>{},disableDefaultRightClickBehaviour:I=!1}){const[L,O]=j.useState(""),$=(m,C)=>{const M=l.filter(X=>X.id!==C);n(M,"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)"},"& .MuiOutlinedInput-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),F?{".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,M)=>{n(C,M,m)},onInputChange:(m,C)=>O(C),noOptionsText:R?S:"Start typing to search",loadingText:w,popupIcon:A,renderInput:m=>o.jsx(r.TextField,h(b(h({},m),{label:s,fullWidth:!0,variant:g,error:v,helperText:k,slotProps:{input:b(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,M)=>{if(t){const X=Je.default(C.label,M.inputValue,{insideWords:!0,findAllOccurrences:!0}),Oe=Ze.default(C.label,X);return j.createElement("li",b(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",b(h({},m),{key:C.id,"data-testid":d?`${d}:option(${C.id.toString()})`:void 0}),C.label)},onContextMenu:_,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:M=>$(M,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:k,disableIconFlip:f,isPlaceholder:D=!1,placeHolderText:F=void 0,onRightClick:E=()=>{},disableDefaultRightClickBehaviour:B=!1})=>{const[N,_]=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)"},"& .MuiOutlinedInput-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:k,renderInput:u=>o.jsx(r.TextField,h(b(h({"data-testid":c?`${c}:Autocomplete:TextField`:void 0},u),{variant:d,label:n,color:l,error:a,helperText:A,placeholder:F}),$)),isOptionEqualToValue:(u,x)=>u.id===x.id,onInputChange:(u,x)=>{_(x)},renderOption:(u,x)=>j.createElement("li",b(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 k=localStorage.getItem("auth0_redirect_count");k?k&&parseInt(k)<2&&(localStorage.setItem("auth0_redirect_count",String(parseInt(k)+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(b(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)),k=(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)),F=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})},_=($=p.current[0])!=null?$:h({},ue),I={};"autoHideDuration"in _&&(I.autoHideDuration=_.autoHideDuration);const L=h(h({},ht),s),O=h(h({open:a,setOpen:S,enqueueNotification:A,enqueueSuccessNotification:v,enqueueInfoNotification:k,enqueueWarningNotification:f,enqueueErrorNotification:D,removeNotification:F},e),t);return o.jsxs(te.Provider,{value:O,children:[i,o.jsx(r.Snackbar,b(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:_.severity,variant:"filled",icon:_.progressIndicator==="circular"?o.jsx(r.CircularProgress,{size:"1em"}):void 0,style:_.progressIndicator==="linear"?gt:void 0,children:_.message}),_.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,b(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),ke=y.atom(e=>e(me),(e,t,n)=>{t(me,n),localStorage.setItem(De,JSON.stringify({domainCode:n}))}),Fe={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=Fe[e])!=null?t:""},vt=({isLoading:e,isOpen:t,onClose:n,onDomainChange:i,domainOptions:s,applicationName:l,handleLogout:d})=>{const[a,c]=y.useAtom(ke),[p,g]=j.useState(a),{enqueueSuccessNotification:w}=we(),S=s.length===0,A=!!a&&!s.includes(a)&&!s.includes(p),v=!a||S||A,k=()=>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:k,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:(F,E)=>g(E!=null?E:""),getOptionLabel:ne,options:[...s.toSorted()],renderInput:F=>o.jsx(r.TextField,b(h({},F),{variant:"filled",label:"Select organisation",InputProps:b(h({},F.InputProps),{endAdornment:o.jsxs(o.Fragment,{children:[e?o.jsx(r.CircularProgress,{color:"inherit",size:20,sx:{marginTop:"-20px"}}):null,F.InputProps.endAdornment]})})}))}),D&&o.jsx(r.FormHelperText,{error:!0,children:D})]})},be=()=>{const e=r.useTheme();return r.useMediaQuery(e.breakpoints.down("sm"))},yt=64,jt=72,wt=256,W=y.atom(!0),_e=y.atom(wt),Ee=y.atom(jt),Y=y.atom(""),Te=y.atom(void 0),Ie=y.atom(yt),Me=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`},kt=P.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}),Ft=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))},Pe=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")},Pe(e)),xe=(e,t)=>h({width:t,transition:q(e,"width","leaving")},Pe(e)),bt=P.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&&b(h({},fe(e,n)),{backgroundColor:"","& .MuiDrawer-paper":fe(e,n)})),!t&&b(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 _t(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 Mt(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 Pt({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(Ft,{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=be(),w=y.useSetAtom(W);return o.jsx(kt,{className:H.root,"data-testid":i,children:o.jsxs(bt,{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(Pt,{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=be();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(_e),[v]=y.useAtom(Ee),k=y.useAtomValue(Y),[f]=y.useAtom(Ie),[D]=y.useAtom(Te),[F]=y.useAtom(Me);return o.jsxs(ce.default,{children:[o.jsx(tt.default,{}),o.jsx($t,{titleText:k,"data-testid":l,height:f,middle:D}),o.jsxs(ce.default,{sx:{display:"flex"},children:[o.jsx(Bt,{open:S,top:F,middle:a,bottom:c,user:p,domainCode:g,widthOpen:A,widthClosed:v,offsetTop:f,"data-testid":d,useNewAvatar:w}),o.jsx(Nt,b(h({"data-testid":s,topBarHeight:f},i),{children:e}))]})]})}const qt=P.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=P.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:P.alpha(e.palette.secondary.main,e.palette.action.selectedOpacity),"&:hover":{backgroundColor:P.alpha(e.palette.secondary.main,e.palette.action.selectedOpacity)},"&.Mui-focusVisible":{backgroundColor:P.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=Fe;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=_t;exports.domainCodeAtom=ke;exports.fed21Theme=qt;exports.getAuth0Expiry=ye;exports.getDomainOptionLabel=ne;exports.getValidBusinessRoles=Tt;exports.internalAgSystemsTheme=Ut;exports.navBarOpenAtom=W;exports.navBarTopAtom=Me;exports.navBarWidthClosedAtom=Ee;exports.navBarWidthOpenAtom=_e;exports.simpleHashCode=Ne;exports.suppressConsole=It;exports.titleTextAtom=Y;exports.topBarHeightAtom=Ie;exports.topBarMiddleAtom=Te;exports.unsuppressConsole=Mt;exports.useAutocompleteOptions=ee;exports.useSaladBar=we;exports.useValidDomains=Et;exports.withSaladBarProvider=St;
2
2
  //# sourceMappingURL=index.cjs.map