import{c,b as o,s as h}from"./dc0o8kHW.js";import{t as y}from"./HL7kq492.js";async function S(){return c.get("/admin-next/preferences")}async function v(e){return c.patch("/admin-next/preferences/user",e)}async function x(){return c.delete("/admin-next/preferences/user")}async function T(e){return c.patch("/admin-next/preferences/site",e)}async function w(e){return c.patch("/admin-next/branding",e)}async function P(e,n){return c.uploadFile(`/admin-next/branding/logo?variant=${e}`,n,{fieldName:"file"})}async function k(e){return c.delete(`/admin-next/branding/logo?variant=${e}`)}const m=200;let t={},r=null,a=null,s=0,u=0;const f=new Set;function F(e,n){t[e]=n,r!==null&&clearTimeout(r),r=setTimeout(()=>{d()},m)}async function E(){return r!==null&&(clearTimeout(r),r=null),d()}async function d(){if(r=null,Object.keys(t).length===0)return null;const e=t;return t={},a=(async()=>{try{const n=await v(e);s=0;for(const i of f)try{i(n)}catch{}return n}catch(n){s++,console.error("[preferences] sync failed:",n);const i=Date.now();return s>=2&&i-u>3e4&&(u=i,y.error("Preferences are not syncing to the server. Changes you make won't carry over to other devices.")),t={...e,...t},null}finally{a=null}})(),a}function l(){if(r!==null&&(clearTimeout(r),r=null),Object.keys(t).length===0)return;const e=t;t={};const n=`${o.serverUrl}${o.apiPrefix||"/api/v1"}/admin-next/preferences/user`,i={"Content-Type":"application/json",Accept:"application/json"};o.accessToken&&(i["X-API-Token"]=o.accessToken),i["X-Grav-Environment"]=o.gravEnvironment;try{fetch(n,{method:"PATCH",headers:i,body:JSON.stringify(e),keepalive:!0}).catch(()=>{t={...e,...t}})}catch{t={...e,...t}}}typeof window<"u"&&(window.addEventListener("pagehide",l),document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&l()}));function O(e){return f.add(e),()=>f.delete(e)}function U(){return Object.keys(t).length>0||a!==null}const g=h("grav_admin_boot_cache");function j(e){if(!(typeof localStorage>"u"))try{const n={colorMode:e.effective.colorMode,accentHue:e.effective.accentHue,accentSaturation:e.effective.accentSaturation,fontFamily:e.effective.fontFamily,fontSize:e.effective.fontSize,editorMode:e.effective.editorMode,editorKeymap:e.effective.editorKeymap,editorStickyToolbar:e.effective.editorStickyToolbar,editorFixedHeight:e.effective.editorFixedHeight,branding:e.branding,brandingUrls:e.branding_urls};localStorage.setItem(g,JSON.stringify(n))}catch{}}function B(){if(typeof localStorage>"u")return null;try{const e=localStorage.getItem(g);if(!e)return null;const n=JSON.parse(e);return!n||typeof n!="object"?null:n}catch{return null}}export{T as a,w as b,v as c,k as d,E as f,S as g,U as h,B as l,O as o,F as q,x as r,j as s,P as u};
