1import{b3 as P,c7 as R,bK as n,bX as l,b_ as t,bs as s}from"./index-B4NHUQaw.js";import{L as p}from"./loader-circle-Dhd4cV8X.js";import{P as K}from"./plus-BZSBoLeL.js";import{E as M}from"./eye-CG_VIHuE.js";import{T as Q}from"./trash-2-CQw6qu0q.js";import{S as B}from"./save-DUfUFFHR.js";const H=[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],O=P("eye-off",H);function q(d){return d.split(",").map(c=>c.trim()).filter(Boolean)}function I(){const{isAdmin:d,loading:c}=R(),[u,m]=n.useState([]),[w,g]=n.useState(!0),[b,f]=n.useState(null),[h,y]=n.useState(""),[k,v]=n.useState(""),[j,N]=n.useState(!1),x=n.useCallback(async()=>{g(!0);const{data:e,error:r}=await l.from("health_quiz_questions").select("id, question, warning, sort_order, active, tags, hashtags, seo_keywords").order("sort_order",{ascending:!0});if(r){t.error("Yüklenemedi",{description:r.message}),g(!1);return}m((e??[]).map(a=>({id:a.id,question:a.question,warning:a.warning,sort_order:a.sort_order,active:a.active,tags:(a.tags??[]).join(", "),hashtags:(a.hashtags??[]).join(", "),seo_keywords:a.seo_keywords??""}))),g(!1)},[]);n.useEffect(()=>{d&&x()},[d,x]);const S=async e=>{e.preventDefault();const r=h.trim(),a=k.trim();if(r.length<5){t.error("Soru en az 5 karakter olmalı");return}if(a.length<5){t.error("Uyarı metni en az 5 karakter olmalı");return}N(!0);const o=u.reduce((L,A)=>Math.max(L,A.sort_order),0),{error:_}=await l.from("health_quiz_questions").insert({question:r.slice(0,500),warning:a.slice(0,1e3),sort_order:o+1});if(N(!1),_){t.error("Eklenemedi",{description:_.message});return}t.success("Soru eklendi"),y(""),v(""),x()},i=(e,r)=>{m(a=>a.map(o=>o.id===e?{...o,...r}:o))},z=async e=>{f(e.id);const{error:r}=await l.from("health_quiz_questions").update({question:e.question.trim().slice(0,500),warning:e.warning.trim().slice(0,1e3),sort_order:e.sort_order,active:e.active,tags:q(e.tags).map(a=>a.slice(0,60)).slice(0,12),hashtags:q(e.hashtags).map(a=>a.replace(/^#+/,"").slice(0,40)).slice(0,15),seo_keywords:e.seo_keywords.trim().slice(0,500)}).eq("id",e.id);if(f(null),r){t.error("Kaydedilemedi",{description:r.message});return}t.success("Kaydedildi")},C=async e=>{const r=!e.active;i(e.id,{active:r});const{error:a}=await l.from("health_quiz_questions").update({active:r}).eq("id",e.id);a&&(t.error("Güncellenemedi",{description:a.message}),i(e.id,{active:e.active}))},E=async e=>{if(!confirm("Bu soruyu silmek istiyor musun?"))return;const{error:r}=await l.from("health_quiz_questions").delete().eq("id",e);if(r){t.error("Silinemedi",{description:r.message});return}t.success("Silindi"),m(a=>a.filter(o=>o.id!==e))};return c?s.jsx("div",{className:"container-page py-24 flex items-center justify-center text-muted-foreground",children:s.jsx(p,{className:"h-5 w-5 animate-spin"})}):d?s.jsxs("section",{className:"container-page py-12 max-w-3xl",children:[s.jsx("p",{className:"text-xs uppercase tracking-[0.18em] text-primary mb-2",children:"Yönetim"}),s.jsx("h1",{className:"font-serif text-3xl",children:"SaÄlık Soruları"}),s.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Ana sayfadaki sayaç kartında çıkan soruları buradan ekleyip düzenleyebilirsin. Pasif sorular ziyaretçilere gösterilmez."}),s.jsxs("form",{onSubmit:S,className:"mt-8 rounded-2xl border border-border bg-card p-5 space-y-3",children:[s.jsx("h2",{className:"text-sm font-semibold",children:"Yeni soru ekle"}),s.jsx("input",{value:h,onChange:e=>y(e.target.value),maxLength:500,placeholder:"Soru: ör. 'Son 1 saat içinde su içtiniz mi?'",className:"w-full rounded-xl border border-border bg-background px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-ring"}),s.jsx("textarea",{value:k,onChange:e=>v(e.target.value),maxLength:1e3,rows:2,placeholder:"'Hayır' yanıtında çıkacak kısa uyarı/tavsiye metni",className:"w-full rounded-xl border border-border bg-background px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-ring resize-y"}),s.jsx("div",{className:"flex justify-end",children:s.jsxs("button",{type:"submit",disabled:j,className:"inline-flex items-center gap-2 rounded-full bg-primary px-5 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-60",children:[j?s.jsx(p,{className:"h-4 w-4 animate-spin"}):s.jsx(K,{className:"h-4 w-4"}),"Ekle"]})})]}),s.jsx("div",{className:"mt-8 space-y-4",children:w?s.jsx("div",{className:"h-40 rounded-2xl bg-muted animate-pulse"}):u.length===0?s.jsx("p",{className:"rounded-2xl border border-dashed border-border bg-card p-10 text-center text-sm text-muted-foreground",children:"Henüz soru yok."}):u.map(e=>s.jsxs("div",{className:`rounded-2xl border bg-card p-4 space-y-3 ${e.active?"border-border":"border-dashed border-border opacity-70"}`,children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("input",{type:"number",value:e.sort_order,onChange:r=>i(e.id,{sort_order:Number(r.target.value)}),className:"w-16 rounded-lg border border-border bg-background px-2 py-1.5 text-xs text-center",title:"Sıra"}),s.jsx("input",{value:e.question,onChange:r=>i(e.id,{question:r.target.value}),maxLength:500,className:"flex-1 rounded-lg border border-border bg-background px-3 py-2 text-sm font-medium focus:outline-none focus:ring-2 focus:ring-ring"})]}),s.jsx("textarea",{value:e.warning,onChange:r=>i(e.id,{warning:r.target.value}),maxLength:1e3,rows:2,className:"w-full rounded-lg border border-border bg-background px-3 py-2 text-sm text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring resize-y"}),s.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[s.jsxs("label",{className:"block",children:[s.jsx("span",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Etiketler (virgülle)"}),s.jsx("input",{value:e.tags,onChange:r=>i(e.id,{tags:r.target.value}),placeholder:"saÄlık, bitki çayı, adaçayı",className:"mt-1 w-full rounded-lg border border-border bg-background px-3 py-2 text-xs focus:outline-none focus:ring-2 focus:ring-ring"})]}),s.jsxs("label",{className:"block",children:[s.jsx("span",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"Hashtag (virgülle, # olmadan)"}),s.jsx("input",{value:e.hashtags,onChange:r=>i(e.id,{hashtags:r.target.value}),placeholder:"saglikliyasam, bitkicayi",className:"mt-1 w-full rounded-lg border border-border bg-background px-3 py-2 text-xs focus:outline-none focus:ring-2 focus:ring-ring"})]})]}),s.jsxs("label",{className:"block",children:[s.jsx("span",{className:"text-[11px] uppercase tracking-wide text-muted-foreground",children:"SEO anahtar kelimeleri (virgülle)"}),s.jsx("input",{value:e.seo_keywords,onChange:r=>i(e.id,{seo_keywords:r.target.value}),placeholder:"adaçayı faydaları, boÄaz aÄrısı için bitki çayı",className:"mt-1 w-full rounded-lg border border-border bg-background px-3 py-2 text-xs focus:outline-none focus:ring-2 focus:ring-ring"})]}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("button",{type:"button",onClick:()=>C(e),className:"inline-flex items-center gap-1.5 rounded-full border border-border px-3 py-1.5 text-xs hover:border-primary/40",children:e.active?s.jsxs(s.Fragment,{children:[s.jsx(M,{className:"h-3.5 w-3.5 text-primary"})," Aktif"]}):s.jsxs(s.Fragment,{children:[s.jsx(O,{className:"h-3.5 w-3.5 text-muted-foreground"})," Pasif"]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("button",{type:"button",onClick:()=>E(e.id),className:"inline-flex items-center gap-1.5 rounded-full border border-border px-3 py-1.5 text-xs text-destructive hover:border-destructive/40",children:[s.jsx(Q,{className:"h-3.5 w-3.5"})," Sil"]}),s.jsxs("button",{type:"button",onClick:()=>z(e),disabled:b===e.id,className:"inline-flex items-center gap-1.5 rounded-full bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-60",children:[b===e.id?s.jsx(p,{className:"h-3.5 w-3.5 animate-spin"}):s.jsx(B,{className:"h-3.5 w-3.5"}),"Kaydet"]})]})]})]},e.id))})]}):s.jsx("div",{className:"container-page py-24 text-center text-muted-foreground",children:"Bu sayfaya eriÅim yetkin yok."})}export{I 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.