import{d as b,k as y,m as _,r as n,o as h,a as w,f as t,t as p,v as u,z as D,x as V,j as k}from"./app-bWy6VYs1.js";import{g as C}from"./AppLayout.vue_vue_type_script_setup_true_lang-BwuDxc8O.js";const j={key:0,class:"rounded-md border border-indigo-200 bg-indigo-50/60 p-2"},S={class:"mb-2 flex items-center justify-between gap-2"},T={class:"text-xs font-semibold text-indigo-900"},A={class:"flex gap-2"},N=["disabled"],$=b({__name:"AiDraftHelper",props:{modelValue:{},context:{},label:{}},emits:["update:modelValue"],setup(c,{emit:m}){const i=c,f=m,v=y(),g=_(()=>!!v.props.ai?.allowed),o=n(""),a=n(!1),s=n(""),r=n("insert"),x=async()=>{if(!o.value.trim())return;a.value=!0;const l=await fetch("/ai/draft",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json",Accept:"application/json","X-CSRF-TOKEN":C()},body:JSON.stringify({prompt:o.value.trim(),context:i.context||""})});if(a.value=!1,!l.ok)return;const e=await l.json();s.value=(e.text||"").trim(),s.value&&f("update:modelValue",r.value==="replace"?s.value:`${i.modelValue||""}${i.modelValue?`
`:""}${s.value}`)};return(l,e)=>g.value?(h(),w("div",j,[t("div",S,[t("p",T,p(l.label||"AI Draft Helper"),1),u(t("select",{"onUpdate:modelValue":e[0]||(e[0]=d=>r.value=d),class:"rounded border border-indigo-200 bg-white px-2 py-1 text-[11px]"},[...e[2]||(e[2]=[t("option",{value:"insert"},"Insert",-1),t("option",{value:"replace"},"Replace",-1)])],512),[[D,r.value]])]),t("div",A,[u(t("input",{"onUpdate:modelValue":e[1]||(e[1]=d=>o.value=d),type:"text",class:"flex-1 rounded border border-indigo-200 bg-white px-2 py-1.5 text-xs",placeholder:"e.g. Draft a concise professional update"},null,512),[[V,o.value]]),t("button",{type:"button",class:"rounded bg-indigo-600 px-2 py-1 text-xs font-medium text-white hover:bg-indigo-700 disabled:opacity-60",disabled:a.value||!o.value.trim(),onClick:x},p(a.value?"Drafting…":"Draft"),9,N)])])):k("",!0)}});export{$ as _};
