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 { BLOCK_ID_ATTR } from '../../../../consts.js';
import { DeleteIcon, OpenIcon } from '../../../../icons/index.js';
let ReferencePopupMoreMenu = class ReferencePopupMoreMenu extends WithDisposable(LitElement) {
    get referencePageId() {
        const pageId = this.inlineEditor.getFormat(this.targetInlineRange).reference
            ?.pageId;
        assertExists(pageId);
        return pageId;
    }
    get blockElement() {
        const blockElement = this.inlineEditor.rootElement.closest(`[${BLOCK_ID_ATTR}]`);
        assertExists(blockElement);
        return blockElement;
    }
    get std() {
        const std = this.blockElement.std;
        assertExists(std);
        return std;
    }
    _openPage() {
        const refPageId = this.referencePageId;
        const blockElement = this.blockElement;
        if (refPageId === blockElement.model.page.id)
            return;
        const pageElement = this.std.view.viewFromPath('block', [
            blockElement.model.page.root?.id ?? '',
        ]);
        assertExists(pageElement);
        pageElement.slots.pageLinkClicked.emit({ pageId: refPageId });
    }
    _delete() {
        if (this.inlineEditor.isValidInlineRange(this.targetInlineRange)) {
            this.inlineEditor.deleteText(this.targetInlineRange);
        }
        this.abortController.abort();
    }
    render() {
        return html `<div class="reference-popup-more-menu">
      <icon-button
        width="126px"
        height="32px"
        class="menu-item open"
        text="Open"
        @click=${() => this._openPage()}
      >
        ${OpenIcon}
      </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> `;
    }
};
ReferencePopupMoreMenu.styles = css `
    .reference-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 })
], ReferencePopupMoreMenu.prototype, "inlineEditor", void 0);
__decorate([
    property({ attribute: false })
], ReferencePopupMoreMenu.prototype, "targetInlineRange", void 0);
__decorate([
    property({ attribute: false })
], ReferencePopupMoreMenu.prototype, "abortController", void 0);
ReferencePopupMoreMenu = __decorate([
    customElement('reference-popup-more-menu')
], ReferencePopupMoreMenu);
export { ReferencePopupMoreMenu };
//# sourceMappingURL=reference-popup-more-menu-popup.js.map