import{u as V,_ as T}from"./Bym0NDoT.js";import{h as B,r as g,y as S,ar as W,be as F,z as f,b4 as $,bf as j,o as D,c as E,ai as A,J,x as Z,A as q,B as G,bg as I,b as p,d as s,w as d,l as y,K as L,F as P,V as Q,D as X,L as z,bh as Y,Z as ee,t as te,e as b,C as oe,T as ae,N as ne,bi as se}from"./DbTgESvQ.js";import{u as le}from"./C-G9LxTU.js";const ie=B({__name:"MonacoEditor.client",props:{lang:{default:()=>"plaintext"},options:{default:()=>({})},modelValue:{default:()=>""}},emits:["update:modelValue","load"],setup(w,{expose:c,emit:l}){const t=w,u=l,k=g(!0),v=S(()=>t.lang||t.options.language),i=W(),r=g(),a=F(),x={automaticLayout:!0};let e,n;return f(()=>t.modelValue,()=>{(e==null?void 0:e.getValue())!==t.modelValue&&(e==null||e.setValue(t.modelValue))}),f(()=>t.lang,()=>{n&&n.dispose(),n=a.editor.createModel(t.modelValue,v.value),e==null||e.setModel(n)}),f(()=>t.options,()=>{e==null||e.updateOptions($(t.options,x))}),f(r,(C,_)=>{!r.value||_||(e=a.editor.create(r.value,$(t.options,x)),n=a.editor.createModel(t.modelValue,v.value),i.value=e,e.layout(),e.setModel(n),e.onDidChangeModelContent(()=>{u("update:modelValue",e.getValue())}),k.value=!1,u("load",e))}),c({$editor:i}),j(()=>{e==null||e.dispose(),n==null||n.dispose()}),(C,_)=>(D(),E("div",{ref_key:"editorElement",ref:r},[k.value?A(C.$slots,"default",{key:0}):J("",!0)],512))}}),re=se(ie),de={class:"grid items-start lg:grid-cols-5"},ce={class:"grid grid-cols-1 lg:col-span-4 bg-backdrop dark:bg-backdrop-dark"},ue={class:"h-10 flex items-center justify-between px-4"},me={class:"font-semibold"},pe={class:"flex items-center select-none"},ge={class:"overflow-hidden border-l border-t dark:border-gray-600"},he=B({__name:"[name]",setup(w){const c=g(!1),l=S(()=>Q().params.name),t=g(""),u=g(""),k=Z(),v=S(()=>k.value==="light"?"vs-light":"vs-dark"),i=g();le({title:`${l.value} - Jesse`}),f(v,o=>{i.value.$editor.updateOptions({theme:o})}),q(async()=>{setTimeout(async()=>{t.value=await V().getStrategy(l.value),u.value=t.value,i.value.$editor.updateOptions({theme:v.value})},200),window.addEventListener("keydown",_)}),G(()=>{window.removeEventListener("keydown",_)});const r=S(()=>t.value!==u.value),a=S(()=>X().settings.editor),x={automaticLayout:!0,minimap:{enabled:a.value.minimap},fontSize:a.value.fontSize,padding:{top:16,bottom:16},cursorStyle:a.value.cursorStyle,cursorWidth:a.value.cursorWidth,lineHeight:a.value.lineHeight,cursorBlinking:a.value.cursorBlinking,renderLineHighlight:a.value.renderLineHighlight};f(a,o=>{console.log("2",o),i.value.$editor.updateOptions({minimap:{enabled:o.minimap},fontSize:o.fontSize,cursorStyle:o.cursorStyle,cursorWidth:o.cursorWidth,lineHeight:o.lineHeight,cursorBlinking:o.cursorBlinking,renderLineHighlight:o.renderLineHighlight})},{deep:!0});function e(){navigator.clipboard.writeText(t.value),z("success","Code copied to clipboard")}async function n(){if(r.value){if(t.value===""){z("error","Code cannot be empty");return}await V().saveStrategy(l.value,t.value),u.value=t.value}}const C=I.debounce(async()=>{await n()},300);function _(o){o.key==="s"&&(navigator.platform.match("Mac")?o.metaKey:o.ctrlKey)&&(o.preventDefault(),C())}function H(){i.value.$editor.trigger("source","actions.find",{})}function O(){V().deleteStrategy(l.value),ae().push("/strategies")}return(o,m)=>{const R=T,h=ne,N=re,U=Y,K=ee;return D(),E(P,null,[p("section",de,[s(R),p("div",ce,[s(U,null,{default:d(()=>[p("div",ue,[p("h2",me,te(y(l)),1),p("div",pe,[s(h,{size:"xs",icon:"i-heroicons-trash",color:"gray",variant:"ghost",class:"ml-2",onClick:m[0]||(m[0]=M=>c.value=!0)},{default:d(()=>[b(" Delete ")]),_:1}),s(h,{size:"xs",icon:"i-heroicons-clipboard",color:"gray",variant:"ghost",class:"ml-2",onClick:e},{default:d(()=>[b(" Copy ")]),_:1}),s(h,{size:"xs",icon:"i-heroicons-magnifying-glass",class:"ml-2",color:"gray",variant:"ghost",onClick:H},{default:d(()=>[b(" Find ")]),_:1}),s(h,{size:"xs",icon:"i-heroicons-check",class:"ml-2",color:"teal",variant:"ghost",disabled:!y(r),onClick:n},{default:d(()=>[b(" Save ")]),_:1},8,["disabled"])])]),p("div",ge,[s(N,{ref_key:"editorRef",ref:i,modelValue:y(t),"onUpdate:modelValue":m[1]||(m[1]=M=>L(t)?t.value=M:null),lang:"python",options:x,style:oe({height:"calc(100vh - 4rem - 4px - 2.5rem)"})},{default:d(()=>[b(" Loading editor... ")]),_:1},8,["modelValue","style"])])]),_:1})])]),s(K,{modelValue:y(c),"onUpdate:modelValue":m[2]||(m[2]=M=>L(c)?c.value=M:null),title:"Delete strategy",description:`Are you sure you want to delete the strategy '${y(l)}'?`,type:"info"},{default:d(()=>[s(h,{variant:"solid",color:"red",class:"flex justify-center",label:"Delete",onClick:O})]),_:1},8,["modelValue","description"])],64)}}});export{he as default};
