import { d as waitAfterIdleCallback } from './helpers.js';

const stopEventBubbling = (ev) => {
    if (ev) {
        ev.preventDefault();
        ev.stopPropagation();
    }
};
const getInputTarget = (ev) => {
    return ev.target;
};
const getNativeInputValue = (component) => {
    var _a;
    return ((_a = component.nativeInput) === null || _a === void 0 ? void 0 : _a.value) || '';
};
const getUpcomingValue = (component, ev) => {
    var _a, _b;
    const value = ((_a = component.nativeInput) === null || _a === void 0 ? void 0 : _a.value) || '';
    const idx = (_b = ev.target) === null || _b === void 0 ? void 0 : _b.selectionStart;
    return value.slice(0, idx) + ev.key + value.slice(idx + Math.abs(0));
};
const inputSetBlur = (component) => {
    if (component.nativeInput) {
        component.nativeInput.blur();
    }
};
const inputListenOnClick = (component, ev) => {
    if ((component.disabled || component.readonly) && ev.target && ev.target === component.el) {
        stopEventBubbling(ev);
    }
};
const inputSetFocus = async (component) => {
    var _a;
    await waitAfterIdleCallback();
    (_a = component === null || component === void 0 ? void 0 : component.nativeInput) === null || _a === void 0 ? void 0 : _a.focus();
};
const inputHandleHostClick = (component, ev) => {
    if (component.disabled || component.readonly) {
        stopEventBubbling(ev);
    }
};
const inputHandleClick = (component, ev) => {
    if (!component.disabled && !component.readonly && component.balClick) {
        component.balClick.emit(ev);
    }
};
const inputHandleFocus = (component, ev) => {
    component.focused = true;
    component.inputValue = component.value;
    if (!component.disabled && component.balFocus) {
        component.balFocus.emit(ev);
    }
};
const inputHandleReset = (component, defaultValue = undefined, timer) => {
    component.value = defaultValue;
    component.inputValue = component.value;
    clearTimeout(timer);
    timer = setTimeout(() => {
        if (component.nativeInput) {
            component.nativeInput.value = component.value;
        }
    });
};
const inputHandleBlur = (component, ev) => {
    component.focused = false;
    if (!component.disabled && component.balBlur) {
        component.balBlur.emit(ev);
    }
};
const inputHandleChange = (component) => {
    if (component.value !== component.inputValue) {
        component.value = component.inputValue;
        component.balChange.emit(component.value);
    }
};

export { inputSetBlur as a, inputHandleFocus as b, inputHandleHostClick as c, inputListenOnClick as d, inputHandleBlur as e, inputHandleChange as f, getInputTarget as g, inputHandleClick as h, inputSetFocus as i, inputHandleReset as j, getUpcomingValue as k, getNativeInputValue as l, stopEventBubbling as s };
