/**
 * Copyright 2019 Penn State University
 * @license Apache-2.0, see License.md for full text.
 */
import{LitElement as t,html as e,css as i}from"../../../../lit/index.js";import{RichTextEditorButtonBehaviors as s}from"./rich-text-editor-button.js";import"../singletons/rich-text-editor-prompt.js";const RichTextEditorPromptButtonBehaviors=function(t){return class extends(s(t)){static get tag(){return"rich-text-editor-prompt-button"}render(){return super.render()}static get properties(){return{...super.properties,fields:{type:Array},id:{name:"id",type:String,reflect:!0,attribute:"id"},value:{type:Object},__wrap:{name:"__wrap",type:Object},__oldValue:{name:"__oldValue",type:Object}}}constructor(){super(),this.editableSelection=!1,this.fields=[{property:"innerHTML",title:"Text",inputMethod:"textfield",description:"Text currently selected",disabled:!0,required:!0}],this.tagsList="span",this.value={innerHTML:void 0}}firstUpdated(t){super.firstUpdated(t)}get promptCommand(){return this.toggledCommand&&!this.toggled?this.toggledCommand:this.command}get promptCommandVal(){return this.commandVal}get setsInnerHTML(){let t=(this.fields||[]).filter((t=>"innerHTML"===t.property));return t&&t.length>0}get targetedNode(){let t=this.__highlight.querySelectorAll(this.tagsList);return 1===t.length?t[0]:this.__highlight}tagClickCallback(t={}){t.detail&&this.open(t.detail)}cancel(){this.close()}close(){this.__highlight.unwrap(this.range),this.range&&this.range.collapse(),this.dispatchEvent(new CustomEvent("rich-text-editor-prompt-close",{bubbles:!0,cancelable:!0,composed:!0,detail:this}))}confirm(t){this.value=t,this.dispatchEvent(new CustomEvent("rich-text-editor-prompt-confirm",{bubbles:!0,cancelable:!0,composed:!0,detail:this})),this.setToggled(),this.updateSelection(),this.close()}getPropValue(t){let e=!!this.value&&{...this.value},i=!(!e||!e[t])&&(e[t].trim?e[t].trim():e[t]);return!(!i||""===i)&&i}getValue(){return{innerHTML:this.targetedNode.innerHTML||""}}open(t){this.highlightNode(t),this.value=this.getValue(),this.dispatchEvent(new CustomEvent("rich-text-editor-prompt-open",{bubbles:!0,cancelable:!0,composed:!0,detail:this}))}setInnerHTML(t){this.setsInnerHTML&&(this.targetedNode.innerHTML=t)}setToggled(){this.toggled=!this.value}updateSelection(){let t=this.promptCommand,e=this.promptCommandVal;this.setInnerHTML(this.getPropValue("innerHTML")),this.targetedNode===this.__highlight?this.selectNodeContents(this.targetedNode):this.selectNode(this.targetedNode),this._handleCommand(t,e,this.range,this.value)}_handleClick(t){t.preventDefault(),this.open()}_rangeChanged(t,e){this.value=this.getValue(),this.setToggled()}}};class RichTextEditorPromptButton extends(RichTextEditorPromptButtonBehaviors(t)){}customElements.define(RichTextEditorPromptButton.tag,RichTextEditorPromptButton);export{RichTextEditorPromptButton,RichTextEditorPromptButtonBehaviors};