var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { assertExists } from '@blockeditor/global/utils';
import { WithDisposable } from '@blockeditor/lit';
import { css, html, LitElement } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { toast } from '../../../../../components/toast.js';
import { CopyIcon, DeleteIcon, OpenIcon, UnlinkIcon, } from '../../../../../icons/index.js';
let LinkPopupMoreMenu = class LinkPopupMoreMenu extends WithDisposable(LitElement) {
    get currentLink() {
        const link = this.inlineEditor.getFormat(this.targetInlineRange).link;
        assertExists(link);
        return link;
    }
    _openLink() {
        let link = this.currentLink;
        if (!link.match(/^[a-zA-Z]+:\/\//)) {
            link = 'https://' + link;
        }
        window.open(link, '_blank');
        this.abortController.abort();
    }
    _copyUrl() {
        navigator.clipboard.writeText(this.currentLink).catch(console.error);
        toast(this.host, 'Copied link to clipboard');
        this.abortController.abort();
    }
    _removeLink() {
        if (this.inlineEditor.isValidInlineRange(this.targetInlineRange)) {
            this.inlineEditor.formatText(this.targetInlineRange, {
                link: null,
            });
        }
        this.abortController.abort();
    }
    _delete() {
        if (this.inlineEditor.isValidInlineRange(this.targetInlineRange)) {
            this.inlineEditor.deleteText(this.targetInlineRange);
        }
        this.abortController.abort();
    }
    render() {
        return html `<div class="link-popup-more-menu">
      <icon-button
        width="126px"
        height="32px"
        class="menu-item open"
        text="Open"
        @click=${() => this._openLink()}
      >
        ${OpenIcon}
      </icon-button>

      <icon-button
        width="126px"
        height="32px"
        class="menu-item copy"
        text="Copy"
        @click=${() => this._copyUrl()}
      >
        ${CopyIcon}
      </icon-button>

      <icon-button
        width="126px"
        height="32px"
        class="menu-item unlink"
        text="Remove link"
        @click=${() => this._removeLink()}
      >
        ${UnlinkIcon}
      </icon-button>

      <div class="divider"></div>

      <icon-button
        width="126px"
        height="32px"
        class="menu-item delete"
        text="Delete"
        @click=${() => this._delete()}
      >
        ${DeleteIcon}
      </icon-button>
    </div> `;
    }
};
LinkPopupMoreMenu.styles = css `
    .link-popup-more-menu {
      border-radius: 8px;
      padding: 8px;
      background: var(--affine-background-overlay-panel-color);
      box-shadow: var(--affine-shadow-2);
    }

    .menu-item {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      width: 100%;
    }

    .menu-item:hover {
      background: var(--affine-hover-color);
    }

    .menu-item:hover.delete {
      background: var(--affine-background-error-color);
      color: var(--affine-error-color);
    }
    .menu-item:hover.delete > svg {
      color: var(--affine-error-color);
    }

    .menu-item svg {
      margin: 0 8px;
    }

    .divider {
      width: 148px;
      height: 1px;
      margin: 8px;
      background-color: var(--affine-border-color);
    }
  `;
__decorate([
    property({ attribute: false })
], LinkPopupMoreMenu.prototype, "inlineEditor", void 0);
__decorate([
    property({ attribute: false })
], LinkPopupMoreMenu.prototype, "targetInlineRange", void 0);
__decorate([
    property({ attribute: false })
], LinkPopupMoreMenu.prototype, "abortController", void 0);
__decorate([
    property({ attribute: false })
], LinkPopupMoreMenu.prototype, "host", void 0);
LinkPopupMoreMenu = __decorate([
    customElement('link-popup-more-menu')
], LinkPopupMoreMenu);
export { LinkPopupMoreMenu };
//# sourceMappingURL=link-popup-more-menu-popup.js.map