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 './note-menu.js';
import { WithDisposable } from '@blockeditor/lit';
import { css, html, LitElement } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
import { ArrowUpIcon, NoteIcon } from '../../../../../_common/icons/index.js';
import { getTooltipWithShortcut } from '../../../components/utils.js';
import { createPopper } from '../common/create-popper.js';
let EdgelessNoteToolButton = class EdgelessNoteToolButton extends WithDisposable(LitElement) {
    constructor() {
        super(...arguments);
        this.active = false;
        this.childFlavour = 'affine:paragraph';
        this.childType = 'text';
        this.tip = 'Text';
        this._noteMenu = null;
        this._states = ['childFlavour', 'childType', 'tip'];
    }
    _toggleNoteMenu() {
        if (this._noteMenu) {
            this._disposeMenu();
            this.requestUpdate();
        }
        else {
            this.edgeless.tools.setEdgelessTool({
                type: 'affine:note',
                childFlavour: this.childFlavour,
                childType: this.childType,
                tip: this.tip,
            });
            this._noteMenu = createPopper('edgeless-note-menu', this, {
                x: 110,
                y: -40,
            });
            this._noteMenu.element.edgeless = this.edgeless;
            this._noteMenu.element.childFlavour = this.childFlavour;
            this._noteMenu.element.childType = this.childType;
            this._noteMenu.element.tip = this.tip;
            this._noteMenu.element.onChange = (props) => {
                this._states.forEach(key => {
                    if (props[key] != undefined) {
                        Object.assign(this, { [key]: props[key] });
                    }
                });
                this.edgeless.slots.edgelessToolUpdated.emit({
                    type: 'affine:note',
                    childFlavour: this.childFlavour,
                    childType: this.childType,
                    tip: this.tip,
                });
            };
        }
    }
    _disposeMenu() {
        this._noteMenu?.dispose();
        this._noteMenu = null;
    }
    connectedCallback() {
        super.connectedCallback();
        this._disposables.add(this.edgeless.slots.edgelessToolUpdated.on(newTool => {
            if (newTool.type !== 'affine:note') {
                this._disposeMenu();
            }
        }));
    }
    disconnectedCallback() {
        this._disposeMenu();
        super.disconnectedCallback();
    }
    render() {
        const { active } = this;
        const arrowColor = active ? 'currentColor' : '#77757D';
        return html `
      <edgeless-tool-icon-button
        class="edgeless-note-button"
        .tooltip=${this._noteMenu ? '' : getTooltipWithShortcut('Note', 'N')}
        .tooltipOffset=${17}
        .active=${active}
        .iconContainerPadding=${8}
        @click=${() => {
            this._toggleNoteMenu();
        }}
      >
        ${NoteIcon}
        <span class="arrow-up-icon" style=${styleMap({ color: arrowColor })}>
          ${ArrowUpIcon}
        </span>
      </edgeless-tool-icon-button>
    `;
    }
};
EdgelessNoteToolButton.styles = css `
    :host {
      display: flex;
    }

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