import{useEffect as S,useMemo as c,useState as f}from"react";import{useLocation as A}from"react-router-dom";import{useThemeConfig as w}from"@redocly/theme/core/hooks";import{usePageData as B}from"../../providers/page-data/hooks";import{getBannerForSlug as D,getNextBannerTransition as T,isBannerWithinTimeRange as h}from"./utils/match-banner-target.js";const u="redocly-dismissed-banners",x=2**31-1;function E(){if(typeof window>"u")return new Set;const n=localStorage.getItem(u);if(n){const a=JSON.parse(n);if(Array.isArray(a))return new Set(a)}return new Set}function C(){const{banner:n}=w()||{},t=B()?.props?.frontmatter?.banner,d=A(),[o,g]=f(E()),[s,p]=f(()=>Date.now()),i=d.pathname,m=c(()=>{const r=Array.isArray(n)?n:[],e=Array.isArray(t)?t:[];return[...r,...e]},[n,t]);return S(()=>{const r=T(m,s);if(r===void 0)return;const e=r-Date.now(),y=Math.min(Math.max(0,e),x),l=setTimeout(()=>p(Date.now()),y);return()=>clearTimeout(l)},[m,s]),{banner:c(()=>{const r=(Array.isArray(t)?t:[]).find(e=>!o.has(e.hash)&&h(e,s));if(r)return r;if(!(!n||!Array.isArray(n)||n.length===0))return D(n,i,o,s)},[n,t,i,o,s]),dismissBanner:r=>{const e=new Set(o);e.add(r),g(e),localStorage.setItem(u,JSON.stringify(Array.from(e)))}}}export{u as STORAGE_KEY,E as getDismissedBannersFromStorage,C as useBanner};
