/*!
 * Custom elements for Nanopore-Digital Web applications
 */
import { proxyCustomElement, HTMLElement, createEvent, Build, Host } from '@stencil/core/internal/client';
import { c as closestElement } from './dom.js';
import { a as debounceEvent } from './throttle.js';
import { F as FormControlWrap, a as FormControl } from './form-control.js';
import { t as transformTag, h } from './renderer.js';
import { d as defineCustomElement$5 } from './date-picker.js';
import { d as defineCustomElement$4 } from './dropdown.js';
import { d as defineCustomElement$3 } from './icon.js';
import { d as defineCustomElement$2 } from './icon-button.js';
import { d as defineCustomElement$1 } from './tooltip.js';

const inputCss = ".sc-nano-input-h, *.sc-nano-input, *.sc-nano-input::before, *.sc-nano-input::after {\n  box-sizing: border-box;\n}\n[hidden].sc-nano-input {\n  display: none !important;\n}\n@media (prefers-reduced-motion: reduce) {\n    .sc-nano-input-h, *.sc-nano-input, *.sc-nano-input::before, *.sc-nano-input::after {\n      animation-duration: 0.01ms !important;\n      animation-iteration-count: 1 !important;\n      transition-duration: 0.01ms !important;\n      scroll-behavior: auto !important;\n    }\n  }.sc-nano-input-h, *.sc-nano-input, *.sc-nano-input::before, *.sc-nano-input::after {\n  box-sizing: border-box;\n}\n[hidden].sc-nano-input {\n  display: none !important;\n}\n@media (prefers-reduced-motion: reduce) {\n    .sc-nano-input-h, *.sc-nano-input, *.sc-nano-input::before, *.sc-nano-input::after {\n      animation-duration: 0.01ms !important;\n      animation-iteration-count: 1 !important;\n      transition-duration: 0.01ms !important;\n      scroll-behavior: auto !important;\n    }\n  }slot-fb.sc-nano-input {\n  display: contents !important;\n}\n\n[disabled].sc-nano-input-h:not([disabled=false]) {\n  opacity: 0.5;\n  position: relative;\n}\n[disabled].sc-nano-input-h:not([disabled=false])::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  cursor: not-allowed;\n}\n\n.form-ctrl.sc-nano-input {\n  min-inline-size: 100%;\n  display: block;\n}\n.form-ctrl.has-helper-end.sc-nano-input {\n  display: flex;\n  gap: 1rem;\n  container-type: inline-size;\n}\n.form-ctrl.has-helper-end.sc-nano-input .form-ctrl__wrapper.sc-nano-input {\n  flex: 1 1 100%;\n}\n.form-ctrl.has-helper-end.sc-nano-input .form-ctrl__helper-end.sc-nano-input {\n  display: none;\n}\n@container (min-width: 350px) {\n  .form-ctrl.has-helper-end .form-ctrl__helper-end {\n    display: block !important;\n  }\n  .form-ctrl.has-helper-end .form-ctrl__helper {\n    display: none !important;\n  }\n}\n\n.form-ctrl__wrapper.sc-nano-input {\n  display: block;\n}\n\nlabel.sc-nano-input, .form-ctrl__more.sc-nano-input, .form-ctrl__error.sc-nano-input, .form-ctrl__helper.sc-nano-input {\n  display: block;\n}\nlabel.visually-hide.sc-nano-input, .form-ctrl__more.visually-hide.sc-nano-input, .form-ctrl__error.visually-hide.sc-nano-input, .form-ctrl__helper.visually-hide.sc-nano-input {\n  clip-path: inset(50%);\n  block-size: 1px;\n  overflow: hidden;\n  position: absolute;\n  white-space: nowrap;\n  inline-size: 1px;\n}\n\n.form-ctrl__float-label.sc-nano-input {\n  padding-block: 0;\n  padding-inline: var(--padding-start) 0;\n  color: var(--label-color);\n  position: absolute;\n  font-size: 1em;\n  transform: translateY(-50%);\n  inset-block-start: 50%;\n  transition: all 0.125s ease-in;\n  opacity: 1;\n}\n.has-focus.sc-nano-input-h .form-ctrl__float-label.sc-nano-input, .has-value.sc-nano-input-h .form-ctrl__float-label.sc-nano-input {\n  transform: none;\n  font-size: 0.75em;\n  opacity: 0.7;\n  inset-block-start: var(--padding-top);\n}\n.form-ctrl__float-label.sc-nano-input .form-ctrl__label-charcount.sc-nano-input {\n  opacity: 0;\n  transition: opacity 0.125s ease-in;\n}\n.has-focus.sc-nano-input-h .form-ctrl__float-label.sc-nano-input .form-ctrl__label-charcount.sc-nano-input, .has-value.sc-nano-input-h .form-ctrl__float-label.sc-nano-input .form-ctrl__label-charcount.sc-nano-input {\n  opacity: 1;\n}\n\n.form-ctrl__label.sc-nano-input {\n  color: var(--label-color);\n  font-size: var(--label-font-size);\n  padding-block-end: var(--padding-bottom);\n  line-height: 1;\n  display: flex;\n  align-items: center;\n}\n.form-ctrl__label.sc-nano-input .form-ctrl__label-wrap.sc-nano-input {\n  flex: 1;\n  overflow-x: clip;\n  white-space: nowrap;\n  text-overflow: ellipsis;\n}\n.form-ctrl__label.sc-nano-input .form-ctrl__label-placeholder.sc-nano-input {\n  margin-block: unset;\n  margin-inline: 0 5px;\n  opacity: 0;\n  appearance: none;\n  transition: 0.3s ease opacity;\n  font-size: 0.85em;\n}\n.form-ctrl__label.sc-nano-input .form-ctrl__label-charcount.sc-nano-input {\n  margin-block: unset;\n  margin-inline: auto 0;\n  font-size: var(--nano-font-size-2xs);\n  opacity: 0.5;\n}\n.has-value.sc-nano-input-h .form-ctrl__label.sc-nano-input .form-ctrl__label-placeholder.sc-nano-input {\n  opacity: 0.5;\n}\n\n.has-float-label.sc-nano-input .select__multi-input.sc-nano-input, .has-float-label.sc-nano-input .select__native-input.sc-nano-input, .has-float-label.sc-nano-input .input__native-ctrl.sc-nano-input {\n  opacity: 0;\n  transition: opacity 0.125s ease-in;\n}\n.has-focus.sc-nano-input-h .has-float-label.sc-nano-input .select__multi-input.sc-nano-input, .has-value.sc-nano-input-h .has-float-label.sc-nano-input .select__multi-input.sc-nano-input, .has-focus.sc-nano-input-h .has-float-label.sc-nano-input .select__native-input.sc-nano-input, .has-value.sc-nano-input-h .has-float-label.sc-nano-input .select__native-input.sc-nano-input, .has-focus.sc-nano-input-h .has-float-label.sc-nano-input .input__native-ctrl.sc-nano-input, .has-value.sc-nano-input-h .has-float-label.sc-nano-input .input__native-ctrl.sc-nano-input {\n  opacity: 1;\n}\n\n.form-ctrl__more.sc-nano-input {\n  position: relative;\n  margin-block: var(--padding-bottom) 0;\n  margin-inline: 0;\n  opacity: 0;\n  display: none;\n  transition: all var(--nano-transition-fast) ease;\n  transition-behavior: allow-discrete;\n}\n.form-ctrl__more.sc-nano-input > *.sc-nano-input {\n  grid-column: 1;\n  grid-row: 1;\n}\n.has-helper.sc-nano-input .form-ctrl__more.sc-nano-input, .has-error.sc-nano-input .form-ctrl__more.sc-nano-input {\n  display: grid;\n  opacity: 1;\n}\n\n.form-ctrl__helper.sc-nano-input, .form-ctrl__error.sc-nano-input {\n  font-size: var(--more-font-size);\n  line-height: 1.2;\n  transition: 0.3s ease-out opacity;\n}\n\n.form-ctrl__helper.sc-nano-input {\n  font-style: italic;\n  color: var(--help-msg-color);\n}\n[show-inline-error].sc-nano-input-h:not([show-inline-error=false]).is-invalid .form-ctrl__helper.sc-nano-input {\n  opacity: 0;\n}\n\n.form-ctrl__helper-end.sc-nano-input {\n  flex: 1 1 30%;\n  min-inline-size: 150px;\n  font-size: var(--invalid-msg-font-size);\n  color: var(--help-msg-color);\n  font-style: italic;\n}\n\n.form-ctrl__error.sc-nano-input {\n  opacity: 0;\n  color: var(--invalid-msg-color);\n  font-style: italic;\n}\n.is-invalid.sc-nano-input-h:not([disabled]) .form-ctrl__error.sc-nano-input {\n  opacity: 1;\n}\n\n.form-ctrl__input.sc-nano-input {\n  font-family: inherit;\n  font-size: inherit;\n  font-stretch: inherit;\n  font-style: inherit;\n  font-weight: inherit;\n  letter-spacing: inherit;\n  text-decoration: inherit;\n  text-overflow: inherit;\n  text-transform: inherit;\n  text-align: inherit;\n  white-space: inherit;\n  color: inherit;\n  border-radius: var(--input-border-radius);\n  inline-size: 100%;\n  padding: 0 !important;\n  position: relative;\n  flex: 1 0 auto;\n  display: flex;\n  background: var(--input-bg-color);\n  border: var(--input-border-style) var(--input-border-width);\n  font-size: var(--input-font-size);\n  padding-inline-start: calc(var(--input-invalid-border-hint-width) - var(--input-border-width)) !important;\n}\n.form-ctrl__input.sc-nano-input:focus-visible, .form-ctrl__input.sc-nano-input:focus-within, .has-focus.sc-nano-input-h .form-ctrl__input.sc-nano-input {\n  outline: var(--nano-focus-ring-color) solid 3px;\n  outline-offset: -2px;\n}\n.is-invalid.sc-nano-input-h:not([disabled]) .form-ctrl__input.sc-nano-input {\n  border-inline-start: solid var(--color-invalid) var(--input-invalid-border-hint-width);\n  padding-inline-start: 0 !important;\n}\n.is-invalid.has-focus.sc-nano-input-h:not([disabled]) .form-ctrl__input.sc-nano-input {\n  border-color: var(--color-invalid);\n  border-inline-start: solid var(--color-invalid) var(--input-invalid-border-hint-width);\n  padding-inline-start: 0 !important;\n}\n\n.form-ctrl__input-wrap.sc-nano-input {\n  display: flex;\n  flex: 1;\n  max-inline-size: 100%;\n  align-items: center;\n}\n[type=textarea].sc-nano-input-h .form-ctrl__input-wrap.sc-nano-input {\n  align-items: start;\n}\n\n.form-ctrl__clear-btn.sc-nano-input, .form-ctrl__slot-end.sc-nano-input, .form-ctrl__slot-start.sc-nano-input, .form-ctrl__slot-value-end.sc-nano-input {\n  margin-block: 0;\n  margin-inline: 0;\n  font-size: 1em;\n  border: 0;\n  outline: none;\n  background-color: transparent;\n  background-repeat: no-repeat;\n  display: flex;\n  align-items: center;\n  inline-size: auto;\n  padding-inline-end: var(--padding-end);\n  padding-block: var(--padding-top) var(--padding-bottom);\n}\n.form-ctrl__clear-btn.sc-nano-input:empty, .form-ctrl__slot-end.sc-nano-input:empty, .form-ctrl__slot-start.sc-nano-input:empty, .form-ctrl__slot-value-end.sc-nano-input:empty {\n  display: none;\n}\n\n.form-ctrl__slot-end.sc-nano-input {\n  padding-block: calc(var(--padding-top) / 2) calc(var(--padding-bottom) / 2);\n}\n\n.form-ctrl__slot-start.sc-nano-input {\n  padding-inline-end: 0;\n}\n.has-float-label.sc-nano-input .form-ctrl__slot-start.sc-nano-input {\n  display: none;\n}\n\n.form-ctrl__slot-start.sc-nano-input-s > *, .form-ctrl__slot-start.sc-nano-input-s > *, .form-ctrl__slot-start .sc-nano-input-s > *, .form-ctrl__slot-end.sc-nano-input-s > *, .form-ctrl__slot-end .sc-nano-input-s > *, .form-ctrl__slot-value-end.sc-nano-input-s > :not(slot-fb), .form-ctrl__slot-value-end .sc-nano-input-s > :not(slot-fb) {\n  padding-inline: unset;\n  align-items: center;\n  display: flex;\n  block-size: 100%;\n  z-index: 1;\n}\n.sc-nano-input-h[disabled]:not([disabled=false]) .form-ctrl__slot-start.sc-nano-input-s > *, .form-ctrl__slot-start.sc-nano-input-s > *, .form-ctrl__slot-start .sc-nano-input-s > *, .sc-nano-input-h[disabled]:not([disabled=false]) .form-ctrl__slot-end.sc-nano-input-s > *, .form-ctrl__slot-end .sc-nano-input-s > *, .sc-nano-input-h[disabled]:not([disabled=false]) .form-ctrl__slot-value-end.sc-nano-input-s > :not(slot-fb), .form-ctrl__slot-value-end .sc-nano-input-s > :not(slot-fb) {\n  pointer-events: none;\n}\n\n.form-ctrl__slot-start.sc-nano-input-s > *, .form-ctrl__slot-start.sc-nano-input-s > *, .form-ctrl__slot-start .sc-nano-input-s > * {\n  margin-inline: var(--padding-start) 0;\n}\n\n.form-ctrl__slot-value-end.sc-nano-input-s > *, .form-ctrl__slot-value-end.sc-nano-input-s > *, .form-ctrl__slot-value-end .sc-nano-input-s > *, .form-ctrl__slot-value-end.sc-nano-input *.sc-nano-input {\n  pointer-events: none;\n}\n\n.form-ctrl__clear-btn.sc-nano-input {\n  color: var(--clear-btn-color);\n  padding: 0;\n  opacity: 0;\n  inline-size: 0;\n  appearance: none;\n  align-items: center;\n  overflow: hidden;\n  padding-block: var(--padding-top) var(--padding-bottom);\n}\n.is-invalid.sc-nano-input-h .form-ctrl__clear-btn.sc-nano-input {\n  color: var(--clear-btn-color--invalid);\n}\n.has-value.sc-nano-input-h .form-ctrl__clear-btn.sc-nano-input {\n  padding-inline: 0 var(--padding-end);\n  opacity: 1;\n  inline-size: auto;\n}\n.form-ctrl__clear-btn.sc-nano-input:hover {\n  color: var(--clear-btn-color--hover);\n}\n\n.form-ctrl__validation-icon.sc-nano-input {\n  padding-block: var(--padding-top) var(--padding-bottom);\n  padding-inline-end: var(--padding-end);\n  display: grid;\n  grid-template-areas: \"overlay\";\n}\n.sc-nano-input-h:not(.is-invalid .form-ctrl__validation-icon.sc-nano-input, .is-valid).sc-nano-input-h .form-ctrl__validation-icon.sc-nano-input {\n  display: none;\n}\n\n.form-ctrl__error-icon.sc-nano-input, .form-ctrl__success-icon.sc-nano-input {\n  color: var(--color-valid);\n  opacity: 0;\n  transition: 0.3s ease-out opacity;\n  grid-area: overlay;\n}\n\n.is-valid.sc-nano-input-h .form-ctrl__success-icon.sc-nano-input {\n  opacity: 1;\n}\n\n.form-ctrl__error-icon.sc-nano-input {\n  color: var(--color-invalid);\n}\n.is-invalid.sc-nano-input-h .form-ctrl__error-icon.sc-nano-input {\n  opacity: 1;\n}\n\n.sc-nano-input-h {\n  \n  --placeholder-color: var(--nano-color-neutral-1000);\n  --padding-top: var(--nano-spacing-sm);\n  --padding-end: var(--nano-spacing-sm);\n  --padding-bottom: var(--nano-spacing-sm);\n  --padding-start: var(--nano-spacing-sm);\n  --color-invalid: var(--nano-color-danger-1100);\n  --color-valid: var(--nano-color-success-1000);\n  --input-font-size: var(--nano-font-size-sm);\n  --input-text-color: var(--nano-color-base-1000);\n  --input-border-width: 1px;\n  --input-border-color: var(--nano-color-neutral-300);\n  --input-border-radius: 0px;\n  --input-invalid-border-hint-width: 2px;\n  --input-border-style: solid var(--input-border-color);\n  --input-border-style--focus: solid var(--input-border-width) var(--nano-color-primary-700);\n  --input-bg-color: var(--nano-color-base-0);\n  --invalid-msg-color: var(--color-invalid);\n  --help-msg-color: var(--nano-color-base-1000);\n  --more-font-size: var(--nano-font-size-2xs);\n  --clear-btn-color: rgb(var(--nano-color-base-rgb-1000) / 60%);\n  --clear-btn-color--hover: rgb(var(--nano-color-base-rgb-1000) / 100%);\n  --clear-btn-color--invalid: rgb(var(--color-invalid) / 100%);\n  --label-color: var(--nano-color-base-1000);\n  --label-font-size: var(--nano-font-size-xs);\n  position: relative;\n  inline-size: 100%;\n  padding: 0 !important;\n  color: currentcolor;\n  display: block;\n}\n\n[type=date].sc-nano-input-h .input__date-trigger.sc-nano-input {\n  color: var(--nano-color-primary-1200);\n}\n[type=date].sc-nano-input-h .input__date-dropdown.sc-nano-input {\n  --overflow: visible;\n}\n[type=date].sc-nano-input-h .input__date-close.sc-nano-input {\n  position: absolute;\n  inset-inline-end: 0;\n  inset-block: 0;\n  opacity: 0;\n  z-index: 2;\n}\n[type=date].sc-nano-input-h .input__date-close.sc-nano-input:focus {\n  opacity: 1;\n}\n@supports selector(::-moz-placeholder) {\n  [type=date].sc-nano-input-h .form-ctrl__input-wrap.sc-nano-input {\n    justify-content: end;\n    min-block-size: 2.5em;\n  }\n  [type=date].sc-nano-input-h .input__native-ctrl.sc-nano-input {\n    position: absolute;\n    inset-inline-start: 0;\n    inset-block-start: 0;\n  }\n  [type=date].sc-nano-input-h .input__date-dropdown.sc-nano-input {\n    background-color: var(--nano-color-base-0);\n  }\n}\n\n.input__native-ctrl.sc-nano-input {\n  font-family: inherit;\n  font-size: inherit;\n  font-stretch: inherit;\n  font-style: inherit;\n  font-weight: inherit;\n  letter-spacing: inherit;\n  text-decoration: inherit;\n  text-overflow: inherit;\n  text-transform: inherit;\n  text-align: inherit;\n  white-space: inherit;\n  color: inherit;\n  appearance: none;\n  -webkit-rtl-ordering: logical;\n  padding-block: 0;\n  padding-inline: var(--padding-start) var(--padding-end);\n  border-radius: var(--input-border-radius);\n  text-overflow: ellipsis;\n  color: var(--input-text-color);\n  display: inline-block;\n  flex: 1;\n  inline-size: 100%;\n  max-inline-size: 100%;\n  max-block-size: 100%;\n  border: 0;\n  outline: none;\n  background: transparent;\n  margin: 0;\n  box-sizing: border-box;\n  resize: none;\n  overflow: hidden;\n  line-height: 2.5em;\n  min-block-size: 2.5em;\n  \n}\n.has-float-label.sc-nano-input .input__native-ctrl.sc-nano-input {\n  line-height: 2.1em;\n  min-block-size: 2.1em;\n  padding-block-start: 1.4em;\n}\n.input__native-ctrl.sc-nano-input::placeholder {\n  color: var(--placeholder-color);\n  font-family: inherit;\n  font-style: initial;\n  font-weight: initial;\n  line-height: inherit;\n  min-block-size: initial;\n}\n.input__native-ctrl.sc-nano-input::-moz-placeholder {\n  line-height: 2.8em;\n  text-overflow: ellipsis;\n}\n.input__native-ctrl.sc-nano-input:-webkit-autofill {\n  background-color: transparent;\n}\n.input__native-ctrl.sc-nano-input::-webkit-search-decoration, .input__native-ctrl.sc-nano-input::-webkit-search-cancel-button, .input__native-ctrl.sc-nano-input::-webkit-search-results-button, .input__native-ctrl.sc-nano-input::-webkit-search-results-decoration {\n  appearance: none;\n}\n.input__native-ctrl.sc-nano-input::-webkit-calendar-picker-indicator {\n  display: none;\n}\n.input__native-ctrl.sc-nano-input::-webkit-datetime-edit {\n  display: block;\n  padding: 0;\n}\n.input__native-ctrl.sc-nano-input:invalid {\n  box-shadow: none;\n}\n.input__native-ctrl.sc-nano-input::-ms-clear, .input__native-ctrl.sc-nano-input::-ms-reveal {\n  display: none;\n}\n.input__native-ctrl.input__resizable.sc-nano-input {\n  resize: vertical;\n  overflow: auto;\n}\n.form-ctrl__textarea.sc-nano-input .input__native-ctrl.sc-nano-input {\n  line-height: 1.5em;\n  padding-block: calc(var(--padding-top) - 3px) 0.5em;\n  white-space: pre-wrap;\n}\n.form-ctrl__textarea.sc-nano-input .input__native-ctrl.sc-nano-input::placeholder {\n  line-height: 1.5em;\n}\n.has-float-label.sc-nano-input .form-ctrl__textarea.sc-nano-input .input__native-ctrl.sc-nano-input {\n  padding-block-start: 1.75em;\n}\n[readonly].sc-nano-input-h:not([readonly=false]) .input__native-ctrl.sc-nano-input {\n  -webkit-user-select: none;\n          user-select: none;\n}";

