'use client';'use strict';

var chunkYF5YSZHI_cjs = require('./chunk-YF5YSZHI.cjs');
var chunk5XB54L7P_cjs = require('./chunk-5XB54L7P.cjs');
var react = require('react');
var icons = require('@onbeam/icons');
var reactPopover = require('@radix-ui/react-popover');
var css = require('@onbeam/styled-system/css');
var reactDeviceDetect = require('react-device-detect');
var recipes = require('@onbeam/styled-system/recipes');
var utils = require('@onbeam/utils');
var jsxRuntime = require('react/jsx-runtime');

var g=chunk5XB54L7P_cjs.a(({className:y,...k},D)=>{let r=react.useRef(null),s=react.useRef(null),a=react.useRef(null),[o,I]=react.useState(void 0);react.useImperativeHandle(D,()=>r.current);let i=recipes.timePicker();react.useEffect(()=>{let t=r.current?.value;if(!t)return;let[e,l]=t.split(":").map(Number);if(!utils.isNumber(e)||!utils.isNumber(l))return;let f=new Date;f.setHours(e,l),I(f);},[r.current?.value]);let u=o?.getHours(),c=o?.getMinutes(),H=()=>{let t=!!u&&!!s.current&&s.current.children?.[u];t&&s.current.scrollTo({top:t.offsetTop-s.current.offsetTop,behavior:"instant"});let e=!!c&&!!a.current&&a.current.children?.[c];e&&a.current.scrollTo({top:e.offsetTop-a.current.offsetTop,behavior:"instant"});},C=t=>{let e=o?new Date(o):new Date;e.setHours(t),p(e);},M=t=>{let e=o?new Date(o):new Date;e.setMinutes(t),p(e);},p=t=>{if(!r.current)return;let e=t.toLocaleTimeString("en-GB",{hour:"2-digit",minute:"2-digit",hour12:!1});Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,"value")?.set?.call(r.current,e),r.current?.dispatchEvent(new Event("input",{bubbles:!0}));};return jsxRuntime.jsxs(reactPopover.Popover,{onOpenChange:t=>{t&&setTimeout(H);},children:[jsxRuntime.jsx(reactPopover.PopoverAnchor,{children:jsxRuntime.jsx(reactPopover.PopoverTrigger,{asChild:!0,children:jsxRuntime.jsx(chunkYF5YSZHI_cjs.a,{ref:r,type:"time",size:"sm",className:css.cx(i.input,y),leftAddon:jsxRuntime.jsx(icons.ClockIcon,{height:16,width:16}),...k})})}),jsxRuntime.jsx(reactPopover.PopoverPortal,{children:jsxRuntime.jsxs(reactPopover.PopoverContent,{side:"bottom",align:"end",sideOffset:4,className:css.cx(recipes.customScrollbar(),i.content),"data-desktop":reactDeviceDetect.isDesktop,onOpenAutoFocus:t=>t.preventDefault(),children:[jsxRuntime.jsx("div",{className:i.rowWrapper,children:jsxRuntime.jsx("div",{className:i.row,ref:s,children:new Array(24).fill(null).map((t,e)=>jsxRuntime.jsx("button",{type:"button",className:recipes.timePickerItem(),"data-active":e===u,onClick:()=>C(e),children:utils.padString(e,2,"0")},e))})}),jsxRuntime.jsx("div",{className:i.rowWrapper,children:jsxRuntime.jsx("div",{className:i.row,ref:a,children:new Array(60).fill(null).map((t,e)=>jsxRuntime.jsx("button",{type:"button",className:recipes.timePickerItem(),"data-active":e===c,onClick:()=>M(e),children:utils.padString(e,2,"0")},e))})})]})})]})});g.displayName="TimePicker";

exports.a = g;
//# sourceMappingURL=out.js.map
//# sourceMappingURL=chunk-3AHCV23O.cjs.map