import{i as e}from"./chunk-B3pr0VN8.js";import{n as t}from"./jsx-runtime-wTfS3W87.js";import{i as n,r}from"./appConfig-CuVl6yRs.js";import{o as i}from"./authSession-CrP9lMPq.js";import{r as a}from"./norm-CeclA1Tu.js";import{n as o,t as s}from"./webAppConfig-CqZlh029.js";var c=`https://bysjob.com`,l=()=>{try{if(String(globalThis?.location?.protocol||``)===`chrome-extension:`)return``}catch{}return o()},u=e=>{let t=a(e),n=t.startsWith(`#`)?t.slice(1):t,r=n.startsWith(`/`)?n:`/${n}`;try{if(String(globalThis?.location?.protocol||``)===`chrome-extension:`){let e=globalThis?.chrome?.runtime;if(e?.getURL)return`${String(e.getURL(`index.html`)||``).trim()}#${r}`}}catch{}let i=l();if(i)return`${i}${r}`;try{let e=globalThis?.chrome?.runtime;if(e?.getURL)return`${String(e.getURL(`index.html`)||``).trim()}#${r}`}catch{}try{let e=String(globalThis?.location?.protocol||``),t=String(globalThis?.location?.origin||``);if(e===`chrome-extension:`&&t)return`${t.replace(/\/+$/g,``)}/index.html#${r}`}catch{}return r},d=async e=>{let t=a(e)||`/`,n=t.startsWith(`/`)?t:`/${t}`,r=await s()||c;return`${String(r||c).replace(/\/+$/g,``)}${n}`},f=(e,t)=>{let n=a(e);if(!n)return;let r=typeof t?.active==`boolean`?t.active:!0;try{let e=chrome?.tabs;if(e?.create){e.create({url:n,active:r});return}}catch{}try{window.open(n,`_blank`,`noopener,noreferrer`)}catch{}},p=()=>{try{return String(chrome?.runtime?.id||``).trim()}catch{return``}},m=e=>{let t=[...Array.isArray(e?.expectSkus)?e.expectSkus:[],...typeof e?.expectSku==`string`?[e.expectSku]:[]].map(e=>String(e||``).trim()).filter(Boolean);return Array.from(new Set(t))},h=(e=`/me`)=>{let t=p();return`/auth?source=extension&extRelay=${encodeURIComponent(t)}&returnTo=${encodeURIComponent(String(e||`/me`))}`},g=e=>{let t=p();return`/plugin-checkout?product=plugin&sku=${encodeURIComponent(String(e||``).trim())}&return=extension&extId=${encodeURIComponent(t)}`},_=(e,t)=>{f(e,t)},v=async(e,t)=>{let n=await d(e);return _(n,t),n},y=async e=>v(h(e?.returnTo||`/me`),{active:e?.active}),b=async e=>v(`/me`,e),x=async(e,t)=>v(g(e),t),S=async e=>{let t=Number(e);return n(Number.isFinite(t)&&t>0?{type:`TOGGLE_SIDE_PANEL`,payload:{tabId:t}}:{type:`TOGGLE_SIDE_PANEL`},12e3)},C=async(e,t)=>{let i=m(t),a=await n({type:`REFRESH_ENTITLEMENTS`,reason:e,expectSku:i[0]||void 0,expectSkus:i.length?i:void 0},Math.max(800,Number(t?.timeoutMs||25e3)));return a.success&&r({type:`BILLING_POINTS_UPDATED`,reason:e}),a},w=async e=>{await i(e),r({type:`ENTITLEMENTS_UPDATED`}),r({type:`BILLING_POINTS_UPDATED`,reason:`logout`})},T=e(t(),1),E=3e4,D=Math.floor(3*6e4/E);function O(e,t=!0){(0,T.useEffect)(()=>{if(!t)return;let n=!0,r=0,i=null,a=async()=>{if(n){try{await e(!0)}catch{}r+=1,r>=D&&i&&(globalThis.clearInterval(i),i=null)}};a(),i=globalThis.setInterval(()=>{a()},E);let o=()=>{typeof document>`u`||document.visibilityState===`visible`&&(r=0,a(),i||=globalThis.setInterval(()=>{a()},E))};try{document?.addEventListener?.(`visibilitychange`,o)}catch{}return()=>{n=!1,i&&=(globalThis.clearInterval(i),null);try{document?.removeEventListener?.(`visibilitychange`,o)}catch{}}},[e,t])}export{b as a,S as c,y as i,u as l,w as n,x as o,_ as r,C as s,O as t,f as u};