import{i as e}from"./jsx-runtime-CutOxEx1.js";var t=e=>String(e?.message||e||`unknown_error`),n=()=>{try{return String(chrome.runtime?.lastError?.message||``).trim()}catch{return``}},r=e=>{let t=String(e||``).toLowerCase();return t.includes(`message port closed`)||t.includes(`before a response was received`)||t===`timeout`||t===`empty_response`||t.includes(`could not establish connection`)||t.includes(`receiving end does not exist`)},i=async(e,r)=>new Promise(i=>{let a=!1,o=globalThis.setTimeout(()=>{a||(a=!0,i({success:!1,error:`timeout`}))},Math.max(800,r));try{chrome.runtime.sendMessage(e,e=>{let t=n();if(!a){if(a=!0,globalThis.clearTimeout(o),t){i({success:!1,error:String(t)});return}if(!e||typeof e!=`object`){i({success:!1,error:`empty_response`});return}i(e)}})}catch(e){if(a)return;a=!0,globalThis.clearTimeout(o),i({success:!1,error:t(e)})}}),a=async(e,t=12e3)=>{let n={success:!1,error:`empty_response`};for(let a=0;a<3;a++){if(n=await i(e,t),n.success||!r(String(n.error||``)))return n;a<2&&await new Promise(e=>globalThis.setTimeout(e,220*(a+1)))}return n},o=async(e,r,i=12e3)=>new Promise(a=>{let o=!1,s=globalThis.setTimeout(()=>{o||(o=!0,a({success:!1,error:`timeout`}))},Math.max(800,i));try{chrome.tabs.sendMessage(e,r,e=>{let t=n();if(!o){if(o=!0,globalThis.clearTimeout(s),t){a({success:!1,error:String(t)});return}if(!e||typeof e!=`object`){a({success:!1,error:`empty_response`});return}a(e)}})}catch(e){if(o)return;o=!0,globalThis.clearTimeout(s),a({success:!1,error:t(e)})}}),s=e=>{try{chrome.runtime?.sendMessage?.(e,()=>{n()})}catch{}},c={version:1,privacy:{maskEnabled:!0,maskPhoneNumber:!0,maskEmail:!0,maskIdNumber:!0,maskBankNumber:!0,maskUrl:!1,allowFeedbackScreenshot:!1,cloudClipsSyncEnabled:!0,cloudClipsUploadImages:!0},sites:{boss:{enabled:!0,matches:[`*://*.zhipin.com/*`]}},ui:{preferSidePanel:!0,jobSeekerMinimalMode:!1}},l=e({getAppConfig:()=>_,setAppConfig:()=>v}),u=`offer_lens_app_config_v1`,d=e=>e&&typeof e==`object`&&!Array.isArray(e),f=e=>{try{return e?JSON.parse(e):null}catch{return null}},p=()=>globalThis?.chrome?.storage?.local,m=(e,t)=>{if(!d(e))return d(t)?{...t}:e;if(!d(t))return{...e};let n={...e};for(let r of Object.keys(t)){let i=t[r],a=e[r];n[r]=d(a)&&d(i)?m(a,i):i}return n},h=e=>new Promise(t=>{let n=!1,r=e=>{n||(n=!0,t(e))},i=()=>{try{let t=f(String(localStorage.getItem(u)||``));r(t&&typeof t==`object`?t:e)}catch{r(e)}};try{let t=p();if(t?.get){let n=setTimeout(()=>i(),450);t.get({[u]:e},t=>{clearTimeout(n);let i=t?.[u];r(i&&typeof i==`object`?i:e)});return}}catch{}i()}),g=e=>new Promise((t,n)=>{try{let r=p();if(r?.set){r.set({[u]:e},()=>{let e=globalThis?.chrome?.runtime?.lastError;e?n(e):t()});return}}catch{}try{localStorage.setItem(u,JSON.stringify(e??{})),t()}catch(e){n(e)}}),_=async()=>m(c,await h(c)),v=async e=>{await g(m(await _(),e)),s({type:`SETTINGS_UPDATED`})};export{o as a,a as i,_ as n,s as r,l as t};