import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
import { _ as __decorate, a as __metadata } from './tslib.es6.js';
import { i as isNil } from './index2.js';
import { a as ariaBooleanToString } from './aria.js';
import { i as inheritAttributes } from './attributes.js';
import { B as BEM } from './bem.js';
import { d as defaultConfig } from './config.default.js';
import { L as ListenToConfig } from './config.decorator.js';
import { i as isCtrlOrCommandKey, N as NUMBER_KEYS, A as ACTION_KEYS } from './keys.constant.js';
import { d as defaultBalAriaForm } from './form.js';
import { g as getInputTarget, c as inputHandleFocus, d as inputHandleBlur, e as inputHandleChange, s as stopEventBubbling, j as inputListenOnClick, k as inputHandleReset, i as inputSetFocus, a as inputSetBlur } from './form-input.js';
import { k as debounceEvent } from './helpers.js';
import { L as Logger } from './log.js';
import { i as i18nBalTimeInput } from './bal-time-input.i18n.js';
import { d as defineCustomElement$3 } from './bal-icon2.js';
import { d as defineCustomElement$2 } from './bal-input-group2.js';

const balTimeInputCss = ":root{--bal-time-input-native-placeholder-background-before:var(--bal-color-white);--bal-time-input-native-placeholder-background-disabled-before:var(--bal-color-grey-2);--bal-time-input-native-placeholder-background-danger-before:var(--bal-color-danger-1);--bal-time-input-native-placeholder-background-disabled-danger-before:var(--bal-color-grey-2);--bal-time-input-native-placeholder-background-hover-before:var(--bal-color-grey-1);--bal-time-input-native-text-color:var(--bal-color-primary-3);--bal-time-input-native-text-color-focus-value:var(--bal-color-primary);--bal-time-input-native-text-color-disabled:var(--bal-color-grey-5);--bal-time-input-native-text-color-disabled-value:var(--bal-color-grey-4);--bal-time-input-native-placeholder-text-color-disabled-before:var(--bal-color-grey-5);--bal-time-input-native-placeholder-text-color-before:var(--bal-color-primary-3)}.bal-time-input{-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;display:block;position:relative;-ms-flex:1;flex:1;-ms-flex-align:center;align-items:center;width:100%;padding:0;font-family:var(--bal-font-family-text)}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper{display:flex}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper::-webkit-datetime-edit-text{color:var(--bal-time-input-native-text-color)}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper::-webkit-datetime-edit-hour-field{color:var(--bal-time-input-native-text-color)}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper::-webkit-datetime-edit-minute-field{color:var(--bal-time-input-native-text-color)}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper::-webkit-clear-button{display:none}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper::-webkit-inner-spin-button{display:none}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper::-webkit-calendar-picker-indicator{display:none;background:none}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper.has-focus::-webkit-datetime-edit-text,.bal-time-input__native::-webkit-datetime-edit-fields-wrapper.has-value::-webkit-datetime-edit-text{color:var(--bal-time-input-native-text-color-focus-value)}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper.has-focus::-webkit-datetime-edit-text::-webkit-datetime-edit-hour-field,.bal-time-input__native::-webkit-datetime-edit-fields-wrapper.has-value::-webkit-datetime-edit-text::-webkit-datetime-edit-hour-field{color:var(--bal-time-input-native-text-color-focus-value)}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper.has-focus::-webkit-datetime-edit-text::-webkit-datetime-edit-minute-field,.bal-time-input__native::-webkit-datetime-edit-fields-wrapper.has-value::-webkit-datetime-edit-text::-webkit-datetime-edit-minute-field{color:var(--bal-time-input-native-text-color-focus-value)}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper.is-disabled::-webkit-datetime-edit-text{color:var(--bal-time-input-native-text-color-disabled)}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper.is-disabled::-webkit-datetime-edit-text::-webkit-datetime-edit-hour-field{color:var(--bal-time-input-native-text-color-disabled)}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper.is-disabled::-webkit-datetime-edit-text::-webkit-datetime-edit-minute-field{color:var(--bal-time-input-native-text-color-disabled)}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper.is-disabled::-webkit-datetime-edit-text.has-value::-webkit-datetime-edit-text{color:var(--bal-time-input-native-text-color-disabled-value)}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper.is-disabled::-webkit-datetime-edit-text.has-value::-webkit-datetime-edit-text::-webkit-datetime-edit-hour-field{color:var(--bal-time-input-native-text-color-disabled-value)}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper.is-disabled::-webkit-datetime-edit-text.has-value::-webkit-datetime-edit-text::-webkit-datetime-edit-minute-field{color:var(--bal-time-input-native-text-color-disabled-value)}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper.show-placeholder.is-disabled::before{color:var(--bal-time-input-native-placeholder-text-color-disabled-before);background:var(--bal-time-input-native-placeholder-background-disabled-before)}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper.show-placeholder.is-disabled::before.is-danger::before{background:var(--bal-time-input-native-placeholder-background-danger-before)}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper.show-placeholder.is-disabled::before.is-disabled.is-danger::before{background:var(--bal-time-input-native-placeholder-background-disabled-danger-before)}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper.show-placeholder.is-disabled::before:hover::before{background:var(--bal-time-input-native-placeholder-background-hover-before)}.bal-time-input__native::-webkit-datetime-edit-fields-wrapper.show-placeholder.is-disabled::before::before{color:var(--bal-time-input-native-placeholder-text-color-before);content:attr(placeholder);pointer-events:none;position:absolute;background:var(--bal-time-input-native-placeholder-background-before)}";

