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 { baseTheme } from '@toeverything/theme';
import { css, html, LitElement, nothing, unsafeCSS } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
import { MinusIcon, PlusIcon, ViewBarIcon, } from '../../../../_common/icons/index.js';
import { stopPropagation, } from '../../../../_common/utils/index.js';
import { clamp } from '../../../../_common/utils/math.js';
import { ZOOM_MAX, ZOOM_MIN, ZOOM_STEP, } from '../../../../surface-block/index.js';
let EdgelessZoomToolbar = class EdgelessZoomToolbar extends WithDisposable(LitElement) {
    _isVerticalBar() {
        return this.layout === 'vertical';
    }
    constructor(edgeless) {
        super();
        this._hide = false;
        this.layout = 'horizontal';
        this.setEdgelessTool = (edgelessTool) => {
            this.edgeless.tools.setEdgelessTool(edgelessTool);
        };
        this.edgeless = edgeless;
    }
    get edgelessTool() {
        return this.edgeless.edgelessTool;
    }
    get zoom() {
        return this.viewport.zoom;
    }
    get viewport() {
        return this.edgeless.surface.viewport;
    }
    _setZoomByStep(step) {
        this.viewport.smoothZoom(clamp(this.zoom + step, ZOOM_MIN, ZOOM_MAX));
    }
    _zoomToFit() {
        const { centerX, centerY, zoom } = this.edgeless.getFitToScreenData();
        this.viewport.setViewport(zoom, [centerX, centerY], true);
    }
    setZoomByAction(action) {
        switch (action) {
            case 'fit':
                this._zoomToFit();
                break;
            case 'reset':
                this.viewport.smoothZoom(1.0);
                break;
            case 'in':
            case 'out':
                this._setZoomByStep(ZOOM_STEP * (action === 'in' ? 1 : -1));
        }
    }
    firstUpdated() {
        const { _disposables, edgeless: { slots }, } = this;
        _disposables.add(slots.edgelessToolUpdated.on(tool => {
            if (tool.type !== 'frameNavigator') {
                this._hide = false;
            }
            this.requestUpdate();
        }));
        _disposables.add(slots.viewportUpdated.on(() => this.requestUpdate()));
        _disposables.add(slots.navigatorSettingUpdated.on(({ hideToolbar }) => {
            if (hideToolbar !== undefined) {
                this._hide = hideToolbar;
            }
        }));
    }
    render() {
        const formattedZoom = `${Math.round(this.zoom * 100)}%`;
        const classes = `edgeless-zoom-toolbar-container ${this.layout}`;
        if (this._hide)
            return nothing;
        return html `
      <div
        class=${classes}
        @dblclick=${stopPropagation}
        @mousedown=${stopPropagation}
        @mouseup=${stopPropagation}
        @pointerdown=${stopPropagation}
      >
        <edgeless-tool-icon-button
          .tooltip=${'Fit to screen'}
          .tipPosition=${this._isVerticalBar() ? 'right' : 'top-end'}
          .arrow=${!this._isVerticalBar()}
          @click=${() => this._zoomToFit()}
        >
          ${ViewBarIcon}
        </edgeless-tool-icon-button>
        <edgeless-tool-icon-button
          .tooltip=${'Zoom out'}
          .tipPosition=${this._isVerticalBar() ? 'right' : 'top'}
          .arrow=${!this._isVerticalBar()}
          @click=${() => this._setZoomByStep(-ZOOM_STEP)}
        >
          ${MinusIcon}
        </edgeless-tool-icon-button>
        <span class="zoom-percent" @click=${() => this.viewport.smoothZoom(1)}>
          ${formattedZoom}
        </span>
        <edgeless-tool-icon-button
          .tooltip=${'Zoom in'}
          .tipPosition=${this._isVerticalBar() ? 'right' : 'top'}
          .arrow=${!this._isVerticalBar()}
          @click=${() => this._setZoomByStep(ZOOM_STEP)}
        >
          ${PlusIcon}
        </edgeless-tool-icon-button>
      </div>
    `;
    }
};
EdgelessZoomToolbar.styles = css `
    :host {
      position: absolute;
      bottom: 20px;
      left: 12px;
      z-index: var(--affine-z-index-popover);
      display: flex;
      justify-content: center;
      user-select: none;
    }

    .edgeless-zoom-toolbar-container {
      display: flex;
      align-items: center;
      background: transparent;
      border-radius: 8px;
      fill: currentcolor;
    }

    .edgeless-zoom-toolbar-container.horizantal {
      flex-direction: row;
    }

    .edgeless-zoom-toolbar-container.vertical {
      flex-direction: column;
      width: 40px;
      background-color: var(--affine-background-overlay-panel-color);
      box-shadow: var(--affine-shadow-2);
      border: 1px solid var(--affine-border-color);
      border-radius: 8px;
    }

    .edgeless-zoom-toolbar-container[level='second'] {
      position: absolute;
      bottom: 8px;
      transform: translateY(-100%);
    }

    .edgeless-zoom-toolbar-container[hidden] {
      display: none;
    }

    .zoom-percent {
      display: block;
      box-sizing: border-box;
      width: 48px;
      height: 32px;
      line-height: 22px;
      padding: 5px;
      border-radius: 4px;
      font-size: 12px;
      font-weight: 500;
      text-align: center;
      cursor: pointer;
      color: var(--affine-icon-color);
      font-family: ${unsafeCSS(baseTheme.fontSansFamily)};
    }

    .zoom-percent:hover {
      color: var(--affine-primary-color);
      background-color: var(--affine-hover-color);
    }
  `;
__decorate([
    state()
], EdgelessZoomToolbar.prototype, "_hide", void 0);
__decorate([
    property({ attribute: false })
], EdgelessZoomToolbar.prototype, "layout", void 0);
__decorate([
    property({ attribute: false })
], EdgelessZoomToolbar.prototype, "edgeless", void 0);
EdgelessZoomToolbar = __decorate([
    customElement('edgeless-zoom-toolbar')
], EdgelessZoomToolbar);
export { EdgelessZoomToolbar };
//# sourceMappingURL=zoom-toolbar.js.map