text: !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).mdtimepicker=t()}(this,function(){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function e(e,t,i){return t&&n(e.prototype,t),i&&n(e,i),e}var i,r,o,c="_mdtimepicker",u=[9,112,113,114,115,116,117,118,119,120,121,122,123],l={timeFormat:"hh:mm:ss.000",format:"h:mm tt",theme:"blue",hourPadding:!1,clearBtn:!1,is24hour:!1,events:{ready:null,timeChanged:null,shown:null,hidden:null}},f={appendTo:function(e,t,i){Array.isArray(e)?e.forEach(function(e){0===i?t.insertBefore(e,t.childNodes[i]||null):t.appendChild(e)}):0===i?t.insertBefore(e,t.childNodes[i]||null):t.appendChild(e)},addEvent:function(e,t,i){function n(e,t,i){e.addEventListener(t,i,!1)}Array.isArray(e)?e.forEach(function(e){n(e,t,i)}):n(e,t,i)},removeEvent:function(e,t,i){function n(e,t,i){e.removeEventListener(t,i,!1)}Array.isArray(e)?e.forEach(function(e){n(e,t,i)}):n(e,t,i)},empty:function(e){for(;e.firstChild;)e.removeChild(e.firstChild)},createElem:function(e,t,i,n){e=document.createElement(e);return void 0!==i&&(e[n?"innerHTML":"innerText"]=i),void 0!==t&&f.setAttributes(e,t),e},setAttributes:function(e,t){for(var i in t)e.setAttribute(i,t[i])},extend:function(){var i={},n=!1,e=0,t=arguments.length;"[object Boolean]"===Object.prototype.toString.call(arguments[0])&&(n=arguments[0],e++);for(;e<t;e++)!function(e){for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(n&&"[object Object]"===Object.prototype.toString.call(e[t])?i[t]=f.extend(!0,i[t],e[t]):i[t]=e[t])}(arguments[e]);return i},triggerChange:function(e,t){e.dispatchEvent(new Event("change")),e.dispatchEvent(new Event("onchange")),e.dispatchEvent(new function(e){var t=document.createEvent("CustomEvent");return t.initCustomEvent("timechanged",!1,!1),t.data=e,t}(t))}},d=function(){function i(e,t){a(this,i),this.hour=e,this.minute=t}return e(i,[{key:"setHour",value:function(e){this.hour=e}},{key:"getHour",value:function(e){return e?0<=[0,12].indexOf(this.hour)?12:this.hour%12:this.hour}},{key:"invert",value:function(){"AM"===this.getPeriod()?this.setHour(this.getHour()+12):this.setHour(this.getHour()-12)}},{key:"setMinutes",value:function(e){this.minute=e}},{key:"getMinutes",value:function(){return this.minute}},{key:"getPeriod",value:function(){return this.hour<12?"AM":"PM"}},{key:"format",value:function(e,i){var n=this,r=1<(e.match(/h/g)||[]).length;return e.replace(/(hh|h|mm|ss|tt|t)/g,function(e){switch(e.toLowerCase()){case"h":var t=n.getHour(!0);return i&&t<10?"0"+t:t;case"hh":return n.hour<10?"0"+n.hour:n.hour;case"mm":return n.minute<10?"0"+n.minute:n.minute;case"ss":return"00";case"t":return r?"":n.getPeriod().toLowerCase();case"tt":return r?"":n.getPeriod()}})}}]),i}(),m=function(){function s(e,t){a(this,s);var i=this;this.visible=!1,this.activeView="hours",this.hTimeout=null,this.mTimeout=null,this.input=e,this.input.readOnly=!0,this.config=t,this.time=new d(0,0),this.selected=new d(0,0),this.timepicker={overlay:f.createElem("div",{class:"mdtimepicker hidden"}),wrapper:f.createElem("div",{class:"mdtp__wrapper",tabindex:0}),timeHolder:{wrapper:f.createElem("section",{class:"mdtp__time_holder"}),hour:f.createElem("span",{class:"mdtp__time_h"},"12"),dots:f.createElem("span",{class:"mdtp__timedots"},":"),minute:f.createElem("span",{class:"mdtp__time_m"},"00"),am_pm:f.createElem("span",{class:"mdtp__ampm"},"AM")},clockHolder:{wrapper:f.createElem("section",{class:"mdtp__clock_holder"}),am:f.createElem("span",{class:"mdtp__am"},"AM"),pm:f.createElem("span",{class:"mdtp__pm"},"PM"),clock:{wrapper:f.createElem("div",{class:"mdtp__clock"}),dot:f.createElem("span",{class:"mdtp__clock_dot"}),hours:f.createElem("div",{class:"mdtp__hour_holder"}),minutes:f.createElem("div",{class:"mdtp__minute_holder"})},buttonsHolder:{wrapper:f.createElem("div",{class:"mdtp__buttons"}),btnClear:f.createElem("span",{class:"mdtp__button clear-btn"},"Clear"),btnOk:f.createElem("span",{class:"mdtp__button ok"},"Ok"),btnCancel:f.createElem("span",{class:"mdtp__button cancel"},"Cancel")}}},this.setMinTime(this.input.dataset.mintime||this.config.minTime),this.setMaxTime(this.input.dataset.maxtime||this.config.maxTime);var n,e=i.timepicker;function r(){i.show()}function o(e){return 13===e.keyCode&&i.show(),!(u.indexOf(e.which)<0)}f.appendTo(i._setup(),document.body),f.addEvent(e.overlay,"click",function(){i.hide()}),f.addEvent(e.wrapper,"click",function(e){return e.stopPropagation()}),f.addEvent(e.wrapper,"keydown",function(e){27===e.keyCode&&i.hide()}),t.is24hour||f.addEvent(e.timeHolder.am_pm,"click",function(){i.setPeriod("AM"==i.selected.getPeriod()?"pm":"am")}),f.addEvent(e.clockHolder.am,"click",function(){"AM"!==i.selected.getPeriod()&&i.setPeriod("am")}),f.addEvent(e.clockHolder.pm,"click",function(){"PM"!==i.selected.getPeriod()&&i.setPeriod("pm")}),f.addEvent(e.timeHolder.hour,"click",function(){"hours"!==i.activeView&&i._switchView("hours")}),f.addEvent(e.timeHolder.minute,"click",function(){"minutes"!==i.activeView&&i._switchView("minutes")}),f.addEvent(e.clockHolder.buttonsHolder.btnOk,"click",function(){var e=i.selected;i.isDisabled(e.getHour(),e.getMinutes(),!1)||(i.setValue(e),e=i.getFormattedTime(),i._triggerChange({time:e.time,value:e.value}),i.hide())}),f.addEvent(e.clockHolder.buttonsHolder.btnCancel,"click",function(){i.hide()}),i.config.clearBtn&&f.addEvent(e.clockHolder.buttonsHolder.btnClear,"click",function(){i.input.value="",f.setAttributes(i.input,{value:"","data-time":null}),i._triggerChange({time:null,value:""}),i.hide()}),this._unbindInput=function(){i.input.readOnly=!1,i.input.removeEventListener("click",r),i.input.removeEventListener("keydown",o)},f.addEvent(i.input,"keydown",o),f.addEvent(i.input,"click",r),""!==i.input.value?(n=i.parseTime(i.input.value,i.config.format),i.setValue(n)):(n=i.getSystemTime(),i.time=new d(n.hour,n.minute)),i.resetSelected(),i._switchView(i.activeView),i.config.events&&i.config.events.ready&&i.config.events.ready.call(i,i)}return e(s,[{key:"_setup",value:function(){var i=this,e=i.timepicker,t=e.overlay,n=e.wrapper,r=e.timeHolder,o=e.clockHolder;f.appendTo([r.hour,r.dots,r.minute],r.wrapper),f.appendTo(r.wrapper,n),i.config.is24hour||f.appendTo(r.am_pm,r.wrapper);for(var s=i.config.is24hour?24:12,a=0;a<s;a++){var c=a+1,u=(120+30*a)%360-(i.config.is24hour&&c<13?15:0),l=24===c,u=f.createElem("div",{class:"mdtp__digit rotate-".concat(u),"data-hour":l?0:c}),l=f.createElem("span",null,l?"00":c);f.appendTo(l,u),i.config.is24hour&&c<13&&u.classList.add("inner--digit"),f.addEvent(l,"click",function(){var e=parseInt(this.parentNode.dataset.hour),t=i.selected.getPeriod(),e=i.config.is24hour?e:(e+("PM"===t&&e<12||"AM"===t&&12===e?12:0))%24;i.isDisabled(e,0,!0)||(i.setHour(e),i._switchView("minutes"))}),f.appendTo(u,o.clock.hours)}for(var d=0;d<60;d++){var m=d<10?"0"+d:d,h=f.createElem("div",{class:"mdtp__digit rotate-".concat((90+6*d)%360),"data-minute":d}),p=f.createElem("span");f.appendTo(p,h),d%5==0&&(h.classList.add("marker"),p.innerText=m),f.addEvent(p,"click",function(){var e=parseInt(this.parentNode.dataset.minute),t=i.selected.getHour();i.isDisabled(t,e,!0)||i.setMinute(e)}),f.appendTo(h,o.clock.minutes)}return i.config.is24hour||f.appendTo([o.am,o.pm],o.clock.wrapper),f.appendTo([o.clock.dot,o.clock.hours,o.clock.minutes],o.clock.wrapper),f.appendTo(o.clock.wrapper,o.wrapper),i.config.clearBtn&&f.appendTo(o.buttonsHolder.btnClear,o.buttonsHolder.wrapper),f.appendTo([o.buttonsHolder.btnCancel,o.buttonsHolder.btnOk],o.buttonsHolder.wrapper),f.appendTo(o.buttonsHolder.wrapper,o.wrapper),f.appendTo(o.wrapper,n),n.dataset.theme=i.input.dataset.theme||i.config.theme,f.appendTo(n,t),t}},{key:"setHour",value:function(e){if(void 0===e)throw new Error("Expecting a value.");var t=!this.config.is24hour;this.selected.setHour(e);var i=this.selected.getHour(t);this.timepicker.timeHolder.hour.innerText=t?i:this.selected.format("hh"),this.timepicker.clockHolder.clock.hours.querySelectorAll("div").forEach(function(e){var t=parseInt(e.dataset.hour);e.classList[t===i?"add":"remove"]("active")})}},{key:"setMinute",value:function(i){if(void 0===i)throw new Error("Expecting a value.");this.selected.setMinutes(i),this.timepicker.timeHolder.minute.innerText=i<10?"0"+i:i,this.timepicker.clockHolder.clock.minutes.querySelectorAll("div").forEach(function(e){var t=parseInt(e.dataset.minute);e.classList[t===i?"add":"remove"]("active")})}},{key:"setPeriod",value:function(e){if(void 0===e)throw new Error("Expecting a value.");this.selected.getPeriod()!==e.toUpperCase()&&this.selected.invert();e=this.selected.getPeriod();this._setDisabled(this.activeView),this.timepicker.timeHolder.am_pm.innerText=e,this.timepicker.clockHolder.am.classList["AM"===e?"add":"remove"]("active"),this.timepicker.clockHolder.pm.classList["PM"===e?"add":"remove"]("active")}},{key:"setValue",value:function(e){if(void 0===e)throw new Error("Expecting a value.");e="string"==typeof e?this.parseTime(e,this.config.format):e;this.time=new d(e.hour,e.minute);e=this.getFormattedTime();this.input.value=e.value,f.setAttributes(this.input,{value:e.value,"data-time":e.time})}},{key:"setMinTime",value:function(e){this.minTime=e}},{key:"setMaxTime",value:function(e){this.maxTime=e}},{key:"_setDisabled",value:function(e){var n,t;"hours"!==e&&"minutes"!==e||(t=(n=this).timepicker.clockHolder.clock,"hours"===e&&t.hours.querySelectorAll(".mdtp__digit").forEach(function(e){var t=parseInt(e.dataset.hour),i=n.selected.getPeriod(),t=new d(t,0);n.config.is24hour||i===t.getPeriod()||t.invert();t=n.isDisabled(t.getHour(),0,!0);e.classList[t?"add":"remove"]("digit--disabled")}),"minutes"===e&&t.minutes.querySelectorAll(".mdtp__digit").forEach(function(e){var t=parseInt(e.dataset.minute),i=n.selected.getHour(),t=n.isDisabled(i,t,!0);e.classList[t?"add":"remove"]("digit--disabled")}))}},{key:"isDisabled",value:function(e,t,i){var n=this,r=null,o=null,s=null,a=null,c=new Date,e=new Date(c.getFullYear(),c.getMonth(),c.getDate(),e,t,0,0),t="hours"===n.activeView;return n.minTime&&(r="now"===n.minTime?n.getSystemTime():n.parseTime(n.minTime)),n.maxTime&&(s="now"===n.maxTime?n.getSystemTime():n.parseTime(n.maxTime)),r&&(o=new Date(c.getFullYear(),c.getMonth(),c.getDate(),r.getHour(),t&&i?0:r.getMinutes(),0,0)),s&&(a=new Date(c.getFullYear(),c.getMonth(),c.getDate(),s.getHour(),t&&i?0:s.getMinutes(),0,0)),o&&e<o||a&&a<e}},{key:"resetSelected",value:function(){this.setHour(this.time.hour),this.setMinute(this.time.minute),this.setPeriod(this.time.getPeriod())}},{key:"getFormattedTime",value:function(){return{time:this.time.format(this.config.timeFormat,!1),value:this.time.format(this.config.format,this.config.hourPadding)}}},{key:"getSystemTime",value:function(){return e=new Date,new d(e.getHours(),e.getMinutes());var e}},{key:"parseTime",value:function(e,t){var i=void 0===t?this.config.format:t,n=1<(i.match(/h/g)||[]).length,r=(i.match(/t/g)||[]).length,o=e.length,s=i.indexOf("h"),a=i.lastIndexOf("h"),c="",t="";c=this.config.hourPadding||n?e.substr(s,2):(u=i.substring(s-1,s),l=i.substring(a+1,a+2),a===i.length-1?e.substring(e.indexOf(u,s-1)+1,o):0===s?e.substring(0,e.indexOf(l,s)):e.substring(e.indexOf(u,s-1)+1,e.indexOf(l,s+1)));var a=(i=i.replace(/(hh|h)/g,c)).indexOf("m"),u=i.lastIndexOf("m"),l=i.indexOf("t"),s=i.substring(a-1,a);i.substring(u+1,u+2);t=u===i.length-1?e.substring(e.indexOf(s,a-1)+1,o):0===a?e.substring(0,2):e.substr(a,2),l="pm"===(n?11<parseInt(c)?1<r?"PM":"pm":1<r?"AM":"am":e.substr(l,2)).toLowerCase(),t=new d(parseInt(c),parseInt(t));return(l&&parseInt(c)<12||!l&&12===parseInt(c))&&t.invert(),t}},{key:"_switchView",value:function(e){var t=this,i=this.timepicker;"hours"!==e&&"minutes"!==e||(t.activeView=e,t._setDisabled(e),i.timeHolder.hour.classList["hours"===e?"add":"remove"]("active"),i.timeHolder.minute.classList["hours"===e?"remove":"add"]("active"),i.clockHolder.clock.hours.classList.add("animate"),"hours"===e&&i.clockHolder.clock.hours.classList.remove("hidden"),clearTimeout(t.hTimeout),t.hTimeout=setTimeout(function(){"hours"!==e&&i.clockHolder.clock.hours.classList.add("hidden"),i.clockHolder.clock.hours.classList.remove("animate")},"hours"===e?20:350),i.clockHolder.clock.minutes.classList.add("animate"),"minutes"===e&&i.clockHolder.clock.minutes.classList.remove("hidden"),clearTimeout(t.mTimeout),t.mTimeout=setTimeout(function(){"minutes"!==e&&i.clockHolder.clock.minutes.classList.add("hidden"),i.clockHolder.clock.minutes.classList.remove("animate")},"minutes"===e?20:350))}},{key:"show",value:function(){var e,t=this;""===t.input.value&&(e=t.getSystemTime(),this.time=new d(e.hour,e.minute)),t.resetSelected(),document.body.setAttribute("mdtimepicker-display","on"),t.timepicker.wrapper.classList.add("animate"),t.timepicker.overlay.classList.remove("hidden"),t.timepicker.overlay.classList.add("animate"),setTimeout(function(){t.timepicker.overlay.classList.remove("animate"),t.timepicker.wrapper.classList.remove("animate"),t.timepicker.wrapper.focus(),t.visible=!0,t.input.blur(),t.config.events&&t.config.events.shown&&t.config.events.shown.call(t)},10)}},{key:"hide",value:function(){var e=this;e.timepicker.overlay.classList.add("animate"),e.timepicker.wrapper.classList.add("animate"),setTimeout(function(){e._switchView("hours"),e.timepicker.overlay.classList.add("hidden"),e.timepicker.overlay.classList.remove("animate"),e.timepicker.wrapper.classList.remove("animate"),document.body.removeAttribute("mdtimepicker-display"),e.visible=!1,e.input.focus(),e.config.events&&e.config.events.hidden&&e.config.events.hidden.call(e)},300)}},{key:"destroy",value:function(){this._unbindInput(),this.timepicker.overlay.remove(),delete this.input[c]}},{key:"_triggerChange",value:function(e){f.triggerChange(this.input,e),this.config.events&&this.config.events.timeChanged&&this.config.events.timeChanged.call(this,e,this)}}]),s}();function s(){var i=arguments,n=i[0],r=n instanceof NodeList||Array.isArray(n),o=n instanceof Element,e="string"==typeof n?document.querySelectorAll(n):r?n:o?[n]:document.querySelectorAll(".mdtimepicker-input"),s="object"!==t(n)||r||o?i[1]&&"object"===t(i[1])?i[1]:{}:n,a=f.extend({},m.default_configs||l);s&&s.is24hour&&(a.format="hh:mm"),Array.from(e).forEach(function(e){var t=e[c];t||(e[c]=t=new m(e,f.extend(a,s))),("string"==typeof n||r||o)&&i[1]&&"string"==typeof i[1]&&t[i[1]].apply(t,Array.prototype.slice.call(i).slice(2))})}return o=null,(r="default_configs")in(i=m)?Object.defineProperty(i,r,{value:o,enumerable:!0,configurable:!0,writable:!0}):i[r]=o,s.defaults=function(e){m.default_configs=f.extend(l,e)},s});