text: var DateTimePicker=function(e,t){var l={ru:{monthsFull:["Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь","Декабрь"],monthsShort:["ЯНВ","ФЕВ","МАР","АПР","МАЙ","ИЮН","ИЮЛ","АВГ","СЕН","ОКТ","НОЯ","ДЕК"],apply:"Применить",clear:"Очистить"},en:{monthsFull:["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"],apply:"Apply",clear:"Clear"}},u=this;u.div=$(e[0]),u.datecomponentchanged=new CustomEvent("datecomponentchanged"),DateTimePicker.instances=DateTimePicker.instances||[],u.cfg=$.extend({format:"Y-m-d H:i:s",placeholder:"_",className:"",value:null,defaultYear:(new Date).getFullYear(),defaultMonth:1,defaultDate:1,defaultHours:0,defaultMinutes:0,defaultSeconds:0,invalidClass:"invalid",datePicker:!1,openPickerOnFocus:!0,closePickerOnBlur:!0,externalTrigger:null,externalTriggerClass:"active",closeOnDateSelect:!0,footer:!1,lang:"ru"},t),$.fn.showFlex=function(){$(this).css("display","flex")};function s(e){for(var t=(e+"").split(""),a=0;t[a]===u.cfg.placeholder;)t[a++]="";for(a=t.length-1;t[a]===u.cfg.placeholder;)t[a--]="";return t.join("")}function o(){if(0===_)u.input[0].setSelectionRange(0,0);else{var e=0,t=0;for(t in C)if(C[t]===u.cfg.placeholder&&e++,e===_)break;u.input[0].setSelectionRange(+t+1,+t+1)}}function f(e){for(var t=u.input.val().split(""),a=0;e--;)("0"<=t[e]&&t[e]<="9"||t[e]===u.cfg.placeholder)&&a++;return a}function g(){d=new Date(+O.Y,O.m-1,+O.d,+O.H,+O.i,+O.s)}function r(e){if(""===O[e])return!1;var t=+O[e];if(isNaN(t))return!1;switch(e){case"d":if(t<1||31<t)return!1;break;case"m":if(t<1||12<t)return!1;break;case"Y":if(t<0||9999<t)return!1;break;case"H":if(t<0||24<t)return!1;break;case"i":case"s":if(t<0||59<t)return!1}return!0}function i(){var e=u.cfg.format.split(""),t="";for(var a in e)/[dmYHis]/.test(e[a])&&(t+=O[e[a]]);M=t}function p(){u.input.val(D()),o()}function h(){var e=!0,t=!0,a=u.cfg.format.split("").filter(function(e){return/[dmYHis]/.test(e)});if(0!=s(M).length){t=!1;for(var i=0;i<a.length;i++)if(!r(a[i])){e=!1;break}}u.input.toggleClass(u.cfg.invalidClass,!e),u.cfg.datePicker&&e&&!t&&x("empty",new Date(O.Y,Number(O.m-1),O.d,O.H,O.i,O.s))}function k(e){var t=N,a=u.cfg.format.split(""),i=a.indexOf(t);if(e){do{if(i<a.length-1&&(t=a[++i]),/[dmYHis]/.test(t))break}while(i<a.length)}else do{if(i&&(t=a[--i]),/[dmYHis]/.test(t))break}while(i);return t}function v(e){for(var t=S.split(""),a=t.indexOf(e),i=a;i<t.length&&t[i]===e;i++);return[a,i]}function m(){d instanceof Date&&!isNaN(d)||(d=new Date);var e=d.getDate(),t=d.getMonth(),a=d.getFullYear(),i=d.getHours(),r=d.getMinutes(),n=d.getSeconds();switch(N){case"d":d=new Date(a,t,e+1,i,r,n);break;case"m":(d=new Date(a,t+1,e,i,r,n)).getDate()!==e&&(d=new Date(a,t+2,0,i,r,n));break;case"Y":(d=new Date(a+1,t,e,i,r,n)).getDate()!==e&&(d=new Date(a+1,t+1,0,i,r,n));break;case"H":d=new Date(a,t,e,i+1,r,n);break;case"i":d=new Date(a,t,e,i,r+1,n);break;case"s":d=new Date(a,t,e,i,r,n+1)}M=c(),x("empty",d)}function P(){d instanceof Date&&!isNaN(d)||(d=new Date);var e=d.getDate(),t=d.getMonth(),a=d.getFullYear(),i=d.getHours(),r=d.getMinutes(),n=d.getSeconds();switch(N){case"d":d=new Date(a,t,e-1,i,r,n);break;case"m":(d=new Date(a,t-1,e,i,r,n)).getDate()!==e&&(d=new Date(a,t,0,i,r,n));break;case"Y":(d=new Date(a-1,t,e,i,r,n)).getDate()!==e&&(d=new Date(a-1,t+1,0,i,r,n));break;case"H":d=new Date(a,t,e,i-1,r,n);break;case"i":d=new Date(a,t,e,i,r-1,n);break;case"s":d=new Date(a,t,e,i,r,n-1)}M=c(),w(u.input[0].selectionStart),p(),v(N),x("empty",d)}var c=function(){var e,t="";if(d){var a=u.cfg.format.split("");for(e in a)if(/[dmYHis]/.test(a[e]))switch(a[e]){case"d":t+=("0"+d.getDate()).slice(-2);break;case"m":t+=("0"+(d.getMonth()+1)).slice(-2);break;case"Y":t+=d.getFullYear();break;case"H":t+=("0"+d.getHours()).slice(-2);break;case"i":t+=("0"+d.getMinutes()).slice(-2);break;case"s":t+=("0"+d.getSeconds()).slice(-2)}}else{var i=C.split("");for(e in i)i[e]===u.cfg.placeholder&&(t+=i[e])}return t},D=function(){for(var e=n().split(""),t=M.split(""),a=0,i=0;a<t.length&&i<e.length;)e[i]===u.cfg.placeholder?e[i++]=t[a++]:i++;return e.join("")},n=function(){return u.cfg.format.replace("d",u.cfg.placeholder.repeat(2)).replace("m",u.cfg.placeholder.repeat(2)).replace("Y",u.cfg.placeholder.repeat(4)).replace("H",u.cfg.placeholder.repeat(2)).replace("i",u.cfg.placeholder.repeat(2)).replace("s",u.cfg.placeholder.repeat(2))},a=function(e){return null===d?"":e.replace("d",("0"+d.getDate()).slice(-2)).replace("m",("0"+(d.getMonth()+1)).slice(-2)).replace("Y",d.getFullYear()).replace("H",("0"+d.getHours()).slice(-2)).replace("i",("0"+d.getMinutes()).slice(-2)).replace("s",("0"+d.getSeconds()).slice(-2))},w=function(e){var t=N;N=function(e){var t=S[e];return/[dmYHis]/.test(t)&&void 0!==t||(t=S[e-1]),/[dmYHis]/.test(t)?t:void 0}(e),Object.keys(O).forEach(function(e){O[e]=function(e){var t=S.split(""),a=[];t.forEach(function(e){/[dmYHis]/.test(e)&&a.push(e)}),a=a.join("");var i="";for(var r in M)a[r]===e&&(i+=M[r]);return i}(e)}),t!==N&&u.input.trigger("datecomponentchanged",t)},y=function(){d=null,O={d:0,m:0,Y:0,H:0,i:0,s:0},M=c(),p()},x=function(e,t){if(!0===u.cfg.datePicker){var a=(u.datePicker.date=t).getDate(),i=t.getMonth(),r=t.getFullYear(),n=t.getHours(),c=t.getMinutes(),d=t.getSeconds();switch(u.datePicker.div.find("span").off(".dtpicker_header"),u.datePicker.div.find(".dtpicker_grid").children().hide(),u.datePicker.div.find(".today").on("click.dtpicker_header",function(){x("month",new Date)}),e){case"empty":case"month":u.datePicker.div.find(".text").html(l[u.cfg.lang].monthsFull[t.getMonth()]+" "+r).removeClass("stop").on("click.dtpicker_header",function(){x("year",t)}),u.datePicker.div.find(".prev").on("click.dtpicker_header",function(){x("month",new Date(r,i-1,a,n,c,d))}),u.datePicker.div.find(".next").on("click.dtpicker_header",function(){x("month",new Date(r,i+1,a,n,c,d))}),b(t);break;case"year":u.datePicker.div.find(".text").html(r).removeClass("stop").on("click.dtpicker_header",function(){x("decade",t)}),u.datePicker.div.find(".prev").on("click.dtpicker_header",function(){x("year",new Date(r-1,i,a,n,c,d))}),u.datePicker.div.find(".next").on("click.dtpicker_header",function(){x("year",new Date(r+1,i,a,n,c,d))}),Y(t);break;case"decade":u.datePicker.div.find(".text").html(10*Math.floor(r/10)+" - "+(10*Math.floor(r/10)+10)).addClass("stop"),u.datePicker.div.find(".prev").on("click.dtpicker_header",function(){x("decade",new Date(r-10,i,a,n,c,d))}),u.datePicker.div.find(".next").on("click.dtpicker_header",function(){x("decade",new Date(r+10,i,a,n,c,d))}),T(t)}"empty"!==e&&E(t)}},b=function(e){u.datePicker.div.find(".dtpicker_grid .day").off(".dtpicker_grid").removeClass("selected prevMonth nextMonth"),u.datePicker.div.find(".day_grid").showFlex();for(var t=e.getFullYear(),a=e.getMonth(),i=e.getDate(),r=e.getHours(),n=e.getMinutes(),c=e.getSeconds(),d=new Date(t,a,1).getDay(),l=new Date(t,a,0).getDate(),s=new Date(t,a+1,0).getDate(),o=(d=d?d-1:6)?0:1,f=0;f<d+7*o;f++)u.datePicker.dayGrid[0][d+7*o-f-1].html(l-f).addClass("prevMonth").on("click.dtpicker_grid",function(){var e=new Date(t,a-1,Number($(this).html()),r,n,c);x("month",e),u.cfg.closeOnDateSelect&&u.datePicker.div.hide()});for(var g=0;g<s;g++)u.datePicker.dayGrid[Math.floor((d+g)/7)+o][(d+g)%7].html(g+1).toggleClass("selected",i===g+1).on("click.dtpicker_grid",function(){var e=new Date(t,a,Number($(this).html()),r,n,c);E(u.datePicker.date=e),u.cfg.closeOnDateSelect?(u.datePicker.div.hide(),u.cfg.externalTrigger&&u.cfg.externalTrigger.toggleClass(u.cfg.externalTriggerClass,!1)):($(".dtpicker_grid .selected").removeClass("selected"),$(this).addClass("selected"))});for(f=1;f<43-s-d-7*o;g++,f++)u.datePicker.dayGrid[Math.floor((d+g)/7)+o][(d+g)%7].html(f).addClass("nextMonth").on("click.dtpicker_grid",function(){var e=new Date(t,a+1,$(this).html(),r,n,c);x("month",e),u.cfg.closeOnDateSelect&&u.datePicker.div.hide()})},Y=function(e){var t=e.getFullYear(),a=e.getMonth(),i=e.getDate(),r=e.getHours(),n=e.getMinutes(),c=e.getSeconds();u.datePicker.div.find(".month_grid").show();for(var d=0;d<4;d++)u.datePicker.monthGrid[0][d].html(l[u.cfg.lang].monthsShort[d+8]).addClass("prevYear").data("target-month",d+8).on("click.dtpicker_grid",function(){x("month",new Date(t-1,$(this).data("target-month"),i,r,n,c))}),u.datePicker.monthGrid[4][d].html(l[u.cfg.lang].monthsShort[d]).addClass("nextYear").data("target-month",d).on("click.dtpicker_grid",function(){x("month",new Date(t+1,$(this).data("target-month"),i,r,n,c))});for(d=0;d<12;d++)u.datePicker.monthGrid[1+Math.floor(d/4)][d%4].html(l[u.cfg.lang].monthsShort[d]).toggleClass("selected",d===a).data("target-month",d).on("click.dtpicker_grid",function(){x("month",new Date(t,$(this).data("target-month"),i,r,n,c))})},T=function(e){var t=e.getFullYear(),a=e.getMonth(),i=e.getDate(),r=e.getHours(),n=e.getMinutes(),c=e.getSeconds(),d=10*Math.floor(t/10);u.datePicker.div.find(".year_grid").show();for(var l=0;l<3;l++)u.datePicker.yearGrid[0][l].html(d-(3-l)).addClass("prevDecade").on("click.dtpicker_grid",function(){x("year",new Date(Number($(this).html()),a,i,r,n,c))}),u.datePicker.yearGrid[3][l+1].html(10+d+l).addClass("nextDecade").on("click.dtpicker_grid",function(){x("year",new Date(Number($(this).html()),a,i,r,n,c))});for(l=0;l<10;l++)u.datePicker.yearGrid[Math.floor((l+3)/4)][(l+3)%4].html(d+l).toggleClass("selected",d+l===t).on("click.dtpicker_grid",function(){x("year",new Date(Number($(this).html()),a,i,r,n,c))})},d=u.cfg.value,C=n(),M=c(),S=u.cfg.format.replace("d","dd").replace("m","mm").replace("Y","YYYY").replace("H","HH").replace("i","ii").replace("s","ss"),H=M.length,_=0,N=u.cfg.format[u.cfg.format.search(/[dmYHis]/)],F={d:1<=u.cfg.defaultDate&&u.cfg.defaultDate<=31?u.cfg.defaultDate:1,m:1<=u.cfg.defaultMonth&&u.cfg.defaultMonth<=12?u.cfg.defaultMonth:1,Y:0<=u.cfg.defaultYear&&u.cfg.defaultYear<=9999?u.cfg.defaultYear:(new Date).getFullYear(),H:0<=u.cfg.defaultHours&&u.cfg.defaultHours<=23?u.cfg.defaultHours:0,i:0<=u.cfg.defaultMinutes&&u.cfg.defaultMinutes<=59?u.cfg.defaultMinutes:0,s:0<=u.cfg.defaultSeconds&&u.cfg.defaultSeconds<=59?u.cfg.defaultSeconds:0},O={d:0,m:0,Y:0,H:0,i:0,s:0};function E(e){e instanceof Date&&!isNaN(e)?(d=e,M=c(),w(0),u.input.val(D())):y()}u.input=$('<input type="text" >').appendTo(u.div).addClass(u.cfg.className).val(D()),DateTimePicker.instances.push(this),!0===u.cfg.datePicker&&function(){if(u.div.css("position","relative"),u.datePicker={},u.datePicker.div=$('<div class="dtpicker_datepicker"><header></header><div class="dtpicker_grid"></div></div>').appendTo(u.div).css("top",u.input.outerHeight(!0)+"px").css("left",u.input.position().left+"px"),u.datePicker.header=$('<span class="prev"></span><span class="today"></span><span class="text"></span><span class="next"></span<span>').appendTo(u.datePicker.div.find("header")),u.datePicker.dayGrid=function(){for(var e=$('<div class="day_grid"></div>').appendTo(u.datePicker.div.find(".dtpicker_grid")[0]),t=[],a=0;a<6;a++){t[a]=[];for(var i=0;i<7;i++)t[a][i]=$('<div class="day"></div>').appendTo(e)}return t}(),u.datePicker.monthGrid=function(){for(var e=$('<div class="month_grid"></div>').appendTo(u.datePicker.div.find(".dtpicker_grid")[0]),t=[],a=0;a<5;a++){t[a]=[];for(var i=0;i<4;i++)t[a][i]=$('<div class="month"></div>').appendTo(e)}return t}(),u.datePicker.yearGrid=function(){for(var e=$('<div class="year_grid"></div>').appendTo(u.datePicker.div.find(".dtpicker_grid")[0]),t=[],a=0;a<4;a++){t[a]=[];for(var i=0;i<4;i++)t[a][i]=$('<div class="year"></div>').appendTo(e)}return t}(),u.cfg.footer&&(u.datePicker.footer=$("<footer></footer>").appendTo(u.datePicker.div),u.datePicker.applyBtn=$('<span class="apply"></span>').html(l[u.cfg.lang].apply).appendTo(u.datePicker.footer),u.datePicker.clearBtn=$('<span class="clear"></span>').html(l[u.cfg.lang].clear).appendTo(u.datePicker.footer)),u.cfg.value instanceof Date&&!isNaN(u.cfg.value))var e=u.cfg.value,t="month";else e=new Date,t="empty";x(t,e)}(),w(0),u.debug=function(){return{inputString:M,components:JSON.stringify(O),currentComponent:N,innerCaretPos:_,objValue:d}},u.getValue=function(e){switch(e=e||"text"){case"text":return a(u.cfg.format);case"date":return d;default:return a(u.cfg.format)}},u.setValue=E,u.getFormattedValue=function(e){return a(e)},u.setPickerPosition=function(e){u.cfg.datePicker&&(void 0!==e.left&&u.datePicker.div.css("left",e.left),void 0!==e.top&&u.datePicker.div.css("top",e.top))},u.showDatePicker=function(){u.datePicker.div.showFlex(),null!==u.cfg.externalTrigger&&u.cfg.externalTrigger.toggleClass(u.cfg.externalTriggerClass,!0)},u.hideDatePicker=function(){u.datePicker.div.hide(),null!==u.cfg.externalTrigger&&u.cfg.externalTrigger.toggleClass(u.cfg.externalTriggerClass,!1)},u.cfg.datePicker&&(null!==u.cfg.externalTrigger&&$(u.cfg.externalTrigger).on("click.dtpicker",function(){$(this).toggleClass(u.cfg.externalTriggerClass),$(this).hasClass(u.cfg.externalTriggerClass)?u.datePicker.div.show():u.datePicker.div.hide()}),u.cfg.footer&&(u.datePicker.clearBtn.on("click.dtpicker",function(){y(),u.input.val(C)}),u.datePicker.applyBtn.on("click.dtpicker",function(){E(u.datePicker.date),u.datePicker.div.hide(),u.cfg.externalTrigger&&u.cfg.externalTrigger.toggleClass(u.cfg.externalTriggerClass,!1)})),u.cfg.closePickerOnBlur&&u.datePicker.div.on("blur",function(){u.datePicker.div.hide()}),$._data(window,"events").click&&$._data(window,"events").click.filter(function(e){return"dtpicker"===e.namespace})||$(window).on("click.dtpicker",function(e){var t=e.originalEvent.path;DateTimePicker.instances.forEach(function(e){if(u.cfg.datePicker&&u.cfg.closePickerOnBlur){if(t.includes(e.input[0])||t.includes(e.datePicker.div[0])||null!==e.cfg.externalTrigger&&t.includes(e.cfg.externalTrigger[0]))return;e.hideDatePicker()}})})),u.input.on("keydown.dtpicker",function(e){var t=e.keyCode;if(!(116===t||9===t||17===t||86===t&&e.ctrlKey||67===t&&e.ctrlKey||88===t&&e.ctrlKey||65===t&&e.ctrlKey||37===t&&e.shiftKey&&!e.ctrlKey||39===t&&e.shiftKey&&!e.ctrlKey)){e.preventDefault();var a=this.selectionStart,i=f(this.selectionEnd);if(36===t)_=0,o(),w(this.selectionStart);else if(27===t)u.cfg.datePicker&&("none"===u.datePicker.div.css("display")?(u.datePicker.div.show(),null!==u.cfg.externalTrigger&&u.cfg.externalTrigger.toggleClass(u.cfg.externalTriggerClass,!0)):(u.datePicker.div.hide(),null!==u.cfg.externalTrigger&&u.cfg.externalTrigger.toggleClass(u.cfg.externalTriggerClass,!1)));else if(35===t)_=H,o(),w(this.selectionStart);else if(37===t||39===t||38===t||40===t){var r;switch(t){case 37:e.ctrlKey?(a=(r=v(k(!1)))[0],i=r[1]):a!==this.selectionEnd?i=a:_&&(i=--a);break;case 39:e.ctrlKey?(a=(r=v(k(!0)))[0],i=r[1]):a!==this.selectionEnd?a=i=this.selectionEnd:i=_<H?++a:a;break;case 38:m(),w(a),p(),a=(r=v(N))[0],i=r[1];break;case 40:P(),w(a),p(),a=(r=v(N))[0],i=r[1]}w(a),u.input.val(D()),_=f(a),this.setSelectionRange(a,i)}else if(13===t){var n=this.selectionStart;u.input.trigger("blur"),u.input.focus(),this.selectionStart=n}else if(48<=t&&t<=57||96<=t&&t<=105||46===t||8===t){var c=M.split("");if(48<=t&&t<=57||96<=t&&t<=105){if(_<H){c[_++]=e.key;for(n=_;n<i&&n<H;n++)c[n]=u.cfg.placeholder;M=c.join(""),w(a+1)}}else if(46===t){if(_<H){if(_!==i)for(;_<i;_++)c[_]=u.cfg.placeholder;else c[_++]=u.cfg.placeholder;M=c.join(""),w(a+1)}}else if(8===t){if(_!==i){for(n=_;_<i;_++)c[_]=u.cfg.placeholder;_=n}else _&&(c[--_]=u.cfg.placeholder);M=c.join("");var d=1<a?a-2:a-1;d<0&&(d=0),w(d)}M=M.substring(0,H),s(M).length||y(),u.input.val(D()),o()}h()}}),u.input.on("focus.dtpicker",function(){u.cfg.datePicker&&u.cfg.openPickerOnFocus&&u.datePicker.div.show()}),u.input.on("click.dtpicker",function(){var e=this.selectionStart;_=f(e),w(e)}),u.input.on("paste.dtpicker",function(){var e=(event.clipboardData||event.originalEvent.clipboardData||window.clipboardData).getData("text").split(""),t=f(this.selectionStart),a=f(this.selectionEnd),i=M.split(""),r=[];for(var n in e)/[0-9]/.test(e[n])&&r.push(e[n]);if(t===a){var c=i.slice(0,t),d=i.slice(t);i=c.concat(r,d).slice(0,H)}else for(var n in r)t<a&&(i[t++]=r[n]);M=i.join(""),w(),g(),_=t}),u.input.on("select.dtpicker",function(){_=f(this.selectionStart)}),u.input.on("datecomponentchanged.dtpicker",function(e,t){var a=O[t]+"";s(a).length&&a.includes(u.cfg.placeholder)&&(O[t]=("000"+s(a)).slice("Y"===t?-4:-2)),g(),i()}),u.input.on("blur.dtpicker",function(){if(s(M).length){$(this).trigger("datecomponentchanged.dtpicker",N);var e=Object.keys(O);for(var t in e)r(e[t])||(a=e[t],O[a]=("000"+F[a]).slice("Y"===a?-4:-2));i(),p(),g()}else y();var a;h()}),u.input.on("mousewheel.dtpicker wheel.dtpicker",function(e){var t,a,i;_=(i=(a=(e.originalEvent.deltaY<0?m():P(),p(),(t=v(N))[0]),t[1]),w(a),u.input.val(D()),f(a)),this.setSelectionRange(a,i)})};