import{r as f,j as c}from"./wp-i18n-shim-DUX0OV_V.js";import{a as v}from"./utils-Bl0WAcve.js";import{B as A}from"./Button-BveKhP38.js";import{S as R}from"./scroll-area-JhQW4-1L.js";import{P as B,a as V,b as _}from"./popover-D8UtFi-E.js";import{g as z}from"./dateTimeFormat-yH4yHSCh.js";import{C as F}from"./CalenderCheck-2TB2QVYq.js";const h=i=>{if(!i||typeof i!="string")return null;const[s,r]=i.split(":").map(Number);return isNaN(s)||isNaN(r)||s<0||s>23||r<0||r>59?null:s*60+r},y=(i,s,r,a)=>{const d=h(`${i}:${s}`);if(d===null)return!0;const l=h(r||""),u=h(a||"");return l!==null&&d<l||u!==null&&d>u},M=(i,s=1)=>{const r=[];for(let a=0;a<i;a+=s)r.push(String(a).padStart(2,"0"));return r},G=M(24),J=["12",...M(12).slice(1)],K=M(60,5),L=["AM","PM"],m=(i,s)=>{const r=parseInt(i,10);return s==="AM"?String(r===12?0:r).padStart(2,"0"):String(r===12?12:r+12).padStart(2,"0")};function Q(i,s){const r=h(i);if(r===null)return null;const a=Math.floor(r/60),d=r%60,l=String(d).padStart(2,"0");if(s)return`${String(a).padStart(2,"0")}:${l}`;const u=a>=12?"PM":"AM";return`${a%12===0?12:a%12}:${l} ${u}`}function nt({value:i,onChange:s,className:r,placeholder:a="Pick a time",format24:d,minTime:l,maxTime:u,disabled:w=!1}){const[N,j]=f.useState(!1),k=f.useRef(null),P=f.useRef(null),p=typeof d=="boolean"?d:z()==="24h",o=f.useMemo(()=>{const t=h(i);if(t===null)return{hour24:null,hour12:null,minute:null,period:"AM"};const e=Math.floor(t/60),n=t%60,b=e>=12?"PM":"AM",S=e%12===0?12:e%12;return{hour24:String(e).padStart(2,"0"),hour12:String(S).padStart(2,"0"),minute:String(n).padStart(2,"0"),period:b}},[i]),$=p?G:J,C=p?o.hour24:o.hour12,D=Q(i,p),x=t=>String(Math.floor(parseInt(t,10)/5)*5).padStart(2,"0");f.useEffect(()=>{if(!N)return;const t=setTimeout(()=>{var b,S;const e=(b=k.current)==null?void 0:b.querySelector('[data-active="true"]'),n=(S=P.current)==null?void 0:S.querySelector('[data-active="true"]');e==null||e.scrollIntoView({block:"center"}),n==null||n.scrollIntoView({block:"center"})},0);return()=>clearTimeout(t)},[N]);const g=(t,e)=>{y(t,e,l,u)||s==null||s(`${t}:${e}`)},H=t=>{const e=x(o.minute??"00"),n=p?t:m(t,o.period);g(n,e)},O=t=>{const e=o.hour24??(p?"09":m("09",o.period));g(e,t),j(!1)},I=t=>{const e=x(o.minute??"00"),n=o.hour12??"09";g(m(n,t),e)},E=()=>{const t=new Date,e=String(t.getHours()).padStart(2,"0"),n=x(String(t.getMinutes()).padStart(2,"0"));g(e,n),j(!1)},U=t=>{const e=p?t:m(t,o.period);return y(e,o.minute??"00",l,u)},T=t=>{const e=o.hour24??(p?"09":m("09",o.period));return y(e,t,l,u)},q=t=>{const e=o.hour12??"09";return y(m(e,t),o.minute??"00",l,u)};return c.jsxs(B,{open:N,onOpenChange:j,children:[c.jsx(V,{asChild:!0,children:c.jsxs(A,{type:"button",variant:"outline",disabled:w,className:v("h-9 px-3 gap-2 justify-start text-left font-normal w-[110px]",!D&&"text-muted-foreground",r),children:[c.jsx(F,{className:"h-4 w-4 shrink-0"}),c.jsx("span",{className:"truncate",children:D||a})]})}),c.jsxs(_,{className:"w-auto p-2",align:"start",children:[c.jsxs("div",{className:"flex gap-1",children:[c.jsx(R,{className:"h-56 w-16 rounded-md border",children:c.jsx("div",{ref:k,className:"flex flex-col p-1 gap-0.5",children:$.map(t=>{const e=C===t,n=U(t);return c.jsx("button",{type:"button","data-active":e,onClick:()=>H(t),disabled:n,className:v("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",n&&"opacity-40 pointer-events-none"),children:t},t)})})}),c.jsx(R,{className:"h-56 w-16 rounded-md border",children:c.jsx("div",{ref:P,className:"flex flex-col p-1 gap-0.5",children:K.map(t=>{const e=o.minute===t||o.minute&&x(o.minute)===t,n=T(t);return c.jsx("button",{type:"button","data-active":e,onClick:()=>O(t),disabled:n,className:v("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",n&&"opacity-40 pointer-events-none"),children:t},t)})})}),!p&&c.jsx("div",{className:"flex flex-col gap-0.5 p-1 rounded-md border",children:L.map(t=>{const e=o.period===t,n=q(t);return c.jsx("button",{type:"button","data-active":e,onClick:()=>I(t),disabled:n,className:v("h-8 w-12 rounded-sm text-sm font-medium transition-colors",e?"bg-primary text-primary-foreground":"hover:bg-accent hover:text-accent-foreground",n&&"opacity-40 pointer-events-none"),children:t},t)})})]}),c.jsx(A,{type:"button",variant:"ghost",size:"sm",onClick:E,className:"w-full mt-2 h-8 text-xs",children:"Now"})]})]})}export{nt as T};
//# sourceMappingURL=time-picker-BSbsRgdR.js.map
