{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "time-picker",
  "type": "registry:ui",
  "title": "<ui-time-picker>",
  "description": "Carbon `TimePicker`: a short \"hh:mm\" text field in the code font (code-02) with optional `<ui-time-picker-select>` children beside it (AM / PM, time zone). The text is validated against `pattern` (default: 12-hour `h:mm` or `hh:mm`, so typing what the placeholder shows works) after blur or a submit attempt; set `invalid` / `warn` yourself for server-side messages. Sizes sm 32 / md 40 / lg 48px (default md, as in Carbon). Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [
    "lit@^3.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/core-date",
    "@kanok-ui/shared-element",
    "@kanok-ui/shared-field",
    "@kanok-ui/shared-form-control",
    "@kanok-ui/shared-localize",
    "@kanok-ui/shared-skeleton",
    "@kanok-ui/shared-slots",
    "@kanok-ui/tokens"
  ],
  "files": [
    {
      "path": "src/primitives/time-picker/time-picker-select.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/time-picker/time-picker-select.ts",
      "content": "import { html, LitElement, css, nothing } from 'lit';\nimport { customElement, property, state, query } from 'lit/decorators.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { selectedOptionValue, hasData } from '../shared/field.ts';\nimport { FormControlController } from '../shared/form-control.ts';\nimport { LocalizeController } from '../shared/localize.ts';\nimport { UiElement } from '../shared/element.ts';\nimport type { TimePickerSize } from './time-picker-shared.ts';\n\ninterface SelectOption {\n    value: string;\n    label: string;\n    disabled: boolean;\n}\n\nconst chevron = html`<svg class=\"chevron\" viewBox=\"0 0 16 16\" aria-hidden=\"true\"><path d=\"M8 11 3 6l.7-.7L8 9.6l4.3-4.3.7.7z\" /></svg>`;\n\n/**\n * Carbon `TimePickerSelect`: the compact native select beside a `<ui-time-picker>` input (AM / PM,\n * time zone). Author `<option>` children; the picker passes down `size`, `readonly` and its\n * `disabled`. Form-associated (`name` / `value`); fires `change`.\n *\n * @slot - `<option>` elements\n * @fires change - When the user picks an option\n * @csspart input - The native select\n * @cssprop --ui-field-readonly-background - The box's fill when read-only (default transparent; Kanok: a faint ink tint, so read-only reads as set and never weaker than disabled)\n */\n@customElement('ui-time-picker-select')\nexport class UiTimePickerSelect extends UiElement {\n    /** `el.focus()` lands on the control inside. */\n    static override readonly shadowRootOptions: ShadowRootInit = { ...LitElement.shadowRootOptions, delegatesFocus: true };\n\n    static readonly formAssociated = true;\n\n    static override readonly styles = css`\n        :host {\n            position: relative;\n            display: inline-flex;\n            justify-content: center;\n            font-family: var(--ui-font-family);\n        }\n\n        select {\n            appearance: none;\n            box-sizing: border-box;\n            inline-size: auto;\n            min-inline-size: auto;\n            block-size: var(--ui-field-height-lg, 48px);\n            margin: 0;\n            padding: 0 var(--ui-space-xxl) 0 var(--ui-space-md);\n            /* Carbon: an underline only; --ui-field-border (all sides), --ui-field-radius and --ui-field-background let a design outline the box */\n            border: var(--ui-field-border, none);\n            border-bottom: 1px solid var(--ui-field-underline-color, var(--ui-ink-subtle));\n            border-radius: var(--ui-field-radius, var(--ui-radius-none));\n            background-color: var(--ui-field-background, var(--ui-surface-1));\n            color: var(--ui-ink);\n            font: var(--ui-font-body-sm);\n            font-size: var(--ui-field-font-size, 14px);\n            line-height: 1;\n            letter-spacing: var(--ui-tracking-body);\n            cursor: pointer;\n            outline: var(--ui-field-focus-width, 2px) solid transparent; /* the ring's width (Kanok: 1.5px, on the field's own border) */\n            outline-offset: calc(-1 * var(--ui-field-focus-width, 2px));\n            transition: outline-color var(--ui-duration-fast) var(--ui-easing); /* Carbon select-input: the outline only */\n        }\n\n        :host([size='sm']) select {\n            block-size: var(--ui-field-height-sm, 32px);\n        }\n\n        :host([size='md']) select {\n            block-size: var(--ui-field-height-md, 40px);\n        }\n\n        select:focus {\n            outline-color: var(--ui-focus);\n            box-shadow: var(--ui-field-focus-halo, none); /* a design's halo outside the ring (Kanok: none) */\n        }\n\n        select:disabled {\n            border-color: var(--ui-field-disabled-border-color, currentColor currentColor transparent);\n            color: var(--ui-ink-disabled);\n            cursor: not-allowed;\n        }\n\n        :host([readonly]) select {\n            background-color: var(--ui-field-readonly-background, transparent);\n            border-color: var(--ui-field-readonly-border-color, currentColor currentColor var(--ui-hairline));\n            cursor: default;\n        }\n\n        .chevron {\n            position: absolute;\n            inset-block: 0;\n            inset-inline-end: var(--ui-space-md);\n            width: 16px;\n            height: 100%;\n            fill: var(--ui-ink);\n            pointer-events: none;\n        }\n\n        select:disabled ~ .chevron,\n        :host([readonly]) .chevron {\n            fill: var(--ui-icon-disabled);\n        }\n\n        /* in a fluid time picker (set by the picker): a 64px column with its label inside, like Carbon FluidTimePickerSelect */\n        :host([data-fluid]) {\n            position: relative;\n            display: block;\n            background-color: var(--ui-surface-1);\n        }\n\n        :host([data-fluid]) select {\n            inline-size: 100%;\n            block-size: 64px;\n            padding: 32px 32px 13px var(--ui-space-md);\n            background-color: transparent;\n        }\n\n        :host([data-fluid]) .chevron {\n            inset-block: 34px auto;\n            height: 16px;\n            inset-inline-end: var(--ui-space-sm);\n        }\n\n        .fluid-label {\n            position: absolute;\n            inset-block-start: 13px;\n            inset-inline: var(--ui-space-md);\n            overflow: hidden;\n            color: var(--ui-ink-muted);\n            font: var(--ui-font-caption);\n            letter-spacing: var(--ui-tracking-caption);\n            text-overflow: ellipsis;\n            white-space: nowrap;\n            pointer-events: none;\n        }\n\n        @media (forced-colors: active) {\n            select {\n                border: 1px solid FieldText;\n            }\n        }\n    `;\n\n    /** Accessible name of the select (Carbon default \"open list of options\"). */\n    @property() label = '';\n\n    private readonly localize = new LocalizeController(this);\n\n    @property() value = '';\n\n    @property({ reflect: true }) name = '';\n\n    @property({ reflect: true }) size: TimePickerSize = 'md'; // Carbon default (40px)\n\n    @property({ type: Boolean, reflect: true }) disabled = false;\n\n    @property({ type: Boolean, reflect: true }) readonly = false;\n\n    /** Set by the surrounding `<ui-time-picker>` when it is disabled. */\n    @property({ type: Boolean, attribute: false }) pickerDisabled = false;\n\n    @state() private options: SelectOption[] = [];\n\n    /** Disabled, reset defaults, validation on submit and the name given from outside (shared by the form fields). */\n    private readonly formControl = new FormControlController(this);\n\n    @query('select') private readonly select!: HTMLSelectElement;\n\n    /** Created on connect: there is no MutationObserver when Lit renders on the server. */\n    private observer?: MutationObserver;\n    private defaultValue = '';\n\n    override connectedCallback() {\n        super.connectedCallback();\n        // first connection only: moving the element must not change what reset goes back to\n        this.formControl.captureDefaults(() => {\n            // like a native select, `<option selected>` is the initial (and reset) choice unless `value` is set\n            if (!this.value && !this.hasAttribute('value')) this.value = selectedOptionValue(this) ?? '';\n            this.defaultValue = this.value;\n        });\n        this.readOptions();\n        this.observer ??= new MutationObserver(() => this.readOptions());\n        this.observer.observe(this, { childList: true, subtree: true, characterData: true, attributes: true });\n    }\n\n    override disconnectedCallback() {\n        super.disconnectedCallback();\n        this.observer?.disconnect();\n    }\n\n    get form() {\n        return this.internals.form;\n    }\n\n    get validity() {\n        return this.internals.validity;\n    }\n\n    get validationMessage() {\n        return this.internals.validationMessage;\n    }\n\n    /** Whether the field takes part in constraint validation (not while disabled), as natively. */\n    get willValidate() {\n        return this.internals.willValidate;\n    }\n\n    /** The `<label>`s that point at this field. */\n    get labels() {\n        return this.internals.labels;\n    }\n\n    checkValidity() {\n        return this.internals.checkValidity();\n    }\n\n    reportValidity() {\n        return this.formControl.reportValidity(this.internals);\n    }\n\n    formResetCallback() {\n        this.value = this.defaultValue;\n    }\n\n    formStateRestoreCallback(state: string | File | FormData | null) {\n        if (typeof state === 'string') this.value = state;\n    }\n\n    formDisabledCallback(disabled: boolean) {\n        this.formControl.setFieldsetDisabled(disabled);\n    }\n\n    private get isDisabled() {\n        return this.formControl.disabled || this.pickerDisabled;\n    }\n\n    private readOptions() {\n        this.options = [...this.children]\n            .filter((c): c is HTMLOptionElement => c instanceof HTMLOptionElement)\n            .map((o) => ({ value: o.value, label: o.label || o.text, disabled: o.disabled }));\n        if (!this.value) this.value = [...this.children].find((c): c is HTMLOptionElement => c instanceof HTMLOptionElement && c.selected)?.value ?? '';\n    }\n\n    protected override updated() {\n        if (this.select.value !== this.value) {\n            this.value = this.select.value; // a native select always holds one of its options\n            return;\n        }\n        this.internals.setFormValue(this.isDisabled ? null : this.value);\n    }\n\n    private onMouseDown(event: MouseEvent) {\n        if (!this.readonly) return;\n        event.preventDefault();\n        this.select.focus();\n    }\n\n    private onKeyDown(event: KeyboardEvent) {\n        if (this.readonly && ['ArrowDown', 'ArrowUp', ' ', 'Enter'].includes(event.key)) event.preventDefault();\n    }\n\n    private onInput() {\n        this.value = this.select.value; // before the native `input` reaches the page\n    }\n\n    private onChange() {\n        this.value = this.select.value;\n        this.dispatchEvent(new Event('change', { bubbles: true }));\n    }\n\n    override render() {\n        return html`\n            <select\n                part=\"input\"\n                aria-label=${this.label || this.localize.t.field.timeSelect}\n                ?disabled=${this.isDisabled}\n                aria-readonly=${ifDefined(this.readonly ? 'true' : undefined)}\n                @mousedown=${this.onMouseDown}\n                @keydown=${this.onKeyDown}\n                @input=${this.onInput}\n                @change=${this.onChange}\n            >\n                ${this.options.map((o) => html`<option value=${o.value} ?disabled=${o.disabled} ?selected=${o.value === this.value}>${o.label}</option>`)}\n            </select>\n            ${chevron}\n            ${this.label && hasData(this, 'fluid') ? html`<span class=\"fluid-label\" aria-hidden=\"true\">${this.label}</span>` : nothing}\n        `;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-time-picker-select': UiTimePickerSelect;\n    }\n}\n"
    },
    {
      "path": "src/primitives/time-picker/time-picker-shared.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/time-picker/time-picker-shared.ts",
      "content": "\nexport type TimePickerSize = 'sm' | 'md' | 'lg';\n"
    },
    {
      "path": "src/primitives/time-picker/time-picker-skeleton.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/time-picker/time-picker-skeleton.ts",
      "content": "import { html, css, nothing } from 'lit';\nimport { customElement, property } from 'lit/decorators.js';\nimport { fieldSkeletonStyles, fluidSkeletonBox, skeletonStyles, UiSkeletonElement } from '../shared/skeleton.ts';\n\n/**\n * Carbon `FluidTimePickerSkeleton` (Carbon has no other time picker skeleton): the shape of a fluid `<ui-time-picker>`\n * while its data loads — the time box (25%), the AM / PM select (25%) and the time zone select (50%), each a 64px fluid\n * box with two bars; `is-only-two` (Carbon `isOnlyTwo`) two halves. Hidden from assistive tech.\n *\n * @csspart field - Each box\n */\n@customElement('ui-time-picker-skeleton')\nexport class UiTimePickerSkeleton extends UiSkeletonElement {\n    static override readonly styles = [\n        skeletonStyles,\n        fieldSkeletonStyles,\n        css`\n            .row {\n                display: flex;\n                block-size: 64px;\n            }\n\n            .row > * {\n                inline-size: 25%;\n            }\n\n            .row > :last-child,\n            :host([is-only-two]) .row > :first-child {\n                inline-size: 50%;\n            }\n        `,\n    ];\n\n    /** Two boxes (time and AM / PM), half each. */\n    @property({ type: Boolean, reflect: true, attribute: 'is-only-two' }) isOnlyTwo = false;\n\n    override render() {\n        return html`<div class=\"row\">${fluidSkeletonBox}${fluidSkeletonBox}${this.isOnlyTwo ? nothing : fluidSkeletonBox}</div>`;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-time-picker-skeleton': UiTimePickerSkeleton;\n    }\n}\n"
    },
    {
      "path": "src/primitives/time-picker/time-picker.ts",
      "type": "registry:ui",
      "target": "components/ui/primitives/time-picker/time-picker.ts",
      "content": "// Its child elements are one per file beside it; this module re-exports them (one entry point).\nimport { LitElement, css, html, nothing } from 'lit';\nimport { customElement, property, state, query, queryAssignedElements } from 'lit/decorators.js';\nimport { ifDefined } from 'lit/directives/if-defined.js';\nimport { fieldTextStyles, fluidFieldStyles, uid, submitOnEnter, syncFluid, barWhenDisabled, customErrorMessage, pickMessage, pickErrorText, markStatus, renderLabelText, messageId, renderStatusIcon, renderMessage } from '../shared/field.ts';\nimport { FormControlController } from '../shared/form-control.ts';\nimport { SlotController } from '../shared/slots.ts';\nimport { LocalizeController } from '../shared/localize.ts';\nimport { UiElement } from '../shared/element.ts';\nimport { normalizeTimeText } from '../../core/date.ts';\nimport type { TimePickerSize } from './time-picker-shared.ts';\nimport type { UiTimePickerSelect } from './time-picker-select.ts';\nexport * from './time-picker-select.ts';\nexport type { TimePickerSize } from './time-picker-shared.ts';\n\n/**\n * Carbon `TimePicker`: a short \"hh:mm\" text field in the code font (code-02) with optional\n * `<ui-time-picker-select>` children beside it (AM / PM, time zone). The text is validated\n * against `pattern` (default: 12-hour `h:mm` or `hh:mm`, so typing what the placeholder shows works) after blur or a submit attempt; set\n * `invalid` / `warn` yourself for server-side messages. Sizes sm 32 / md 40 / lg 48px\n * (default md, as in Carbon).\n *\n * Form-associated: submits `value` under `name`. Fires `input` while typing and `change` on commit.\n *\n * State on the host for app styles: `data-show-error` / `data-show-warn` while the error / warning\n * line shows (e.g. `ui-time-picker[data-show-error]::part(input)`).\n *\n * @cssstate show-error - While its error message shows (also `[data-show-error]`)\n * @cssstate show-warn - While its warning message shows (also `[data-show-warn]`)\n * @slot - `<ui-time-picker-select>` elements\n * @slot label - Rich label\n * @slot invalid-text - Rich error text\n * @slot warn-text - Rich warning text\n * @csspart label - The label\n * @csspart base - Row with the input and the selects\n * @csspart input - The text input\n * @csspart error-text - Error text\n * @csspart invalid-text - Same line as `error-text` (named after the `invalid-text` attribute / slot)\n * @csspart warning-text - Warning text\n * @csspart warn-text - Same line as `warning-text` (named after the `warn-text` attribute / slot)\n * @attr max-length - Deprecated: use `maxlength`\n * @cssprop --ui-field-border - Border on every side of the box (default none: Carbon's underline only; Kanok: a 1px outline)\n * @cssprop --ui-field-disabled-border-color - Border colour when disabled (default: the underline transparent)\n * @cssprop --ui-field-readonly-border-color - Border colour when read-only (default: a hairline underline)\n * @cssprop --ui-field-radius - Corner radius of the box (default 0; Kanok: 6px)\n * @cssprop --ui-field-background - Fill of the box (default `--ui-surface-1`; Kanok: transparent)\n * @cssprop --ui-label-font - Font of the label (default `--ui-font-caption`; Kanok: 14px semibold)\n * @cssprop --ui-label-color - Colour of the label (default `--ui-ink-muted`; Kanok: `--ui-ink`)\n * @cssprop --ui-field-readonly-background - The box's fill when read-only (default transparent; Kanok: a faint ink tint, so read-only reads as set and never weaker than disabled)\n */\n@customElement('ui-time-picker')\nexport class UiTimePicker extends UiElement {\n    static override hostStates: readonly string[] = ['show-error', 'show-warn'];\n\n    static readonly formAssociated = true;\n\n    /** `el.focus()` and a `<label for>` reach the text box. */\n    static override readonly shadowRootOptions: ShadowRootInit = { ...LitElement.shadowRootOptions, delegatesFocus: true };\n\n    static override readonly styles = [fieldTextStyles, fluidFieldStyles, css`\n        :host {\n            display: block;\n            font-family: var(--ui-font-family);\n        }\n\n        .label {\n            display: block;\n        }\n\n        /* 2px between the columns (Carbon spacing-01) — a gap here, not a margin on each select's :host, which a page-wide CSS reset would remove */\n        .picker {\n            display: flex;\n            flex-wrap: wrap; /* the selects go below the box when there isn't room beside it */\n            align-items: flex-end;\n            gap: 2px;\n        }\n\n        .input-wrapper {\n            position: relative;\n            display: flex;\n            flex-direction: column;\n        }\n\n        input {\n            box-sizing: border-box;\n            display: flex;\n            align-items: center;\n            inline-size: max(78px, calc(78em / 14)); /* 4.875rem at Carbon's 14px; wider with a larger --ui-field-font-size, so \"12:59\" still fits */\n            block-size: var(--ui-field-height-lg, 48px);\n            margin: 0;\n            padding: 0 var(--ui-space-md);\n            /* Carbon: an underline only; --ui-field-border (all sides), --ui-field-radius and --ui-field-background let a design outline the box */\n            border: var(--ui-field-border, none);\n            border-bottom: 1px solid var(--ui-field-underline-color, var(--ui-ink-subtle));\n            border-radius: var(--ui-field-radius, var(--ui-radius-none));\n            background-color: var(--ui-field-background, var(--ui-surface-1));\n            color: var(--ui-ink);\n            font: var(--ui-font-code-lg);\n            font-size: var(--ui-field-font-size, 14px);\n            letter-spacing: var(--ui-tracking-code);\n            outline: var(--ui-field-focus-width, 2px) solid transparent; /* the ring's width (Kanok: 1.5px, on the field's own border) */\n            outline-offset: calc(-1 * var(--ui-field-focus-width, 2px));\n            transition:\n                outline-color var(--ui-duration-fast) var(--ui-easing),\n                background-color var(--ui-duration-fast) var(--ui-easing);\n        }\n\n        :host([size='sm']) input {\n            block-size: var(--ui-field-height-sm, 32px);\n        }\n\n        :host([size='md']) input {\n            block-size: var(--ui-field-height-md, 40px);\n        }\n\n        /* Carbon fluid time picker: equal 64px columns (text box, then each select), the label inside the first */\n        :host([data-fluid]) .picker {\n            display: grid;\n            gap: 0; /* Carbon fluid: the columns touch */\n            grid-auto-columns: minmax(0, 1fr);\n            grid-auto-flow: column;\n        }\n\n        :host([data-fluid]) .input-wrapper {\n            position: static;\n        }\n\n        :host([data-fluid]) input {\n            inline-size: 100%;\n            block-size: 64px;\n            padding: 32px var(--ui-space-md) 13px;\n            font: var(--ui-font-body-sm);\n            font-size: var(--ui-field-font-size, 14px);\n            letter-spacing: var(--ui-tracking-body);\n        }\n\n        :host([data-fluid]) .status {\n            --ui-fluid-icon-top: 72px;\n            --ui-fluid-icon-end: var(--ui-space-md);\n            position: static;\n            transform: none;\n        }\n\n        input::placeholder {\n            color: var(--ui-ink-placeholder);\n            opacity: 1;\n        }\n\n        input:focus {\n            outline-color: var(--ui-focus);\n            box-shadow: var(--ui-field-focus-halo, none); /* a design's halo outside the ring (Kanok: none) */\n        }\n\n        .has-status input {\n            inline-size: max(98.8px, calc(98.8em / 14)); /* 6.175rem at 14px, as the box above */\n        }\n\n        .invalid input {\n            outline-color: var(--ui-error);\n            box-shadow: var(--ui-field-invalid-halo, none); /* a design's error halo (Kanok: Pixiv's red ring) */\n        }\n\n        .invalid input:focus {\n            outline-color: var(--ui-focus);\n            box-shadow: var(--ui-field-invalid-halo, var(--ui-field-focus-halo, none)); /* an error keeps its halo while focused (Kanok: Pixiv's red) */\n        }\n\n        input:disabled {\n            border-color: var(--ui-field-disabled-border-color, currentColor currentColor transparent);\n            color: var(--ui-ink-disabled);\n            cursor: not-allowed;\n        }\n\n        :host([readonly]) input {\n            background-color: var(--ui-field-readonly-background, transparent);\n            border-color: var(--ui-field-readonly-border-color, currentColor currentColor var(--ui-hairline));\n        }\n\n        .status {\n            position: absolute;\n            inset-block-start: 50%;\n            inset-inline-end: var(--ui-space-md);\n            display: flex;\n            place-items: center;\n            transform: translateY(-50%);\n            pointer-events: none;\n        }\n\n        :host(:disabled) .label,\n        :host([data-group-disabled]) .label,\n        :host([data-disabled]) .label {\n            color: var(--ui-ink-disabled);\n        }\n    `];\n\n    @property() label = '';\n\n    @property({ type: Boolean, attribute: 'hide-label' }) hideLabel = false;\n\n    @property() value = '';\n\n    @property({ reflect: true }) name = '';\n\n    @property() placeholder = 'hh:mm';\n\n    /**\n     * 12-hour time with an optional trailing space. Carbon's default rejects a leading zero, so \"09:30\"\n     * typed as the `hh:mm` placeholder shows would fail; this one accepts \"9:30\" and \"09:30\".\n     */\n    @property() pattern = String.raw`(1[012]|0?[1-9]):[0-5][0-9](\\s)?`;\n\n    /** Like `<input maxlength>` (Carbon `maxLength`); the `max-length` attribute of 0.8 and earlier is still read. */\n    @property({ type: Number, attribute: 'maxlength' }) maxLength = 5;\n\n    static override get observedAttributes() {\n        return [...super.observedAttributes, 'max-length'];\n    }\n\n    override attributeChangedCallback(name: string, old: string | null, value: string | null) {\n        if (name !== 'max-length') super.attributeChangedCallback(name, old, value);\n        else if (value !== null) this.maxLength = Number(value);\n    }\n\n    @property({ reflect: true }) size: TimePickerSize = 'md'; // Carbon default (40px)\n\n    @property({ type: Boolean, reflect: true }) disabled = false;\n\n    @property({ type: Boolean, reflect: true }) readonly = false;\n\n    /** Carbon `FluidTimePicker`: equal 64px columns with labels inside, an error / warning inside the box. `<ui-fluid-form>` sets it for every field inside. */\n    @property({ type: Boolean, reflect: true }) fluid = false;\n\n    @property({ type: Boolean, reflect: true }) required = false;\n\n    @property({ type: Boolean, reflect: true }) invalid = false;\n\n    @property({ attribute: 'invalid-text' }) invalidText = '';\n\n    @property({ type: Boolean, reflect: true }) warn = false;\n\n    @property({ attribute: 'warn-text' }) warnText = '';\n\n    @state() private touched = false;\n\n    /** Disabled, reset defaults, validation on submit and the name given from outside (shared by the form fields). */\n    private readonly formControl = new FormControlController(this, { reveal: () => (this.touched = true), implicitSubmission: true });\n\n    @query('input') private readonly input!: HTMLInputElement;\n\n    @queryAssignedElements({ selector: 'ui-time-picker-select' }) private readonly selects!: UiTimePickerSelect[];\n\n    private readonly localize = new LocalizeController(this);\n\n    /** Message from `setCustomValidity()`; '' = none. */\n    private customValidityMessage = '';\n\n    /** Like `<input>.setCustomValidity()`: a non-empty message makes the field invalid (and is shown as its error once touched) until cleared with ''. */\n    setCustomValidity(message: string) {\n        this.customValidityMessage = message;\n        if (!this.hasUpdated) return;\n        this.syncFormState();\n        this.requestUpdate();\n    }\n    private readonly slots = new SlotController(this);\n    private readonly inputId = uid('ui-time-picker');\n    private defaultValue = '';\n\n    /** Enter in the text box submits the form, like a native input. */\n    private readonly onEnterKey = (event: KeyboardEvent) => submitOnEnter(this, event);\n\n    protected override willUpdate() {\n        syncFluid(this, this.fluid);\n    }\n\n    override connectedCallback() {\n        super.connectedCallback();\n        syncFluid(this, this.fluid);\n        this.addEventListener('keydown', this.onEnterKey);\n        // first connection only: moving the element must not change what reset goes back to\n        this.formControl.captureDefaults(() => {\n            this.defaultValue = this.value;\n        });\n    }\n\n    override disconnectedCallback() {\n        super.disconnectedCallback();\n        this.removeEventListener('keydown', this.onEnterKey);\n    }\n\n    get form() {\n        return this.internals.form;\n    }\n\n    /** Whether the field takes part in constraint validation (not while disabled), as natively. */\n    get willValidate() {\n        return this.internals.willValidate;\n    }\n\n    /** The `<label>`s that point at this field. */\n    get labels() {\n        return this.internals.labels;\n    }\n\n    get validity() {\n        return this.internals.validity;\n    }\n\n    get validationMessage() {\n        return this.internals.validationMessage;\n    }\n\n    checkValidity() {\n        return this.internals.checkValidity();\n    }\n\n    reportValidity() {\n        this.touched = true;\n        return this.formControl.reportValidity(this.internals);\n    }\n\n    formResetCallback() {\n        this.value = this.defaultValue;\n        this.touched = false;\n    }\n\n    formStateRestoreCallback(state: string | File | FormData | null) {\n        if (typeof state === 'string') this.value = state;\n    }\n\n    formDisabledCallback(disabled: boolean) {\n        this.formControl.setFieldsetDisabled(disabled);\n    }\n\n    override focus(options?: FocusOptions) {\n        this.input?.focus(options);\n    }\n\n    private get isDisabled() {\n        return this.formControl.disabled;\n    }\n\n    private get interactive() {\n        return !this.isDisabled && !this.readonly;\n    }\n\n    /** Validity is read during render, so sync it before rendering (after the first render has created the input). */\n    protected override updated() {\n        this.toggleAttribute('data-disabled', this.isDisabled);\n        this.syncSelects();\n        // after render, so the inner input already holds the new value (before it, a value set from code was checked one step late)\n        const { valid } = this.internals.validity;\n        const message = this.internals.validationMessage;\n        this.syncFormState();\n        if (this.internals.validity.valid !== valid || this.internals.validationMessage !== message) this.requestUpdate(); // redraw the error line\n        this.syncHostState();\n    }\n\n    /** Internal states as presence attributes on the host, so app styles can select them (same conditions as render). */\n    private syncHostState() {\n        const kind = this.fieldMessage?.kind;\n        this.toggleAttribute('data-show-error', kind === 'error');\n        this.toggleAttribute('data-show-warn', kind === 'warn');\n    }\n\n    private syncSelects() {\n        for (const select of this.selects) {\n            select.size = this.size;\n            select.readonly = this.readonly;\n            select.pickerDisabled = this.isDisabled;\n            select.toggleAttribute('data-fluid', this.dataset.fluid !== undefined);\n            select.requestUpdate(); // its label shows only when fluid\n        }\n    }\n\n    private syncFormState() {\n        if (barWhenDisabled(this.internals, this.isDisabled)) return;\n        this.internals.setFormValue(this.value);\n        // a disabled / read-only input is barred from constraint validation (no message either)\n        const customError = customErrorMessage(this.invalid, this.invalidText, this.customValidityMessage);\n        if (customError) this.internals.setValidity({ customError: true }, customError, this.input);\n        else if (!this.input.willValidate || this.input.validity.valid) this.internals.setValidity({});\n        else this.internals.setValidity(this.input.validity, this.invalidText || this.input.validationMessage || this.localize.t.field.enterTime, this.input);\n    }\n\n    private get showError() {\n        if (!this.interactive) return false;\n        if (this.invalid) return true;\n        return this.touched && !this.internals.validity.valid;\n    }\n\n    private onInput(event: Event) {\n        const input = event.target as HTMLInputElement;\n        // Thai digits as 0–9, no leading space: what the pattern reads (the caret stays where it was in the text)\n        const text = normalizeTimeText(input.value);\n        if (text !== input.value) {\n            const caret = Math.max(0, (input.selectionEnd ?? text.length) - (input.value.length - text.length));\n            input.value = text;\n            input.setSelectionRange(caret, caret);\n        }\n        this.value = text;\n    }\n\n    private onChange() {\n        this.dispatchEvent(new Event('change', { bubbles: true }));\n    }\n\n    /** The one message line: error > warning (no helper line here). */\n    private get fieldMessage() {\n        return pickMessage({\n            showError: this.showError,\n            errorText: pickErrorText(this.invalid, this.customValidityMessage, this.invalidText || this.internals.validationMessage || ''),\n            showWarn: this.warn && this.interactive,\n            warnText: this.warnText,\n            helperText: '',\n            slots: this.slots,\n        });\n    }\n\n    override render() {\n        const showError = this.showError;\n        const message = this.fieldMessage;\n        markStatus(this, message);\n        const hasStatus = !!message && message.kind !== 'helper';\n        const classes = ['input-wrapper', showError ? 'invalid' : '', hasStatus ? 'has-status' : ''].filter(Boolean).join(' ');\n        return html`\n            <label class=${this.hideLabel ? 'sr-only' : 'label'} part=\"label\" for=${this.inputId}>${renderLabelText(this.label, this.formControl.fallbackName(this.label, this.internals))}</label>\n            <div class=\"picker\" part=\"base\">\n                <div class=${classes}>\n                    <input\n                        part=\"input\"\n                        id=${this.inputId}\n                        type=\"text\"\n                        autocomplete=\"off\"\n                        .value=${this.value}\n                        name=${this.name || nothing}\n                        placeholder=${this.placeholder}\n                        pattern=${this.pattern}\n                        maxlength=${this.maxLength}\n                        ?disabled=${this.isDisabled}\n                        ?readonly=${this.readonly}\n                        ?required=${this.required}\n                        aria-invalid=${showError ? 'true' : 'false'}\n                        aria-describedby=${ifDefined(messageId(this.inputId, message))}\n                        @input=${this.onInput}\n                        @change=${this.onChange}\n                        @blur=${() => (this.touched = true)}\n                    />\n                    <span class=\"status\">${renderStatusIcon(message)}</span>\n                </div>\n                <slot @slotchange=${() => this.syncSelects()}></slot>\n            </div>\n            ${renderMessage(this.inputId, message)}\n        `;\n    }\n}\n\ndeclare global {\n    interface HTMLElementTagNameMap {\n        'ui-time-picker': UiTimePicker;\n    }\n}\n"
    }
  ]
}