const TimeInput = /*@__PURE__*/ proxyCustomElement(class TimeInput extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.balInput = createEvent(this, "balInput", 7);
        this.balChange = createEvent(this, "balChange", 7);
        this.balBlur = createEvent(this, "balBlur", 7);
        this.balFocus = createEvent(this, "balFocus", 7);
        this.balKeyPress = createEvent(this, "balKeyPress", 7);
        this.balClick = createEvent(this, "balClick", 7);
        this.inputId = `bal-time-input-${timeInputIds++}`;
        this.inheritedAttributes = {};
        this.inputValue = this.value;
        this.initialValue = '';
        this.focused = false;
        this.language = defaultConfig.language;
        this.region = defaultConfig.region;
        this.ariaForm = defaultBalAriaForm;
        /**
         * The name of the control, which is submitted with the form data.
         */
        this.name = this.inputId;
        /**
         * If `true` the component gets a invalid style.
         */
        this.invalid = false;
        /**
         * If `true`, the user must fill in a value before submitting a form.
         */
        this.required = false;
        /**
         * If `true`, the element is not mutable, focusable, or even submitted with the form. The user can neither edit nor focus on the control, nor its form control descendants.
         */
        this.disabled = false;
        /**
         * If `true` the element can not mutated, meaning the user can not edit the control.
         */
        this.readonly = false;
        /**
         * Set the amount of time, in milliseconds, to wait to trigger the `balChange` event after each keystroke. This also impacts form bindings such as `ngModel` or `v-model`.
         */
        this.debounce = 0;
        /**
         * The value of the input.
         */
        this.value = undefined;
        /**
         * If `true`, in Angular reactive forms the control will not be set invalid
         */
        this.autoInvalidOff = false;
        this.onInput = (ev) => {
            const input = getInputTarget(ev);
            if (input) {
                this.inputValue = input.value;
            }
            this.balInput.emit(this.inputValue);
        };
        this.onFocus = (ev) => {
            inputHandleFocus(this, ev);
        };
        this.onBlur = (ev) => {
            inputHandleBlur(this, ev);
            const input = ev.target;
            if (input) {
                input.value = this.getFormattedValue();
                inputHandleChange(this);
            }
        };
        this.onKeydown = (ev) => {
            if (!isNil(ev) && !isCtrlOrCommandKey(ev)) {
                if (!this.getAllowedKeys().includes(ev.key)) {
                    return stopEventBubbling(ev);
                }
            }
        };
    }
    createLogger(log) {
        this.log = log;
    }
    debounceChanged() {
        this.balChange = debounceEvent(this.balChange, this.debounce);
    }
    listenOnClick(ev) {
        inputListenOnClick(this, ev);
    }
    resetHandler(ev) {
        const formElement = ev.target;
        if (formElement === null || formElement === void 0 ? void 0 : formElement.contains(this.el)) {
            inputHandleReset(this, this.initialValue, this.resetHandlerTimer);
        }
    }
    connectedCallback() {
        this.debounceChanged();
        this.initialValue = this.value || '';
    }
    componentDidLoad() {
        this.inputValue = this.value;
    }
    componentWillLoad() {
        this.inheritedAttributes = inheritAttributes(this.el, ['aria-label', 'tabindex', 'title', 'data-hj-allow']);
    }
    /**
     * @internal define config for the component
     */
    async configChanged(state) {
        this.language = state.language;
        this.region = state.region;
        if (!this.focused && this.nativeInput) {
            this.nativeInput.value = this.getFormattedValue();
        }
    }
    /**
     * Sets focus on the native `input`. Use this method instead of the global
     * `input.focus()`.
     */
    async setFocus() {
        inputSetFocus(this);
    }
    /**
     * Sets blur on the native `input`. Use this method instead of the global
     * `input.blur()`.
     * @internal
     */
    async setBlur() {
        inputSetBlur(this);
    }
    /**
     * Returns the native `<input>` element used under the hood.
     */
    async getInputElement() {
        return this.nativeInput;
    }
    /**
     * @internal
     */
    async setAriaForm(ariaForm) {
        this.ariaForm = Object.assign({}, ariaForm);
    }
    getAllowedKeys() {
        return [...NUMBER_KEYS, ...ACTION_KEYS, ':', 'A', 'M', 'P'];
    }
    getRawValue() {
        const value = (this.value || '').toString();
        return value;
    }
    getFormattedValue() {
        return this.getRawValue();
    }
    render() {
        const value = this.focused ? this.getRawValue() : this.getFormattedValue();
        const block = BEM.block('time-input');
        const native = block.element('native');
        return (h(Host, { key: '169d820dea13588e19c1e31307cdf506d7cb103d', "aria-disabled": ariaBooleanToString(this.disabled), class: Object.assign({}, block.class()) }, h("bal-input-group", { key: 'a35e45501ec4fab9eb274c5dbc76f76d99794922', disabled: this.disabled || this.readonly, invalid: this.invalid }, h("input", Object.assign({ key: '22a706a78b700fc39b6819d5f34ef3cc7213e293', type: "time", class: Object.assign({ 'input': true, 'is-disabled': this.disabled || this.readonly, 'is-danger': this.invalid, 'has-focus': this.focused, 'show-placeholder': !this.focused && (this.value === '' || this.value === undefined), 'has-value': this.value !== '' && this.value !== undefined }, native.class()), ref: input => (this.nativeInput = input), id: this.ariaForm.controlId || this.inputId, "aria-labelledby": this.ariaForm.labelId, "aria-describedby": this.ariaForm.messageId, "aria-invalid": this.invalid === true ? 'true' : 'false', "aria-disabled": ariaBooleanToString(this.disabled), name: this.name, disabled: this.disabled, readonly: this.readonly, required: this.required, placeholder: `${i18nBalTimeInput[this.language].hours}:${i18nBalTimeInput[this.language].minutes}`, value: value, onInput: ev => this.onInput(ev), onFocus: e => this.onFocus(e), onBlur: e => this.onBlur(e), onKeyDown: e => this.onKeydown(e), onKeyPress: e => this.balKeyPress.emit(e) }, this.inheritedAttributes)), h("bal-icon", { key: '99e813d458b4adb13726057d7cf82f21745bded7', "is-right": true, color: this.disabled || this.readonly ? 'grey' : this.invalid ? 'danger' : 'primary', name: "clock" }))));
    }
    get el() { return this; }
    static get watchers() { return {
        "debounce": ["debounceChanged"]
    }; }
    static get style() { return balTimeInputCss; }
}, [0, "bal-time-input", {
        "name": [1],
        "invalid": [4],
        "required": [4],
        "disabled": [4],
        "readonly": [4],
        "debounce": [2],
        "value": [1025],
        "autoInvalidOff": [516, "auto-invalid-off"],
        "focused": [32],
        "language": [32],
        "region": [32],
        "ariaForm": [32],
        "configChanged": [64],
        "setFocus": [64],
        "setBlur": [64],
        "getInputElement": [64],
        "setAriaForm": [64]
    }, [[6, "click", "listenOnClick"], [6, "reset", "resetHandler"]], {
        "debounce": ["debounceChanged"]
    }]);
__decorate([
    Logger('bal-time-input'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Function]),
    __metadata("design:returntype", void 0)
], TimeInput.prototype, "createLogger", null);
__decorate([
    ListenToConfig(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], TimeInput.prototype, "configChanged", null);
let timeInputIds = 0;
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["bal-time-input", "bal-icon", "bal-input-group"];
    components.forEach(tagName => { switch (tagName) {
        case "bal-time-input":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, TimeInput);
            }
            break;
        case "bal-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "bal-input-group":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
    } });
}

const BalTimeInput = TimeInput;
const defineCustomElement = defineCustomElement$1;

export { BalTimeInput, defineCustomElement };
