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 '../../buttons/tool-icon-button.js';
import './frame-menu.js';
import { WithDisposable } from '@blockeditor/lit';
import { css, html, LitElement } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
import { ArrowUpIcon, LargeFrameIcon, } from '../../../../../_common/icons/index.js';
import { getTooltipWithShortcut } from '../../../components/utils.js';
import { createPopper } from '../common/create-popper.js';
let EdgelessFrameToolButton = class EdgelessFrameToolButton extends WithDisposable(LitElement) {
    constructor() {
        super(...arguments);
        this._frameMenu = null;
    }
    _toggleFrameMenu() {
        if (this._frameMenu) {
            this._frameMenu.dispose();
            this._frameMenu = null;
        }
        else {
            this._frameMenu = createPopper('edgeless-frame-menu', this, {
                x: 90,
                y: -40,
            });
            this._frameMenu.element.edgelessTool = this.edgelessTool;
            this._frameMenu.element.edgeless = this.edgeless;
        }
    }
    updated(changedProperties) {
        if (changedProperties.has('edgelessTool')) {
            if (this.edgelessTool.type !== 'frame') {
                this._frameMenu?.dispose();
                this._frameMenu = null;
            }
            if (this._frameMenu) {
                this._frameMenu.element.edgelessTool = this.edgelessTool;
                this._frameMenu.element.edgeless = this.edgeless;
            }
        }
    }
    connectedCallback() {
        super.connectedCallback();
        this._disposables.add(this.edgeless.slots.edgelessToolUpdated.on(newTool => {
            if (newTool.type !== 'frame') {
                this._frameMenu?.dispose();
                this._frameMenu = null;
            }
        }));
    }
    disconnectedCallback() {
        this._frameMenu?.dispose();
        this._frameMenu = null;
        super.disconnectedCallback();
    }
    render() {
        const type = this.edgelessTool?.type;
        const arrowColor = type === 'frame' ? 'currentColor' : '#77757D';
        return html `
      <edgeless-tool-icon-button
        class="edgeless-frame-button"
        .tooltip=${this._frameMenu ? '' : getTooltipWithShortcut('Frame', 'F')}
        .tooltipOffset=${17}
        .active=${type === 'frame'}
        .iconContainerPadding=${8}
        @click=${() => {
            this.setEdgelessTool({
                type: 'frame',
            });
            this._toggleFrameMenu();
        }}
      >
        ${LargeFrameIcon}
        <span class="arrow-up-icon" style=${styleMap({ color: arrowColor })}>
          ${ArrowUpIcon}
        </span>
      </edgeless-tool-icon-button>
    `;
    }
};
EdgelessFrameToolButton.styles = css `
    :host {
      display: flex;
    }

    .arrow-up-icon {
      position: absolute;
      top: 4px;
      right: 2px;
      font-size: 0;
    }
  `;
__decorate([
    property({ attribute: false })
], EdgelessFrameToolButton.prototype, "edgelessTool", void 0);
__decorate([
    property({ attribute: false })
], EdgelessFrameToolButton.prototype, "edgeless", void 0);
__decorate([
    property({ attribute: false })
], EdgelessFrameToolButton.prototype, "setEdgelessTool", void 0);
EdgelessFrameToolButton = __decorate([
    customElement('edgeless-frame-tool-button')
], EdgelessFrameToolButton);
export { EdgelessFrameToolButton };
//# sourceMappingURL=frame-tool-button.js.map