1import{D as N,j as e,ah as w,i as A,r as a,s as k}from"./index-B5Aoxc7f.js";import{u as S}from"./auth-DCQNNPBD.js";import{A as _,a as C}from"./AdminShell-ubpJOWqi.js";import{L as l}from"./loader-circle-BavV0jUT.js";import{S as v}from"./save-CUR-j9bb.js";import"./dialog-CzbOn1_E.js";import"./input-CaPPmnTN.js";import"./package-Ib0LAcmi.js";import"./flower-2-hJUklDEA.js";import"./info-CDiq_qOh.js";import"./search-C4_LEUwQ.js";const T=[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],G=N("triangle-alert",T);function U(){const{user:n,isAdmin:t,loading:i}=S();return e.jsx(_,{hasUser:!!n,isAdmin:t,loading:i,children:e.jsx(C,{children:e.jsx(M,{})})})}function M(){const n=w(),{data:t,isLoading:i}=A({queryKey:["site-settings"],queryFn:async()=>{const{data:s,error:d}=await k.from("site_settings").select("key, value").in("key",["tracking_head","tracking_body"]);if(d)throw d;const r=Object.fromEntries((s??[]).map(j=>[j.key,j.value]));return{head:r.tracking_head??"",body:r.tracking_body??""}}}),[c,m]=a.useState(""),[p,u]=a.useState(""),[o,x]=a.useState(null),[g,h]=a.useState(null),[b,y]=a.useState(null);a.useEffect(()=>{t&&(m(t.head),u(t.body))},[t]);const f=async(s,d)=>{y(null),h(null),x(s==="tracking_head"?"head":"body");const{error:r}=await k.from("site_settings").upsert({key:s,value:d},{onConflict:"key"});if(x(null),r){y(r.message);return}h(s==="tracking_head"?"Header code saved.":"Body code saved."),n.invalidateQueries({queryKey:["site-settings"]})};return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-3xl font-semibold",children:"Tracking codes"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Paste tracking snippets from Google Ads, Google Analytics, Meta Pixel, TikTok, etc. They run on every page of the public website."})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-secondary/40 p-4 text-sm flex gap-3",children:[e.jsx(G,{className:"h-5 w-5 text-foreground/70 shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Only paste code from sources you trust."}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Anything you paste here is added to every page exactly as written. Bad code can break the site â if that happens, just clear the box and click Save."})]})]}),i&&e.jsxs("div",{className:"text-muted-foreground",children:[e.jsx(l,{className:"inline h-4 w-4 animate-spin"})," Loadingâ¦"]}),e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-5 space-y-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-semibold",children:"Header code (<head>)"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:'For tags labeled "paste in the <head>" â e.g. Google Tag (gtag.js), GA4, Google Ads, Meta Pixel base code.'})]}),e.jsx("textarea",{value:c,onChange:s=>m(s.target.value),rows:10,spellCheck:!1,placeholder:`<!-- Paste your <head> tracking snippets here --> 2<script>...<\/script>`,className:"w-full font-mono text-xs p-3 rounded-lg border border-border bg-background"}),e.jsxs("button",{onClick:()=>f("tracking_head",c),disabled:o==="head",className:"inline-flex items-center gap-1.5 px-3 py-2 rounded-lg bg-foreground text-background text-sm font-semibold disabled:opacity-50",children:[o==="head"?e.jsx(l,{className:"h-4 w-4 animate-spin"}):e.jsx(v,{className:"h-4 w-4"}),"Save header code"]})]}),e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-5 space-y-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-semibold",children:"Body code (<body>)"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:'For tags labeled "paste immediately after the opening <body>" â e.g. Google Tag Manager noscript, Meta Pixel noscript fallback.'})]}),e.jsx("textarea",{value:p,onChange:s=>u(s.target.value),rows:8,spellCheck:!1,placeholder:`<!-- Paste your <body> tracking snippets here --> 3<noscript>...</noscript>`,className:"w-full font-mono text-xs p-3 rounded-lg border border-border bg-background"}),e.jsxs("button",{onClick:()=>f("tracking_body",p),disabled:o==="body",className:"inline-flex items-center gap-1.5 px-3 py-2 rounded-lg bg-foreground text-background text-sm font-semibold disabled:opacity-50",children:[o==="body"?e.jsx(l,{className:"h-4 w-4 animate-spin"}):e.jsx(v,{className:"h-4 w-4"}),"Save body code"]})]}),b&&e.jsx("p",{className:"text-sm text-destructive",children:b}),g&&e.jsx("p",{className:"text-sm text-primary",children:g}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Changes go live on the next page load. Use your browser's Inspect â Network or the platform's tag tester to verify."})]})}
3export{U as component};
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.