import{j as e}from"./createSvgIcon-DlIk-fDn.js";import{R as i}from"./iobroker_javascript__loadShare__react__loadShare__-i8pXne9X.js";import{i as r,I as n}from"./index-Cjl4b70e.js";import{i as a}from"./index-DBgNhNiJ.js";import l from"./ScriptEditorVanillaMonaco-CJS71hoK.js";import{I as c}from"./Save-DXaUpIPM.js";import"./_commonjsHelpers-Cpj98o6Y.js";import"./iobroker_javascript__mf_v__runtimeInit__mf_v__-DZdFIfoQ.js";import"./inheritsLoose-DNrhibGS.js";import"./preload-helper-BDBacUwf.js";const o={textArea:{width:"calc(100% - 10px)",resize:"none"},dialog:{height:"95%"},fullHeight:{height:"100%",overflow:"hidden"},args:s=>({color:s.palette.mode==="dark"?"white":"black",height:30,width:"100%",fontSize:16}),argsTitle:s=>({color:s.palette.mode==="dark"?"white":"black",fontWeight:"bold"})};class k extends i.Component{constructor(t){super(t),this.state={changed:!1,source:!t.source&&t.isReturn?`
return false`:t.source}}componentDidMount(){setTimeout(()=>{var t;try{(t=window.document.getElementById("source-text-area"))==null||t.focus()}catch{}},100)}handleCancel(){this.props.onClose(!1)}handleOk(){(!this.props.isReturn||this.state.source.includes("return "))&&this.props.onClose(this.state.source)}onChange(t){this.setState({changed:!0,source:t})}render(){return e.jsxs(r.Dialog,{onClose:()=>!1,maxWidth:"lg",sx:{"& .MuiDialog-paper":o.dialog},fullWidth:!0,open:!0,"aria-labelledby":"source-dialog-title",children:[e.jsx(r.DialogTitle,{id:"source-dialog-title",children:a.I18n.t("Function editor")}),e.jsxs(r.DialogContent,{style:o.fullHeight,children:[this.props.args&&e.jsxs(r.Box,{sx:o.args,children:[e.jsx(r.Box,{component:"span",sx:o.argsTitle,children:a.I18n.t("function (")}),this.props.args,e.jsx(r.Box,{component:"span",sx:o.argsTitle,children:")"})]},"arguments"),e.jsx(l,{triggerPrettier:1,adapterName:this.props.adapterName,runningInstances:this.props.runningInstances,style:{...o.textArea,height:this.props.args?"calc(100% - 30px)":"100%"},name:"blockly",socket:this.props.socket,readOnly:!1,checkJs:!1,changed:this.state.changed,code:this.state.source,isDark:this.props.themeType==="dark",onChange:t=>this.onChange(t),language:"javascript"},"scriptEditor")]}),e.jsxs(r.DialogActions,{children:[e.jsx(r.Button,{variant:"contained",onClick:()=>this.handleOk(),color:"primary",startIcon:e.jsx(c,{}),children:a.I18n.t("Save")}),e.jsx(r.Button,{color:"grey",variant:"contained",onClick:()=>this.handleCancel(),startIcon:e.jsx(n,{}),children:a.I18n.t("Cancel")})]})]})}}export{k as default};
