import{i as l,m as y,g as e,j as s}from"./BfUaJvxP.js";import{b as i,s as b}from"./CF1ujZlL.js";async function h(){return i.get("/languages")}async function T(t,r){const n=t.startsWith("/")?t.slice(1):t;return i.post(`/pages/${n}/translate`,r)}async function W(t,r){const n=t.startsWith("/")?t.slice(1):t;return i.post(`/pages/${n}/adopt-language`,{lang:r})}async function $(t,r,n){const c=t.startsWith("/")?t.slice(1):t;return i.post(`/pages/${c}/sync`,{source_lang:r,target_lang:n})}const L=b("grav_admin_content_lang");function R(){try{const t=localStorage.getItem(L);return t?JSON.parse(t):{}}catch{return{}}}function I(){const t=R();let r=l(!1),n=l(y([])),c=l(""),g=l(y(t.activeLang??"")),u=l(!1),f=l(!1);function p(){localStorage.setItem(L,JSON.stringify({activeLang:e(g)}))}async function m(){if(!e(u)){s(u,!0);try{const a=await h();s(r,a.enabled,!0),s(n,a.languages,!0),s(c,a.default??"",!0);const o=a.languages.map(d=>d.code);(!e(g)||!o.includes(e(g)))&&s(g,e(c),!0),p(),s(f,!0)}catch{s(r,!1),s(f,!0)}finally{s(u,!1)}}}function S(a){s(g,a,!0),p()}function v(a){const o=e(n).find(d=>d.code===a);return o?.native_name??o?.name??a}function _(a){return e(n).find(o=>o.code===a)}return{get enabled(){return e(r)},get languages(){return e(n)},get defaultLang(){return e(c)},get activeLang(){return e(g)},get loading(){return e(u)},get loaded(){return e(f)},get isDefault(){return e(g)===e(c)},load:m,setLanguage:S,getLanguageName:v,getLanguageInfo:_}}const w=I();export{W as a,T as b,w as c,$ as s};
