1import{r as d,j as e}from"./index-L9AYrVUw.js";import{dM as R,bD as L,bu as M,g4 as W,aE as v,a3 as G,n as N,u as p}from"./PlanAccessModal-P_W2GThH.js";import{m as Y}from"./ArrowClockwise.es-CEsBpyry.js";import{s as m}from"./productFunnel-DiJFcMU2.js";import"./locale-Cctu0V3Y.js";function K(){const o=R(),[u,C]=d.useState([]),[A,F]=d.useState({}),[I,B]=d.useState([]),[b,j]=d.useState(!1),[y,_]=d.useState(null),c=d.useCallback(async()=>{j(!0);try{const[{data:i},{data:t},{data:a}]=await Promise.all([m.from("image_styles").select("id,name,prompt_base,negative_prompt,build_prompt_template").order("name"),m.from("style_calibrations").select("style_id,status"),m.from("style_calibration_patches").select("*").order("created_at",{ascending:!1}).limit(50)]),n=i??[],r=new Map;L.forEach(s=>{r.set(s.id,{id:s.id,name:s.name,prompt_base:s.promptBase??"",negative_prompt:s.negativePrompt??"",build_prompt_template:""})}),M.forEach(s=>{r.has(s.id)||r.set(s.id,{id:s.id,name:s.label,prompt_base:s.briefing??"",negative_prompt:"",build_prompt_template:""})}),n.forEach(s=>r.set(s.id,s));const g=s=>{!s||r.has(s)||r.set(s,{id:s,name:s,prompt_base:"",negative_prompt:"",build_prompt_template:""})};(t??[]).forEach(s=>g(s.style_id)),(a??[]).forEach(s=>g(s.style_id));const h=Array.from(r.values()).sort((s,l)=>s.name.localeCompare(l.name));C(h);const f={};(t??[]).forEach(s=>{const l=f[s.style_id]??{style_id:s.style_id,pending:0,proposed:0};s.status==="pending"&&(l.pending+=1),f[s.style_id]=l}),(a??[]).forEach(s=>{if(s.status==="proposed"){const l=f[s.style_id]??{style_id:s.style_id,pending:0,proposed:0};l.proposed+=1,f[s.style_id]=l}}),F(f),B(a??[])}finally{j(!1)}},[]);d.useEffect(()=>{c()},[c]);const D=async i=>{_(i);try{const{data:t,error:a}=await m.functions.invoke("propose-style-calibration",{body:{style_id:i}});if(a)throw a;if(t!=null&&t.error)throw new Error(t.error);p.success("Patch proposto"),c()}catch(t){p.error((t==null?void 0:t.message)??"Falha ao propor patch")}finally{_(null)}},P=async i=>{try{const{data:t,error:a}=await m.functions.invoke("apply-style-calibration",{body:{patch_id:i}});if(a)throw a;if(t!=null&&t.error)throw new Error(t.error);p.success("Patch aplicado"),c()}catch(t){p.error((t==null?void 0:t.message)??"Falha ao aplicar")}},T=async i=>{const{error:t}=await m.from("style_calibration_patches").update({status:"rejected"}).eq("id",i);t?p.error(t.message):(p.success("Patch rejeitado"),c())},x=I.filter(i=>i.status==="proposed");return e.jsxs("div",{style:{padding:32,maxWidth:1100,margin:"0 auto",fontFamily:"Inter, system-ui, sans-serif"},children:[e.jsxs("header",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:24},children:[e.jsxs("div",{children:[e.jsx("h1",{style:{fontSize:22,fontWeight:600,margin:0},children:"Calibragem de Presets"}),e.jsx("p",{style:{color:"#666",fontSize:13,marginTop:4},children:"Consolida feedbacks pós-geração em sugestões de prompt para cada estilo."})]}),e.jsxs("div",{style:{display:"flex",gap:10,alignItems:"center"},children:[e.jsxs("label",{style:{display:"inline-flex",alignItems:"center",gap:6,fontSize:12,color:"#444"},children:[e.jsx("input",{type:"checkbox",checked:o,onChange:i=>W(i.target.checked)}),"Modo admin (mostra nos cards)"]}),e.jsxs("button",{onClick:c,style:E,disabled:b,children:[b?e.jsx(v,{size:14,className:"animate-spin"}):e.jsx(Y,{size:14}),"Atualizar"]})]})]}),!o&&e.jsx("div",{style:{background:"#FFF7E6",border:"1px solid #F0D38C",borderRadius:8,padding:"10px 14px",fontSize:12,color:"#7a5a00",marginBottom:16},children:"Modo admin desligado â o botão de calibragem não aparece nos cards. Ative no toggle acima."}),x.length>0&&e.jsxs("section",{style:{marginBottom:32},children:[e.jsxs("h2",{style:{fontSize:14,color:"#999",textTransform:"uppercase",letterSpacing:.6,marginBottom:10},children:["Patches aguardando aprovação (",x.length,")"]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:12},children:x.map(i=>{var a;const t=u.find(n=>n.id===i.style_id);return e.jsxs("article",{style:S,children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:14,fontWeight:600},children:(t==null?void 0:t.name)??i.style_id}),e.jsxs("div",{style:{fontSize:11,color:"#999"}
1,children:[new Date(i.created_at).toLocaleString()," · ",i.source_calibration_ids.length," feedbacks"]})]}),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsxs("button",{onClick:()=>P(i.id),style:z,children:[e.jsx(G,{size:14})," Aplicar"]}),e.jsxs("button",{onClick:()=>T(i.id),style:E,children:[e.jsx(N,{size:14})," Rejeitar"]})]})]}),((a=i.patch)==null?void 0:a.rationale)&&e.jsx("p",{style:{margin:"8px 0 12px",fontSize:13,color:"#444"},children:i.patch.rationale}),["prompt_base","negative_prompt","build_prompt_template"].map(n=>{var h;const r=(h=i.patch)==null?void 0:h[n];if(typeof r!="string")return null;const g=(t==null?void 0:t[n])??"";return e.jsxs("div",{style:{marginTop:10},children:[e.jsx("div",{style:{fontSize:11,color:"#999",textTransform:"uppercase",letterSpacing:.5,marginBottom:4},children:n}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},children:[e.jsx("pre",{style:w(!1),children:g||"(vazio)"}),e.jsx("pre",{style:w(!0),children:r})]})]},n)})]},i.id)})})]}),e.jsxs("section",{children:[e.jsx("h2",{style:{fontSize:14,color:"#999",textTransform:"uppercase",letterSpacing:.6,marginBottom:10},children:"Estilos"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:u.map(i=>{const t=A[i.id]??{style_id:i.id,pending:0,proposed:0};return e.jsxs("div",{style:{...S,display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:14,fontWeight:600},children:i.name}),e.jsxs("div",{style:{fontSize:11,color:"#999"},children:["id: ",i.id]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[e.jsxs("span",{style:k(t.pending>0?"#f0a500":"#ccc"),children:[t.pending," pendentes"]}),e.jsxs("span",{style:k(t.proposed>0?"#3b82f6":"#ccc"),children:[t.proposed," propostos"]}),e.jsxs("button",{onClick:()=>D(i.id),disabled:t.pending===0||y===i.id,style:{...z,opacity:t.pending===0||y===i.id?.4:1},children:[y===i.id?e.jsx(v,{size:14,className:"animate-spin"}):null,"Gerar patch"]})]})]},i.id)})})]})]})}const S={background:"#fff",border:"1px solid #EEE",borderRadius:10,padding:16},E={height:32,padding:"0 12px",borderRadius:8,border:"1px solid #E5E5E5",background:"#fff",fontSize:12,cursor:"pointer",display:"inline-flex",alignItems:"center",gap:6},z={height:32,padding:"0 12px",borderRadius:8,border:"1px solid #111",background:"#111",color:"#fff",fontSize:12,cursor:"pointer",display:"inline-flex",alignItems:"center",gap:6},k=o=>({fontSize:11,padding:"4px 8px",borderRadius:999,background:`${o}20`,color:o,fontWeight:600}),w=o=>({margin:0,background:o?"#ECFDF3":"#FAFAFA",border:`1px solid ${o?"#A8E1C3":"#EEE"}`,borderRadius:6,padding:10,fontSize:11,color:"#333",whiteSpace:"pre-wrap",wordBreak:"break-word",maxHeight:220,overflow:"auto"});export{K 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.