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 { css, html, LitElement } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { repeat } from 'lit/directives/repeat.js';
import { stopPropagation } from '../../../../_common/utils/event.js';
const MIN_SIZE = 1;
const MAX_SIZE = 200;
let EdgelessSizePanel = class EdgelessSizePanel extends LitElement {
    constructor() {
        super(...arguments);
        this.labels = ['Small', 'Medium', 'Large', 'Huge'];
        this.minSize = MIN_SIZE;
        this.maxSize = MAX_SIZE;
        this._onKeydown = (e) => {
            e.stopPropagation();
            if (e.key === 'Enter' && !e.isComposing) {
                e.preventDefault();
                const input = e.target;
                // Handle edge case where user enters a non-number
                if (isNaN(parseInt(input.value))) {
                    input.value = '';
                    return;
                }
                let size = parseInt(input.value);
                // Handle edge case when user enters a number that is out of range
                if (size < this.minSize) {
                    size = this.minSize;
                }
                else if (size > this.maxSize) {
                    size = this.maxSize;
                }
                this._onSelect(size);
                input.value = '';
                this._onPopperClose();
            }
        };
    }
    _onSelect(size) {
        if (this.onSelect)
            this.onSelect(size);
    }
    _onPopperClose() {
        if (this.onPopperCose)
            this.onPopperCose();
    }
    render() {
        return html `
      <div class="size-container">
        <div class="size-content">
          ${repeat(this.sizes, size => size, (size, index) => html ` <div
                class="size-button"
                role="button"
                ?active=${this.size === size}
                @click=${() => {
            this._onSelect(size);
        }}
              >
                <div class="size-button-label">${this.labels[index]}</div>
              </div>`)}

          <div
            class="size-input-container"
            @click=${(e) => {
            e.preventDefault();
            e.stopPropagation();
        }}
          >
            <input
              class="size-input"
              type="text"
              inputmode="numeric"
              pattern="[0-9]*"
              placeholder=${Math.trunc(this.size)}
              @keydown=${this._onKeydown}
              @input=${stopPropagation}
              @pointerdown=${stopPropagation}
            />
          </div>
        </div>
      </div>
    `;
    }
};
EdgelessSizePanel.styles = css `
    :host {
      box-shadow: var(--affine-menu-shadow);
    }

    .size-container {
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 4px 8px;
      background: var(--affine-background-overlay-panel-color);
      border-radius: 8px;
    }

    .size-content {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      width: 64px;
    }

    .size-button {
      display: flex;
      align-items: center;
      justify-content: start;
      width: 64px;
      height: 32px;
      padding: 0 8px;
    }

    .size-button[active] .size-button-label {
      background: var(--affine-hover-color);
    }

    .size-button-label {
      text-align: justify;
      font-size: 15px;
      font-style: normal;
      width: 48px;
      height: 24px;
      font-weight: 400;
      line-height: 24px;
      color: var(--affine-icon-color);
      padding: 0 8px;
      border-radius: 4px;
    }

    .size-button-label:hover {
      cursor: pointer;
      background: var(--affine-hover-color);
    }

    .size-input-container {
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .size-input {
      width: 48px;
      height: 18px;
      border: 1px solid var(--affine-border-color);
      border-radius: 8px;
      padding: 4px 8px;
    }

    .size-input::placeholder {
      color: var(--affine-placeholder-color);
    }

    .size-input:focus {
      outline-color: var(--affine-primary-color);
    }

    menu-divider {
      width: 100%;
    }
  `;
__decorate([
    property({ attribute: false })
], EdgelessSizePanel.prototype, "size", void 0);
__decorate([
    property({ attribute: false })
], EdgelessSizePanel.prototype, "sizes", void 0);
__decorate([
    property({ attribute: false })
], EdgelessSizePanel.prototype, "labels", void 0);
__decorate([
    property({ attribute: false })
], EdgelessSizePanel.prototype, "onSelect", void 0);
__decorate([
    property({ attribute: false })
], EdgelessSizePanel.prototype, "onPopperCose", void 0);
__decorate([
    property({ attribute: false })
], EdgelessSizePanel.prototype, "minSize", void 0);
__decorate([
    property({ attribute: false })
], EdgelessSizePanel.prototype, "maxSize", void 0);
EdgelessSizePanel = __decorate([
    customElement('edgeless-size-panel')
], EdgelessSizePanel);
export { EdgelessSizePanel };
//# sourceMappingURL=size-panel.js.map