import {
html, unsafeCSS, type PropertyValues,
} from 'lit';
import { PieElement } from '@justeattakeaway/pie-webc-core/src/internals/PieElement';
import { property, query } from 'lit/decorators.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { classMap, type ClassInfo } from 'lit/directives/class-map.js';
import { live } from 'lit/directives/live.js';
import {
validPropertyValues, RtlMixin, FormControlMixin, wrapNativeEvent, type PIEInputElement,
safeCustomElement,
DelegatesFocusMixin,
} from '@justeattakeaway/pie-webc-core';
import '@justeattakeaway/pie-assistive-text';
import styles from './text-input.scss?inline';
import {
type TextInputProps, types, statusTypes, defaultProps,
sizes,
} from './defs';
import 'element-internals-polyfill';
// Valid values available to consumers
export * from './defs';
const componentSelector = 'pie-text-input';
const assistiveTextIdValue = 'assistive-text';
/**
* @tagname pie-text-input
* @event {InputEvent} input - when the input value is changed.
* @event {CustomEvent} change - when the input value is changed.
* @slot leadingText - Short text to display at the start of the input. Wrap the text in a . Do not use with leadingIcon at the same time.
* @slot leadingIcon - An icon to display at the start of the input. Do not use with leadingText at the same time.
* @slot trailingText - Short text to display at the end of the input. Wrap the text in a . Do not use with trailingIcon at the same time.
* @slot trailingIcon - An icon to display at the end of the input. Do not use with trailingText at the same time.
*/
@safeCustomElement('pie-text-input')
export class PieTextInput extends FormControlMixin(RtlMixin(DelegatesFocusMixin(PieElement))) implements TextInputProps, PIEInputElement {
@property({ type: String, reflect: true })
@validPropertyValues(componentSelector, types, defaultProps.type)
public type = defaultProps.type;
@property({ type: String })
public value = defaultProps.value;
@property({ type: String, reflect: true })
public name: TextInputProps['name'];
@property({ type: Boolean, reflect: true })
public disabled = defaultProps.disabled;
@property({ type: String })
public pattern: TextInputProps['pattern'];
@property({ type: Number })
public minlength: TextInputProps['minlength'];
@property({ type: Number })
public maxlength: TextInputProps['maxlength'];
@property({ type: String })
public autocomplete: TextInputProps['autocomplete'];
@property({ type: String })
public placeholder: TextInputProps['placeholder'];
@property({ type: Boolean })
public autoFocus: TextInputProps['autoFocus'];
@property({ type: String })
public inputmode: TextInputProps['inputmode'];
@property({ type: Boolean })
public readonly = defaultProps.readonly;
@property({ type: String })
public defaultValue: TextInputProps['defaultValue'];
@property({ type: String })
public assistiveText: TextInputProps['assistiveText'];
@property({ type: String })
@validPropertyValues(componentSelector, statusTypes, defaultProps.status)
public status = defaultProps.status;
@property({ type: Number })
public step: TextInputProps['step'];
@property({ type: Number })
public min: TextInputProps['min'];
@property({ type: Number })
public max: TextInputProps['max'];
@property({ type: String })
@validPropertyValues(componentSelector, sizes, defaultProps.size)
public size = defaultProps.size;
@property({ type: Boolean })
public required = false;
@query('input')
private input!: HTMLInputElement;
@query('input')
public focusTarget!: HTMLElement;
/**
* (Read-only) returns a ValidityState with the validity states that this element is in.
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
*/
public get validity (): ValidityState {
return this.input.validity;
}
/**
* Called after the disabled state of the element changes,
* either because the disabled attribute of this element was added or removed;
* or because the disabled state changed on a