import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_mathjs__ from "mathjs";
import * as __WEBPACK_EXTERNAL_MODULE__input_number_ReadPretty_mjs__ from "../input-number/ReadPretty.mjs";
const isNumberLike = (index)=>(0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.isNum)(index) || /^-?\d+(\.\d+)?$/.test(index);
const toValue = (value, callback)=>{
    if (isNumberLike(value)) return __WEBPACK_EXTERNAL_MODULE_mathjs__.round(callback(value), 9);
    return null;
};
const Percent = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.connect)((props)=>{
    const { value, onChange } = props;
    const v = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>toValue(value, (v)=>100 * v), [
        value
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.InputNumber, {
        ...props,
        addonAfter: "%",
        value: v,
        onChange: (v)=>{
            if (onChange) onChange(toValue(v, (v)=>v / 100));
        }
    });
}, (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.mapReadPretty)((props)=>{
    const value = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>toValue(props.value, (v)=>100 * v), [
        props.value
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__input_number_ReadPretty_mjs__.ReadPretty, {
        ...props,
        value: value
    });
}));
export { Percent };
