!function(t,e){if("function"==typeof define&&define.amd)define(["exports","moment","Draggabilly"],e);else if("undefined"!=typeof exports)e(exports,require("moment"),require("Draggabilly"));else{var i={exports:{}};e(i.exports,t.moment,t.Draggabilly),t.mdDateTimePicker=i.exports}}(this,function(t,e,i){"use strict";function a(t){return t&&t.__esModule?t:{default:t}}function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var d=a(e),l=a(i),o=function(){function t(t,e){for(var i=0;i12&&(m-=120,u.classList.add(d)),u.classList.add(s+m),n===r&&(u.id=i,u.classList.add(a),e.classList.add(s+m)),24===r&&0===n&&(u.id=i,u.classList.add(a),e.classList.add(s+m)),u.appendChild(h),o.appendChild(u)}}else{n=parseInt(this._sDialog.tDate.format("h"),10);for(var p=1,g=10;p<=12;p++,g+=10){var v=document.createElement("div"),D=document.createElement("span");v.classList.add(l),D.textContent=p,v.classList.add(s+g),n===p&&(v.id=i,v.classList.add(a),e.classList.add(s+g)),v.appendChild(D),o.appendChild(v)}}for(;t.lastChild;)t.removeChild(t.lastChild);t.appendChild(o)}},{key:"_initMinute",value:function(){for(var t=this._sDialog.minuteView,e=parseInt(this._sDialog.tDate.format("m"),10),i="mddtp-minute__selected",a="mddtp-picker__cell--selected",s="mddtp-picker__cell--rotate-",d="mddtp-picker__cell",l=document.createDocumentFragment(),o=5,n=10;o<=60;o+=5,n+=10){var c=document.createElement("div"),r=document.createElement("span");c.classList.add(d),60===o?r.textContent=this._numWithZero(0):r.textContent=this._numWithZero(o),0===e&&(e=60),c.classList.add(s+n),(e===o||e-1===o||e+1===o||1===e&&60===o)&&(c.id=i,c.classList.add(a)),c.appendChild(r),l.appendChild(c)}for(;t.lastChild;)t.removeChild(t.lastChild);t.appendChild(l)}},{key:"_initDateDialog",value:function(t){var e=this._sDialog.subtitle,i=this._sDialog.title,a=this._sDialog.titleDay,s=this._sDialog.titleMonth;this._fillText(e,t.format("YYYY")),this._fillText(a,t.format("ddd, ")),this._fillText(s,t.format("MMM D")),this._initYear(),this._initViewHolder(),this._attachEventHandlers(),this._changeMonth(),this._switchToView(e),this._switchToView(i),this._setButtonText()}},{key:"_initViewHolder",value:function(){var t=this._sDialog.tDate,e=this._sDialog.current,i=this._sDialog.previous,a=this._sDialog.next,s=this._past,l=this._future;t.isBefore(s,"month")&&(t=s.clone()),t.isAfter(l,"month")&&(t=l.clone()),this._sDialog.tDate=t,this._initMonth(e,t),this._initMonth(a,(0,d.default)(this._getMonth(t,1))),this._initMonth(i,(0,d.default)(this._getMonth(t,-1))),this._toMoveMonth()}},{key:"_initMonth",value:function(t,e){var i=e.format("MMMM YYYY"),a=t.getElementsByTagName("div");this._fillText(a[0],i);var s=document.createDocumentFragment(),l=a[3],o=d.default.weekdays(!0).indexOf(d.default.weekdays(!1,(0,d.default)(e).date(1).day())),n=-1,c=-1,r=parseInt((0,d.default)(e).endOf("month").format("D"),10)+o-1,_=o,u="mddtp-picker__cell",h=r;(0,d.default)().isSame(e,"month")&&(n=parseInt((0,d.default)().format("D"),10),n+=o-1),this._past.isSame(e,"month")&&(_=parseInt(this._past.format("D"),10),_+=o-1),this._future.isSame(e,"month")&&(h=parseInt(this._future.format("D"),10),h+=o-1),this._sDialog.sDate.isSame(e,"month")&&(c=parseInt((0,d.default)(e).format("D"),10),c+=o-1);for(var m=0;m<42;m++){var p=document.createElement("span"),g=m-o+1;m>=o&&m<=r&&(m>h||m<_?p.classList.add(u+"--disabled"):p.classList.add(u),this._fillText(p,g)),n===m&&p.classList.add(u+"--today"),c===m&&(p.classList.add(u+"--selected"),p.id="mddtp-date__selected"),s.appendChild(p)}for(;l.lastChild;)l.removeChild(l.lastChild);l.appendChild(s),this._addCellClickEvent(l)}},{key:"_initYear",value:function(){for(var t=this._sDialog.years,e=this._sDialog.tDate.year(),i=document.createDocumentFragment(),a=this._past.year(),s=this._future.year(),d=a;d<=s;d++){var l=document.createElement("li");l.textContent=d,d===e&&(l.id="mddtp-date__currentYear",l.classList.add("mddtp-picker__li--current")),i.appendChild(l)}for(;t.lastChild;)t.removeChild(t.lastChild);t.appendChild(i),this._changeYear(t)}},{key:"_switchToView",value:function(t){var e=this;"date"==this._type?t.onclick=function(){e._switchToDateView(t,e)}:(this._inner24===!0&&e._mode&&(parseInt(e._sDialog.sDate.format("H"),10)>12?e._sDialog.needle.classList.add("mddtp-picker__cell--rotate24"):e._sDialog.needle.classList.remove("mddtp-picker__cell--rotate24")),t.onclick=function(){e._switchToTimeView(e)})}},{key:"_switchToTimeView",value:function(e){var i=e._sDialog.hourView,a=e._sDialog.minuteView,s=e._sDialog.hour,d=e._sDialog.minute,l="mddtp-picker__color--active",o="mddtp-picker__circularView--hidden",n="mddtp-picker__selection",c=e._sDialog.needle,r=e._sDialog.circularHolder,_=e._sDialog.circle,u=e._sDialog.fakeNeedle,h=60,m=void 0;i.classList.toggle(o),a.classList.toggle(o),s.classList.toggle(l),d.classList.toggle(l),c.className="",c.classList.add(n),t.dialog.view?(m=e._sDialog.sDate.format("m"),e._autoClose!==!0&&setTimeout(function(){var t=r.getBoundingClientRect(),e=_.getBoundingClientRect();u.setAttribute("style","left:"+(e.left-t.left)+"px;top:"+(e.top-t.top)+"px")},300)):e._mode?(h=24,m=parseInt(e._sDialog.sDate.format("H"),10),0===m&&(m=24)):(h=12,m=e._sDialog.sDate.format("h"));var p=e._calcRotation(h,parseInt(m,10));p&&c.classList.add(p),t.dialog.view=!t.dialog.view}},{key:"_switchToDateView",value:function(e,i){e.setAttribute("disabled","");var a=i._sDialog.viewHolder,s=i._sDialog.years,d=i._sDialog.title,l=i._sDialog.subtitle,o=document.getElementById("mddtp-date__currentYear");t.dialog.view?(a.classList.add("zoomOut"),s.classList.remove("mddtp-picker__years--invisible"),s.classList.add("zoomIn"),o.scrollIntoViewIfNeeded()):(s.classList.add("zoomOut"),a.classList.remove("zoomOut"),a.classList.add("zoomIn"),setTimeout(function(){s.classList.remove("zoomIn","zoomOut"),s.classList.add("mddtp-picker__years--invisible"),a.classList.remove("zoomIn")},300)),d.classList.toggle("mddtp-picker__color--active"),l.classList.toggle("mddtp-picker__color--active"),t.dialog.view=!t.dialog.view,setTimeout(function(){e.removeAttribute("disabled")},300)}},{key:"_addClockEvent",value:function(){var t=this,e=this._sDialog.hourView,i=this._sDialog.minuteView,a="mddtp-picker__cell--selected";e.onclick=function(e){var i="mddtp-hour__selected",s=document.getElementById(i),d=0;e.target&&"SPAN"==e.target.nodeName&&(s.id="",s.classList.remove(a),e.target.parentNode.classList.add(a),e.target.parentNode.id=i,d=t._mode?parseInt(e.target.textContent,10):"AM"===t._sDialog.sDate.format("A")?e.target.textContent:parseInt(e.target.textContent,10)+12,t._sDialog.sDate.hour(d),t._sDialog.hour.textContent=e.target.textContent,t._switchToTimeView(t))},i.onclick=function(e){var i="mddtp-minute__selected",s=document.getElementById(i),d=0;e.target&&"SPAN"==e.target.nodeName&&(s&&(s.id="",s.classList.remove(a)),e.target.parentNode.classList.add(a),e.target.parentNode.id=i,d=e.target.textContent,t._sDialog.sDate.minute(d),t._sDialog.minute.textContent=d,t._switchToTimeView(t),t._autoClose===!0&&t._sDialog.ok.onclick())}}},{key:"_addCellClickEvent",value:function(t){var e=this;t.onclick=function(t){if(t.target&&"SPAN"==t.target.nodeName&&t.target.classList.contains("mddtp-picker__cell")){var i=t.target.textContent,a=e._sDialog.tDate.date(i),s="mddtp-date__selected",d="mddtp-picker__cell--selected",l=document.getElementById(s),o=e._sDialog.subtitle,n=e._sDialog.titleDay,c=e._sDialog.titleMonth;l&&(l.classList.remove(d),l.id=""),t.target.classList.add(d),t.target.id=s,e._sDialog.sDate=a.clone(),e._fillText(o,a.year()),e._fillText(n,a.format("ddd, ")),e._fillText(c,a.format("MMM D")),e._autoClose===!0&&e._sDialog.ok.onclick()}}}},{key:"_toMoveMonth",value:function(){var t=this._sDialog.tDate,e=this._sDialog.left,i=this._sDialog.right,a=this._past,s=this._future;e.removeAttribute("disabled"),i.removeAttribute("disabled"),e.classList.remove("mddtp-button--disabled"),i.classList.remove("mddtp-button--disabled"),t.isSame(a,"month")&&(e.setAttribute("disabled",""),e.classList.add("mddtp-button--disabled")),t.isSame(s,"month")&&(i.setAttribute("disabled",""),i.classList.add("mddtp-button--disabled"))}},{key:"_changeMonth",value:function(){function t(t,s){var d=!1,o=e._sDialog.next,n=e._sDialog.current,c=e._sDialog.previous;i.setAttribute("disabled",""),a.setAttribute("disabled",""),n.classList.add(t),c.classList.add(t),o.classList.add(t);var r=s.cloneNode(!0),_=void 0;s===o?(_=c,n.parentNode.appendChild(r),o.id=n.id,n.id=c.id,c=n,n=o,o=r):(d=!0,_=o,c.id=n.id,n.id=o.id,o=n,n=c),setTimeout(function(){s===c&&(n.parentNode.insertBefore(r,n),c=r),e._sDialog.next=o,e._sDialog.current=n,e._sDialog.previous=c,n.classList.add(l),o.classList.add(l),c.classList.add(l),n.classList.remove(t),o.classList.remove(t),c.classList.remove(t),_.parentNode.removeChild(_)},300),setTimeout(function(){n.classList.remove(l),o.classList.remove(l),c.classList.remove(l),d?e._sDialog.tDate=e._getMonth(e._sDialog.tDate,-1):e._sDialog.tDate=e._getMonth(e._sDialog.tDate,1),e._initViewHolder()},350),setTimeout(function(){i.classList.contains("mddtp-button--disabled")||i.removeAttribute("disabled"),a.classList.contains("mddtp-button--disabled")||a.removeAttribute("disabled")},400)}var e=this,i=this._sDialog.left,a=this._sDialog.right,s="mddtp-picker__view--left",d="mddtp-picker__view--right",l="mddtp-picker__view--pause";i.onclick=function(){t(d,e._sDialog.previous)},a.onclick=function(){t(s,e._sDialog.next)}}},{key:"_changeYear",value:function(t){var e=this;t.onclick=function(i){if(i.target&&"LI"==i.target.nodeName){var a=document.getElementById("mddtp-date__currentYear");a.id="",a.classList.remove("mddtp-picker__li--current"),i.target.id="mddtp-date__currentYear",i.target.classList.add("mddtp-picker__li--current"),e._switchToDateView(t,e),e._sDialog.tDate.year(parseInt(i.target.textContent,10)),e._initViewHolder()}}}},{key:"_changeM",value:function(){var t=this,e=this._sDialog.AM,i=this._sDialog.PM;e.onclick=function(a){var s="AM";t._sDialog.sDate._locale.isPM(t._sDialog.sDate.format("A"))&&(s="PM"),"PM"===s&&(t._sDialog.sDate.subtract(12,"h"),e.classList.toggle("mddtp-picker__color--active"),i.classList.toggle("mddtp-picker__color--active"))},i.onclick=function(a){var s="AM";t._sDialog.sDate._locale.isPM(t._sDialog.sDate.format("A"))&&(s="PM"),"AM"===s&&(t._sDialog.sDate.add(12,"h"),e.classList.toggle("mddtp-picker__color--active"),i.classList.toggle("mddtp-picker__color--active"))}}},{key:"_dragDial",value:function(){var t=this,e=this._sDialog.needle,i=this._sDialog.circle,a=this._sDialog.fakeNeedle,s=this._sDialog.circularHolder,d=this._sDialog.minute,o="mddtp-picker__selection--quick",n="mddtp-picker__selection",c="mddtp-picker__cell--selected",r="mddtp-picker__cell--rotate-",_=s.getBoundingClientRect(),u=void 0,h=new l.default(a,{containment:!0});h.on("pointerDown",function(t){_=s.getBoundingClientRect()}),h.on("pointerMove",function(t){var i=t.clientX,a=t.clientY;void 0===i&&(void 0===t.pageX?t.touches&&t.touches.length>0?(i=t.touches[0].clientX,a=t.touches[0].clientY):console.error("coult not detect pageX, pageY"):(i=pageX-document.body.scrollLeft-document.documentElement.scrollLeft,a=pageY-document.body.scrollTop-document.documentElement.scrollTop));var s=i-_.left-_.width/2,d=a-_.top-_.height/2,l=Math.atan2(-d,s);e.className="",l<0&&(l+=2*Math.PI),l*=180/Math.PI,l=360-l,l>270&&(l-=360),u=parseInt(l/6);var c=Math.abs(6*u-l),h=Math.abs(6*(u+1)-l);h0&&(m/=5,m--,l[m].id=n,l[m].classList.add(c)),d.textContent=t._numWithZero(u),t._sDialog.sDate.minutes(u)})}},{key:"_attachEventHandlers",value:function(){var t=this,e=this._sDialog.ok,i=this._sDialog.cancel,a=new CustomEvent("onCancel"),s=new CustomEvent("onOk");i.onclick=function(){t.toggle(),t._trigger&&t._trigger.dispatchEvent(a)},e.onclick=function(){t._init=t._sDialog.sDate,t.toggle(),t._trigger&&t._trigger.dispatchEvent(s)}}},{key:"_setButtonText",value:function(){this._sDialog.cancel.textContent=this._cancel,this._sDialog.ok.textContent=this._ok}},{key:"_changeUnicodeToChars",value:function(t){return t.replace(/\\u[\dA-F]{4}/gi,function(t){return String.fromCharCode(parseInt(t.replace(/\\u/g,""),16))})}},{key:"_getMonth",value:function(t,e){var i=void 0;return i=t.clone(),e>0?i.add(Math.abs(e),"M"):i.subtract(Math.abs(e),"M")}},{key:"_nearestDivisor",value:function(t,e){return t%e===0?t:(t-1)%e===0?t-1:(t+1)%e===0?t+1:-1}},{key:"_numWithZero",value:function(t){return t>9?""+t:"0"+t}},{key:"_fillText",value:function(t,e){t.firstChild?t.firstChild.nodeValue=e:t.appendChild(document.createTextNode(e))}},{key:"_addId",value:function(t,e){t.id="mddtp-"+this._type+"__"+e}},{key:"_addClass",value:function(t,e,i){t.classList.add("mddtp-picker__"+e);var a=0;for(i&&(a=i.length,i.reverse());a--;)t.classList.add(i[a])}},{key:"_addView",value:function(t){for(var e=document.createElement("div"),i=document.createElement("div"),a=document.createElement("div"),s=document.createElement("div"),l=d.default.weekdaysMin(!0).reverse(),o=7;o--;){var n=document.createElement("span");n.textContent=l[o],a.appendChild(n)}this._addClass(e,"month"),this._addClass(i,"grid"),this._addClass(a,"th"),this._addClass(s,"tr"),t.appendChild(e),t.appendChild(i),i.appendChild(a),i.appendChild(s)}},{key:"_calcRotation",value:function(t,e){return e*=12===t?10:24===t?5:2,60===t&&0===e&&(e=120),"mddtp-picker__cell--rotate-"+e}},{key:"time",get:function(){return this._init},set:function(t){t&&(this._init=t)}},{key:"trigger",get:function(){return this._trigger},set:function(t){t&&(this._trigger=t)}}],[{key:"dialog",get:function(){return t._dialog},set:function(e){t.dialog=e}}]),t}();n._dialog={view:!0,state:!1},t.default=n});