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 './connector-menu.js';
import { css, html } from 'lit';
import { customElement, state } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';
import { ArrowUpIcon, ConnectorIcon, } from '../../../../../_common/icons/index.js';
import { LineWidth } from '../../../../../_common/utils/index.js';
import { ConnectorMode } from '../../../../../surface-block/index.js';
import { GET_DEFAULT_LINE_COLOR } from '../../panel/color-panel.js';
import { createPopper } from '../common/create-popper.js';
import { EdgelessToolButton } from '../edgeless-toolbar-button.js';
let EdgelessConnectorToolButton = class EdgelessConnectorToolButton extends EdgelessToolButton {
    constructor() {
        super(...arguments);
        this.mode = ConnectorMode.Curve;
        this.stroke = GET_DEFAULT_LINE_COLOR();
        this.strokeWidth = LineWidth.LINE_WIDTH_TWO;
        this._type = 'connector';
        this._states = [
            'mode',
            'stroke',
            'strokeWidth',
        ];
    }
    _toggleMenu() {
        if (this._menu) {
            this._disposeMenu();
            this.requestUpdate();
        }
        else {
            this._menu = createPopper('edgeless-connector-menu', this, {
                x: 50,
                y: -40,
            });
            this._menu.element.edgeless = this.edgeless;
            this.updateMenu();
            this._menu.element.onChange = (props) => {
                this.edgeless.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,
                    mode: this.mode,
                });
            }
        }
    }
    render() {
        const { active } = this;
        const arrowColor = active ? 'currentColor' : '#77757D';
        return html `
      <edgeless-tool-icon-button
        .tooltip=${this._menu ? '' : 'Connector'}
        .tooltipOffset=${17}
        .active=${active}
        .iconContainerPadding=${8}
        class="edgeless-connector-button"
        @click=${() => {
            this.edgeless.tools.setEdgelessTool({
                type: 'connector',
                mode: this.mode,
            });
            this._toggleMenu();
        }}
      >
        ${ConnectorIcon}
        <span class="arrow-up-icon" style=${styleMap({ color: arrowColor })}>
          ${ArrowUpIcon}
        </span>
      </edgeless-tool-icon-button>
    `;
    }
};
EdgelessConnectorToolButton.styles = css `
    :host {
      display: flex;
    }
    .edgeless-connector-button {
      display: flex;
      position: relative;
    }
    .arrow-up-icon {
      position: absolute;
      top: 4px;
      right: 2px;
      font-size: 0;
    }
  `;
__decorate([
    state()
], EdgelessConnectorToolButton.prototype, "mode", void 0);
__decorate([
    state()
], EdgelessConnectorToolButton.prototype, "stroke", void 0);
__decorate([
    state()
], EdgelessConnectorToolButton.prototype, "strokeWidth", void 0);
EdgelessConnectorToolButton = __decorate([
    customElement('edgeless-connector-tool-button')
], EdgelessConnectorToolButton);
export { EdgelessConnectorToolButton };
//# sourceMappingURL=connector-tool-button.js.map