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, nothing } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { CANVAS_TEXT_FONT_FAMILY, CanvasTextFontFamily, CanvasTextFontStyle, CanvasTextFontWeight, } from '../../../../surface-block/consts.js';
import { getFontFacesByFontFamily } from '../../../../surface-block/elements/text/utils.js';
let EdgelessFontWeightAndStylePanel = class EdgelessFontWeightAndStylePanel extends LitElement {
    constructor() {
        super(...arguments);
        this.fontFamily = CanvasTextFontFamily.Inter;
        this.fontWeight = CanvasTextFontWeight.Regular;
        this.fontStyle = CanvasTextFontStyle.Normal;
    }
    _onSelect(fontWeight, fontStyle = CanvasTextFontStyle.Normal) {
        this.fontWeight = fontWeight;
        this.fontStyle = fontStyle;
        if (this.onSelect) {
            this.onSelect(fontWeight, fontStyle);
        }
    }
    _isDisabled(fontWeight, fontStyle = CanvasTextFontStyle.Normal) {
        // Compatible with old data
        if (!CANVAS_TEXT_FONT_FAMILY.includes(this.fontFamily))
            return false;
        const fonts = document.fonts;
        const fontFace = [...fonts.keys()].find(fontFace => {
            return (fontFace.family === this.fontFamily &&
                fontFace.weight === fontWeight &&
                fontFace.style === fontStyle);
        });
        return !fontFace;
    }
    _isActive(fontWeight, fontStyle = CanvasTextFontStyle.Normal) {
        return this.fontWeight === fontWeight && this.fontStyle === fontStyle;
    }
    render() {
        let fontFaces = getFontFacesByFontFamily(this.fontFamily);
        // Compatible with old data
        if (fontFaces.length === 0) {
            fontFaces = getFontFacesByFontFamily(CanvasTextFontFamily.Inter);
        }
        const fontFacesWithNormal = fontFaces.filter(fontFace => {
            return fontFace.style === CanvasTextFontStyle.Normal;
        });
        const fontFacesWithItalic = fontFaces.filter(fontFace => {
            return fontFace.style === CanvasTextFontStyle.Italic;
        });
        return html `
      <div class="container">
        ${fontFacesWithNormal.length > 0
            ? html `${fontFacesWithNormal.map(fontFace => html `
                <edgeless-tool-icon-button
                  class=${fontFace.weight}
                  .disabled=${this._isDisabled(fontFace.weight)}
                  .active=${this._isActive(fontFace.weight)}
                  .activeMode=${'background'}
                  .iconContainerPadding=${2}
                  @click=${() => {
                this._onSelect(fontFace.weight);
            }}
                >
                  <div>
                    ${fontFace.weight === CanvasTextFontWeight.Light
                ? 'Light'
                : fontFace.weight === CanvasTextFontWeight.Regular
                    ? 'Regular'
                    : 'Semibold'}
                  </div>
                </edgeless-tool-icon-button>
              `)}`
            : nothing}
        ${fontFacesWithItalic.length > 0
            ? html `<component-toolbar-menu-divider
                .vertical=${false}
              ></component-toolbar-menu-divider>

              ${fontFacesWithItalic.map(fontFace => html `
                  <edgeless-tool-icon-button
                    class="${fontFace.weight} italic"
                    .disabled=${this._isDisabled(fontFace.weight, CanvasTextFontStyle.Italic)}
                    .active=${this._isActive(fontFace.weight, CanvasTextFontStyle.Italic)}
                    .activeMode=${'background'}
                    .iconContainerPadding=${2}
                    @click=${() => {
                this._onSelect(fontFace.weight, CanvasTextFontStyle.Italic);
            }}
                  >
                    <div>
                      ${fontFace.weight === CanvasTextFontWeight.Light
                ? 'Light Italic'
                : fontFace.weight === CanvasTextFontWeight.Regular
                    ? 'Regular Italic'
                    : 'Semibold Italic'}
                    </div>
                  </edgeless-tool-icon-button>
                `)} `
            : nothing}
      </div>
    `;
    }
};
EdgelessFontWeightAndStylePanel.styles = css `
    :host {
      display: flex;
    }

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

    .container edgeless-tool-icon-button {
      width: 100%;
    }

    component-toolbar-menu-divider {
      width: 100%;
    }
  `;
__decorate([
    property({ attribute: false })
], EdgelessFontWeightAndStylePanel.prototype, "fontFamily", void 0);
__decorate([
    property({ attribute: false })
], EdgelessFontWeightAndStylePanel.prototype, "fontWeight", void 0);
__decorate([
    property({ attribute: false })
], EdgelessFontWeightAndStylePanel.prototype, "fontStyle", void 0);
__decorate([
    property({ attribute: false })
], EdgelessFontWeightAndStylePanel.prototype, "onSelect", void 0);
EdgelessFontWeightAndStylePanel = __decorate([
    customElement('edgeless-font-weight-and-style-panel')
], EdgelessFontWeightAndStylePanel);
export { EdgelessFontWeightAndStylePanel };
//# sourceMappingURL=font-weight-and-style-panel.js.map