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 { html } from 'lit';
import { property } from 'lit/decorators.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { live } from 'lit/directives/live.js';
import { registerComponent } from '../common/definitions/register.js';
import { createFormValueState } from '../common/mixins/forms/form-value.js';
import { partMap } from '../common/part-map.js';
import { bindIf, isEmpty } from '../common/util.js';
import IgcValidationContainerComponent from '../validation-container/validation-container.js';
import { IgcInputBaseComponent } from './input-base.js';
import { numberValidators, stringValidators } from './validators.js';
class IgcInputComponent extends IgcInputBaseComponent {
    constructor() {
        super(...arguments);
        this._formValue = createFormValueState(this, {
            initialValue: '',
        });
        this.type = 'text';
        this.validateOnly = false;
    }
    static register() {
        registerComponent(IgcInputComponent, IgcValidationContainerComponent);
    }
    get __validators() {
        return this.type !== 'number' ? stringValidators : numberValidators;
    }
    set value(value) {
        this._formValue.setValueAndFormState(value);
    }
    get value() {
        return this._formValue.value;
    }
    set pattern(value) {
        this._pattern = value;
        this._validate();
    }
    get pattern() {
        return this._pattern;
    }
    set minLength(value) {
        this._minLength = value;
        this._validate();
    }
    get minLength() {
        return this._minLength;
    }
    set maxLength(value) {
        this._maxLength = value;
        this._validate();
    }
    get maxLength() {
        return this._maxLength;
    }
    set min(value) {
        this._min = value;
        this._validate();
    }
    get min() {
        return this._min;
    }
    set max(value) {
        this._max = value;
        this._validate();
    }
    get max() {
        return this._max;
    }
    set step(value) {
        this._step = value;
        this._validate();
    }
    get step() {
        return this._step;
    }
    setRangeText(replacement, start, end, selectMode = 'preserve') {
        super.setRangeText(replacement, start, end, selectMode);
        this.value = this.input.value;
    }
    select() {
        return this.input.select();
    }
    stepUp(n) {
        this.input.stepUp(n);
        this.value = this.input.value;
    }
    stepDown(n) {
        this.input.stepDown(n);
        this.value = this.input.value;
    }
    handleInput() {
        this._setTouchedState();
        this.value = this.input.value;
        this.emitEvent('igcInput', { detail: this.value });
    }
    handleChange() {
        this._setTouchedState();
        this.value = this.input.value;
        this.emitEvent('igcChange', { detail: this.value });
    }
    renderInput() {
        const hasNegativeTabIndex = this.getAttribute('tabindex') === '-1';
        const hasHelperText = !isEmpty(this._helperText);
        return html `
      <input
        id=${this.inputId}
        part=${partMap(this.resolvePartNames('input'))}
        name=${ifDefined(this.name)}
        type=${ifDefined(this.type)}
        pattern=${ifDefined(this.pattern)}
        placeholder=${ifDefined(this.placeholder)}
        .value=${live(this.value)}
        ?readonly=${this.readOnly}
        ?disabled=${this.disabled}
        ?required=${this.required}
        ?autofocus=${this.autofocus}
        tabindex=${bindIf(hasNegativeTabIndex, -1)}
        autocomplete=${ifDefined(this.autocomplete)}
        inputmode=${ifDefined(this.inputMode)}
        min=${bindIf(!this.validateOnly, this.min)}
        max=${bindIf(!this.validateOnly, this.max)}
        minlength=${ifDefined(this.minLength)}
        maxlength=${bindIf(!this.validateOnly, this.maxLength)}
        step=${ifDefined(this.step)}
        aria-describedby=${bindIf(hasHelperText, 'helper-text')}
        @change=${this.handleChange}
        @input=${this.handleInput}
        @blur=${this._handleBlur}
      />
    `;
    }
}
IgcInputComponent.tagName = 'igc-input';
export default IgcInputComponent;
__decorate([
    property()
], IgcInputComponent.prototype, "value", null);
__decorate([
    property({ reflect: true })
], IgcInputComponent.prototype, "type", void 0);
__decorate([
    property({ attribute: 'inputmode' })
], IgcInputComponent.prototype, "inputMode", void 0);
__decorate([
    property()
], IgcInputComponent.prototype, "pattern", null);
__decorate([
    property({ type: Number, attribute: 'minlength' })
], IgcInputComponent.prototype, "minLength", null);
__decorate([
    property({ type: Number, attribute: 'maxlength' })
], IgcInputComponent.prototype, "maxLength", null);
__decorate([
    property({ type: Number })
], IgcInputComponent.prototype, "min", null);
__decorate([
    property({ type: Number })
], IgcInputComponent.prototype, "max", null);
__decorate([
    property({ type: Number })
], IgcInputComponent.prototype, "step", null);
__decorate([
    property({ type: Boolean })
], IgcInputComponent.prototype, "autofocus", void 0);
__decorate([
    property()
], IgcInputComponent.prototype, "autocomplete", void 0);
__decorate([
    property({ type: Boolean, reflect: true, attribute: 'validate-only' })
], IgcInputComponent.prototype, "validateOnly", void 0);
//# sourceMappingURL=input.js.map