!function(h){var n="wapf-dp",e="ontouchstart"in window,o=n+"-hide",r=n+"-top-left",l=n+"-bottom-left",d=[r,l].join(" ");function c(t){return"[object Date]"===Object.prototype.toString.call(t)&&!isNaN(t.getTime())}function p(t,e){var i=String(Math.abs(t)),a=i.length,s="";for(t<0&&(s+="-");a<e;)a+=1,s+="0";return s+i}function Y(t,e){return[31,(t=t)%4==0&&t%100!=0||t%400==0?29:28,31,30,31,30,31,31,30,31,30,31][e]}function u(t,e,i){return Math.min(i,Y(t,e))}function s(t,e){var i,a,s;this.options=h.extend({},{autoShow:!1,autoHide:!1,autoPick:!1,container:null,trigger:null,language:"",format:"mm/dd/yyyy",date:null,startDate:null,endDate:null,weekStart:0,yearFirst:!1,yearSuffix:"",days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],daysShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],daysMin:["S","M","T","W","T","F","S"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],monthsShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],itemTag:"li",mutedClass:"muted",pickedClass:"picked",disabledClass:"disabled",highlightedClass:"highlighted",template:'<div class="wapf-dp-c" tabindex="-1"><div class="dp-panel" data-action="days picker"><div class="wapf-dp-header"><div data-action="month prev" class="dp-prev"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M18.7 256l22.6 22.6 160 160L224 461.3 269.3 416l-22.6-22.6L109.3 256 246.6 118.6 269.3 96 224 50.7 201.4 73.4l-160 160L18.7 256z"/></svg></div><div class="wapf-dp-my"><select class="wapf-dp-month" tabindex="-1" aria-label="Month"></select><div class="wapf-dp-year-wrap"><input class="wapf-dp-year" type="number" tabindex="-1" maxlength="4" aria-label="Year" /><span class="dp-year-min">-</span><span class="dp-year-plus">+</span></div><div data-action="clear" class="dp-clr"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zm97.9-320l-17 17-47 47 47 47 17 17L320 353.9l-17-17-47-47-47 47-17 17L158.1 320l17-17 47-47-47-47-17-17L192 158.1l17 17 47 47 47-47 17-17L353.9 192z"/></svg></div> </div><div data-action="month next" class="dp-next"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M301.3 256l-22.6 22.6-160 160L96 461.3 50.7 416l22.6-22.6L210.7 256 73.4 118.6 50.7 96 96 50.7l22.6 22.6 160 160L301.3 256z"/></svg></div></div><ul class="dp-weeks"></ul><ul class="dp-days notranslate"></ul></div></div>',offset:10,zIndex:2e3,filter:null},e),this.$element=h(t),this.element=t,this.$trigger=h(this.options.trigger),this.isInput=this.$element.is("input")||this.$element.is("textarea"),this.$scrollParent=(i=!0,t=(n=h(o=t)).css("position"),a="absolute"===t,s=i?/auto|scroll|hidden/:/auto|scroll/,n=n.parents().filter(function(t,e){e=h(e);return(!a||"static"!==e.css("position"))&&s.test(e.css("overflow")+e.css("overflow-y")+e.css("overflow-x"))}).eq(0),"fixed"!==t&&n.length?n:h(o.ownerDocument||document)),this.format=this.parseFormat(this.options.format),this.built=!1,this.shown=!1;var n=(""+this.getValue()).trim(),o=this.parseDate(n||this.options.date);n.length&&this.$element.data("selected",o),this.date=o,this.viewDate=new Date(o),this.onPlace=this.place.bind(this),this.onGlobalClick=this.onGlobalClick.bind(this),this.onGlobalKeyup=this.onGlobalKeyup.bind(this),this.onTouchStart=this.onTouchStart.bind(this),this.onClick=this.onClick.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onShow=this.show.bind(this),this.bind(),e.autoShow&&this.show(),e.autoPick&&this.pick()}s.prototype={constructor:s,getValue:function(){return this.$element[this.isInput?"val":"text"]()},setValue:function(t){t=t||"",this.isInput&&this.$element.val(t),e&&this.$picker.find(".dp-clr").css("display",t.length?"flex":"none")},formatDate:function(t,e){var i,a,s=e?window.dpParseFormat(e):this.format,n="";return c(t)&&(i=t.getFullYear(),e=t.getMonth(),t=t.getDate(),a={d:t,dd:p(t,2),m:e+1,mm:p(e+1,2),yy:String(i).substring(2),yyyy:p(i,4)},n=s.source,s.parts.forEach(function(t){n=n.replace(t,a[t])})),n},parseFormat:function(t){var e=(""+t).toLowerCase(),t=e.match(/[ymd]+/g);if(!t||!t.length)throw new Error("Invalid date format");return{source:e,parts:t}},parseDate:function(a,t){var s=t?window.dpParseFormat(t):this.format,t=[];return c(a)||("string"==typeof a&&(t=a.match(/\d+/g)||[]),c(a=a?new Date(a):new Date)||(a=new Date),t.length===s.parts.length&&(t.forEach(function(t,e){var i=parseInt(t);switch(s.parts[e]){case"yy":a.setFullYear(2e3+i);break;case"yyyy":a.setFullYear(2===t.length?2e3+i:i);break;case"mm":case"m":a.setMonth(i-1)}}),t.forEach(function(t,e){t=parseInt(t);"d"!==s.parts[e]&&"dd"!==s.parts[e]||a.setDate(t)}))),new Date(a.getFullYear(),a.getMonth(),a.getDate())},bind:function(){var t=this.$element;this.isInput?(t.on("keydown",this.onKeyDown),t.on("focus",this.onShow)):t.on("click",this.onShow)},unbind:function(){var t=this.$element;t.off("keydown",this.onKeyDown),t.off("focus",this.onShow),t.off("click",this.onShow)},build:function(){var t,e,i,a,s=this;this.built||(this.built=!0,t=this.options,e=h(this.options.template),this.$picker=e,i=this.viewDate.getMonth(),this.$monthPicker=e.find(".wapf-dp-month"),this.$yearPicker=e.find(".wapf-dp-year"),this.$week=e.find(".dp-weeks"),this.$days=e.find(".dp-days"),this.$monthPicker.html(t.monthsShort.map(function(t,e){return'<option value="'+e+'" '+(e===i?"selected":"")+">"+t+"</option>"}).join("")),this.$yearPicker.val(this.viewDate.getFullYear()),a=function(){var t,e,i=s.$yearPicker.val();(""+i).length<4||(t=s.viewDate.getMonth(),e=s.viewDate.getDate(),s.viewDate.setDate(u(i,t,e)),s.viewDate.setFullYear(i),s.renderDays())},this.$yearPicker.on("input",function(t){t.preventDefault(),a()}),e.find(".dp-year-plus, .dp-year-min").on("click",function(t){t.preventDefault(),s.$yearPicker[0][this.classList.contains("dp-year-min")?"stepDown":"stepUp"](),a()}),this.$monthPicker.on("change",function(){var t=s.$monthPicker.val(),e=s.viewDate.getDate(),i=s.viewDate.getFullYear();s.viewDate.setFullYear(i),s.viewDate.setDate(u(i,t,e)),s.viewDate.setMonth(t),s.renderDays()}),e.addClass(o+" "+n+"-dropdown").css({zIndex:t.zIndex}).attr("aria-hidden","true").appendTo(document.body),this.renderWeek())},createItem:function(t){var e=this.options,i=e.itemTag,a={text:"",view:"",muted:!1,picked:!1,disabled:!1,highlighted:!1},s=[];return h.extend(a,t),a.muted&&s.push(e.mutedClass),a.highlighted&&s.push(e.highlightedClass),a.picked&&s.push(e.pickedClass),a.disabled&&s.push(e.disabledClass),"<"+i+' class="'+s.join(" ")+'" '+(a.picked?'aria-selected="true"':"")+' data-action="'+a.view+'"><span>'+a.text+"</span></"+i+">"},renderWeek:function(){var e=this,i=[],t=this.options.weekStart%7,a=this.options.daysMin;(a=a.slice(t).concat(a.slice(0,t))).forEach(function(t){i.push(e.createItem({text:t}))}),this.$week.html(i.join(""))},renderDays:function(){var t=this.$element,e=this.options,i=this.viewDate,a=this.date,s=e.filter,e=e.weekStart,n=i.getFullYear(),o=i.getMonth(),i=new Date,r=i.getFullYear(),h=i.getMonth(),l=i.getDate(),d=a.getFullYear(),c=a.getMonth(),p=a.getDate(),u=[],f=n,m=o;0===o?(--f,m=11):--m;var w,g=Y(f,m);for((w=new Date(n,o,1).getDay()-e%7)<=0&&(w+=7),F=g-(w-1);F<=g;F+=1){var v=new Date(f,m,F),y=!!s&&!1===s.call(t,v,"day");u.push(this.createItem({disabled:y,highlighted:f===r&&m===h&&v.getDate()===l,muted:!0,picked:f===d&&m===c&&F===p,text:F,view:"day prev"}))}var k=[],D=n,b=o;for(11===o?(D+=1,b=0):b+=1,g=Y(n,o),w=42-(u.length+g),F=1;F<=w;F+=1){var $=new Date(D,b,F),x=D===d&&b===c&&F===p,S=!!s&&!1===s.call(t,$,"day");k.push(this.createItem({disabled:S,picked:x,highlighted:D===r&&b===h&&$.getDate()===l,muted:!0,text:F,view:"day next"}))}for(var C=[],F=1;F<=g;F+=1){var M=new Date(n,o,F),P=!!s&&!1===s.call(t,M,"day"),I=n===d&&o===c&&F===p,T=I?"day picked":"day";C.push(this.createItem({disabled:P,picked:I,highlighted:n===r&&o===h&&M.getDate()===l,text:F,view:P?"day disabled":T}))}this.$days.html(u.join("")+C.join("")+k.join(""))},hide:function(){this.shown&&(this.shown=!1,this.$picker.addClass(o).attr("aria-hidden","true").off("click",this.onClick),this.$scrollParent.off("scroll",this.onPlace),h(window).off("resize",this.onPlace),h(document).off("mousedown",this.onGlobalClick),h(document).off("click",this.onGlobalClick),h(document).off("keyup",this.onGlobalKeyup),h(document).off("touchstart",this.onTouchStart))},show:function(){this.built||this.build(),!this.shown&&this.$picker.length&&(this.shown=!0,this.$picker.removeClass(o).attr("aria-hidden","false").on("click",this.onClick),this.renderDays(),h(document).on(e?"click":"mousedown",this.onGlobalClick),this.$scrollParent.on("scroll",this.onPlace),h(window).on("resize",this.onPlace),h(document).on("keyup",this.onGlobalKeyup),h(document).on("touchstart",this.onTouchStart),this.place())},place:function(){var t=this.element.getBoundingClientRect(),e=this.options.offset,i=this.$element.offset(),a=this.element.offsetHeight,s=this.$picker[0].offsetHeight,n=window.innerHeight-t.top,o=i.left,t=i.top,i=l;0<n&&0<=n-(s+a)?(t+=a+e,i=r):t-=s+e,this.$picker.removeClass(d).addClass(i).css({top:t,left:o})},pick:function(){var t=this.$element;this.setValue(this.formatDate(this.date)),this.isInput&&t.trigger("input").trigger("change"),t.data("selected",this.date||null),"function"==typeof this.options.pick&&this.options.pick(this.date)},destroy:function(){this.unbind(),this.built=!1,this.$picker.remove(),this.$element.removeData(n)},onKeyDown:function(t){var e;this.isInput&&(-1===(e=["Backspace","Delete"]).concat(["Tab","Escape","Shift"]).indexOf(t.key)&&t.preventDefault(),-1<e.indexOf(t.key)&&(this.setValue(),this.$element.data("selected",null)))},onGlobalClick:function(t){for(var e=t.target,i=!0,a=this.$trigger[0],s=this.$picker[0];e!==document.body;){if(e===a||e===this.element||e===s){i=!1;break}e=e.parentNode}i&&this.hide()},onGlobalKeyup:function(t){var e=t.target;this.shown&&this.isInput&&("Escape"!==t.key&&(e===this.element||"Tab"!==t.key&&9!==t.keyCode)||this.hide())},onTouchStart:function(t){t=t.target;this.isInput&&t!==this.element&&!h.contains(this.$picker[0],t)&&(this.hide(),this.element.blur())},onClick:function(t){var e=h(t.target);if(!(e=e.is("span")||e.is("svg")?e.parent():e).hasClass("disabled")){var i=e.data("action");if(i){var a=this.date,s=this.viewDate;t.stopPropagation(),t.preventDefault();var n=s.getFullYear(),o=s.getMonth(),r=s.getDate();switch(i){case"clear":this.setValue(),this.$element.data("selected",null);break;case"month prev":case"month next":case"day prev":case"day next":(o=-1<i.indexOf("prev")?o-1:o+1)<0?(--n,o+=12):11<o&&(n+=1,o-=12),s.setFullYear(n),s.setDate(u(n,o,r)),s.setMonth(o),this.$monthPicker.val(o),this.$yearPicker.val(n),this.renderDays();break;case"day":r=parseInt(e.find("span").text()),a.setFullYear(n),a.setMonth(o,1),a.setDate(r),s.setFullYear(n),s.setMonth(o,1),s.setDate(r),this.hide(),this.pick();break;case"day picked":this.pick(),this.hide()}}}}},window.dpParseFormat=s.prototype.parseFormat,window.dpParseDate=s.prototype.parseDate,window.dpFormatDate=s.prototype.formatDate,h.fn.dp=function(a){return this.each(function(t,e){var i=h(e);i.data(n)||i.data(n,new s(e,a))}),this}}(jQuery);