import{r as i,c as t,h as e}from"./p-DBTJNfo7.js";import{t as s}from"./p-DVRaJQvC.js";import{a,E as n}from"./p-CxzDbuiY.js";const o=class{constructor(e){i(this,e),this.cancel=t(this,"cancel"),this.save=t(this,"save"),this.linkChange=t(this,"linkChange"),this.language="en",this.isOpen=!1,this.getTranslation=i=>s.get(i,this.language),this.isValid=i=>{try{new URL(i)}catch(i){return!1}return!0},this.handleKeyDown=i=>{var t;i.key===a&&(this.saveButton&&this.saveButton.focus(),i.preventDefault(),this.isValid(null===(t=this.link)||void 0===t?void 0:t.href)&&this.handleSave(i))},this.handleCancel=i=>{i instanceof KeyboardEvent&&i.key!==n||(i.stopPropagation(),i.preventDefault(),this.cancel.emit())},this.handleSave=i=>{i.stopPropagation(),this.save.emit()},this.handleLinkInputAction=i=>{window.open(this.link.href,"_blank"),i.stopPropagation()},this.handleLinkTitleChange=i=>{var t;this.emitLinkChange(i.detail,null===(t=this.link)||void 0===t?void 0:t.href)},this.handleLinkValueChange=i=>{var t;this.emitLinkChange(null===(t=this.link)||void 0===t?void 0:t.text,i.detail)},this.emitLinkChange=(i,t)=>{this.linkChange.emit({text:i,href:t})}}connectedCallback(){this.setupGlobalHandlers()}disconnectedCallback(){this.teardownGlobalHandlers()}setupGlobalHandlers(){this.isOpen&&document.addEventListener("keyup",this.handleCancel)}teardownGlobalHandlers(){document.removeEventListener("keyup",this.handleCancel)}componentDidLoad(){this.focusOnTextInput()}focusOnTextInput(){if(this.textInput){const i=this.textInput.shadowRoot.querySelector("input");i&&requestAnimationFrame((()=>{i.focus()}))}}render(){var i,t;const s=this.isValid(this.link.href);return[e("limel-input-field",{key:"59a19c43140dc628d165014767ed46d2c01012d4",label:this.getTranslation("editor-link-menu.text"),value:(null===(i=this.link)||void 0===i?void 0:i.text)||"",leadingIcon:"text_cursor",onChange:this.handleLinkTitleChange,onKeyDown:this.handleKeyDown,ref:i=>this.textInput=i}),e("limel-input-field",{key:"de5d72e0ff74a96278615c55871a86883ebc8ad5",label:this.getTranslation("editor-link-menu.link"),value:(null===(t=this.link)||void 0===t?void 0:t.href)||"",type:"text",leadingIcon:"-lime-text-link",trailingIcon:"external_link",invalid:!s,onChange:this.handleLinkValueChange,onAction:this.handleLinkInputAction,onKeyDown:this.handleKeyDown}),e("div",{key:"28e258290e650ae336b348bc8ff5d749100438f0",class:"actions"},e("limel-button",{key:"de6ca7d3594dd64897a8589c5e2fc04e7f0b623e",label:this.getTranslation("cancel"),onClick:this.handleCancel}),e("limel-button",{key:"be505a063196c20992e4918fa60d1d0bcd0b40d5",primary:!0,label:this.getTranslation("save"),disabled:!s,onClick:this.handleSave,ref:i=>this.saveButton=i,slot:"button"}))]}};o.style=":host(limel-text-editor-link-menu){animation:fade 0.2s ease forwards;animation-delay:0.1s;opacity:0;display:flex;flex-direction:column;gap:0.5rem;padding:0.5rem;max-width:calc(100vw - 2rem);border-radius:0.5rem;background-color:var(--lime-elevated-surface-background-color);box-shadow:var(--shadow-depth-16)}.actions{display:flex;justify-content:end;gap:0.5rem}@keyframes fade{0%{scale:0.86;opacity:0}100%{scale:1;opacity:1}}";export{o as limel_text_editor_link_menu}