import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-BdVwMG9u.js';
import { _ as __decorate, a as __metadata } from './tslib.es6-dfXERft2.js';
import { i as isNil } from './index-zWZxKBfo.js';
import { a as ariaBooleanToString } from './aria-DBsOHTWj.js';
import { i as inheritAttributes } from './attributes-C4sZQbkT.js';
import { B as BEM } from './bem-ByiN-QjD.js';
import { i as isCtrlOrCommandKey, N as NUMBER_KEYS, A as ACTION_KEYS } from './keys.constant-xVPGsAdF.js';
import { d as defaultBalAriaForm } from './form-FCLKfv6B.js';
import { g as getInputTarget, a as inputHandleFocus, b as inputHandleBlur, e as inputHandleChange, s as stopEventBubbling, h as inputListenOnClick, j as inputHandleReset, c as inputSetFocus, d as inputSetBlur } from './form-input-DYvzaBlM.js';
import { n as debounceEvent } from './helpers-BNj87EbG.js';
import { L as Logger } from './log-CwssmmaV.js';
import { i as i18nBalTimeInput } from './bal-time-input.i18n-B4aDEwd8.js';
import { d as defaultConfig } from './config.default-RE8-gLMQ.js';
import { L as ListenToConfig } from './config.decorator-3bfyZ-0Y.js';
import './_commonjsHelpers-BFTU3MAI.js';
import './browser-B1u-Mq75.js';
import './config.utils-B7jugjyM.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 = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.balInput = createEvent(this, "balInput");
        this.balChange = createEvent(this, "balChange");
        this.balBlur = createEvent(this, "balBlur");
        this.balFocus = createEvent(this, "balFocus");
        this.balKeyPress = createEvent(this, "balKeyPress");
        this.balClick = createEvent(this, "balClick");
        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: '6b1b0a24a554e6c36befcc44f888a4a6582b2ada', "aria-disabled": ariaBooleanToString(this.disabled), class: Object.assign({}, block.class()) }, h("bal-input-group", { key: 'e0a53ed0fa5bc08deb818fb6e7119bef8bf5bed1', disabled: this.disabled || this.readonly, invalid: this.invalid }, h("input", Object.assign({ key: '7ede7fc70c763cae673b67192a4ab467f0a5c7fc', 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: 'cce0762bb6cb91dd62ced90ab7b8defbf75ca7ac', "is-right": true, color: this.disabled || this.readonly ? 'grey' : this.invalid ? 'danger' : 'primary', name: "clock" }))));
    }
    get el() { return getElement(this); }
    static get watchers() { return {
        "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;
TimeInput.style = balTimeInputCss;

export { TimeInput as bal_time_input };
