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 './text-menu.js';
import { css, html } from 'lit';
import { customElement, state } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
import { EdgelessTextIcon } from '../../../../../_common/icons/index.js';
import { GET_DEFAULT_TEXT_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 EdgelessTextToolButton = class EdgelessTextToolButton extends EdgelessToolButton {
    constructor() {
        super(...arguments);
        this.color = GET_DEFAULT_TEXT_COLOR();
        this._type = 'text';
        this._states = ['color'];
    }
    _toggleTextMenu() {
        if (this._menu) {
            this._disposeMenu();
            this.requestUpdate();
        }
        else {
            this.edgeless.tools.setEdgelessTool({
                type: this._type,
            });
            this._menu = createPopper('edgeless-text-menu', this, {
                x: 130,
                y: -40,
            });
            this.updateMenu();
            this._menu.element.edgeless = this.edgeless;
            this._menu.element.onChange = (props) => {
                this.service.editSession.record(this._type, props);
            };
        }
    }
    updated(changedProperties) {
        if (this._states.some(key => changedProperties.has(key))) {
            if (this._menu) {
                this.updateMenu();
            }
        }
    }
    render() {
        const { active } = this;
        return html `
      <edgeless-toolbar-button
        class="edgeless-text-button"
        .tooltip=${this._menu ? '' : getTooltipWithShortcut('Text', 'T')}
        .tooltipOffset=${15}
        .active=${active}
        .activeMode=${'background'}
        @click=${() => {
            this._toggleTextMenu();
        }}
      >
        <div class="edgeless-text-button">
          <div class=${active ? 'active-mode' : ''}></div>
          <div style=${styleMap({ color: `var(${this.color})` })}>
            ${EdgelessTextIcon}
          </div>
        </div>
      </edgeless-toolbar-button>
    `;
    }
};
EdgelessTextToolButton.styles = css `
    :host {
      display: flex;
    }
    .edgeless-text-button {
      position: relative;
      width: 54px;
      height: 44px;
      overflow-y: hidden;
    }
  `;
__decorate([
    state()
], EdgelessTextToolButton.prototype, "color", void 0);
EdgelessTextToolButton = __decorate([
    customElement('edgeless-text-tool-button')
], EdgelessTextToolButton);
export { EdgelessTextToolButton };
//# sourceMappingURL=text-tool-button.js.map