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{i18n as a}from"./translation.js";import{CcEnvChangeEvent as o}from"./components/cc-env-var-form/cc-env-var-form.events.js";import"./cc-input-text.js";import"./cc-link.js";import"./cc-notice.js";const l=[{name:"VARIABLE_ONE",value:""},{name:"VARIABLE_FOOBAR",value:""},{name:"VARIABLE_PORT",value:""}];class c 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:a("cc-env-var-editor-expert.errors.invalid-name",{name:r}),isWarning:!1}:t===e.DUPLICATED_NAME?{line:i.line,msg:a("cc-env-var-editor-expert.errors.duplicated-name",{name:r}),isWarning:!1}:t===e.INVALID_LINE?{line:i.line,msg:a("cc-env-var-editor-expert.errors.invalid-line"),isWarning:!1}:t===e.INVALID_VALUE?{line:i.line,msg:a("cc-env-var-editor-expert.errors.invalid-value"),isWarning:!1}:t===e.INVALID_NAME_STRICT?{line:i.line,msg:a("cc-env-var-editor-expert.errors.invalid-name-strict",{name:r}),isWarning:!1}:t===e.JAVA_INFO?{line:i.line,msg:a("cc-env-var-editor-expert.info.java-prop",{name:r}),isWarning:!0}:{line:"?",msg:a("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),this.dispatchEvent(new o(r))}willUpdate(e){if(e.has("state")){this._skeleton="loading"===this.state.type;const e=("loaded"===this.state.type?this.state.variables:l).filter((({isDeleted:e})=>!e));this._variablesAsText=r(e),this._setErrors([])}}render(){return s`
      ${this.readonly?"":s` <div class="example">${a("cc-env-var-editor-expert.example")}</div> `}
      <cc-input-text
        label=${a("cc-env-var-editor-expert.label")}
        hidden-label
        multi
        clipboard
        value=${this._variablesAsText}
        ?readonly=${this.readonly||this.disabled}
        ?skeleton=${this._skeleton}
        @cc-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>${a("cc-env-var-editor-expert.errors.line")} ${e}:</strong> ${t}
                    </div>
                  </cc-notice>
                `))}
            </div>
          `:""}
    `}static get styles(){return[n`
        :host {
          display: block;
        }

        :host([hidden]) {
          display: none;
        }

        .error-list {
          display: grid;
          grid-gap: 0.75em;
          margin-top: 1em;
        }

        .example {
          line-height: 1.5;
          padding-bottom: 1em;
        }

        /* i18n error message may contain <code> tags */

        cc-notice code,
        .example code {
          background-color: var(--cc-color-bg-neutral, #eee);
          border-radius: var(--cc-border-radius-default, 0.25em);
          font-family: var(--cc-ff-monospace, monospace);
          padding: 0.15em 0.3em;
        }

        cc-input-text {
          --cc-input-font-family: var(--cc-ff-monospace, monospace);
        }
      `]}}window.customElements.define("cc-env-var-editor-expert",c);export{c as CcEnvVarEditorExpert};
//# sourceMappingURL=cc-env-var-editor-expert.js.map
