import{r as t,i as m,aC as L,u as M,av as O,au as E,c as U,g as K,H as A,aj as F,j as s,aD as G,A as B,R,am as W,aE as k,s as T,o as q,a5 as P,ah as z,aF as H,aG as Q,O as J}from"./index-e867d936.js";const V=(a,x)=>{const i=t.useCallback(()=>m.generalTranslations.getMany(a).then(({data:d})=>d.data),[a]),r=t.useMemo(()=>["generalTranslations",a],[a]),n=L(r,i,{enabled:!!a,...x});return t.useMemo(()=>({...n,key:r}),[n,r])},Y=()=>{const{t:a}=M(),x=O(),i=E(),r=U(),{lang:n}=K(),d=A(),[p,{open:y,close:v}]=F(!1),[b,g]=t.useState(!1),{data:l,isLoading:N,refetch:u}=V(n,{refetchOnMount:!p,refetchOnWindowFocus:!p}),[o,f]=t.useState(l),C=t.useMemo(()=>Object.entries(o||{}).sort(([e],[c])=>e.localeCompare(c)),[o]),S=t.useCallback(async(e,c)=>{f({...o||{},[e]:c})},[o]),j=async e=>{(l==null?void 0:l[e])!=o[e]&&(g(!0),await d({title:"Saving",message:a("Saving, please wait..."),successMessage:a("Key translated!")},async()=>{await m.generalTranslations.updateTranslation(e,o[e],n),await u(),g(!1),v()}))};t.useEffect(()=>{f(l)},[l]),t.useEffect(()=>{u()},[x]);const I=t.useCallback(e=>async()=>{if(confirm(a("Do you really want to delete this key for ALL languages?")))try{d({title:"Deleting",message:a("Deleting selected key, please wait..."),successMessage:a("Key deleted!")},async()=>{await m.generalTranslations.deleteKey(e),await u()})}catch{}},[a,u]),w=s.jsxs("tr",{children:[s.jsx("th",{children:a("Translation key")}),s.jsx("th",{className:"w-full max-w-[350px]",children:a("Translation value")}),s.jsx("th",{className:"w-full max-w-[100px] opacity-0",children:"Tools"})]}),D=C.map(([e,c])=>s.jsxs("tr",{children:[s.jsx("td",{className:"align-top",children:e}),s.jsx("td",{className:"w-full max-w-[350px]",children:s.jsx(G,{onFocus:y,onBlur:()=>j(e),onChange:h=>S(e,h.currentTarget.value),onKeyDown:h=>{h.key==="Enter"&&j(e)},value:c,placeholder:e})}),s.jsx("td",{className:"w-full max-w-[100px]",children:s.jsx(B,{onClick:I(e),color:"red",children:s.jsx(R,{})})})]},e));return s.jsxs(s.Fragment,{children:[s.jsxs(W,{position:"apart",mb:"md",mt:"md",children:[s.jsx(k,{label:"",value:n,disabledOptions:[i==null?void 0:i.i18n.default],onChange:e=>e&&r(T.settings.translations(e).list)}),s.jsx(q,{to:T.settings.translations(n).create,color:"green",leftIcon:s.jsx(P,{}),component:z,children:a("Add new")})]}),s.jsxs("div",{className:"relative min-h-[400px]",children:[s.jsx(H,{visible:N||b,overlayBlur:2}),s.jsxs(Q,{className:"-mx-5",horizontalSpacing:"xl",verticalSpacing:"sm",children:[s.jsx("thead",{children:w}),s.jsx("tbody",{children:D}),s.jsx("tfoot",{children:w})]})]}),s.jsx(J,{})]})};export{Y as GeneralTranslationsSettings,Y as default};
