"use client";var Q=Object.create;var H=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var ee=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports);var ne=(e,n,o,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of Y(n))!_.call(e,t)&&t!==o&&H(e,t,{get:()=>n[t],enumerable:!(a=X(n,t))||a.enumerable});return e};var te=(e,n,o)=>(o=e!=null?Q(Z(e)):{},ne(n||!e||!e.__esModule?H(o,"default",{value:e,enumerable:!0}):o,e));var D=ee((fe,v)=>{(function(){"use strict";var e={}.hasOwnProperty;function n(){for(var t="",u=0;u<arguments.length;u++){var i=arguments[u];i&&(t=a(t,o(i)))}return t}function o(t){if(typeof t=="string"||typeof t=="number")return t;if(typeof t!="object")return"";if(Array.isArray(t))return n.apply(null,t);if(t.toString!==Object.prototype.toString&&!t.toString.toString().includes("[native code]"))return t.toString();var u="";for(var i in t)e.call(t,i)&&t[i]&&(u=a(u,i));return u}function a(t,u){return u?t?t+" "+u:t+u:t}typeof v<"u"&&v.exports?(n.default=n,v.exports=n):typeof define=="function"&&typeof define.amd=="object"&&define.amd?define("classnames",[],function(){return n}):window.classNames=n})()});import P from"react";import{Controller as ae}from"react-hook-form";var b=te(D());import c,{useLayoutEffect as R,useRef as ue,useState as B}from"react";import{useEffect as re,useRef as oe}from"react";function T(e){let n=oe(null);return re(()=>{e&&(typeof e=="function"?e(n.current):e.current=n.current)},[n,e]),n}function E(e){if(e===void 0||isNaN(e))return"";if(e.toString().includes("e")){let[o,a]=e.toString().split("e"),t=o.split(".")[1]?.length||0,u=Number(a);return u<0?e.toFixed(-u+t):e.toLocaleString("fullwide",{useGrouping:!1})}return e.toString()}function S(e){if(e===void 0||isNaN(e))return"";let[n,o]=E(e).split("."),a=n.replace(/\B(?=(\d{3})+(?!\d))/g,",");return o?`${a}.${o}`:a}function h(e){if(!e)return NaN;let n=new RegExp("[^-+0-9.]","g"),o=e.replace(n,"");return parseFloat(o)}var O=c.forwardRef(function({value:n,label:o,clearable:a=!0,errorMessage:t,step:u=1,min:i=0,max:m,commas:p,prefix:g,onValueChange:d,onEnter:k,...s},U){let l=T(U),C=ue(null),[V,W]=B(M(n)),[A,F]=B(!1),y=p?S:E;R(()=>{C.current&&l.current&&(l.current.style.paddingLeft=`calc(10px + ${C.current.offsetWidth}px)`)},[g]),R(()=>{typeof n=="number"&&l.current&&(l.current.value=y(n))},[n]);function M(r){return r!==""&&r!==void 0}function L(r){return!!(/^-0?$/.test(r)||/[^.]\.{1}0*$/.test(r))}function K(r){return typeof i=="number"&&r<i?r=i:typeof m=="number"&&m<r&&(r=m),r}function $(r){if(L(r.currentTarget.value))return;let f=y(h(r.currentTarget.value));l.current&&(l.current.value=f),s.onChange?.(r),d?.(h(f)),W(M(r.target.value))}function j(r){s.onFocus?.(r),F(!0)}function G(r){if(s.onBlur?.(r),F(!1),L(r.currentTarget.value))return;let f=K(h(r.currentTarget.value));w(y(f))}function q(r){s.onKeyDown?.(r);let f=h(r.currentTarget.value);r.key==="Enter"&&k?.(f);let N=r.shiftKey?u*10:u;if(r.key==="ArrowDown"){let x=(f||0)-N,I=Math.max(i,x);w(y(I)),r.preventDefault()}if(r.key==="ArrowUp"){let x=(f||0)+N,I=m===void 0?x:Math.min(x,m);w(y(I)),r.preventDefault()}}function z(){w("")}function w(r){if(!l.current)return;Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,"value")?.set?.call(l.current,r);let N=new Event("input",{bubbles:!0});l.current.dispatchEvent(N)}let J=a&&V&&!s.disabled&&!s.readOnly;return c.createElement("div",{className:(0,b.default)("leaf-input-container","leaf-number-input",{filled:V,focused:A,error:!!t,disabled:s.disabled})},c.createElement("div",{className:"leaf-label-area"},o&&c.createElement("label",{className:"leaf-label"},o)),c.createElement("div",{className:(0,b.default)("leaf-input-area")},g&&c.createElement("span",{className:(0,b.default)("leaf-prefix","leaf-label"),ref:C},g),c.createElement("input",{...s,className:(0,b.default)("leaf-input",{clearable:a},s.className),type:"text",ref:l,onChange:$,onFocus:j,onBlur:G,onKeyDown:q,style:s.style}),J&&c.createElement("button",{type:"button",className:"leaf-clear-button",onClick:z,tabIndex:-1})),c.createElement("div",{className:"leaf-extra-area"},t&&c.createElement("p",{className:(0,b.default)("leaf-error-message","leaf-desc")},t)))});function ie(e){let{name:n,rules:o,defaultValue:a,control:t,shouldUnregister:u,...i}=e,m={name:n,rules:o,defaultValue:a,shouldUnregister:u};return t&&(m.control=t),P.createElement(ae,{...m,render:({field:p,fieldState:g})=>P.createElement(O,{...i,name:p.name,value:p.value,ref:p.ref,onValueChange:d=>{p.onChange(d),i.onValueChange?.(d)},onBlur:d=>{p.onBlur(),i.onBlur?.(d)},errorMessage:g.error?.message})})}export{ie as default,E as formatNumber,S as formatNumberWithCommas};
/*! Bundled license information:

classnames/index.js:
  (*!
  	Copyright (c) 2018 Jed Watson.
  	Licensed under the MIT License (MIT), see
  	http://jedwatson.github.io/classnames
  *)
*/