let inputIds = 0;
const Input = /*@__PURE__*/ proxyCustomElement(class Input extends HTMLElement {
    nativeInput;
    inputId = `nano-input-${inputIds++}`;
    didBlurAfterEdit = false;
    rtl = false;
    mo;
    charCount = 0;
    hasRendered = false;
    pickerDropdown;
    picker;
    pickerCloseBtn;
    shouldValidate = false;
    // we don't want these rendered eles decorated with @State
    // because that will cause re-renders. User get/set to set datalist options
    _nativeInputWrap;
    get nativeInputWrap() {
        return this._nativeInputWrap;
    }
    set nativeInputWrap(ele) {
        if (this._nativeInputWrap === ele)
            return;
        this._nativeInputWrap = ele;
        this.setDataListOpts();
    }
    constructor() {
        super();
        this.__registerHost();
        this.nanoInput = createEvent(this, "nanoInput", 7);
        this.nanoChange = createEvent(this, "nanoChange", 7);
        this.nanoBlur = createEvent(this, "nanoBlur", 7);
        this.nanoFocus = createEvent(this, "nanoFocus", 7);
        this.nanoDidLoad = createEvent(this, "nanoDidLoad", 7);
        this.nanoDidUnload = createEvent(this, "nanoDidUnload", 7);
        this.nanoValidate = createEvent(this, "nanoValidate", 7);
        this.handleBlur = this.handleBlur.bind(this);
    }
    hasFocus = false;
    hasLabelSlot = false;
    hasHelperSlot = false;
    hasHelperEndSlot = false;
    errorMessage = '';
    datalist = null;
    setDataListOpts() {
        if (!this.datalist)
            return;
        const currDWConfig = this.datalist.dropDownConfig || {};
        this.datalist.dropDownConfig = {
            distance: 10,
            ...currDWConfig,
            skidding: -1,
            tetherTo: this.nativeInputWrap,
        };
    }
    get el() { return this; }
    /**
     * This will be true when the control is in an invalid state.
     * Validity is determined by the `required` prop. Or if custom validity message is set. @readonly
     */
    get invalid() {
        return this._invalid;
    }
    _invalid = null;
    /**
     * Current validation message - if any. @readonly
     */
    get validityMessage() {
        if (!this.nativeInput)
            return '';
        return this.nativeInput.validationMessage;
    }
    /**
     * If the value of the type attribute is `"file"`, then this attribute will indicate the types of files that the server accepts, otherwise it will be ignored. The value must be a comma-separated list of unique content type specifiers.
     */
    accept;
    /**
     * Indicates whether and how the text value should be automatically capitalized as it is entered/edited by the user.
     */
    autocapitalise = 'none';
    /**
     * Indicates whether the value of the control can be automatically completed by the browser.
     */
    autocomplete = 'off';
    /**
     * Whether auto correction should be enabled when the user is entering/editing the text value.
     */
    autocorrect = 'off';
    /**
     * This Boolean attribute lets you specify that a form control should have input focus when the page loads.
     */
    autofocus = false;
    /**
     * If `true`, a clear icon will appear in the input when there is a value. Clicking it clears the input.
     */
    clearable = false;
    /**
     * If `true`, the value will be cleared after focus upon edit. Defaults to `true` when `type` is `"password"`, `false` for all other types.
     */
    clearOnEdit;
    /**
     * Set the amount of time, in milliseconds, to wait to trigger the `nanoChange` event after each keystroke.
     */
    debounce = 0;
    debounceChanged() {
        this.nanoChange = debounceEvent(this.nanoChange, this.debounce);
    }
    /**
     * If `true`, the user cannot interact with the input.
     */
    disabled = false;
    /**
     * A hint to the browser for which keyboard to display.
     * Possible values: `"none"`, `"text"`, `"tel"`, `"url"`,
     * `"email"`, `"numeric"`, `"decimal"`, and `"search"`.
     */
    inputmode;
    /**
     * When should the field perform validation
     */
    validateOn = 'submitThenDirty';
    /**
     * Whether to show validation errors underneath input
     */
    showInlineError = true;
    _label = '';
    /**
     * String to place within a label element. Alternatively you may use a label slot.
     */
    get label() {
        return this.required && !this._label.endsWith('*')
            ? this._label + ' *'
            : this._label;
    }
    set label(value) {
        this._label = value;
    }
    /**
     * Sometimes it can be helpful to always show the placeholder, even when the input has a value.
     * For example a postcode field could have a placeholder `e.g. LD1 1AA` which is helpful to show.
     */
    alwaysShowPlaceholder = false;
    /**
     * Visually hide the label - but make it accessible.
     */
    hideLabel = false;
    /**
     * Enable floating label behaviour. Will disable placeholder if set.
     */
    floatLabel = false;
    /**
     * The maximum value, which must not be less than its minimum (min attribute) value.
     */
    max;
    /**
     * If the value of the type attribute is `text`, `email`, `search`, `password`, `tel`, or `url`, this attribute specifies the maximum number of characters that the user can enter.
     */
    maxlength;
    /**
     * The minimum value, which must not be greater than its maximum (max attribute) value.
     */
    min;
    /**
     * If the value of the type attribute is `text`, `email`, `search`, `password`, `tel`, or `url`, this attribute specifies the minimum number of characters that the user can enter.
     */
    minlength;
    /**
     * If `true`, the user can enter more than one value. This attribute applies when the type attribute is set to `"email"` or `"file"`, otherwise it is ignored.
     */
    multiple;
    /**
     * The name of the control, which is submitted with the form data.
     */
    name = this.inputId;
    /**
     * A regular expression that the value is checked against. The pattern must match the entire value, not just some subset. Use the title attribute to describe the pattern to help the user. This attribute applies when the value of the type attribute is `"text"`, `"search"`, `"tel"`, `"url"`, `"email"`, or `"password"`, otherwise it is ignored.
     */
    pattern;
    /**
     * Instructional text that shows before the input has a value.
     */
    placeholder;
    /**
     * If `true`, the user cannot modify the value.
     */
    readonly = false;
    /**
     * If `true`, the user must fill in a value before submitting a form.
     * By default, setting this will also add an asterisk to the label.
     */
    required = false;
    /**
     * If `true`, the element will have its spelling and grammar checked.
     */
    spellcheck = false;
    /**
     * Works with the min and max attributes to limit the increments at which a value can be set.
     * Possible values are: `"any"` or a positive floating point number.
     */
    step;
    /**
     * The initial size of the control. This value is in pixels unless the value of the type attribute
     * is `"text"` or `"password"`, in which case it is an integer number of characters.
     * This attribute applies only when the `type` attribute is set to `"text"`, `"search"`, `"tel"`, `"url"`, `"email"`, or `"password"`, otherwise it is ignored.
     */
    size;
    /**
     * The type of control to display. The default type is text.
     */
    type = 'text';
    /**
     * The form element to associate the input with (its form owner). Must be the id of a form.
     */
    form;
    /**
     * The value of the input.
     */
    value = '';
    /**
     * Update the native input element when the value changes
     */
    valueChanged() {
        this.nanoChange.emit({ value: this.value });
        this.charCount = this.value?.length || 0;
        if (this.type === 'textarea' && this.resize === 'auto') {
            this.nativeInput.style.height = 'auto';
            if (this.value?.length)
                this.nativeInput.style.height = this.nativeInput.scrollHeight + 'px';
        }
        if (this.type === 'date') {
            if (this.isDateDisabled(this.valueAsDate)) {
                this.nativeInput.setCustomValidity('Date selected is not available.');
            }
            else if (this.nativeInput.validationMessage === 'Date selected is not available.') {
                this.nativeInput.setCustomValidity('');
            }
        }
        this.shouldValidate = true;
    }
    /** Represents the value of the input or NaN if numeric conversion is impossible */
    get valueAsNumber() {
        if (this.type === 'textarea')
            return NaN;
        return this.nativeInput?.valueAsNumber || NaN;
    }
    /** Represents the current value of the input as a Date, or null if conversion is not possible */
    get valueAsDate() {
        if (this.type === 'textarea')
            return null;
        return new Date(this.value);
    }
    /**
     * Whether to show a character count / remaining count when using the `maxlength` attribute.
     */
    showCharCount = false;
    handleValidatePropChange() {
        if (!this.hasRendered)
            return;
        this.shouldValidate = true;
    }
    ///// TYPE SPECIFIC PROPS /////
    /**
     * relevant to `type="textarea"`. Vertical resizing - enable / disable or make automatic.
     */
    resize = 'auto';
    /**
     * relevant to `type="textarea"`. Default number of rows to show
     */
    rows = 2;
    /**
     * relevant to `type="date"`. Whether to show a date picker.
     * Date pickers are not very useful if the potential input is too far in the distance or past e.g. Birthdays
     */
    showPicker = true;
    /** relevant to `type="date"`. Controls which days are disabled and therefore disallowed.
     * For example, this can be used to disallow selection of weekends.
     * @returns `false` for not disabled and `true` for disabled */
    isDateDisabled = () => false;
    /**
     * relevant to `type="date"`. Initial picker date. Defaults to `value` if set and today's date if not.
     * Must be in IS0-8601 format: YYYY-MM-DD.
     */
    initialPickerDate;
    /**
     * relevant to `type="date"`. If `true`, the input will close after a date is picked.
     */
    closeAfterPicked = true;
    /**
     * relevant to `type="date"`. Other options to pass to the date picker.
     * See the `nano-date-picker` docs for more information.
     */
    pickerOptions = {};
    /**
     * Emitted when a keyboard input occurred.
     */
    nanoInput;
    /**
     * Emitted when the value has changed.
     */
    nanoChange;
    /**
     * Emitted when the input loses focus.
     */
    nanoBlur;
    /**
     * Emitted when the input has focus.
     */
    nanoFocus;
    /**
     * Emitted when the input has been created.
     * @internal
     */
    nanoDidLoad;
    /**
     * Emitted when the input has been removed.
     * @internal
     */
    nanoDidUnload;
    /**
     * Called when validation is performed (which depends on `validateOn`).
     * @returns event.detail: `{ isValid: boolean, errorMessage: string, originalEvent: Event }`.
     */
    nanoValidate;
    /**
     * Get the current state of the control.
     * @param validateFirst - perform validation first before reporting
     * @returns `{ isValid: boolean, errorMessage: string }`
     */
    async reportValidity(validateFirst) {
        return new Promise((resolve) => {
            if (validateFirst)
                this.validate();
            setTimeout(() => {
                resolve({
                    isValid: !this._invalid,
                    errorMessage: this.nativeInput.validationMessage,
                });
            }, 50);
        });
    }
    /**
     * Sets focus on the specified `nano-input`. Use this method instead of the global
     * `input.focus()`.
     */
    async setFocus() {
        if (this.nativeInput) {
            this.nativeInput.focus();
            this.nativeInput.click();
        }
    }
    /**
     * Sets focus and select the text on the specified `nano-input`. Use this method instead of the global
     * `input.select()`.
     */
    async select() {
        if (this.nativeInput) {
            this.nativeInput.select();
        }
    }
    /**
     * @returns the native `<input>` element used under the hood.
     */
    getInputElement() {
        return Promise.resolve(this.nativeInput);
    }
    /**
     * Invalidate the field and show a custom error message. To clear the error you will need to re-call this method with an empty string.
     */
    async showError(message) {
        if (this.nativeInput) {
            this.nativeInput.setCustomValidity(message);
            this.validate();
        }
    }
    onReset(e) {
        const form = this.form
            ? document.querySelector('#' + this.form)
            : this.el.closest('form');
        if (!form || e.target !== this.el.closest('form'))
            return;
        this.value = '';
    }
    handleBlur(e) {
        if (!this.hasFocus)
            return;
        const kev = e;
        let target;
        requestAnimationFrame(() => {
            if (e instanceof KeyboardEvent && kev.key) {
                if (kev.key !== 'Tab')
                    return;
                target = document.activeElement;
            }
            else if (e instanceof FocusEvent) {
                target = document.activeElement;
            }
            else
                target = e.target;
            if (closestElement(this.el.tagName.toLowerCase(), target) !== this.el) {
                this.onBlur();
            }
        });
    }
    shouldClearOnEdit() {
        const { type, clearOnEdit } = this;
        return clearOnEdit === undefined ? type === 'password' : clearOnEdit;
    }
    getValue() {
        return this.value || '';
    }
    validate = (ev) => {
        if (this.validateOn === 'submitThenDirty')
            this.validateOn = 'dirty';
        if (!this.nativeInput.validity?.valid) {
            if (this.showInlineError) {
                if (ev)
                    ev.preventDefault();
                this.errorMessage = this.nativeInput.validationMessage;
            }
            this._invalid = true;
        }
        else
            this._invalid = false;
        this.nanoValidate.emit({
            isValid: !this._invalid,
            errorMessage: this.nativeInput.validationMessage,
            originalEvent: ev,
        });
    };
    onInput = (ev) => {
        const input = ev.target;
        this.value = input?.value || '';
        this.nanoInput.emit(ev);
    };
    onBlur = () => {
        this.hasFocus = false;
        this.focusChanged();
        if (this.validateOn === 'dirty')
            this.validate();
        this.nanoBlur.emit();
    };
    onFocus = (e) => {
        if (this.type === 'date') {
            // fix to stop native date picker from showing
            e.preventDefault();
        }
        this.hasFocus = true;
        this.focusChanged();
        this.nanoFocus.emit();
    };
    onKeydown = (e) => {
        if (this.type === 'date' && [' '].includes(e.key)) {
            // fix to stop native date picker from showing
            e.preventDefault();
            if (this.showPicker) {
                this.pickerDropdown?.show();
            }
        }
        if (this.shouldClearOnEdit()) {
            // Did the input value change after it was blurred and edited?
            if (this.didBlurAfterEdit && this.hasValue()) {
                // Clear the input
                this.clearTextInput();
            }
            // Reset the flag
            this.didBlurAfterEdit = false;
        }
    };
    clearTextInput = (ev) => {
        if (this.clearable && !this.readonly && !this.disabled && ev) {
            ev.preventDefault();
            ev.stopPropagation();
        }
        this.value = '';
        this.nativeInput.value = '';
        const event = new window.Event('change');
        this.nativeInput.dispatchEvent(event);
    };
    focusChanged() {
        // If clearOnEdit is enabled and the input blurred but has a value, set a flag
        if (!this.hasFocus && this.shouldClearOnEdit() && this.hasValue()) {
            this.didBlurAfterEdit = true;
        }
    }
    hasValue() {
        return this.getValue().length > 0;
    }
    slotChangeObserver() {
        if (!Build.isBrowser)
            return;
        if (this.mo)
            this.mo.disconnect();
        const mo = (this.mo = new MutationObserver(() => this.processSlottedContent()));
        mo.observe(this.el, { childList: true, subtree: true });
    }
    processSlottedContent() {
        // see if we have label / button content
        this.hasLabelSlot = !!this.el.querySelectorAll('[slot="label"]');
        this.hasHelperSlot = !!this.el.querySelector('[slot="helper"]');
        this.hasHelperEndSlot = !!this.el.querySelector('[slot="helper-end"]');
        this.datalist = this.el.querySelector(`${transformTag('nano-datalist')}:not([slot])`);
    }
    connectedCallback() {
        this.debounceChanged();
        if (Build.isBrowser) {
            this.el.dispatchEvent(new CustomEvent('nanoDidLoad', {
                detail: this.el,
            }));
        }
    }
    disconnectedCallback() {
        if (Build.isBrowser) {
            document.dispatchEvent(new CustomEvent('nanoDidUnload', {
                detail: this.el,
            }));
        }
        if (this.mo)
            this.mo.disconnect();
    }
    componentDidLoad() {
        this.slotChangeObserver();
        this.hasRendered = true;
        if (this.autofocus)
            setTimeout((_) => this.setFocus(), 300);
    }
    componentWillLoad() {
        this.processSlottedContent();
    }
    componentDidRender() {
        if (this.shouldValidate) {
            this.validate();
            this.shouldValidate = false;
        }
    }
    render() {
        const value = this.getValue();
        const labelId = this.inputId + '-lbl';
        const moreId = this.showInlineError || this.hasHelperSlot ? this.inputId + '-more' : '';
        const helperEndId = this.hasHelperEndSlot ? this.inputId + '-helper' : '';
        this.rtl = this.el.ownerDocument.dir === 'rtl';
        const compWrapOptions = (({ el, floatLabel, label, alwaysShowPlaceholder, errorMessage, type, showInlineError, hasHelperSlot, hasLabelSlot, hideLabel, placeholder, maxlength, charCount, showCharCount, rtl, hasHelperEndSlot, }) => ({
            el,
            floatLabel,
            label,
            alwaysShowPlaceholder,
            errorMessage,
            type,
            showInlineError,
            hasHelperSlot,
            hasLabelSlot,
            hideLabel,
            placeholder,
            maxlength,
            charCount,
            showCharCount,
            rtl,
            hasHelperEndSlot,
        }))(this);
        const wrapOptions = {
            ...compWrapOptions,
            labelId,
            moreId,
            helperEndId,
            hasValue: this.hasValue(),
            controlId: this.inputId,
        };
        const controlOptions = (({ clearable, readonly, disabled }) => ({
            clearable,
            readonly,
            disabled,
            clearControl: this.clearable,
        }))(this);
        return (h(Host, { key: '636d7624bcfe136a0e93b55cf9fc38e272f7aed6', "aria-disabled": this.disabled ? 'true' : null, class: {
                'has-value': this.hasValue(),
                'has-focus': this.hasFocus,
                'is-invalid': this._invalid === true,
                'is-valid': this._invalid === false,
                'nano-input': true,
            } }, h("div", { key: '942db1636f7d08dd581359b66df66ebf080d23ae', style: { width: '100%' } }, h(FormControlWrap, { key: 'd944b897545398b51ab0a76e1f8d62c57cd85843', ...wrapOptions, class: {
                'has-helper': this.hasHelperSlot,
                'has-error': !!this.errorMessage &&
                    this.showInlineError &&
                    this._invalid === true,
            } }, h(FormControl, { key: 'efd29f841ff0724228fc47754a5aad8d82f88d49', ...controlOptions, onClearText: this.clearTextInput, control: this.el, ref: (el) => (this.nativeInputWrap = el), showInlineError: this.showInlineError, endSlot: this.showPicker &&
                this.type === 'date' &&
                !this.readonly &&
                !this.disabled && [
                h("nano-dropdown", { slot: "end", dialogTitle: "Choose a date", class: "input__date-dropdown", part: "date__dropdown", placement: "bottom-end", skidding: 10, distance: 12, ref: (dd) => (this.pickerDropdown = dd), onNanoAfterShow: () => this.picker.setFocus(true) }, h("nano-icon-button", { label: "Open date picker", iconName: "light/calendar-days", slot: "trigger", class: "input__date-trigger" }), h("div", null, h("div", { class: "date-field__close-bar" }, h("nano-icon-button", { label: "Close date picker", iconName: "light/xmark", class: "input__date-close", onClick: (e) => {
                        e.target
                            .closest('nano-dropdown')
                            ?.hide();
                    }, ref: (btn) => (this.pickerCloseBtn = btn) })), h("nano-date-picker", { part: "date__picker", ref: (dp) => {
                        this.picker = dp;
                        this.picker.firstFocusEle = this.pickerCloseBtn;
                    }, ...this.pickerOptions, isDateDisabled: this.isDateDisabled, onNanoDatePicked: (e) => {
                        this.value = e.detail.value;
                        this.pickerDropdown?.hide();
                    }, min: this.min, max: this.max, "is-modal": true, selectedDate: this.value || this.initialPickerDate || undefined }))),
            ] }, this.type !== 'textarea' && (h("input", { key: 'ce5547777de11926717b27712f7d687171d0dde7', id: this.inputId, class: "input__native-ctrl", ref: (input) => (this.nativeInput = input), "aria-labelledby": labelId + ' ' + moreId + ' ' + helperEndId, disabled: this.disabled, accept: this.accept, autoCapitalize: this.autocapitalise, autoComplete: this.autocomplete, autoCorrect: this.autocorrect, autoFocus: this.autofocus, inputMode: this.inputmode, form: this.form, min: this.min, max: this.max, minLength: this.minlength, maxLength: this.maxlength, multiple: this.multiple, name: this.name, pattern: this.pattern, placeholder: this.placeholder, readOnly: this.readonly, required: this.required, spellcheck: this.spellcheck, step: this.step, size: this.size, type: this.type, value: value, onInput: this.onInput, onClick: (e) => e.preventDefault(), onChange: this.onInput, onFocus: this.onFocus, onBlur: this.handleBlur, onKeyDown: this.onKeydown, onInvalid: this.validate })), this.type === 'textarea' && (h("textarea", { key: 'e1dc2377200cdccda85cdbb6cda08a49d8459c1e', rows: this.floatLabel ? 1 : this.rows, id: this.inputId, class: {
                'input__native-ctrl': true,
                input__resizable: this.resize === 'true',
            }, ref: (input) => (this.nativeInput = input), "aria-labelledby": labelId + ' ' + moreId + ' ' + helperEndId, disabled: this.disabled, autoCapitalize: this.autocapitalise, autoCorrect: this.autocorrect, autoFocus: this.autofocus, inputMode: this.inputmode, form: this.form, minLength: this.minlength, maxLength: this.maxlength, name: this.name, placeholder: this.placeholder, readOnly: this.readonly, required: this.required, spellcheck: this.spellcheck, value: value, onInput: this.onInput, onChange: this.onInput, onFocus: this.onFocus, onKeyDown: this.onKeydown, onInvalid: this.validate, onBlur: this.handleBlur })))), h("slot", { key: '564511c369dc13eb85cbf7e1c48b5d5fbbea8679' }))));
    }
    static get watchers() { return {
        "datalist": ["setDataListOpts"],
        "debounce": ["debounceChanged"],
        "value": ["valueChanged"],
        "minlength": ["handleValidatePropChange"],
        "maxlength": ["handleValidatePropChange"],
        "min": ["handleValidatePropChange"],
        "max": ["handleValidatePropChange"],
        "required": ["handleValidatePropChange"],
        "disabled": ["handleValidatePropChange"],
        "readonly": ["handleValidatePropChange"],
        "pattern": ["handleValidatePropChange"],
        "inputmode": ["handleValidatePropChange"],
        "type": ["handleValidatePropChange"]
    }; }
    static get style() { return inputCss; }
}, [262, "nano-input", {
        "invalid": [2568],
        "validityMessage": [2049, "validity-message"],
        "accept": [1],
        "autocapitalise": [1],
        "autocomplete": [1],
        "autocorrect": [1],
        "autofocus": [4],
        "clearable": [4],
        "clearOnEdit": [4, "clear-on-edit"],
        "debounce": [2],
        "disabled": [516],
        "inputmode": [1],
        "validateOn": [1025, "validate-on"],
        "showInlineError": [516, "show-inline-error"],
        "label": [7169],
        "alwaysShowPlaceholder": [4, "always-show-placeholder"],
        "hideLabel": [4, "hide-label"],
        "floatLabel": [4, "float-label"],
        "max": [1],
        "maxlength": [2],
        "min": [1],
        "minlength": [2],
        "multiple": [4],
        "name": [1],
        "pattern": [1],
        "placeholder": [1],
        "readonly": [516],
        "required": [4],
        "spellcheck": [4],
        "step": [1],
        "size": [2],
        "type": [513],
        "form": [1],
        "value": [1025],
        "valueAsNumber": [2050, "value-as-number"],
        "valueAsDate": [2064, "value-as-date"],
        "showCharCount": [4, "show-char-count"],
        "resize": [1],
        "rows": [2],
        "showPicker": [4, "show-picker"],
        "isDateDisabled": [16, "is-date-disabled"],
        "initialPickerDate": [1, "initial-picker-date"],
        "closeAfterPicked": [4, "close-after-picked"],
        "pickerOptions": [16, "picker-options"],
        "hasFocus": [32],
        "hasLabelSlot": [32],
        "hasHelperSlot": [32],
        "hasHelperEndSlot": [32],
        "errorMessage": [32],
        "datalist": [32],
        "_invalid": [32],
        "reportValidity": [64],
        "setFocus": [64],
        "select": [64],
        "getInputElement": [64],
        "showError": [64]
    }, [[16, "reset", "onReset"], [17, "mousedown", "handleBlur"], [0, "keydown", "handleBlur"]], {
        "datalist": ["setDataListOpts"],
        "debounce": ["debounceChanged"],
        "value": ["valueChanged"],
        "minlength": ["handleValidatePropChange"],
        "maxlength": ["handleValidatePropChange"],
        "min": ["handleValidatePropChange"],
        "max": ["handleValidatePropChange"],
        "required": ["handleValidatePropChange"],
        "disabled": ["handleValidatePropChange"],
        "readonly": ["handleValidatePropChange"],
        "pattern": ["handleValidatePropChange"],
        "inputmode": ["handleValidatePropChange"],
        "type": ["handleValidatePropChange"]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["nano-input", "nano-date-picker", "nano-dropdown", "nano-icon", "nano-icon-button", "nano-tooltip"];
    components.forEach(tagName => { switch (tagName) {
        case "nano-input":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, Input);
            }
            break;
        case "nano-date-picker":
            if (!customElements.get(tagName)) {
                defineCustomElement$5();
            }
            break;
        case "nano-dropdown":
            if (!customElements.get(tagName)) {
                defineCustomElement$4();
            }
            break;
        case "nano-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "nano-icon-button":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
        case "nano-tooltip":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}

export { Input as I, defineCustomElement as d };
