import{d as ne,G as ae,x as oe,l,r as v,v as R,u as le,o as re,s as ie,c as r,e as a,j as C,t as n,h as e,q as ce,F as ue,C as de,D as pe,H as me,g as q,b as i,_ as ve}from"./tpFEFzWU.js";import{u as fe}from"./jiBgvKN8.js";import{u as ge}from"./BS2O5lAl.js";import{u as D}from"./Grz13CMP.js";const ye={class:"column-prompt-page"},_e={class:"page-header card"},he={class:"header-left"},be={key:0,class:"pipeline-badge"},ke={class:"header-right"},Ce=["disabled"],we=["disabled"],Pe={key:0,class:"loading card"},Se={key:1,class:"error-message card"},$e={key:2,class:"prompt-container card"},xe={key:0,class:"prompt-content"},Ne={class:"prompt-meta"},Be={class:"meta-item"},Te={class:"meta-item"},Ve={key:0,class:"meta-item meta-dirty"},Fe=ne({__name:"prompt",async setup(Ie){let u,g;const w=ae(),N=oe(),{success:P,error:B}=fe(),{pipelineConfig:E,isColumnInPipeline:M,addColumnBySlug:j,removeColumnBySlug:z,savePipeline:T,loadActivePipeline:H}=ge(),d=l(()=>w.params.slug),y=l(()=>w.query.pipeline||""),G=l(()=>w.query.name||""),U=l(()=>G.value||d.value),J=()=>{window.history.length>1?N.back():N.push("/kanban")},S=v(!1),c=v(!1),m=v(""),p=v(!1),_=v(!1),h=v(!1),{data:b,status:L,error:V,refresh:W}=([u,g]=R(()=>D(()=>{const s=new URLSearchParams;y.value&&s.set("pipeline",y.value);const o=s.toString();return`/api/columns/${d.value}/prompt${o?`?${o}`:""}`},"$jZPB4J8e0r")),u=await u,g(),u),f=l(()=>b.value?typeof b.value=="string"?b.value:b.value.content||"":""),F=l(()=>c.value?m.value:f.value),Z=l(()=>{const s=F.value;return!s||typeof s!="string"?0:s.split(`
`).length}),K=l(()=>{const s=F.value;return!s||typeof s!="string"?0:s.length}),O=async()=>{if(f.value)try{await navigator.clipboard.writeText(f.value),S.value=!0,setTimeout(()=>{S.value=!1},2e3)}catch(s){console.error("Failed to copy:",s)}},Q=()=>{m.value=f.value,p.value=!1,c.value=!0},X=()=>{p.value&&!confirm("Vous avez des modifications non enregistrées. Voulez-vous vraiment annuler ?")||(c.value=!1,p.value=!1)},Y=async()=>{_.value=!0;try{await $fetch(`/api/columns/${d.value}/actions`,{method:"PATCH",body:{content:m.value}}),P(t("pipeline.promptSaved")),p.value=!1,await W(),c.value=!1}catch{B(t("error.saveFailed"))}finally{_.value=!1}},{t}=le(),{data:I}=([u,g]=R(()=>D("/api/catalog","$8GjW2wVST-")),u=await u,g(),u),k=l(()=>{if(!I.value)return null;const s=d.value.replace(/^\d+_/,"");for(const o of["definition","action","finish"]){const A=I.value.segments[o].columns.find(se=>se.slug.replace(/^\d+_/,"")===s);if(A)return{...A,segment:o}}return null}),ee=l(()=>M(d.value)),$=l(()=>ee.value.inPipeline),te=async()=>{if(k.value){h.value=!0;try{if($.value)z(d.value),await T(),P(t("pipeline.columnRemoved"));else{const s=k.value.segment;j(d.value,k.value.name,s),await T(),P(t("pipeline.columnAdded"))}}catch{B(t("error.saveFailed"))}finally{h.value=!1}}};return re(()=>{H()}),ie({title:l(()=>`${d.value} - AutoCode`)}),(s,o)=>(i(),r("div",ye,[a("header",_e,[a("div",he,[a("button",{class:"back-link",onClick:J},"← "+n(e(t)("nav.back")),1),o[2]||(o[2]=a("span",{class:"header-separator"},"/",-1)),a("h1",null,n(e(U)),1),e(y)?(i(),r("span",be,n(e(y)),1)):C("",!0)]),a("div",ke,[!e(c)&&e(k)&&e(E)?(i(),r("button",{key:0,class:ce(["btn btn-sm",e($)?"btn-danger":"btn-success"]),disabled:e(h),onClick:te},n(e(h)?"...":e($)?e(t)("column.deactivate"):e(t)("column.activate")),11,Ce)):C("",!0),e(c)?C("",!0):(i(),r("button",{key:1,class:"btn btn-secondary btn-sm",onClick:O},n(e(S)?e(t)("form.copied"):e(t)("form.copy")),1)),e(c)?(i(),r(ue,{key:3},[a("button",{class:"btn btn-secondary btn-sm",onClick:X},n(e(t)("modal.cancel")),1),a("button",{class:"btn btn-primary btn-sm",disabled:e(_)||!e(p),onClick:Y},n(e(_)?e(t)("form.saving"):e(t)("form.save")),9,we)],64)):(i(),r("button",{key:2,class:"btn btn-primary btn-sm",onClick:Q},n(e(t)("column.edit")),1))])]),e(L)==="pending"?(i(),r("div",Pe,n(e(t)("app.loading")),1)):e(V)?(i(),r("div",Se,n(e(V).message),1)):(i(),r("div",$e,[e(c)?de((i(),r("textarea",{key:1,"onUpdate:modelValue":o[0]||(o[0]=x=>me(m)?m.value=x:null),class:"code-editor",spellcheck:"false",onInput:o[1]||(o[1]=x=>p.value=!0)},null,544)),[[pe,e(m)]]):(i(),r("pre",xe,[a("code",null,n(e(f)),1)])),a("div",Ne,[a("span",Be,[a("strong",null,n(e(t)("column.lines"))+":",1),q(" "+n(e(Z)),1)]),a("span",Te,[a("strong",null,n(e(t)("column.chars"))+":",1),q(" "+n(e(K)),1)]),e(c)&&e(p)?(i(),r("span",Ve,n(e(t)("form.unsavedChanges")),1)):C("",!0)])]))]))}}),Ee=ve(Fe,[["__scopeId","data-v-bf4ee782"]]);export{Ee as default};
