/**
 * Copyright 2019 Penn State University
 * @license Apache-2.0, see License.md for full text.
 */
import{LitElement as t,html as e,css as r}from"../../../../lit/index.js";import{RichTextEditorPromptButtonBehaviors as i}from"./rich-text-editor-prompt-button.js";const o={property:"href",title:"Link",description:"The URL to a resource.",required:!0,inputMethod:"haxupload",autofocus:!0};class RichTextEditorLink extends(i(t)){static get tag(){return"rich-text-editor-link"}render(){return super.render()}static get properties(){return{...super.properties,allowTarget:{type:Boolean}}}constructor(){super(),super.fields?this.fields=[...super.fields,o]:this.fields=[o,{property:"innerHTML",title:"Text",inputMethod:"textfield",description:"Text currently selected",disabled:!0,required:!0}],this.command="createLink",this.icon="link",this.label="Link",this.toggledCommand="unlink",this.toggledLabel="Edit link",this.toggles="true",this.tagsList="a",this.value={...super.value,href:null,target:"_blank"},this.shortcutKeys="ctrl+k"}get defaultFields(){return[o,{property:"innerHTML",title:"Text",inputMethod:"textfield",description:"Text currently selected",disabled:!0,required:!0}]}updated(t){super.updated&&super.updated(t),t.forEach(((t,e)=>{"allowTarget"===e&&(this.fields=this.allowTarget?[...this.defaultFields,{property:"target",title:"Target",description:"Where to open the link.",inputMethod:"select",options:{"":"Same window",_blank:"New window - _blank",_top:"Top window - _top",_parent:"Parent window - _parent"}}]:[...this.defaultFields])}))}get promptCommandVal(){return this.getPropValue("href")||void 0}get isToggled(){return this.toggled}getValue(){return{...super.getValue(),target:this.allowTarget&&this.targetedNode&&this.targetedNode.getAttribute&&this.targetedNode.getAttribute("target")?this.targetedNode.getAttribute("target"):"_blank",href:this.targetedNode&&this.targetedNode.getAttribute?this.targetedNode.getAttribute("href"):void 0}}setToggled(){this.toggled=!!this.getPropValue("href")}updateSelection(){let t=this.range,e=this.value&&this.value.target&&this.value.href?this.value.target:void 0;super.updateSelection(),e&&t.commonAncestorContainer.children[0].setAttribute("target",e)}}customElements.define(RichTextEditorLink.tag,RichTextEditorLink);export{RichTextEditorLink};