import{c as I,a as S}from"./utils-Q0fnGDhj.js";import{r as p,j as s}from"./client-BbMi5ewG.js";import{B as M}from"./Button-1dacbE2T.js";import{S as $}from"./scroll-area-BldTLQYj.js";import{P as q,a as A,b as E}from"./popover-C75zZF26.js";import{C as O}from"./CalenderCheck-BuHSX8YD.js";/**
 * @license lucide-react v0.525.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const T=[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",key:"1cjeqo"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",key:"19qd67"}]],J=I("link",T),m=o=>{if(!o||typeof o!="string")return null;const[r,n]=o.split(":").map(Number);return isNaN(r)||isNaN(n)||r<0||r>23||n<0||n>59?null:r*60+n},b=(o,r,n,a)=>{const d=m(`${o}:${r}`);if(d===null)return!0;const i=m(n||""),l=m(a||"");return i!==null&&d<i||l!==null&&d>l},P=(o,r=1)=>{const n=[];for(let a=0;a<o;a+=r)n.push(String(a).padStart(2,"0"));return n},H=P(24),L=P(60,5);function B(o,r){const n=m(o);if(n===null)return null;const a=Math.floor(n/60),d=n%60,i=String(d).padStart(2,"0");if(r)return`${String(a).padStart(2,"0")}:${i}`;const l=a>=12?"PM":"AM";return`${a%12===0?12:a%12}:${i} ${l}`}function K({value:o,onChange:r,className:n,placeholder:a="Pick a time",format24:d=!0,minTime:i,maxTime:l,disabled:N=!1}){const[f,h]=p.useState(!1),j=p.useRef(null),v=p.useRef(null),u=p.useMemo(()=>{const t=m(o);return t===null?{hour:null,minute:null}:{hour:String(Math.floor(t/60)).padStart(2,"0"),minute:String(t%60).padStart(2,"0")}},[o]),y=B(o,d),x=t=>String(Math.floor(parseInt(t,10)/5)*5).padStart(2,"0");p.useEffect(()=>{if(!f)return;const t=setTimeout(()=>{var k,w;const e=(k=j.current)==null?void 0:k.querySelector('[data-active="true"]'),c=(w=v.current)==null?void 0:w.querySelector('[data-active="true"]');e==null||e.scrollIntoView({block:"center"}),c==null||c.scrollIntoView({block:"center"})},0);return()=>clearTimeout(t)},[f]);const g=(t,e)=>{b(t,e,i,l)||r==null||r(`${t}:${e}`)},C=t=>{const e=u.minute??"00";g(t,x(e))},R=t=>{const e=u.hour??"09";g(e,t),h(!1)},D=()=>{const t=new Date,e=String(t.getHours()).padStart(2,"0"),c=x(String(t.getMinutes()).padStart(2,"0"));g(e,c),h(!1)};return s.jsxs(q,{open:f,onOpenChange:h,children:[s.jsx(A,{asChild:!0,children:s.jsxs(M,{type:"button",variant:"outline",disabled:N,className:S("h-9 px-3 gap-2 justify-start text-left font-normal w-[110px]",!y&&"text-muted-foreground",n),children:[s.jsx(O,{className:"h-4 w-4 shrink-0"}),s.jsx("span",{className:"truncate",children:y||a})]})}),s.jsxs(E,{className:"w-auto p-2",align:"start",children:[s.jsxs("div",{className:"flex gap-1",children:[s.jsx($,{className:"h-56 w-16 rounded-md border",children:s.jsx("div",{ref:j,className:"flex flex-col p-1 gap-0.5",children:H.map(t=>{const e=u.hour===t,c=b(t,u.minute??"00",i,l);return s.jsx("button",{type:"button","data-active":e,onClick:()=>C(t),disabled:c,className:S("h-8 w-full rounded-sm text-sm font-medium transition-colors",e?"bg-primary text-primary-foreground":"hover:bg-accent hover:text-accent-foreground",c&&"opacity-40 pointer-events-none"),children:t},t)})})}),s.jsx($,{className:"h-56 w-16 rounded-md border",children:s.jsx("div",{ref:v,className:"flex flex-col p-1 gap-0.5",children:L.map(t=>{const e=u.minute===t||u.minute&&x(u.minute)===t,c=b(u.hour??"09",t,i,l);return s.jsx("button",{type:"button","data-active":e,onClick:()=>R(t),disabled:c,className:S("h-8 w-full rounded-sm text-sm font-medium transition-colors",e?"bg-primary text-primary-foreground":"hover:bg-accent hover:text-accent-foreground",c&&"opacity-40 pointer-events-none"),children:t},t)})})})]}),s.jsx(M,{type:"button",variant:"ghost",size:"sm",onClick:D,className:"w-full mt-2 h-8 text-xs",children:"Now"})]})]})}export{J as L,K as T};
//# sourceMappingURL=time-picker-MqsQbh0l.js.map
