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 { WithDisposable } from '@blockeditor/lit';
import { Slice } from '@blockeditor/store';
import { css, html, LitElement } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { CopyIcon, DeleteIcon, DuplicateIcon, OpenIcon, RefreshIcon, } from '../../icons/text.js';
import { toast } from '../toast.js';
let EmbedCardMoreMenu = class EmbedCardMoreMenu extends WithDisposable(LitElement) {
    _open() {
        this.block.open();
        this.abortController.abort();
    }
    async _copyBlock() {
        const slice = Slice.fromModels(this.model.page, [this.model]);
        await this.std.clipboard.copySlice(slice);
        toast('Copied link to clipboard');
        this.abortController.abort();
    }
    _duplicateBlock() {
        const model = this.model;
        const keys = model.keys;
        const values = keys.map(key => model[key]);
        const blockProps = Object.fromEntries(keys.map((key, i) => [key, values[i]]));
        const { width, height, xywh, rotate, zIndex, ...duplicateProps } = blockProps;
        const { page } = model;
        const parent = page.getParent(model);
        const index = parent?.children.indexOf(model);
        page.addBlock(model.flavour, duplicateProps, parent, index);
        this.abortController.abort();
    }
    _refreshData() {
        this.block.refreshData();
        this.abortController.abort();
    }
    render() {
        return html `<div class="embed-card-more-menu">
      <icon-button
        width="126px"
        height="32px"
        class="menu-item open"
        text="Open"
        @click=${() => this._open()}
      >
        ${OpenIcon}
      </icon-button>

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

      <icon-button
        width="126px"
        height="32px"
        class="menu-item duplicate"
        text="Duplicate"
        ?disabled=${this.model.page.readonly}
        @click=${() => this._duplicateBlock()}
      >
        ${DuplicateIcon}
      </icon-button>

      <icon-button
        width="126px"
        height="32px"
        class="menu-item reload"
        text="Reload"
        ?disabled=${this.model.page.readonly}
        @click=${() => this._refreshData()}
      >
        ${RefreshIcon}
      </icon-button>

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

      <icon-button
        width="126px"
        height="32px"
        class="menu-item delete"
        text="Delete"
        ?disabled=${this.model.page.readonly}
        @click=${() => this.model.page.deleteBlock(this.model)}
      >
        ${DeleteIcon}
      </icon-button>
    </div> `;
    }
};
EmbedCardMoreMenu.styles = css `
    .embed-card-more-menu {
      border-radius: 8px;
      padding: 8px;
      background: var(--affine-background-overlay-panel-color);
      box-shadow: var(--affine-shadow-2);
    }

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

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

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

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

    .embed-card-more-menu .divider {
      width: 148px;
      height: 1px;
      margin: 8px;
      background-color: var(--affine-border-color);
    }
  `;
__decorate([
    property({ attribute: false })
], EmbedCardMoreMenu.prototype, "model", void 0);
__decorate([
    property({ attribute: false })
], EmbedCardMoreMenu.prototype, "block", void 0);
__decorate([
    property({ attribute: false })
], EmbedCardMoreMenu.prototype, "std", void 0);
__decorate([
    property({ attribute: false })
], EmbedCardMoreMenu.prototype, "abortController", void 0);
EmbedCardMoreMenu = __decorate([
    customElement('embed-card-more-menu')
], EmbedCardMoreMenu);
export { EmbedCardMoreMenu };
//# sourceMappingURL=embed-card-more-menu-popper.js.map