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 { computePosition } from '@floating-ui/dom';
import { css, html, LitElement } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
import { MoreIcon } from '../../../../_common/icons/index.js';
import { stopPropagation } from '../../../../_common/utils/index.js';
import { EdgelessZoomToolbar } from './zoom-toolbar.js';
function createZoomMenuPopper(reference, edgeless) {
    const zoomBar = new EdgelessZoomToolbar(edgeless);
    assertExists(reference.shadowRoot);
    zoomBar.layout = 'vertical';
    reference.shadowRoot.appendChild(zoomBar);
    computePosition(reference, zoomBar, {
        placement: 'top',
    })
        .then(({ x, y }) => {
        Object.assign(zoomBar.style, {
            left: `${x}px`,
            top: `${y - 10}px`,
        });
    })
        .catch(console.error);
    return {
        element: zoomBar,
        dispose: () => {
            zoomBar.remove();
        },
    };
}
let ZoomBarToggleButton = class ZoomBarToggleButton extends LitElement {
    _closeZoomMenu() {
        this._zoomBar?.dispose();
        this._zoomBar = null;
        this._showPopper = false;
    }
    _toggleNoteMenu() {
        if (this._zoomBar) {
            this._closeZoomMenu();
        }
        else {
            this._zoomBar = createZoomMenuPopper(this, this.edgeless);
            this._zoomBar.element.edgeless = this.edgeless;
            this._zoomBar.element.edgeless = this.edgeless;
            this._showPopper = true;
        }
    }
    constructor(edgeless) {
        super();
        this._showPopper = false;
        this._zoomBar = null;
        this.edgeless = edgeless;
    }
    connectedCallback() {
        super.connectedCallback();
        this.edgeless.handleEvent('click', () => {
            if (this._zoomBar && this._showPopper) {
                this._closeZoomMenu();
            }
        });
    }
    disconnectedCallback() {
        this._zoomBar?.dispose();
        this._zoomBar = null;
        this._showPopper = false;
        super.disconnectedCallback();
    }
    render() {
        return html `
      <div class="toggle-button" @pointerdown=${stopPropagation}>
        <edgeless-tool-icon-button
          class=${this._showPopper ? 'actived' : 'non-actived'}
          .tooltip=${'Toggle Zoom Tool Bar'}
          .tipPosition=${'right'}
          .active=${this._showPopper}
          .arrow=${false}
          .activeMode=${'background'}
          @click=${() => this._toggleNoteMenu()}
        >
          ${MoreIcon}
        </edgeless-tool-icon-button>
      </div>
    `;
    }
};
ZoomBarToggleButton.styles = css `
    :host {
      display: flex;
      position: absolute;
      bottom: 20px;
      left: 12px;
    }
    .toggle-button {
      display: flex;
      position: relative;
    }
    edgeless-zoom-toolbar {
      position: absolute;
      bottom: initial;
    }
  `;
__decorate([
    property({ attribute: false })
], ZoomBarToggleButton.prototype, "edgeless", void 0);
__decorate([
    state()
], ZoomBarToggleButton.prototype, "_showPopper", void 0);
ZoomBarToggleButton = __decorate([
    customElement('zoom-bar-toggle-button')
], ZoomBarToggleButton);
export { ZoomBarToggleButton };
//# sourceMappingURL=zoom-bar-toggle-button.js.map