import{html as e,PolymerElement as t}from"../../@polymer/polymer/polymer-element.js";import{FlattenedNodesObserver as r}from"../../@polymer/polymer/lib/utils/flattened-nodes-observer.js";import{IronFormElementBehavior as o}from"../../@polymer/iron-form-element-behavior/iron-form-element-behavior.js";import{IronValidatableBehavior as s}from"../../@polymer/iron-validatable-behavior/iron-validatable-behavior.js";import{mixinBehaviors as a}from"../../@polymer/polymer/lib/legacy/class.js";class MtzMarkedEditor extends(a([o,s],t)){static get template(){return e`
      <style>
        :host {
          display: block;
        }
      </style>
      <slot name="controls"></slot> <slot name="textarea"></slot>
      <slot name="footer"></slot>
    `}static get tag(){return"mtz-marked-editor"}static get properties(){return{...super.properties,autofocus:Boolean,readonly:Boolean,textareaSelector:{type:String,value:"textarea"},__textarea:Object}}constructor(){super(),this.addEventListener("register-control",this.__bindControlToEditor.bind(this))}connectedCallback(){super.connectedCallback(),this.__textarea=this.queryDistributedElements('[slot="textarea"]')[0]}queryDistributedElements(e){let t=r.getFlattenedNodes(this),o=[];for(let r,s=0,a=t.length;s<a&&(r=t[s]);s++)r.nodeType===Node.ELEMENT_NODE&&matchesSelector(r,e)&&o.push(r);return o}disconnectedCallback(){this.removeEventListener("register-control",this.__bindControlToEditor),super.disconnectedCallback()}getTextarea(){return this.__textarea}getLines(){return this.getContent().split(/(?=\n|\r\n)$/gm)}getContent(){return void 0!==this.getTextarea()?this.getTextarea().value:""}setContent(e){this.getTextarea().value=e}getSelection(e=this.getTextarea()){const t=e.selectionStart,r=e.selectionEnd;return{start:t,end:r,length:r-t,text:e.value.substring(t,r)}}setSelection(e,t,r=this.getTextarea()){r.selectionStart=e,r.selectionEnd=t}replaceSelection(e,t=this.getTextarea(),r=this.getSelection()){const o=t.value;t.value=`${o.substr(0,r.start)}${e}${o.substr(r.end,o.length)}`}__bindControlToEditor(e){e.stopPropagation(),e.target.__editor=this}}window.customElements.define(MtzMarkedEditor.tag,MtzMarkedEditor);export{MtzMarkedEditor};const n=Element.prototype,l=n.matches||n.matchesSelector||n.mozMatchesSelector||n.msMatchesSelector||n.oMatchesSelector||n.webkitMatchesSelector;export const matchesSelector=function(e,t){return l.call(e,t)};