"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),t=require("@babel/runtime/helpers/slicedToArray"),r=require("react/jsx-runtime"),n=require("react"),a=require("lodash"),u=require("classnames"),s=require("moment"),i=require("../../Tabs/Tabs.js"),o=require("./TimePicker.scss.js");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=c(e),f=c(t),d=c(u),b=c(s);function m(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function p(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?m(Object(r),!0).forEach((function(t){l.default(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):m(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var v=new Array(48).fill(0).map((function(e,t){var r=new Date(2e3,0,1,0,15*t),n=r.getHours(),u=0===n?12:n,s=a.padStart(String(u),2,"0"),i=a.padStart(String(r.getMinutes()),2,"0");return{offset:900*t,title:"".concat(s,":").concat(i)}})),h=[{value:"am",label:"AM"},{value:"pm",label:"PM"}],j=function(e){var t=e.offset,a=e.title,u=e.setOffset,s=e.disabled,i=e.selected,c=n.useCallback((function(){return u(t)}),[u,t]);return r.jsx("button",{"data-offset":t,"data-selected":String(i),className:d.default(o.button,s&&o.disabled,i&&o.selected),onClick:c,disabled:s,children:a})},y=n.forwardRef((function(e,t){var a=e.value,u=e.onChange,s=!a,c=n.useState(),l=f.default(c,2),m=l[0],y=l[1],O=n.useRef(null),g=n.useRef(!1),P=n.useState(),T=f.default(P,2),x=T[0],q=T[1],M=n.useMemo((function(){return h.map((function(e){return p(p({},e),{},{disabled:s})}))}),[s]),S=n.useMemo((function(){if(a){var e=b.default(a).startOf("day").toDate();return Math.ceil((a.getTime()-e.getTime())/1e3)}}),[a]);n.useEffect((function(){y(void 0!==S?S>=43200?"pm":"am":void 0)}),[S]);var w=n.useMemo((function(){return v.map((function(e){return p(p({},e),{},{offset:e.offset+("pm"===m?43200:0)})}))}),[m]);n.useEffect((function(){setTimeout((function(){if(void 0!==S&&O.current&&!g.current){g.current=!1;var e=O.current.querySelector('[data-selected="true"]');if(e){var t=e.offsetTop,r=e.clientHeight,n=t-(O.current.clientHeight-r)/2;O.current.scrollTo({top:Math.max(n,0)})}}}),0)}),[S]),n.useEffect((function(){var e;s&&(null===(e=O.current)||void 0===e||e.scrollTo({top:0}))}),[s]);var k=n.useCallback((function(e){g.current=!0,u(e)}),[u]);return n.useImperativeHandle(t,(function(){return{flash:function(){return q(1+Math.random())}}}),[]),r.jsxs("div",{className:d.default(o.root,x&&o.flash),children:[r.jsx("div",{className:o.header,children:r.jsx(i.Tabs,{size:"small",type:"secondary",items:M,value:m,onChange:y})}),r.jsx("div",{className:o.body,children:r.jsx("div",{className:d.default(o.buttons,s&&o.disabled),ref:O,children:w.map((function(e,t,n){var a=e.offset,u=e.title,i=t===n.length-1?a+900:n[t+1].offset,o=void 0!==S&&S>=a&&S<i;return r.jsx(j,{offset:a,title:u,disabled:s,setOffset:k,selected:o},a)}))})})]},x)}));exports.TimePicker=y;
//# sourceMappingURL=TimePicker.js.map
