import {
  useNumberInput
} from "./chunk-T6Q43UMB.js";
import {
  TextInput
} from "./chunk-H5MRGJQP.js";
import {
  __objRest,
  __spreadProps,
  __spreadValues
} from "./chunk-W7FAWX6T.js";

// src/components/NumberInput.tsx
import { useCallback, useRef } from "react";
import { jsx } from "@emotion/react/jsx-runtime";
function NumberInput(_a) {
  var _b = _a, {
    maxValue,
    onRightButtonClick,
    onChange: onChangeProp
  } = _b, rest = __objRest(_b, [
    "maxValue",
    "onRightButtonClick",
    "onChange"
  ]);
  const ref = useRef(null);
  const {
    getRenderValue,
    handleOnChange,
    handleOnBlur,
    handleOnFocus,
    handleOnKeyDown,
    handleOnKeyUp
  } = useNumberInput(__spreadProps(__spreadValues({}, rest), {
    onChange: onChangeProp,
    ref
  }));
  const onChange = useCallback(
    (value, event) => {
      handleOnChange(event);
    },
    [handleOnChange]
  );
  const handleRightButtonClick = useCallback(
    (event) => {
      event.preventDefault();
      if (maxValue && onChangeProp) {
        onChangeProp(maxValue.toString());
      }
      if (onRightButtonClick) {
        onRightButtonClick(event);
      }
    },
    [maxValue, onRightButtonClick, onChangeProp]
  );
  const onKeyDown = useCallback(
    (keyValue, event) => {
      handleOnKeyDown(event);
    },
    [handleOnKeyDown]
  );
  return /* @__PURE__ */ jsx(
    TextInput,
    __spreadProps(__spreadValues({
      placeholder: "Enter a number"
    }, rest), {
      onKeyDown,
      onKeyUp: handleOnKeyUp,
      onChange,
      onBlur: handleOnBlur,
      onFocus: handleOnFocus,
      value: getRenderValue(),
      inputRef: ref,
      type: "text",
      inputMode: "decimal",
      pattern: "[0-9,.]*",
      rightButtonText: maxValue ? "Max" : void 0,
      onRightButtonClick: handleRightButtonClick
    })
  );
}
var NumberInput_default = NumberInput;

export {
  NumberInput,
  NumberInput_default
};
