1import{c7 as I,cm as j,cj as R,bK as n,bs as e,o as T,I as E,aG as L,b_ as N}from"./index-B4NHUQaw.js";import{s as K}from"./social_stats-Uo2Ddw2e.js";import{g as z,a as F}from"./social-stats.functions-DcvLNmYF.js";import{L as x}from"./loader-circle-Dhd4cV8X.js";import{S as M}from"./save-DUfUFFHR.js";const v={youtube:{name:"YouTube",Icon:L,auto:!1,fields:[{key:"followers",label:"Abone"},{key:"views",label:"Toplam İzlenme"},{key:"videos",label:"Video Sayısı"}]},instagram:{name:"Instagram",Icon:E,auto:!1,fields:[{key:"followers",label:"Takipçi"},{key:"posts",label:"Gönderi"},{key:"views",label:"Reels İzlenme"}]},facebook:{name:"Facebook",Icon:T,auto:!1,fields:[{key:"followers",label:"Takipçi"},{key:"likes",label:"BeÄeni"},{key:"views",label:"EtkileÅim/Ay"}]}},Y=["youtube","instagram","facebook"];function G(){const{isAdmin:i,loading:o}=I(),b=j(z),w=j(F),S=R(),[g,c]=n.useState({youtube:null,instagram:null,facebook:null}),[A,f]=n.useState(!0),[y,h]=n.useState(null),[p,d]=n.useState(!1),k=n.useCallback(async()=>{f(!0);const a={youtube:null,instagram:null,facebook:null};try{const s=await b();for(const t of s.stats)a[t.platform]=t;d(s.source!=="database")}catch{for(const s of K.rows)a[s.platform]=s;d(!0)}c(a),f(!1)},[b]);n.useEffect(()=>{!o&&i&&k()},[o,i,k]);const u=(a,s,t)=>{c(r=>{const l=r[a];if(!l)return r;const m=s==="handle"||s==="url"?t:t===""?null:Math.max(0,Number(t.replace(/\D/g,"")));return{...r,[a]:{...l,[s]:m}}})},C=async a=>{const s=g[a];if(s){h(a);try{const t=await w({data:{platform:a,handle:s.handle,url:s.url,followers:Number(s.followers||0),views:s.views==null?null:Number(s.views),likes:s.likes==null?null:Number(s.likes),videos:s.videos==null?null:Number(s.videos),posts:s.posts==null?null:Number(s.posts)}});c(r=>({...r,[a]:t.stat})),d(!1),await S.invalidateQueries({queryKey:["social-stats"]}),N.success(`${v[a].name} güncellendi`)}catch(t){N.error("Kaydedilemedi",{description:t instanceof Error?t.message:String(t)})}finally{h(null)}}};return o?e.jsx("div",{className:"container-page py-16 flex items-center justify-center",children:e.jsx(x,{className:"h-5 w-5 animate-spin"})}):i?e.jsxs("div",{className:"container-page py-10 max-w-4xl",children:[e.jsx("div",{className:"flex items-start justify-between gap-4 mb-8 flex-wrap",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl md:text-3xl",children:"Sosyal Medya İstatistikleri"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"YouTube dahil tüm hesapların verilerini diÄer hesaplar gibi manuel yönetin."})]})}),p&&e.jsx("div",{className:"mb-5 rounded-xl border border-amber-300/60 bg-amber-50 p-4 text-sm text-amber-900 dark:border-amber-400/30 dark:bg-amber-950/30 dark:text-amber-200",children:"Kalıcı veritabanına ulaÅılamadıÄı için yedek deÄerler gösteriliyor. Bu uyarı görünürken yapılan deÄiÅiklikler kaydedilmez."}),A?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx(x,{className:"h-5 w-5 animate-spin"})}):e.jsx("div",{className:"space-y-5",children:Y.map(a=>{const s=v[a],t=g[a],r=s.Icon;return t?e.jsxs("section",{className:"rounded-2xl border border-border bg-card p-5",children:[e.jsx("header",{className:"flex items-center justify-between gap-3 mb-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"inline-flex h-10 w-10 items-center justify-center rounded-xl bg-muted",children:e.jsx(r,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg leading-tight",children:s.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Son güncelleme: ",new Date(t.updated_at).toLocaleString("tr-TR"),s.auto&&e.jsx("span",{className:"ml-2 inline-flex items-center rounded-full bg-emerald-500/10 px-2 py-0.5 text-emerald-600 dark:text-emerald-400",children:"Otomatik"})]})]})]})}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Kullanıcı adı"}),e.jsx("input",{type:"text",value:t.handle??"",onChange:l=>u(a,"handle",l.target.value),className:"mt-1 w-full rounded-lg border border-border bg-background px-3 py-2 text-sm"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Profil URL"}),e.jsx("input",{type:"url",value:t.url??"",onChange:l=>u(a,"url",l.target.value),className:"mt-1 w-full rounded-lg border border-border bg-background px-3 py-2 text-sm"})]}),s.fields.map(l=>e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:l.label}),e.jsx("input",{type:"number",min:0,value:t[l.key]??"",onChange:m=>u(a,l.key,m.target.value),className:"mt-1 w-full rounded-lg border border-border bg-background px-3 py-2 text-sm"})]},l.key))]}),e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsxs("button",{type:"button",onClick:()=>C(a),disabled:y===a||p,className:"inline-flex items-center gap-2 rounded-full bg-foreground px-4 py-2 text-sm font-medium text-background hover:opacity-90 disabled:opacity-60",children:[y===a?e.jsx(x,{className:"h-4 w-4 animate-spin"}):e.jsx(M,{className:"h-4 w-4"}),"Kaydet"]})})]},a):null})})]}):e.jsxs("div",{className:"container-page py-16",children:[e.jsx("h1",{className:"text-2xl",children:"Yetkisiz"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"Bu sayfayı görüntülemek için admin yetkisi gerekiyor."})]})}
1export{G 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.