import{ERROR_TYPES as e,parseRaw as t,toNameEqualsValueString as r}from"@clevercloud/client/esm/utils/env-vars.js";import{LitElement as i,html as s,css as n}from"lit";import{dispatchCustomEvent as a}from"./lib/events.js";import{linkStyles as o}from"./templates/cc-link/cc-link.js";import{i18n as l}from"./translation.js";import"./cc-input-text.js";import"./cc-notice.js";const c=[{name:"VARIABLE_ONE",value:""},{name:"VARIABLE_FOOBAR",value:""},{name:"VARIABLE_PORT",value:""}];class d extends i{static get properties(){return{disabled:{type:Boolean},readonly:{type:Boolean},state:{type:Object},_errors:{type:Array,state:!0},_skeleton:{type:Boolean,state:!0},_variablesAsText:{type:Array,state:!0}}}constructor(){super(),this.disabled=!1,this.readonly=!1,this.state={type:"loading"},this._errors=[],this._skeleton=!1,this._variablesAsText=""}_setErrors(t){this._errors=t.map((({type:t,name:r,pos:i})=>t===e.INVALID_NAME?{line:i.line,msg:l("cc-env-var-editor-expert.errors.invalid-name",{name:r}),isWarning:!1}:t===e.DUPLICATED_NAME?{line:i.line,msg:l("cc-env-var-editor-expert.errors.duplicated-name",{name:r}),isWarning:!1}:t===e.INVALID_LINE?{line:i.line,msg:l("cc-env-var-editor-expert.errors.invalid-line"),isWarning:!1}:t===e.INVALID_VALUE?{line:i.line,msg:l("cc-env-var-editor-expert.errors.invalid-value"),isWarning:!1}:t===e.INVALID_NAME_STRICT?{line:i.line,msg:l("cc-env-var-editor-expert.errors.invalid-name-strict",{name:r}),isWarning:!1}:t===e.JAVA_INFO?{line:i.line,msg:l("cc-env-var-editor-expert.info.java-prop",{name:r}),isWarning:!0}:{line:"?",msg:l("cc-env-var-editor-expert.errors.unknown"),isWarning:!1}))}_onInput({detail:e}){if("loading"===this.state.type)return;this._variablesAsText=e;const{variables:r,errors:i}=t(e,{mode:this.state.validationMode});this._setErrors(i),a(this,"change",r)}willUpdate(e){if(e.has("state")){this._skeleton="loading"===this.state.type;const e=("loaded"===this.state.type?this.state.variables:c).filter((({isDeleted:e})=>!e));this._variablesAsText=r(e),this._setErrors([])}}render(){return s`${this.readonly?"":s`<div class=example>${l("cc-env-var-editor-expert.example")}</div>`}<cc-input-text label=${l("cc-env-var-editor-expert.label")} hidden-label multi clipboard value=${this._variablesAsText} ?disabled=${this.disabled} ?readonly=${this.readonly} ?skeleton=${this._skeleton} @cc-input-text:input=${this._onInput}></cc-input-text>${this._errors.length>0?s`<div class=error-list>${this._errors.map((({line:e,msg:t,isWarning:r})=>s`<cc-notice intent=${r?"info":"warning"}><div slot=message><strong>${l("cc-env-var-editor-expert.errors.line")} ${e}:</strong> ${t}</div></cc-notice>`))}</div>`:""}`}static get styles(){return[o,n`:host{display:block}:host([hidden]){display:none}.error-list{display:grid;grid-gap:.75em;margin-top:1em}.example{line-height:1.5;padding-bottom:1em}.example code,cc-notice code{background-color:var(--cc-color-bg-neutral,#eee);border-radius:var(--cc-border-radius-default,.25em);font-family:var(--cc-ff-monospace,monospace);padding:.15em .3em}cc-input-text{--cc-input-font-family:var(--cc-ff-monospace, monospace)}`]}}window.customElements.define("cc-env-var-editor-expert",d);export{d as CcEnvVarEditorExpert};
//# sourceMappingURL=cc-env-var-editor-expert.js.map
