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;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _PlayResizableTextInput_instances, _PlayResizableTextInput_onInput, _PlayResizableTextInput_resizeInput;
import { LitElement, css, html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { Bubble } from '../bubble.js';
let PlayResizableTextInput = class PlayResizableTextInput extends LitElement {
    constructor() {
        super(...arguments);
        _PlayResizableTextInput_instances.add(this);
        this.text = '';
        this.placeholder = '';
    }
    render() {
        return html `<input
      type="text"
      placeholder=${this.placeholder}
      .value=${this.text}
      @input=${__classPrivateFieldGet(this, _PlayResizableTextInput_instances, "m", _PlayResizableTextInput_onInput)}
    />`;
    }
    updated() {
        __classPrivateFieldGet(this, _PlayResizableTextInput_instances, "m", _PlayResizableTextInput_resizeInput).call(this, this.shadowRoot?.querySelector('input'));
    }
};
_PlayResizableTextInput_instances = new WeakSet();
_PlayResizableTextInput_onInput = function _PlayResizableTextInput_onInput(ev) {
    this.dispatchEvent(Bubble('edit-text', ev.currentTarget.value));
};
_PlayResizableTextInput_resizeInput = function _PlayResizableTextInput_resizeInput(input) {
    const span = document.createElement('span');
    span.innerText = this.text || this.placeholder;
    span.style.visibility = 'hidden';
    span.style.whiteSpace = 'pre';
    span.style.fontFamily = 'inherit';
    span.style.fontSize = '24px';
    span.style.fontStyle = 'normal';
    span.style.fontWeight = '400';
    document.body.appendChild(span);
    input.style.width = `${span.offsetWidth}px`;
    document.body.removeChild(span);
};
PlayResizableTextInput.styles = css `
    input {
      margin: 0;
      padding-top: 2px;
      padding-right: 8px;
      padding-bottom: 2px;
      padding-left: 8px;
      color: var(--rpl-neutral-content-strong);
      font-family: inherit;
      font-size: 24px;
      font-style: normal;
      font-weight: 400;
      line-height: 28px;
      background-color: var(--rpl-neutral-background);
      border: none;
      border-radius: 4px;
      caret-color: var(--rpl-brand-background);
    }

    input::placeholder {
      color: var(--rpl-neutral-content-weak);
    }

    input:focus {
      outline-width: 2px;
      outline-style: solid;
      outline-color: var(--rpl-brand-background);
    }

    input:hover {
      background-color: var(--rpl-secondary-background);
    }

    input::selection {
      color: var(--rpl-brand-onBackground);
      background-color: var(--rpl-brand-background);
    }
  `;
__decorate([
    property({ attribute: false })
], PlayResizableTextInput.prototype, "text", void 0);
__decorate([
    property()
], PlayResizableTextInput.prototype, "placeholder", void 0);
PlayResizableTextInput = __decorate([
    customElement('play-resizable-text-input')
], PlayResizableTextInput);
export { PlayResizableTextInput };
