import{g as U,D as w,z as B,r as m,s as $,h as x,i as p,n as O,x as L,V as z,H as I,I as S,k as K,w as u,C as j,o as A,d as l,b as o,a3 as H,E as R,G as q,e as G,q as W,A as F}from"./DClyChXX.js";import{_ as J}from"./CB7fxO7O.js";const P=q(J),Q={class:"flex items-center justify-between"},X={class:"space-y-4"},Y={class:"flex justify-end gap-3"},te=U({__name:"BacktestNotesModal",props:w({sessionId:{},initialTitle:{},initialDescription:{}},{modelValue:{type:Boolean,default:!1},modelModifiers:{}}),emits:w(["saved"],["update:modelValue"]),setup(y,{emit:b}){const n=y,V=b,s=B(y,"modelValue"),i=m(n.initialTitle||""),d=m(n.initialDescription||""),v=m(!1),c=m(),h=$(),g=x(()=>h.value==="light"?"vs-light":"vs-dark"),C={automaticLayout:!0,minimap:{enabled:!1},fontSize:15,lineHeight:21,wordWrap:"on"},k=x(()=>i.value!==(n.initialTitle||"")||d.value!==(n.initialDescription||""));p(g,t=>{var e,r;(r=(e=c.value)==null?void 0:e.$editor)==null||r.updateOptions({theme:t})}),p(()=>n.initialTitle,t=>{i.value=t||""}),p(()=>n.initialDescription,t=>{d.value=t||""}),p(s,async t=>{t?(await O(),setTimeout(()=>{var e;(e=c.value)!=null&&e.$editor&&(c.value.$editor.updateOptions({theme:g.value}),c.value.$editor.addCommand(2051,()=>{_()}))},100),window.addEventListener("keydown",f)):window.removeEventListener("keydown",f)}),L(()=>{window.removeEventListener("keydown",f)});function f(t){(t.metaKey||t.ctrlKey)&&t.key==="Enter"&&(t.preventDefault(),_())}async function _(){if(k.value){v.value=!0;try{await z().updateSessionNotes(n.sessionId,i.value,d.value),I("success","Notes saved successfully"),V("saved",{title:i.value,description:d.value}),s.value=!1}catch(t){S(t)}finally{v.value=!1}}}return(t,e)=>{const r=W,E=H,T=P,D=R,N=F,M=j;return A(),K(M,{modelValue:s.value,"onUpdate:modelValue":e[4]||(e[4]=a=>s.value=a),ui:{width:"sm:max-w-3xl"}},{default:u(()=>[l(N,null,{header:u(()=>[o("div",Q,[e[5]||(e[5]=o("h3",{class:"text-lg font-semibold"},"Add Title & Notes",-1)),l(r,{color:"gray",variant:"ghost",icon:"i-heroicons-x-mark",size:"sm",onClick:e[0]||(e[0]=a=>s.value=!1)})])]),footer:u(()=>[o("div",Y,[l(r,{color:"gray",variant:"ghost",label:"Cancel",onClick:e[3]||(e[3]=a=>s.value=!1)}),l(r,{color:"primary",label:"Save",icon:"i-heroicons-check",disabled:!k.value,loading:v.value,onClick:_},null,8,["disabled","loading"])])]),default:u(()=>[o("div",X,[o("div",null,[e[6]||(e[6]=o("label",{class:"block text-sm font-medium mb-2"},"Title",-1)),l(E,{modelValue:i.value,"onUpdate:modelValue":e[1]||(e[1]=a=>i.value=a),placeholder:"Enter a title for this backtest",maxlength:"255",size:"lg"},null,8,["modelValue"])]),o("div",null,[e[8]||(e[8]=o("label",{class:"block text-sm font-medium mb-2"},"Description",-1)),l(D,null,{default:u(()=>[l(T,{ref_key:"descriptionEditorRef",ref:c,modelValue:d.value,"onUpdate:modelValue":e[2]||(e[2]=a=>d.value=a),lang:"markdown",options:C,class:"border border-gray-200 dark:border-gray-800 rounded",style:{height:"400px"}},{default:u(()=>e[7]||(e[7]=[G(" Loading editor... ")])),_:1},8,["modelValue"])]),_:1})])])]),_:1})]),_:1},8,["modelValue"])}}});export{te as _};
