1import{af as E,aj as T,r as u,c3 as j,c4 as L,j as e,ad as _,c5 as q,a6 as A,s as y,aa as v}from"./index-CEqNdWMB.js";import{T as D}from"./textarea-BCupudha.js";import{L as $}from"./label-MzaZtEZW.js";import{S as B,a as K,b as O,c as P,d as Q}from"./select-B9ajeO-3.js";import{S as R}from"./save-C88H4vFI.js";import"./index-BdQq_4o_.js";import"./index-NdaxtzIS.js";import"./index-BSd2hjwl.js";import"./form-layout-CimphA65.js";import"./chevron-up-C686eY-E.js";import"./check-CYl4c-Z5.js";const Y=()=>{const N=E(),{adminLocale:a,locales:b}=T(),[i,S]=u.useState("home"),[l,g]=u.useState({}),[h,p]=u.useState(!1),c=b.find(t=>t.code===a),f=(c==null?void 0:c.is_default)??a==="en",m=j[i].fields,{data:d,isLoading:w}=L(i,a);u.useEffect(()=>{g(d??{})},[d,i,a]);const r=u.useMemo(()=>m.filter(t=>(l[t.key]??"")!==((d==null?void 0:d[t.key])??"")).map(t=>t.key),[l,d,m]),k=m.filter(t=>(l[t.key]??"").trim()).length,C=async()=>{if(r.length===0)return;p(!0);const t=r.filter(s=>(l[s]??"").trim()).map((s,x)=>({page:i,locale:a,key:s,value:{text:l[s].trim()},sort_order:x})),o=r.filter(s=>!(l[s]??"").trim());let n=null;if(t.length&&(n=(await y.from("site_content").upsert(t,{onConflict:"page,locale,key"})).error),!n&&o.length&&(n=(await y.from("site_content").delete().eq("page",i).eq("locale",a).in("key",o)).error),p(!1),n){v({title:"Save failed",description:n.message,variant:"destructive"});return}v({title:`${r.length} field(s) saved`}),N.invalidateQueries({queryKey:["site_content",i,a]})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-lg font-semibold text-foreground",children:"Site Content"}),e.jsx("p",{className:"text-body-sm text-muted-foreground mt-1",children:"Translate the wording of public pages for the language selected in the top bar."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(B,{value:i,onValueChange:S,children:[e.jsx(K,{className:"w-[180px]",children:e.jsx(O,{})}),e.jsx(P,{children:Object.entries(j).map(([t,o])=>e.jsx(Q,{value:t,children:o.title},t))})]}),!f&&e.jsxs(_,{size:"sm",className:"gap-1.5",onClick:C,disabled:h||r.length===0,children:[e.jsx(R,{className:"h-4 w-4"})," ",h?"Savingâ¦":`Save${r.length?` (${r.length})`:""}`]})]})]}),f?e.jsxs("div",{className:"card-warm p-12 text-center",children:[e.jsx(q,{className:"h-12 w-12 text-muted-foreground/40 mx-auto mb-4"}),e.jsx("h3",{className:"font-display text-lg font-medium text-foreground mb-2",children:"English is the built-in wording"}),e.jsx("p",{className:"text-body-sm text-muted-foreground",children:"Switch the language in the top bar (e.g. ES) to translate this page. English stays as the fallback for anything left blank."})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between text-sm text-muted-foreground",children:[e.jsxs("span",{children:["Editing ",e.jsx("strong",{className:"text-foreground",children:(c==null?void 0:c.name)??a})," · ",k,"/",m.length," translated"]}),e.jsx("span",{children:"Blank fields show the English text."})]}),e.jsx("div",{className:"card-warm divide-y divide-border",children:w?e.jsx("p",{className:"p-12 text-center text-muted-foreground",children:"Loadingâ¦"}):m.map(t=>{const o=l[t.key]??"",n=r.includes(t.key);return e.jsxs("div",{className:"grid md:grid-cols-2 gap-4 p-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx($,{className:"text-xs font-medium text-muted-foreground",children:t.label}),e.jsx("p",{className:"text-sm text-foreground mt-1.5 whitespace-pre-wrap",children:t.fallback})]}),e.jsx("div",{children:t.multiline?e.jsx(D,{rows:3,value:o,placeholder:"Translationâ¦",onChange:s=>g(x=>({...x,[t.key]:s.target.value})),className:n?"border-primary":void 0}):e.jsx(A,{value:o,placeholder:"Translationâ¦",onChange:s=>g(x=>({...x,[t.key]:s.target.value})),className:n?"border-primary":void 0})})]},t.key)})})]})]})};export{Y as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.