import{a as e,n as t,r as n}from"./useStore-CusP06SD.js";import{a as r}from"./dist-DhH_lYkz.js";import{t as i}from"./input-CsfmMUT5.js";import{a,i as o,n as s,r as c,t as l}from"./select-CZn10WME.js";import{i as u}from"./index-DinSQfHc.js";import{r as d}from"./form-context-B-ekdUc0.js";import{n as f,t as p}from"./required-indicator-BXf2UzTH.js";import{t as m}from"./FieldInfo-FLjtPgL4.js";var h=e(n(),1),g=t(),_=[{label:`Millisecond`,labelPlural:`Milliseconds`,value:`milliseconds`,ms:1},{label:`Second`,labelPlural:`Seconds`,value:`seconds`,ms:1e3},{label:`Minute`,labelPlural:`Minutes`,value:`minutes`,ms:60*1e3},{label:`Hour`,labelPlural:`Hours`,value:`hours`,ms:3600*1e3},{label:`Day`,labelPlural:`Days`,value:`days`,ms:1440*60*1e3}];function v({id:e,className:t,value:n,onChange:u,onBlur:d,units:f=_,disabled:p=!1}){let m=(0,h.useMemo)(()=>f,[f]),v=(0,h.useMemo)(()=>C(n),[n]),[S,T]=(0,h.useState)(()=>v==null?m[2]?.value??m[0].value:y(v,m).value),[E,D]=(0,h.useState)(``),[O,k]=(0,h.useState)(!1),A=m.find(e=>e.value===S)??m[0],j=w(A,b(E));(0,h.useEffect)(()=>{if(!O&&v!=null){let e=y(v,m);e.value!==S&&T(e.value)}},[O,v,S,m]),(0,h.useEffect)(()=>{if(v==null){D(``);return}D(x(v,(m.find(e=>e.value===S)??m[0]).ms))},[v,S,m]);let M=e=>{k(!0),D(e);let t=b(e);if(t==null){u(null);return}u(t*A.ms)};return(0,g.jsxs)(`div`,{className:r(`flex items-center gap-3`,t),children:[(0,g.jsx)(i,{id:e,name:e,type:`number`,min:0,step:`any`,className:`flex-1 shadow-none`,value:E,onBlur:d,inputMode:`decimal`,disabled:p,onChange:e=>M(e.target.value)}),(0,g.jsxs)(l,{value:A.value,onValueChange:e=>{k(!0),T(e)},disabled:p,children:[(0,g.jsx)(o,{className:`w-32 shadow-none`,children:(0,g.jsx)(a,{"aria-label":j,children:j})}),(0,g.jsx)(s,{children:m.map(e=>(0,g.jsx)(c,{value:e.value,children:e.labelPlural??`${e.label}s`},e.value))})]})]})}function y(e,t){if(!Number.isFinite(e)||e<=0)return t[0];for(let n=t.length-1;n>=0;--n){let r=t[n];if(e>=r.ms)return r}return t[0]}function b(e){if(!e||e.trim()===``)return null;let t=Number(e);return!Number.isFinite(t)||t<0?null:t}function x(e,t){if(t===0)return``;let n=e/t;return Number.isInteger(n)?n.toString():S(n.toFixed(6))}function S(e){return e.includes(`.`)?e.replace(/\.?0+$/,``):e}function C(e){if(e==null)return null;if(typeof e==`number`)return Number.isFinite(e)?e:null;let t=Number(e);return Number.isFinite(t)?t:null}function w(e,t){return t==null||t!==1?e.labelPlural??`${e.label}s`:e.label}var T=({label:e,className:t,hideLabel:n=!1})=>{let i=d(),{isFieldRequired:a}=f();return(0,g.jsxs)(`div`,{className:r(`space-y-3`,t),children:[!n&&(0,g.jsxs)(u,{htmlFor:i.name,className:`block w-full`,children:[e,a(i.name)&&(0,g.jsx)(p,{})]}),(0,g.jsx)(v,{id:i.name,value:i.state.value??null,onBlur:i.handleBlur,onChange:e=>i.handleChange(e)}),(0,g.jsx)(m,{fieldMeta:i.state.meta})]})};export{T as default};