import _toConsumableArray from"@babel/runtime/helpers/toConsumableArray";import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import{format,isValid,parse}from"date-fns";import{useCallback,useEffect}from"react";import{IMask}from"react-imask";import{getForm}from"../FieldGroup";import{useMutableRef}from"../../hooks/useMutableRef";import{getTimeNumbers}from"../DateTime/helpers";export var datePickerPropSeparatorDefault=".";export var datePickerPropFormatTypeDate="dd".concat(".","MM").concat(".","yyyy");export var datePickerPropFormatTypeTime="HH:mm:ss";export var datePickerPropFormatTypeDateTime="".concat(datePickerPropFormatTypeDate," ").concat("HH:mm:ss");export var datePickerPropFormatTypeYear="yyyy";export var datePickerPropFormatTypeMonth="MM".concat(".","yyyy");export var normalizeRangeValue=function(a){var b,c;return a[0]&&a[1]&&(null===(b=a[0])||void 0===b?void 0:b.getTime())>(null===(c=a[1])||void 0===c?void 0:c.getTime())?[a[1],a[0]]:a};export var getTimeOptionsByFormat=function(a,b){var c,d=null===(c=a.split(" ")[1])||void 0===c?void 0:c.split(":"),e={HH:null===b||void 0===b?void 0:b.hours,mm:null===b||void 0===b?void 0:b.minutes,ss:null===b||void 0===b?void 0:b.seconds},f=["HH","mm","ss"].map(function(a){return null!==d&&void 0!==d&&d.includes(a)?e[a]:[]}),g=_slicedToArray(f,3),h=g[0],i=g[1],j=g[2];return{hours:h,minutes:i,seconds:j}};export var adaptFormat=function(a,b){for(var c,d=a.split(" "),e=null!==(c=d[1])&&void 0!==c?c:a,f=function shouldRemoveTimePart(a){return!!(a&&Array.isArray(a)&&0===a.length)||a&&!Array.isArray(a)&&0===a.step},g=[{marker:"HH",timeOption:null===b||void 0===b?void 0:b.hours},{marker:"mm",timeOption:null===b||void 0===b?void 0:b.minutes},{marker:"ss",timeOption:null===b||void 0===b?void 0:b.seconds}],h=0,i=g;h<i.length;h++){var j=i[h],k=j.marker,l=j.timeOption;f(l)&&(e=e.replace(new RegExp(":?".concat(k),"g"),""))}return e=e.replace(/:+$/,"").replace(/^:+/,"").replace(/:+/g,":").replace(/\s+/g," ").trim(),1<d.length?(d[1]=e,d.filter(function(a){return 0<a.length}).join(" ")):e};export var placeholderByFormat=function placeholderByFormat(a){return a.replace(/yyyy/g,"\u0413\u0413\u0413\u0413").replace(/MM/g,"\u041C\u041C").replace(/dd/g,"\u0414\u0414").replace(/HH/g,"\u0427\u0427").replace(/mm/g,"\u041C\u041C").replace(/ss/g,"\u0421\u0421")};export var getMaskBlocks=function getMaskBlocks(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},b=a.includeDate,c=void 0===b||b,d=a.includeTime,e=void 0===d||d,f={};return c&&(f.dd={mask:IMask.MaskedRange,from:1,to:31},f.MM={mask:IMask.MaskedRange,from:1,to:12},f.yyyy={mask:IMask.MaskedRange,from:1,to:9999}),e&&(f.HH={mask:IMask.MaskedRange,from:0,to:23},f.mm={mask:IMask.MaskedRange,from:0,to:59},f.ss={mask:IMask.MaskedRange,from:0,to:59}),f};export var getFormForStart=function getFormForStart(a){return getForm(a,0,2)};export var getFormForEnd=function getFormForEnd(a){return getForm(a,1,2)};export var getPartDate=function getPartDate(a,b,c){var d=a.indexOf(c);return 0<=d&&b[d]&&b[d].length===c.length?b[d]:void 0};export var getParts=function getParts(a,b,c){if(c){var d=a.split(" "),e=_slicedToArray(d,2),f=e[0],g=e[1];return[].concat(_toConsumableArray(f?f.split(b):[]),_toConsumableArray(g?g.split(":"):[]))}return a.split(b)};export var getPartsDate=function getPartsDate(a,b,c,d,e){var f=getParts(b,c,d),g=getParts(a,c,d);return e.map(function(a){return getPartDate(f,g,a)})};export var isTypeWithTime=function isTypeWithTime(a){return-1!==a.indexOf("time")};var fieldPrefixs=["start","end"];export var getFieldName=function getFieldName(a,b){return a?Array.isArray(a)?a[b]:"".concat(a,"_").concat(fieldPrefixs[b]):void 0};export var getDropdownZIndex=function getDropdownZIndex(a){return"number"==typeof(null===a||void 0===a?void 0:a.zIndex)?a.zIndex+1:void 0};export var useStringValue=function useStringValue(a,b,c,d,e){var f=e.value,g=useMutableRef([e.setValue,a]),h=useCallback(function(a){var b;g.current[0](a),null!==(b=e.ref)&&void 0!==b&&b.current&&(e.ref.current.value=a),e.maskRef.current&&e.maskRef.current.updateValue()},[]),i=useCallback(function(a){if(h(""),g.current[1]){var b;null===(b=d.current)||void 0===b?void 0:b.call(d,null,{e:a})}},[]);return useEffect(function(){if(a&&isValid(a)&&h(format(a,b)),!a&&f){var d=getParts(b,c,!1),e=getParts(f,c,!1),g=d.map(function(a){return getPartDate(d,e,a)}).filter(function(a){return!!a}),i=d.length===g.length?parse(e.join(datePickerPropSeparatorDefault),d.join(datePickerPropSeparatorDefault),new Date):void 0;isValid(i)&&h("")}},[null===a||void 0===a?void 0:a.getTime()]),i};export var isValidTimeByTimeOptions=function isValidTimeByTimeOptions(a,b){var c=function isUnitValid(a,b,c){if(!c)return!0;var d=getTimeNumbers(a,c);return!(0!==d.length)||d.includes(b)};if(!b)return!0;var d=c("hours",a.getHours(),b.hours),e=c("minutes",a.getMinutes(),b.minutes),f=c("seconds",a.getSeconds(),b.seconds);return d&&e&&f};
//# sourceMappingURL=helpers.js.map