/**
 * `<input-ui>` — Text + email + password + number + tel + url + search input.
 *
 * @see https://ui-kit.exe.xyz/site/components/input
 */

import { UIFormElement } from '../../core/form.js';

/** Native HTML input types this primitive supports. */
export type UIInputType =
  | 'text'
  | 'email'
  | 'password'
  | 'number'
  | 'tel'
  | 'url'
  | 'search';

export interface InputChangeEventDetail {
  value: string;
}
export type InputChangeEvent = CustomEvent<InputChangeEventDetail>;
export type InputInputEvent = CustomEvent<InputChangeEventDetail>;

export class UIInput extends UIFormElement {
  placeholder: string;
  type: UIInputType;
  label: string;
  prefix: string;
  suffix: string;
  /** Raw mode — drops chrome (border, padding) for inline composition. */
  raw: boolean;
  /**
   * §247 (v0.5.10, FB-26 §1): mobile keyboard hint per HTML `inputmode`
   * spec — `numeric` / `decimal` / `email` / `tel` / `url` / `search` /
   * `none`. Forwards to the underlying contenteditable surface. Empty
   * string = no hint (browser default).
   */
  inputmode: string;
  /**
   * §247 (v0.5.10, FB-26 §1): HTML `autocomplete` attribute (`off` /
   * `name` / `email` / `current-password` / `new-password` etc).
   * Forwards to the underlying contenteditable surface for browser
   * autofill behavior.
   */
  autocomplete: string;

  // ── Number-mode properties (active when type="number") ──
  /** Minimum value. `null` to disable. */
  min: number | null;
  /** Maximum value. `null` to disable. */
  max: number | null;
  /** Step size for stepper buttons + arrow keys. */
  step: number;
  /** Decimal precision (places); `null` to derive from step. */
  precision: number | null;
  /**
   * BCP-47 locale tag for number formatting — e.g. `"de-DE"` / `"fr-FR"` /
   * `"en-IN"`. Default empty = en-US (`.` decimal separator, no thousands
   * grouping). `.value` stays canonical (`Number(v)` round-trips).
   */
  locale: string;

  // ── Number-mode accessor ──
  /** Parsed numeric value. Returns `NaN` if value isn't a number. */
  readonly valueAsNumber: number;

  addEventListener<K extends keyof HTMLElementEventMap>(
    type: K,
    listener: (this: UIInput, ev: HTMLElementEventMap[K]) => unknown,
    options?: boolean | AddEventListenerOptions,
  ): void;
  addEventListener(type: 'change', listener: (ev: InputChangeEvent) => unknown, options?: boolean | AddEventListenerOptions): void;
  addEventListener(type: 'input', listener: (ev: InputInputEvent) => unknown, options?: boolean | AddEventListenerOptions): void;
  /** §207 (v0.5.7): Enter-key + native form-submit semantics; dispatched bubbling. */
  addEventListener(type: 'submit', listener: (ev: Event) => unknown, options?: boolean | AddEventListenerOptions): void;
}
