import{d as Y,r,G as B,Q as G,u as J,X as T,o as O,U as Q,b as d,c as h,v as e,e as C,E as P,y as p,I as S,z as X,F as j,J as W,$ as Z,B as b,t as ee,L as te,H as se,N as ae,O as ne,q as oe}from"./registerWidgets.fff064a1.js";import{q as D,r as re,v as le}from"./icons.b8ff2c28.js";import{l as g}from"./WidgetsFrame.7e48c68b.js";const ie=l=>(ae("data-v-3ea58118"),l=l(),ne(),l),ce={class:"smart-console"},ue={class:"header"},de=ie(()=>e("div",{class:"left"},"Console",-1)),pe={class:"right"},ve={class:"cli"},he={class:"left"},me={class:"entry ai-output"},ye={key:0},ge={class:"local-entry"},_e={key:0,class:"input"},fe=["pointer-events","onKeydown"],Se={class:"right"},ke=Y({__name:"SmartConsole",props:{inputEnabled:{type:Boolean},dashPlayerState:null,formCode:null,runtime:null},emits:["clear-terminal","restart","enter"],setup(l,{emit:x}){const o=l,m=r(""),i=r(null),H=te(),w=B(()=>o.runtime==="dashes"?f:g.logs),K=r(!1),N=()=>{g.clear(),x("restart")};G(H,()=>{g.clear(),x("clear-terminal")});const _=r(null),$=r("assistant"),q=async t=>{var a;if(t.preventDefault(),m.value=((a=_.value)==null?void 0:a.innerText)||"",t.shiftKey){document.execCommand("insertLineBreak");return}_.value&&(_.value.innerText=""),await V()},V=async()=>{m.value&&(c({type:"eval-request",log:`>>> ${m.value}`}),A(m.value),m.value="")},f=J([]),c=async t=>{f.push(t),await T(),i.value&&(i.value.scrollTop=i.value.scrollHeight)},A=t=>{var a,n,u;(u=(a=o.dashPlayerState)==null?void 0:a.broker)==null||u.send({type:"eval",expression:t,state:(n=o.dashPlayerState)==null?void 0:n.apiPageState})};(()=>{var t,a,n,u,R,z;(t=o.dashPlayerState)==null||t.on("eval-return",s=>{s.repr&&c({type:"log",log:s.repr})}),(a=o.dashPlayerState)==null||a.on("eval-error",s=>{c({type:"error",log:s.repr})}),(n=o.dashPlayerState)==null||n.on("stderr",s=>{c({type:"stderr",log:s.log})}),(u=o.dashPlayerState)==null||u.on("stdout",s=>{c({type:"stdout",log:s.log})}),(R=o.dashPlayerState)==null||R.on("widgets-computed",s=>{var y;(y=s.errors)!=null&&y.general&&c({type:"error",log:s.errors.general.repr})}),(z=o.dashPlayerState)==null||z.on("program-start-failed",s=>{var y;c({type:"error",log:(y=s.error)!=null?y:""})})})();const F=()=>{$.value==="assistant"?g.clear():f.splice(0,f.length)};g.listen(async t=>{t.type!=="restart"&&(v.value=!0,await T(),i.value&&(i.value.scrollTop=i.value.scrollHeight))});const v=r(!1),E=r(400),M=B(()=>({height:`${E.value}px`})),k=r(!1),U=()=>k.value=!0,I=t=>{!k.value||(E.value=document.body.clientHeight-t.clientY)},L=()=>k.value=!1;return O(()=>{document.addEventListener("mousemove",I),document.addEventListener("mouseup",L)}),Q(()=>{document.removeEventListener("mousemove",I),document.removeEventListener("mouseup",L)}),(t,a)=>(d(),h("div",ce,[e("div",ue,[de,e("div",pe,[e("div",{class:"changes-container"},[e("button",{class:"header-button",onClick:N},"Restart")]),e("div",{class:"toggle-button",onClick:a[0]||(a[0]=n=>v.value=!v.value)},[C(S,{class:P(["icon",{open:v.value}]),path:p(D),fill:"#fff"},null,8,["class","path"])])])]),v.value?(d(),h("div",{key:0,class:"terminal",style:X(p(M))},[e("div",{class:"resize-handler",onMousedown:U},null,32),e("div",ve,[e("div",he,[e("div",{ref_key:"entriesContainer",ref:i,class:"entries"},[e("div",me,[p(w).length==0?(d(),h("span",ye," You can inspect your code here. ")):(d(!0),h(j,{key:1},W(p(w),(n,u)=>(d(),h("div",{key:u,class:P([n.type,"entry"])},[e("div",ge,se(n.type==="restart"?"-- restarted --":n.log),1)],2))),128))])],512),l.runtime==="dashes"?(d(),h("div",_e,[C(S,{class:P(["icon",{open:v.value}]),path:p(D)},null,8,["class","path"]),e("div",{ref_key:"inputRef",ref:_,class:"input-text",contenteditable:"","pointer-events":K.value?"none":"auto",placeholder:"Ask AI anything",onKeydown:Z(q,["enter"])},null,40,fe)])):b("",!0)]),e("div",Se,[e("div",{class:"icons",onClick:F},[C(S,{class:"icon",path:p(re)},null,8,["path"])]),e("div",null,[l.runtime==="dashes"?(d(),ee(S,{key:0,class:"icon",path:p(le)},null,8,["path"])):b("",!0)])])])],4)):b("",!0)]))}});const we=oe(ke,[["__scopeId","data-v-3ea58118"]]);export{we as S};
//# sourceMappingURL=SmartConsole.779b6df2.js.map
