import{d as H,r as p,l as R,s as V,c,e,j as y,t as a,C as B,D as J,h as t,H as z,g as I,F as N,p as A,y as M,b as i,q as O,z as q,_ as G}from"./tpFEFzWU.js";import{u as L}from"./jiBgvKN8.js";const U={class:"autocreate-page"},W={class:"page-header"},K={class:"page-description"},Q={class:"card input-section"},X={class:"form-group"},Y={class:"form-label",for:"prompt"},Z=["placeholder"],x=["disabled"],ee={key:0,class:"card streaming-section"},se={key:0,class:"cursor"},te={key:1,class:"card error-section"},ae={class:"error-text"},oe={key:2,class:"proposals-section"},le={class:"proposals-grid"},re=["onClick"],ne={class:"proposal-header"},ce=["checked","onChange"],ie={class:"proposal-description"},ue={class:"proposal-meta"},pe={class:"badge"},de={class:"proposals-actions"},he=["disabled"],ve={key:3,class:"card results-section"},fe={class:"results-list"},_e={class:"result-icon"},ge={class:"result-name"},me={key:0,class:"result-error"},ye=H({__name:"autocreate",setup(be){const{success:F,error:C}=L(),f=p(""),_=p(!1),k=p(!1),b=p(""),$=p(null),d=p([]),n=p([]),h=p([]),g=p(""),w=R(()=>d.value.length>0&&n.value.length===d.value.length),j=async()=>{if(f.value.trim()){_.value=!0,b.value="",d.value=[],h.value=[],n.value=[],g.value="";try{const s=await fetch("/api/catalog/autocreate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:f.value})});if(!s.ok)throw new Error(`HTTP error: ${s.status}`);const o=s.body?.getReader(),l=new TextDecoder;if(o){let r="";for(;;){const{done:m,value:v}=await o.read();if(m)break;r+=l.decode(v,{stream:!0});const P=r.split(`
`);r=P.pop()||"";for(const S of P)if(S.startsWith("data: "))try{const u=JSON.parse(S.slice(6));u.type==="thinking"&&u.content?(b.value+=u.content,M(()=>{$.value&&($.value.scrollTop=$.value.scrollHeight)})):u.type==="proposals"&&u.proposals?(d.value=u.proposals,b.value=""):u.type==="error"&&u.message&&(g.value=u.message)}catch{}}}}catch{g.value="Failed to generate proposals. Please try again.",C("Generation failed")}finally{_.value=!1}}},T=s=>{const o=n.value.indexOf(s);o===-1?n.value.push(s):n.value.splice(o,1)},D=()=>{w.value?n.value=[]:n.value=d.value.map((s,o)=>o)},E=async()=>{if(n.value.length){k.value=!0,h.value=[];try{const s=n.value.map(v=>d.value[v]),o=await fetch("/api/catalog/autocreate/apply",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({proposals:s})});if(!o.ok)throw new Error("Failed to apply proposals");const l=await o.json();h.value=l;const r=h.value.filter(v=>v.success).length,m=h.value.filter(v=>!v.success).length;m===0?F(`Successfully applied ${r} columns`):C(`Applied ${r}, failed ${m}`)}catch{C("Failed to apply proposals")}finally{k.value=!1}}};return V({title:"Autocreate - AutoCode"}),(s,o)=>(i(),c("div",U,[e("header",W,[e("h1",null,a(s.$t("autocreate.title")),1),e("p",K,a(s.$t("autocreate.description")),1)]),e("div",Q,[e("div",X,[e("label",Y,a(s.$t("autocreate.prompt")),1),B(e("textarea",{id:"prompt","onUpdate:modelValue":o[0]||(o[0]=l=>z(f)?f.value=l:null),class:"form-input",rows:"4",placeholder:s.$t("autocreate.promptPlaceholder")},null,8,Z),[[J,t(f)]])]),e("button",{class:"btn btn-primary",disabled:!t(f).trim()||t(_),onClick:j},a(t(_)?s.$t("autocreate.generating"):s.$t("autocreate.generate")),9,x)]),t(b)||t(_)?(i(),c("div",ee,[e("h2",null,a(s.$t("autocreate.thinking")),1),e("div",{ref_key:"streamingRef",ref:$,class:"streaming-output"},[I(a(t(b))+" ",1),t(_)?(i(),c("span",se,"▊")):y("",!0)],512)])):y("",!0),t(g)?(i(),c("div",te,[e("p",ae,a(t(g)),1),e("button",{class:"btn btn-secondary",onClick:o[1]||(o[1]=l=>g.value="")},a(s.$t("form.dismiss")),1)])):y("",!0),t(d).length?(i(),c("div",oe,[e("h2",null,a(s.$t("autocreate.proposals")),1),e("div",le,[(i(!0),c(N,null,A(t(d),(l,r)=>(i(),c("div",{key:r,class:O(["proposal-card card",{selected:t(n).includes(r)}]),onClick:m=>T(r)},[e("div",ne,[e("input",{type:"checkbox",checked:t(n).includes(r),onClick:o[2]||(o[2]=q(()=>{},["stop"])),onChange:m=>T(r)},null,40,ce),e("h3",null,a(l.name),1)]),e("p",ie,a(l.description),1),e("div",ue,[e("span",pe,a(l.type),1)])],10,re))),128))]),e("div",de,[e("button",{class:"btn btn-secondary",onClick:D},a(t(w)?s.$t("autocreate.deselectAll"):s.$t("autocreate.selectAll")),1),e("button",{class:"btn btn-primary",disabled:!t(n).length||t(k),onClick:E},a(t(k)?s.$t("autocreate.applying"):s.$t("autocreate.apply"))+" ("+a(t(n).length)+") ",9,he)])])):y("",!0),t(h).length?(i(),c("div",ve,[e("h2",null,a(s.$t("autocreate.results")),1),e("ul",fe,[(i(!0),c(N,null,A(t(h),(l,r)=>(i(),c("li",{key:r,class:O({success:l.success,error:!l.success})},[e("span",_e,a(l.success?"✓":"✗"),1),e("span",ge,a(l.name),1),l.error?(i(),c("span",me,a(l.error),1)):y("",!0)],2))),128))])])):y("",!0)]))}}),Ce=G(ye,[["__scopeId","data-v-8a41c3ab"]]);export{Ce as default};
