1import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,Bt as n,Ct as r,Jt as i,Mt as a,Pn as o,at as s,c,et as l,f as u,gn as d,i as f,m as p,n as m,nt as h,on as g,sn as ee,un as _,yn as v}from"./vendor-icons-BaJ3n9Nn.js";import{P as y}from"./vendor-radix-core-CqfRsY-I.js";import{C as b,D as x,E as S,_ as C,a as w,b as T,d as E,g as D,h as O,i as k,l as te,m as A,o as j,r as M,t as ne,u as N}from"./query-CSj0fYYf.js";import{t as P}from"./env-TxWn27KL.js";import{a as re}from"./vendor-router-q3A2qVfm.js";import{n as ie}from"./use-toast-BjSY6eyf.js";import{t as F}from"./authService-N43c8Nx4.js";import{t as I}from"./authedFetch-sYUUrXgb.js";import{t as L}from"./propertyApiService-B29DasdI.js";var R=class extends M{#e;#t;#n;#r;constructor(e){super(),this.#e=e.client,this.mutationId=e.mutationId,this.#n=e.mutationCache,this.#t=[],this.state=e.state||z(),this.setOptions(e.options),this.scheduleGc()}setOptions(e){this.options=e,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(e){this.#t.includes(e)||(this.#t.push(e),this.clearGcTimeout(),this.#n.notify({type:`observerAdded`,mutation:this,observer:e}))}removeObserver(e){this.#t=this.#t.filter(t=>t!==e),this.scheduleGc(),this.#n.notify({type:`observerRemoved`,mutation:this,observer:e})}optionalRemove(){this.#t.length||(this.state.status===`pending`?this.scheduleGc():this.#n.remove(this))}continue(){return this.#r?.continue()??this.execute(this.state.variables)}async execute(e){let t=()=>{this.#i({type:`continue`})},n={client:this.#e,meta:this.options.meta,mutationKey:this.options.mutationKey};this.#r=k({fn:()=>this.options.mutationFn?this.options.mutationFn(e,n):Promise.reject(Error(`No mutationFn found`)),onFail:(e,t)=>{this.#i({type:`failed`,failureCount:e,error:t})},onPause:()=>{this.#i({type:`pause`})},onContinue:t,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>this.#n.canRun(this)});let r=this.state.status===`pending`,i=!this.#r.canStart();try{if(r)t();else{this.#i({type:`pending`,variables:e,isPaused:i}),this.#n.config.onMutate&&await this.#n.config.onMutate(e,this,n);let t=await this.options.onMutate?.(e,n);t!==this.state.context&&this.#i({type:`pending`,context:t,variables:e,isPaused:i})}let a=await this.#r.start();return await this.#n.config.onSuccess?.(a,e,this.state.context,this,n),await this.options.onSuccess?.(a,e,this.state.context,n),await this.#n.config.onSettled?.(a,null,this.state.variables,this.state.context,this,n),await this.options.onSettled?.(a,null,e,this.state.context,n),this.#i({type:`success`,data:a}),a}catch(t){try{await this.#n.config.onError?.(t,e,this.state.context,this,n)}catch(e){Promise.reject(e)}try{await this.options.onError?.(t,e,this.state.context,n)}catch(e){Promise.reject(e)}try{await this.#n.config.onSettled?.(void 0,t,this.state.variables,this.state.context,this,n)}catch(e){Promise.reject(e)}try{await this.options.onSettled?.(void 0,t,e,this.state.context,n)}catch(e){Promise.reject(e)}throw this.#i({type:`error`,error:t}),t}finally{this.#n.runNext(this)}}#i(e){let t=t=>{switch(e.type){case`failed`:return{...t,failureCount:e.failureCount,failureReason:e.error};case`pause`:return{...t,isPaused:!0};case`continue`:return{...t,isPaused:!1};case`pending`:return{...t,context:e.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:e.isPaused,status:`pending`,variables:e.variables,submittedAt:Date.now()};case`success`:return{...t,data:e.data,failureCount:0,failureReason:null,error:null,status:`success`,isPaused:!1};case`error`:return{...t,data:void 0,error:e.error,failureCount:t.failureCount+1,failureReason:e.error,isPaused:!1,status:`error`}}};this.state=t(this.state),j.batch(()=>{this.#t.forEach(t=>{t.onMutationUpdate(e)}),this.#n.notify({mutation:this,type:`updated`,action:e})})}};function z(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:`idle`,variables:void 0,submittedAt:0}}var B=class extends x{constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#n=0}#e;#t;#n;build(e,t,n){let r=new R({client:e,mutationCache:this,mutationId:++this.#n,options:e.defaultMutationOptions(t),state:n});return this.add(r),r}add(e){this.#e.add(e);let t=V(e);if(typeof t==`string`){let n=this.#t.get(t);n?n.push(e):this.#t.set(t,[e])}this.notify({type:`added`,mutation:e})}remove(e){if(this.#e.delete(e)){let t=V(e);if(typeof t==`string`){let n=this.#t.get(t);if(n){if(n.length>1){let t=n.indexOf(e);t!==-1&&n.splice(t,1)}else n[0]===e&&this.#t.delete(t)}}}this.notify({type:`removed`,mutation:e})}canRun(e){let t=V(e);if(typeof t==`string`){let n=this.#t.get(t)?.find(e=>
1e.state.status===`pending`);return!n||n===e}return!0}runNext(e){let t=V(e);return typeof t==`string`?(this.#t.get(t)?.find(t=>t!==e&&t.state.isPaused))?.continue()??Promise.resolve():Promise.resolve()}clear(){j.batch(()=>{this.#e.forEach(e=>{this.notify({type:`removed`,mutation:e})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(e){let t={exact:!0,...e};return this.getAll().find(e=>A(t,e))}findAll(e={}){return this.getAll().filter(t=>A(e,t))}notify(e){j.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>e.state.isPaused);return j.batch(()=>Promise.all(e.map(e=>e.continue().catch(D))))}};function V(e){return e.options.scope?.id}var H=class extends x{constructor(e={}){super(),this.config=e,this.#e=new Map}#e;build(e,t,n){let r=t.queryKey,i=t.queryHash??E(r,t),a=this.get(i);return a||(a=new ne({client:e,queryKey:r,queryHash:i,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(r)}),this.add(a)),a}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:`added`,query:e}))}remove(e){let t=this.#e.get(e.queryHash);t&&(e.destroy(),t===e&&this.#e.delete(e.queryHash),this.notify({type:`removed`,query:e}))}clear(){j.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){let t={exact:!0,...e};return this.getAll().find(e=>O(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>O(e,t)):t}notify(e){j.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){j.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){j.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},U=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e={}){this.#e=e.queryCache||new H,this.#t=e.mutationCache||new B,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#a=0}mount(){this.#a++,this.#a===1&&(this.#o=S.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#s=w.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#a--,this.#a===0&&(this.#o?.(),this.#o=void 0,this.#s?.(),this.#s=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:`fetching`}).length}isMutating(e){return this.#t.findAll({...e,status:`pending`}).length}getQueryData(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){let t=this.defaultQueryOptions(e),n=this.#e.build(this,t),r=n.state.data;return r===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(T(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:e,state:t})=>[e,t.data])}setQueryData(e,t,n){let r=this.defaultQueryOptions({queryKey:e}),i=this.#e.get(r.queryHash)?.state.data,a=te(t,i);if(a!==void 0)return this.#e.build(this,r).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return j.batch(()=>this.#e.findAll(e).map(({queryKey:e})=>[e,this.setQueryData(e,t,n)]))}getQueryState(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){let t=this.#e;j.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let n=this.#e;return j.batch(()=>(n.findAll(e).forEach(e=>{e.reset()}),this.refetchQueries({type:`active`,...e},t)))}cancelQueries(e,t={}){let n={revert:!0,...t},r=j.batch(()=>this.#e.findAll(e).map(e=>e.cancel(n)));return Promise.all(r).then(D).catch(D)}invalidateQueries(e,t={}){return j.batch(()=>(this.#e.findAll(e).forEach(e=>{e.invalidate()}),e?.refetchType===`none`?Promise.resolve():this.refetchQueries({...e,type:e?.refetchType??e?.type??`active`},t)))}refetchQueries(e,t={}){let n={...t,cancelRefetch:t.cancelRefetch??!0},r=j.batch(()=>this.#e.findAll(e).filter(e=>!e.isDisabled()&&!e.isStatic()).map(e=>{let t=e.fetch(void 0,n);return n.throwOnError||(t=t.catch(D)),e.state.fetchStatus===`paused`?Promise.resolve():t}));return Promise.all(r).then(D)}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t);return n.isStaleByTime(T(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(D).catch(D)}fetchInfiniteQuery(e){return e._type=`infinite`,this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(D).catch(D)}ensureInfiniteQueryData(e){return e._type=`infinite`,this.ensureQueryData(e)}resumePausedMutations(){return w.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(e){this.#n=e}setQueryDefaults(e,t){this.#r.set(N(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],n={};return t.forEach(t=>{C(e,t.queryKey)&&Object.assign(n,t.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(N(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],n={};return t.forEach(t=>{C(e,t.mutationKey)&&Object.assign(n,t.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;let t={...this.#n.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||=E(t.queryKey,t),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!==`always`),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode=`offlineFirst`),t.queryFn===b&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#n.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}},W=e(o(),1),G=new U({defaultOptions:{queries:{staleTime:3e5,retry:1,refetchOnWindowFocus:!1}}}),ae=`modulepreload`,oe=function(e){return`/`+e},K={},q=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=oe(t,n),t=s(t),t in K)return;K[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:ae,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n
1)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};function J(){return Promise.resolve(null)}function se(){try{localStorage.getItem(`vs_consent_v1`)===`granted`&&J()}catch{}}function Y(e,t){J().then(n=>{n&&n.capture(e,t)})}var X={user:0,agent:0,admin:10,super_admin:20},ce=-1;function le(e){let t=(e??``).trim().toLowerCase();return t in X?X[t]:ce}function Z(e,t){return t in X&&le(e)>=X[t]}var ue=new Set([`admin`,`super_admin`]);function de(e,t){return t?ue.has(t)?Z(e,t):(e??``).trim().toLowerCase()===t||Z(e,`admin`):!0}function Q(e){return Z(e,`super_admin`)?`/super-admin`:Z(e,`admin`)?`/admin`:`/overview`}var fe=`[email protected]`;function pe(e){return(e||``).trim().toLowerCase()===fe}function me(e){return Z(e,`super_admin`)}function he(e){let[t,n]=(0,W.useState)([]),[r,i]=(0,W.useState)(!1),a=(0,W.useCallback)(async()=>{if(!e){n([]);return}i(!0);try{let e=await I(`${P()}/feedback-conversation/requests/pending`);if(!e.ok){n([]);return}let t=await e.json();n(Array.isArray(t?.requests)?t.requests:[])}catch{n([])}finally{i(!1)}},[e]);return(0,W.useEffect)(()=>{a()},[a]),{requests:t,isLoading:r,refresh:a,dismiss:(0,W.useCallback)(e=>{n(t=>t.filter(t=>t.id!==e))},[])}}var ge=[`agent`,`admin`,`super_admin`];function $(e){return ge.includes((e||``).toLowerCase())}function _e(e,t){return t===`client`&&$(e)?`user`:e??void 0}async function ve({fetchMe:e,onImage:t}){let n;try{n=await e()}catch{return}let r=n?.data?.profile_image_url;if(typeof r==`string`&&r!==``){t(r);try{localStorage.setItem(`user_profile_image_url`,r)}catch{}}}var ye=class e{constructor(){this.CACHE_PREFIX=`vs_cache_`,this.DEFAULT_TTL=18e5}static getInstance(){return e.instance||=new e,e.instance}shouldSkipCache(){try{return localStorage.getItem(`user_role`)!==`agent`}catch{return!0}}isPageRefresh(){let e=sessionStorage.getItem(`vs_nav_type_checked`);if(typeof window<`u`&&window.performance)try{let t=window.performance.getEntriesByType(`navigation`)[0];if(t){let n=Number(t.type)===1;return e||(sessionStorage.setItem(`vs_is_refresh`,n?`true`:`false`),sessionStorage.setItem(`vs_nav_type_checked`,`true`)),n}}catch{}let t=sessionStorage.getItem(`vs_is_refresh`);return t!==null&&t===`true`}markPageLoad(){this.shouldSkipCache()||this.isPageRefresh()}resetNavigationCheck(){sessionStorage.removeItem(`vs_nav_type_checked`),sessionStorage.removeItem(`vs_is_refresh`)}get(e){if(this.shouldSkipCache())return null;try{let t=`${this.CACHE_PREFIX}${e}`,n=sessionStorage.getItem(t);if(!n)return null;let r=JSON.parse(n);return Date.now()>r.expiresAt?(sessionStorage.removeItem(t),null):r.data}catch(t){return console.error(`Error reading cache for key ${e}:`,t),null}}set(e,t,n){if(!this.shouldSkipCache())try{let r=`${this.CACHE_PREFIX}${e}`,i=Date.now(),a={data:t,timestamp:i,expiresAt:i+(n||this.DEFAULT_TTL)};sessionStorage.setItem(r,JSON.stringify(a))}catch(t){console.error(`Error setting cache for key ${e}:`,t),t instanceof DOMException&&t.name===`QuotaExceededError`&&this.clearExpired()}}has(e){let t=`${this.CACHE_PREFIX}${e}`,n=sessionStorage.getItem(t);if(!n)return!1;try{let e=JSON.parse(n);return Date.now()>e.expiresAt?(sessionStorage.removeItem(t),!1):!0}catch{return!1}}remove(e){let t=`${this.CACHE_PREFIX}${e}`;sessionStorage.removeItem(t)}clear(){Object.keys(sessionStorage).forEach(e=>{e.startsWith(this.CACHE_PREFIX)&&sessionStorage.removeItem(e)})}clearExpired(){let e=Object.keys(sessionStorage),t=Date.now();e.forEach(e=>{if(e.startsWith(this.CACHE_PREFIX))try{let n=sessionStorage.getItem(e);if(n){let r=JSON.parse(n);t>r.expiresAt&&sessionStorage.removeItem(e)}}catch{sessionStorage.removeItem(e)}})}async getOrFetch(e,t,n,r=!1){if(this.shouldSkipCache())return await t();if(this.isPageRefresh()||r){this.remove(e);let r=await t();return this.set(e,r,n),sessionStorage.setItem(`vs_is_refresh`,`false`),r}let i=this.get(e);if(i!==null)return i;let a=await t();return this.set(e,a,n),a}
1async fetchWithoutCache(e){return e()}invalidatePattern(e){Object.keys(sessionStorage).forEach(t=>{t.startsWith(this.CACHE_PREFIX)&&t.includes(e)&&sessionStorage.removeItem(t)})}}.getInstance(),be=[{title:`Core`,items:[{key:`overview`,label:`Overview`,href:`/overview`,icon:r},{key:`listings`,label:`My Listings`,href:`/listings`,icon:d,aliases:[`/agent-dashboard`]},{key:`showings`,label:`Showings`,href:`/agent-showings`,icon:_,badge:`showings`},{key:`offers`,label:`Offers`,href:`/agent-offers`,icon:a,badge:`offers`},{key:`reports`,label:`Reports`,href:`/reports`,icon:g},{key:`messages`,label:`Messages`,href:`/messages`,icon:l,badge:`messages`}]},{title:`Lead Management`,items:[{key:`leads`,label:`Leads`,href:`/leads`,icon:u},{key:`feedback`,label:`Feedback`,href:`/feedback`,icon:t},{key:`email-templates`,label:`Email Templates`,href:`/email-templates`,icon:s}]},{title:`Collaboration`,items:[{key:`teams`,label:`Teams`,href:`/teams`,icon:m},{key:`blaster`,label:`Open-House Blaster`,href:`/open-house-blaster`,icon:h},{key:`knowledge`,label:`Knowledge Base`,href:`/knowledge-base`,icon:v}]},{title:`Account`,items:[{key:`billing`,label:`Billing`,href:`/billing`,icon:n},{key:`profile`,label:`Profile`,href:`/profile`,icon:f},{key:`edit-profile`,label:`Edit Profile`,href:`/agent-profile-edit`,icon:c},{key:`trash`,label:`Trash`,href:`/trash`,icon:p},{key:`help`,label:`Help & Guide`,href:`/user-guide`,icon:i}]}],xe=[{items:[{key:`overview`,label:`Overview`,href:`/overview`,icon:r},{key:`agents`,label:`Find Agents`,href:`/agents`,icon:m,aliases:[`/dashboard`]},{key:`my-offers`,label:`My Offers`,href:`/my-offers`,icon:a,badge:`offers`},{key:`invitations`,label:`Invitations`,href:`/my-invitations`,icon:s,badge:`invitations`},{key:`messages`,label:`Messages`,href:`/messages`,icon:l,badge:`messages`}]},{title:`Account`,items:[{key:`profile`,label:`Profile`,href:`/profile`,icon:f},{key:`help`,label:`Help & Guide`,href:`/user-guide`,icon:i}]}],Se=[{items:[{key:`admin`,label:`Admin Dashboard`,href:`/admin`,icon:ee}]},...be.map(e=>({...e,items:e.items.filter(e=>e.key!==`overview`)}))],Ce=new Set([]);function we(e,t=!0){if(Z(e,`admin`))return Se;let n=e===`agent`?be:xe;return t?n:n.map(e=>({...e,items:e.items.filter(e=>!Ce.has(e.key))})).filter(e=>e.items.length>0)}function Te(e,t){for(let n of t)for(let t of n.items)if(t.href===e||t.aliases?.some(t=>t===e))return t}function Ee(e,t=!0){let n=we(e,t),r=[];for(let e of n)for(let t of e.items)r.push(t.href),t.aliases&&r.push(...t.aliases);return Z(e,`super_admin`)&&r.push(`/super-admin`),r}var De=y();function Oe(e){if(!e)return`agent`;try{return localStorage.getItem(`view_context_${e}`)===`client`?`client`:`agent`}catch{return`agent`}}var ke=(0,W.createContext)(void 0);function Ae({children:e}){let[t,n]=(0,W.useState)(!1),[r,i]=(0,W.useState)(!0),[a,o]=(0,W.useState)(null),[s,c]=(0,W.useState)(!1),[l,u]=(0,W.useState)(!1),[d,f]=(0,W.useState)(!1),[p,m]=(0,W.useState)(!1),[h,g]=(0,W.useState)(!1),[ee,_]=(0,W.useState)(`post_tour`),[v,y]=(0,W.useState)(void 0),{requests:b,refresh:x,dismiss:S}=he(t&&a?.user_role!==`agent`),[C,w]=(0,W.useState)(!1),[,T]=re(),{toast:E}=ie();(0,W.useEffect)(()=>{(async()=>{let e=F.isAuthenticated()&&F.isTokenValid();if(F.isAuthenticated()&&!e)try{e=await F.refreshSession()}catch{e=!1}if(n(e),e){let e=F.getUserData();o(e),F.fetchMe().then(t=>{if(t.success&&t.data){let n={...e,id:t.data.id||e?.id,email:t.data.email||e?.email,full_name:t.data.full_name??e?.full_name,zuid:t.data.zuid??e?.zuid,profile_image_url:t.data.profile_image_url??e?.profile_image_url,user_role:t.data.user_role||e?.user_role,onboarding_completed:!!t.data.onboarding_completed,tour_progress:t.data.tour_progress||{},email_verified:t.data.email_verified===void 0?e?.email_verified!==!1:!!t.data.email_verified};if(o(n),t.data.user_role)try{localStorage.setItem(`user_role`,t.data.user_role)}catch{}n.email_verified===!1&&window.location.pathname!==`/verify-email`&&window.location.replace(`/verify-email`),n.user_role===`agent`&&!n.onboarding_completed&&localStorage.getItem(`onboarding_skipped`)!==`true`&&w(!0)}}).catch(()=>{});let t=window.location.pathname,n=[`/privacy-policy`,`/terms-of-service`,`/cookie-policy`,`/subprocessors`,`/status`,`/reset-password`,`/about-us`,`/pricing`],r=[`/team-invite`,`/apply`,`/unsubscribe`,`/verify-email`,`/teams/accept`],a=_e(e?.user_role,Oe(e?.id)),s=Ee(a
1).some(e=>t===e||t.startsWith(e+`/`)),c=n.includes(t)||r.some(e=>t.startsWith(e)),l=t.startsWith(`/property/`),u=t.startsWith(`/agent/`),d=t===`/`||t===`/auth`||t===`/login`,f=new URLSearchParams(window.location.search);if(f.get(`feedback`)===`true`&&e?.user_role!==`agent`){let e=f.get(`type`);_(e===`non_tourer`?`non_tourer`:`post_tour`),g(!0);let t=window.location.pathname;window.history.replaceState({},``,t)}if(d||!s&&!c&&!l&&!u){T(Q(a)),i(!1);return}}else o(null);i(!1)})()},[]),(0,W.useEffect)(()=>{if(!t)return;let e=0,n=setInterval(async()=>{if(F.isTokenNearExpiry()&&await F.refreshSession()){e=0;return}if(F.isTokenValid())e=0;else{if(await F.refreshSession()){e=0;return}e+=1,e>=2&&P()}},6e4);return()=>clearInterval(n)},[t]),(0,W.useEffect)(()=>{if(!t)return;let e=async()=>{F.isTokenValid()||await F.refreshSession()};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[t]),(0,W.useEffect)(()=>{let e=e=>{if(!e.key)return;if(e.key===`user_profile_image_url`){o(t=>t&&{...t,profile_image_url:e.newValue||void 0});return}if(![`access_token`,`refresh_token`,`user_id`,`user_role`,`user_email`].includes(e.key))return;if(e.key===`access_token`&&e.newValue==null){F.reloadFromStorage(),n(!1),o(null);return}F.reloadFromStorage();let t=F.getUserData(),r=F.isAuthenticated();n(r),o(t)};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[]);let D=async(e,t)=>{let r=await F.login(e,t);if(r.mfaChallenge)return r;if(r.success){n(!0);let e=F.getUserData();o(e),ve({fetchMe:()=>F.fetchMe(),onImage:e=>o(t=>t&&{...t,profile_image_url:e})}),Y(`login_completed`,{role:e?.user_role}),E({title:`Login Successful`,description:`Welcome back!`});let t=sessionStorage.getItem(`return_url`);sessionStorage.removeItem(`return_url`);let r=e?.user_role||`user`,i=Q(r),a=e=>{if(!e.startsWith(`/`)||e.startsWith(`//`)||e.startsWith(`/\\`))return null;try{let t=new URL(e,window.location.origin);return t.origin===window.location.origin?t.pathname+t.search:null}catch{return null}},s=[`/overview`,`/dashboard`,`/agents`,`/my-offers`,`/my-invitations`,`/profile`,`/messages`,`/privacy-policy`,`/terms-of-service`,`/cookie-policy`,`/subprocessors`,`/status`,`/reset-password`,`/property/`,`/agent/`,`/team-invite`],c=[`/overview`,`/agent-dashboard`,`/listings`,`/agent-profile-edit`,`/agent-showings`,`/agent-offers`,`/open-house-blaster`,`/billing`,`/reports`,`/profile`,`/property/`,`/agent/`,`/messages`,`/knowledge-base`,`/leads`,`/teams`,`/email-templates`,`/team-invite`],l=i,u=t?a(t):null;if(u){let e=s.some(e=>e.endsWith(`/`)?u.startsWith(e):u===e||u.startsWith(e+`/`)||u.startsWith(e+`?`)),t=c.some(e=>e.endsWith(`/`)?u.startsWith(e):u===e||u.startsWith(e+`/`)||u.startsWith(e+`?`));(r===`user`&&e||r===`agent`&&t||r===`admin`&&(e||t||u.startsWith(`/admin`)))&&(l=u)}setTimeout(()=>T(l),150)}else{let t=r.message||``;if(t.includes(`EMAIL_NOT_VERIFIED`)||t.toLowerCase().includes(`verify your email`)){try{sessionStorage.setItem(`pending_verify_email`,e)}catch{}E({title:`Email not verified`,description:`Please check your inbox and click the verification link before logging in.`}),T(`/verify-email`)}}return r},O=async(e,t,n,r)=>{let i=await F.signup(e,t,n,r);if(i.success){Y(`signup_completed`,{role:r||`user`});try{sessionStorage.setItem(`pending_verify_email`,e)}catch{}E({title:`Check your email`,description:`We sent a verification link. Click it to activate your account.`}),setTimeout(()=>{T(`/verify-email`)},500)}else E({title:`Signup Failed`,description:i.message||`Signup failed. Please try again.`,variant:`destructive`});return i},k=async(e,t)=>{let n=t?.navigate!==!1;try{localStorage.setItem(`user_full_name`,e);let t=a?.id||``;t&&await L.updateProfile(t,e);let r={...a,full_name:e};o(r),n&&T(`/profile`),E({title:`Profile Completed`,description:`Your profile has been updated successfully!`})}catch{E({title:`Error`,description:`Failed to complete profile. Please try again.`,variant:`destructive`})}},te=()=>{c(!0),f(!0)},A=()=>{c(!1),f(!1),m(!0),setTimeout(()=>{m(!1)},100)},j=async(e,t)=>{try{u(!0);let n=a?.id||``;if(!n)throw Error(`User ID not available`);let r=await L.updateProfile(n,e,t);localStorage.setItem(`user_full_name`,r.data.full_name||e);let i={...a,full_name:r.data.full_name||e,email:r.data.email||a?.email};typeof r.data.profile_image_url==`string`&&(i.profile_image_url=r.data.profile_image_url,localStorage.setItem(`user_profile_image_url`,r.data.profile_image_url)),o(i);try{ye.remove(`user_profile_${n}`)}catch{}A(),E({title:`Profile Updated`,description:`Your profile has been updated successfully!`})}catch(e){throw E({title:`Error`,description:`Failed to update profile. Please try again.`,variant:`destructive`}),e}finally{u(!1)}},M=async(e,t)=>await D(e,t),ne=async(e,t,n,r)=>await O(e,t,n,r),N=async()=>{let e=await F.logout();n(!1),o(null),sessionStorage.removeItem(`oauth_needed`),sessionStorage.removeItem(`oauth_completed`),sessionStorage.removeItem(`admin_dashboard_snapshot_v1`),sessionStorage.removeItem(`agent_profile_exists`),sessionStorage.removeItem(`agent_profile_check_time`),sessionStorage.removeItem(`agent_profile_check_user`);let{default:t}=await q(async()=>{let{default:e}=await import(`./localStorageCache-Cec7spmf.js`);return{default:e}},[]);return t.clearAllCache(),G.clear(),T(`/auth`),e},P=async()=>{n(!1),o(null),sessionStorage.removeItem(`agent_profile_exists`),sessionStorage.removeItem(`agent_profile_check_time`),sessionStorage.removeItem(`agent_profile_check_user`);let{default:e}=await q(async()=>{let{default:e}=await import(`./localStorageCache-Cec7spmf.js`);return{default:e}},[]);e.clearAllCache(),G.clear(),E({title:`Session Expired`,description:`Your session has expired. Please log in again.`,variant:`destructive`}),setTimeout(()=>{T(`/auth`)},1e3),await F.handleTokenExpiration()},I=a?.id?`view_context_${a.id}`:null,[R,z]=(0,W.useState)(null),B=$(a?.user_role),V=R&&R.userId===(a?.id??null)?R.view:null,H=B?V??Oe(a?.id):`client`,U={viewContext:H,effectiveRole:_e(a?.user_role,H),canSwitchContext:B,setVie
1wContext:e=>{if(B){z({userId:a?.id??null,view:e});try{I&&localStorage.setItem(I,e)}catch{}}},isAuthenticated:t,isLoading:r,user:a,showEditProfile:s,isUpdatingProfile:l,isEditProfileOpen:d,justClosedEditProfile:p,login:M,signup:ne,logout:N,completeProfile:k,openEditProfile:te,closeEditProfile:A,updateProfile:j,getAuthHeaders:()=>F.getAuthHeaders(),getAccessToken:()=>F.getAccessToken(),getRefreshToken:()=>F.getRefreshToken(),handleTokenExpiration:P,showFeedback:h,feedbackType:ee,pendingFeedback:b,refreshPendingFeedback:x,dismissPendingFeedback:S,activeFeedbackId:v,openFeedback:(e,t)=>{e&&_(e),y(t);try{let e=a?.id||F.getUserId()||``;if(e){let t=`feedback_minimized_${e}`;sessionStorage.removeItem(t)}}catch{}g(!0)},closeFeedback:()=>g(!1),showOnboarding:C,completeOnboarding:async()=>{try{await F.completeOnboarding()}catch{}o(e=>e&&{...e,onboarding_completed:!0}),w(!1)},skipOnboarding:()=>{localStorage.setItem(`onboarding_skipped`,`true`),w(!1)}};return(0,De.jsx)(ke.Provider,{value:U,children:e})}function je(){let e=(0,W.useContext)(ke);if(e===void 0){try{console.warn(`useAuthContext called outside AuthProvider â returning safe defaults`)}catch{}return{isAuthenticated:!1,isLoading:!1,user:null,showEditProfile:!1,isUpdatingProfile:!1,isEditProfileOpen:!1,justClosedEditProfile:!1,login:async()=>({success:!1,message:`Not available`}),signup:async()=>({success:!1,message:`Not available`}),logout:async()=>({success:!0}),completeProfile:async()=>{},openEditProfile:()=>{},closeEditProfile:()=>{},updateProfile:async()=>{},getAuthHeaders:()=>({}),getAccessToken:()=>null,getRefreshToken:()=>null,handleTokenExpiration:async()=>{},showFeedback:!1,feedbackType:`post_tour`,pendingFeedback:[],refreshPendingFeedback:async()=>{},dismissPendingFeedback:()=>{},activeFeedbackId:void 0,openFeedback:(e,t)=>{},closeFeedback:()=>{},showOnboarding:!1,completeOnboarding:async()=>{},skipOnboarding:()=>{}}}return e}export{ye as a,Q as c,de as d,se as f,z as g,G as h,we as i,Z as l,q as m,je as n,$ as o,Y as p,Te as r,me as s,Ae as t,pe as u};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.