import*as e from"lit/directives/style-map.js";import*as t from"lit/directives/repeat.js";import*as i from"lit";import*as s from"@momentum-ui/utils/lib/getColorValue";import*as r from"lit/directives/if-defined.js";import*as a from"lit/directives/class-map.js";import*as o from"mobx";import*as l from"lit/decorators.js";import*as n from"@momentum-ui/icons/data/momentumUiIconsNames.json";import{default as d}from"dompurify";var p,m,h={1156(t,i,s){var r,a;t.exports=(r={styleMap:()=>e.styleMap},a={},s.d(a,r),a)},2577(e,i,s){var r,a;e.exports=(r={repeat:()=>t.repeat},a={},s.d(a,r),a)},2927(e,t,s){var r,a;e.exports=(r={LitElement:()=>i.LitElement,css:()=>i.css,html:()=>i.html,nothing:()=>i.nothing},a={},s.d(a,r),a)},3496(e,t,i){var r,a;e.exports=(r={default:()=>s.default},a={},i.d(a,r),a)},3517(e,t,i){var s,a;e.exports=(s={ifDefined:()=>r.ifDefined},a={},i.d(a,s),a)},4955(e,t,i){var s,r;e.exports=(s={classMap:()=>a.classMap},r={},i.d(r,s),r)},4980(e,t,i){var s,r;e.exports=(s={action:()=>o.action,observable:()=>o.observable},r={},i.d(r,s),r)},8899(e,t,i){var s,r;e.exports=(s={property:()=>l.property,query:()=>l.query,state:()=>l.state},r={},i.d(r,s),r)},9500(e,t,i){var s,r;e.exports=(s={default:()=>n.default},r={},i.d(r,s),r)},9503(e,t,i){i.d(t,{I:()=>f,O:()=>c}),i(9189);var s=i(9609),r=i(3331),a=i(4084),o=i(2927),l=i(8899),n=i(4955),p=i(3517),m=i(9956),h=function(e,t,i,s){var r,a=arguments.length,o=a<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,s);else for(var l=e.length-1;l>=0;l--)(r=e[l])&&(o=(a<3?r(o):a>3?r(t,i,o):r(t,i))||o);return a>3&&o&&Object.defineProperty(t,i,o),o};const c=["left","right","center"];var f;!function(e){let t=class extends o.LitElement{constructor(){super(...arguments),this.alignment="left",this.disabled=!1,this.isEditing=!1,this.maxLines="",this.content="Click to edit text",this.message={type:"error",message:"That is not a valid input."},this.alert=!1,this.hideMessage=!1,this.pattern="",this.type=null,this.ariaLabel="editable field",this.ariaDescribedBy="",this.reportValidity=()=>{this.dispatchEvent(new Event("invalid",{bubbles:!1,cancelable:!0,composed:!0}))},this.checkValidity=e=>{let t=!0;const i=i=>{null===e.match(i)&&(t=!1)};if(this.pattern)i(new RegExp(this.pattern));else if(e&&this.type)switch(this.type){case"integer":i(new RegExp(r.b.integerString));break;case"decimal":i(new RegExp(r.b.decimalString))}return t},this.handleFocus=()=>{this.disabled||(this.isEditing=!0,this.setRange())},this.handleKeydown=e=>{var t,i;const{key:s,code:r}=e;if(!["Tab","Meta","Shift","Delete","Backspace","Arrow"].some(e=>r.includes(e)))if("integer"===this.type&&(s.includes(".")||"-"===s&&(null===(t=this.editableField)||void 0===t?void 0:t.innerText.includes("-"))))e.preventDefault();else if("integer"!==this.type&&"decimal"!==this.type||!r.match("Space")){if(this.type&&1===s.length){const t=((null===(i=this.editableField)||void 0===i?void 0:i.innerText.trim())||"")+s;("integer"!==this.type||/^-?\d*$/.test(t))&&("decimal"!==this.type||/^-?\d*\.?\d*$/.test(t))||e.preventDefault()}}else e.preventDefault()},this.handleBlur=()=>{var e,t,i;this.isEditing=!1,this.maxLines.length>0&&(null===(e=this.editableField)||void 0===e||e.scrollTo(0,0));const s=(null===(i=null===(t=this.editableField)||void 0===t?void 0:t.innerText)||void 0===i?void 0:i.trim())||"",r=d.sanitize(s);r!==this.content&&(this.content=r),this.alert=!1,this.handleValidation()}}connectedCallback(){super.connectedCallback(),this.addEventListener("focus",this.handleFocus)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("focus",this.handleFocus)}firstUpdated(e){super.firstUpdated(e),this.innerText&&this.innerText.trim().length>0&&this.innerText.trim()!==this.content&&(this.content=this.innerText.trim())}setRange(){var e;if(this.editableField){const t=document.createRange(),i=window.getSelection(),s=this.editableField.childNodes[0];if(!s||s.nodeType!==Node.TEXT_NODE)return;const r=(null===(e=s.nodeValue)||void 0===e?void 0:e.length)||0;t.setStart(s,r),t.collapse(!0),i&&0===i.toString().length&&(i.removeAllRanges(),i.addRange(t)),this.maxLines.length>0&&(this.editableField.scrollTop=this.editableField.scrollHeight)}}handleValidation(){var e;(this.type||this.pattern)&&((null===(e=this.checkValidity)||void 0===e?void 0:e.call(this,this.content))||(this.reportValidity(),this.showAlert()))}showAlert(){this.alert=!0}static get styles(){return[a.A,m.A]}get overflowStyles(){return this.maxLines.length&&this.maxLines.length>0&&`max-height: ${2*parseInt(this.maxLines)}rem; -webkit-line-clamp: ${this.maxLines}; word-break: break-all;`}messagesTemplate(){var e,t,i;return this.alert?o.html`
            <div class="md-editable-textfield__messages" style="display: ${this.hideMessage?"none":"block"}">
              <md-help-text
                id="alert-message"
                role="alert"
                aria-live="assertive"
                .messageType=${null===(e=this.message)||void 0===e?void 0:e.type}
                aria-errormessage=${(0,p.ifDefined)(null===(t=this.message)||void 0===t?void 0:t.message)}
              >
                ${null===(i=this.message)||void 0===i?void 0:i.message}
              </md-help-text>
            </div>
          `:o.nothing}render(){var e;const t={[`md-editable-textfield--${this.alignment}`]:this.alignment,"md-editable-textfield--disabled":this.disabled,[`md-editable-textfield--${null===(e=this.message)||void 0===e?void 0:e.type}`]:this.alert&&!!this.message,"md-editable-textfield--textoverflow":this.maxLines.length>0&&!this.isEditing};return o.html`
        <div
          part="editable-textfield"
          style="${this.overflowStyles}"
          class="md-editable-textfield ${(0,n.classMap)(t)}"
          role=${(0,p.ifDefined)(this.disabled?void 0:"textbox")}
          tabindex=${this.disabled?"-1":"0"}
          ?contenteditable=${this.isEditing}
          @focus=${this.handleFocus}
          @blur=${this.handleBlur}
          @keydown=${e=>{this.handleKeydown(e)}}
          aria-invalid=${(0,p.ifDefined)(this.disabled?void 0:this.alert?"true":"false")}
          aria-label=${(0,p.ifDefined)(this.disabled?void 0:this.ariaLabel)}
          aria-describedby=${(0,p.ifDefined)(this.disabled?void 0:this.ariaDescribedBy)}
          .innerText=${this.content}
        ></div>
        ${this.messagesTemplate()}
      `}};h([(0,l.property)({type:String})],t.prototype,"alignment",void 0),h([(0,l.property)({type:Boolean})],t.prototype,"disabled",void 0),h([(0,l.property)({type:Boolean})],t.prototype,"isEditing",void 0),h([(0,l.property)({type:String,attribute:"max-lines",reflect:!0})],t.prototype,"maxLines",void 0),h([(0,l.property)({type:String,reflect:!0})],t.prototype,"content",void 0),h([(0,l.property)({type:Object})],t.prototype,"message",void 0),h([(0,l.property)({type:Boolean,reflect:!0})],t.prototype,"alert",void 0),h([(0,l.property)({type:Boolean})],t.prototype,"hideMessage",void 0),h([(0,l.property)({type:String})],t.prototype,"pattern",void 0),h([(0,l.property)({type:String})],t.prototype,"type",void 0),h([(0,l.property)({type:String})],t.prototype,"ariaLabel",void 0),h([(0,l.property)({type:String,attribute:"aria-described-by"})],t.prototype,"ariaDescribedBy",void 0),h([(0,l.query)(".md-editable-textfield")],t.prototype,"editableField",void 0),t=h([(0,s.w)("md-editable-field")],t),e.ELEMENT=t}(f||(f={}))}},c={};function f(e){var t=c[e];if(void 0!==t)return t.exports;var i=c[e]={exports:{}};return h[e](i,i.exports,f),i.exports}f.m=h,p=[],f.O=(e,t,i,s)=>{if(!t){var r=1/0;for(n=0;n<p.length;n++){for(var[t,i,s]=p[n],a=!0,o=0;o<t.length;o++)(!1&s||r>=s)&&Object.keys(f.O).every(e=>f.O[e](t[o]))?t.splice(o--,1):(a=!1,s<r&&(r=s));if(a){p.splice(n--,1);var l=i();void 0!==l&&(e=l)}}return e}s=s||0;for(var n=p.length;n>0&&p[n-1][2]>s;n--)p[n]=p[n-1];p[n]=[t,i,s]},f.d=(e,t)=>{for(var i in t)f.o(t,i)&&!f.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},f.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);export{f as __webpack_require__};m={502:0,1745:0,1807:0,2169:0,4545:0,4928:0,5369:0,6060:0,6920:0,8111:0,8442:0},f.C=e=>{var t,i,{__webpack_esm_ids__:s,__webpack_esm_modules__:r,__webpack_esm_runtime__:a}=e,o=0;for(t in r)f.o(r,t)&&(f.m[t]=r[t]);for(a&&a(f);o<s.length;o++)i=s[o],f.o(m,i)&&m[i]&&m[i][0](),m[s[o]]=0;f.O()},f.O.j=e=>0===m[e];import*as v from"../9609.js";f.C(v);import*as y from"../4084.js";f.C(y);import*as b from"../3305.js";f.C(b);import*as g from"../4739.js";f.C(g);import*as u from"../7154.js";f.C(u);import*as x from"../9773.js";f.C(x);import*as j from"../5983.js";f.C(j);import*as C from"../9488.js";f.C(C);import*as w from"../1821.js";f.C(w);import*as $ from"../519.js";f.C($);import*as E from"../8441.js";f.C(E);import*as _ from"../2797.js";f.C(_);import*as T from"../9983.js";f.C(T);import*as k from"../3970.js";f.C(k);import*as L from"../7906.js";f.C(L);import*as O from"../9336.js";f.C(O);import*as D from"../2369.js";f.C(D);import*as S from"../9189.js";f.C(S);import*as F from"../3331.js";f.C(F);import*as R from"../9956.js";f.C(R);var B=f.O(void 0,[9609,4084,3305,4739,7154,9773,5983,9488,1821,519,8441,2797,9983,3970,7906,9336,2369,9189,3331,9956],()=>f(9503));const M=(B=f.O(B)).I,V=B.O;export{M as EditableTextfield,V as alignment};