var __decorate=this&&this.__decorate||function(e,t,r,i){var o,s=arguments.length,a=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,i);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(a=(s<3?o(a):s>3?o(t,r,a):o(t,r))||a);return s>3&&a&&Object.defineProperty(t,r,a),a};import{OrRulesRuleChangedEvent as e}from"./index";import{css as t,html as r,LitElement as i}from"lit";import{customElement as o,property as s}from"lit/decorators.js";import"ace-builds/src-noconflict/mode-javascript";import"ace-builds/src-noconflict/mode-json";import"ace-builds/src-noconflict/mode-groovy";import"@openremote/or-components/or-ace-editor";import{createRef as a,ref as l}from"lit/directives/ref.js";let style=t`
    :host {
        display: flex;
        width: 100%;
        height: 100%;
    }

    #ace-editor {
        position: relative;
        height: 100%;
        width: 100%;
    }

    @media screen and (max-width: 1400px) {
        :host > * {
            flex-grow: 0;
        }

        :host {
            flex-direction: column;
        }
    }
`,OrRuleTextViewer=class extends i{constructor(){super(...arguments),this._aceEditor=a()}static get styles(){return style}set ruleset(e){this._ruleset!==e&&(this._ruleset=e,e.rules?this._rules=e.rules:this._rules=this._createRules())}_createRules(){return""}render(){return r`
            <or-ace-editor ${l(this._aceEditor)} @or-ace-editor-changed="${e=>this._onEditorChanged(e)}" .mode="${this._getMode()}" .readonly="${this.readonly}" .value="${this._getRulesString()}"></or-ace-editor>
        `}_getMode(){switch(this._ruleset.lang){case"JAVASCRIPT":return"ace/mode/javascript";case"GROOVY":return"ace/mode/groovy";case"JSON":return"ace/mode/json"}}_getRulesString(){if(!this._rules)return"";switch(this._ruleset.lang){case"JAVASCRIPT":case"GROOVY":return this._rules;case"JSON":return JSON.stringify(JSON.parse(this._rules),null,2)}}_onEditorChanged(t){let r=t.detail.valid;this.dispatchEvent(new e(r))}beforeSave(){!this.readonly&&this._aceEditor.value&&(this._ruleset.rules=this._aceEditor.value.getValue())}validate(){return!!this._aceEditor.value&&this._aceEditor.value.validate()}};__decorate([s({attribute:!1})],OrRuleTextViewer.prototype,"readonly",void 0),__decorate([s({attribute:!1})],OrRuleTextViewer.prototype,"config",void 0),__decorate([s({attribute:!1})],OrRuleTextViewer.prototype,"_ruleset",void 0),OrRuleTextViewer=__decorate([o("or-rule-text-viewer")],OrRuleTextViewer);export{OrRuleTextViewer};