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/toolbar-button.js';
import './brush-menu.js';
import { css, html } from 'lit';
import { customElement, state } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
import { EdgelessPenIcon } from '../../../../../_common/icons/index.js';
import { LineWidth } from '../../../../../_common/utils/index.js';
import { DEFAULT_BRUSH_COLOR } from '../../panel/color-panel.js';
import { getTooltipWithShortcut } from '../../utils.js';
import { createPopper } from '../common/create-popper.js';
import { EdgelessToolButton } from '../edgeless-toolbar-button.js';
let EdgelessBrushToolButton = class EdgelessBrushToolButton extends EdgelessToolButton {
    constructor() {
        super(...arguments);
        this.color = DEFAULT_BRUSH_COLOR;
        this.lineWidth = LineWidth.LINE_WIDTH_FOUR;
        this._type = 'brush';
        this._states = ['color', 'lineWidth'];
    }
    _toggleBrushMenu() {
        const { surface } = this.edgeless;
        if (this._menu) {
            this._disposeMenu();
        }
        else {
            this.edgeless.tools.setEdgelessTool({
                type: this._type,
            });
            this._menu = createPopper('edgeless-brush-menu', this, {
                x: 110,
                y: -40,
            });
            this._menu.element.edgeless = this.edgeless;
            this.updateMenu();
            this._menu.element.onChange = (props) => {
                surface.service.editSession.record(this._type, props);
            };
        }
    }
    updated(changedProperties) {
        if (this._states.some(key => changedProperties.has(key))) {
            if (this._menu) {
                this.updateMenu();
                this.edgeless.slots.edgelessToolUpdated.emit({
                    type: this._type,
                });
            }
        }
    }
    render() {
        const { active } = this;
        return html `
      <edgeless-toolbar-button
        class="edgeless-brush-button"
        .tooltip=${this._menu ? '' : getTooltipWithShortcut('Pen', 'P')}
        .tooltipOffset=${4}
        .active=${active}
        @click=${() => {
            this._toggleBrushMenu();
        }}
      >
        <div class="edgeless-brush-button">
          <div class=${active ? 'active-mode' : ''}></div>
          <div style=${styleMap({ color: `var(${this.color})` })}>
            ${EdgelessPenIcon}
          </div>
        </div>
      </edgeless-toolbar-button>
    `;
    }
};
EdgelessBrushToolButton.styles = css `
    :host {
      display: flex;
    }
    .edgeless-brush-button {
      position: relative;
      height: 66px;
      width: 40px;
      overflow-y: hidden;
    }
    .active-mode {
      position: absolute;
      top: 4px;
      left: 5px;
      width: 30px;
      height: 66px;
      border-top-left-radius: 22px;
      border-top-right-radius: 22px;
      background: var(--affine-hover-color);
    }
    #edgeless-pen-icon {
      position: absolute;
      left: 3px;
      transform: translateY(10px);
      transition: transform 0.3s ease-in-out;
    }
    #edgeless-pen-icon:hover {
      transform: translateY(5px);
    }
  `;
__decorate([
    state()
], EdgelessBrushToolButton.prototype, "color", void 0);
__decorate([
    state()
], EdgelessBrushToolButton.prototype, "lineWidth", void 0);
EdgelessBrushToolButton = __decorate([
    customElement('edgeless-brush-tool-button')
], EdgelessBrushToolButton);
export { EdgelessBrushToolButton };
//# sourceMappingURL=brush-tool-button.js.map