import t from"@babel/runtime/helpers/toConsumableArray";import r from"@babel/runtime/helpers/defineProperty";import e from"lodash/isNumber";import i from"lodash/get";import n from"lodash/has";import a from"lodash/set";import d from"moment";import{convertValue as o,getUnitPreference as s}from"./convert.js";function p(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);r&&(i=i.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,i)}return e}function u(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?p(Object(i),!0).forEach((function(e){r(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):p(Object(i)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(i,r))}))}return t}var c=function(t){return 0!==t&&!t},l=function(t,r,i,n){return c(t)?!!n:e(t)&&t>r&&t<i},m=function(t,r,i){return e(t)?r&&i?o(t,r,i):parseFloat(t):null},f=function(t,r,i){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:5;return e(t)?r&&i?o(t,r,s(r),i,n):parseFloat(t):null},v=function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],d=m(i(r,["data","mud_density"]),"density","ppg"),o=m(i(r,["data","depth"]),"length","ft"),s=m(i(r,["data","tvd"]),"length","ft"),p=u(u({},r),{},{data:u(u({},r.data),{},{mud_density:d,depth:o,tvd:s})});return p=e.reduce((function(e,d){var o=["data"].concat(t(d.key.split(".")));if(!n(r,o))return e;var s=m(i(r,o),d.unitType,d.unit);return a(e,o,s)}),p)},y=function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],o=r,s=i(r,["data","date_str"]);if(s){var p=d(new Date(s));p.isValid()&&(o=a(o,["data","date"],p.unix()))}var c=f(i(r,["data","mud_density"]),"density","ppg"),l=f(i(r,["data","depth"]),"length","ft"),m=f(i(r,["data","tvd"]),"length","ft"),v=u(u({},o),{},{data:u(u({},o.data),{},{mud_density:c,depth:l,tvd:m,date_str:null})});return v=e.reduce((function(e,d){var o=["data"].concat(t(d.key.split(".")));if(!n(r,o))return e;var s=f(i(r,o),d.unitType,d.unit);return a(e,o,s)}),v)},g=function(t){var r=t.data,e=r.date_str,i=r.mud_density,n=r.mud_type,a=r.viscosity,o=a.pv,s=a.yp,p=a.rpm_readings,u=!1,f={viscosity:{rpm_readings:[]}};e&&!d(new Date(e)).isValid()&&(u=!0,f.date="Invalid Date."),n||(u=!0,f.mud_type="Mud Type is required");var v=m(5,"density","ppg"),y=m(30,"density","ppg");l(i,v,y,!1)||(u=!0,f.mud_density="It should be ".concat(v," ~ ").concat(y)),(c(o)||c(s))&&p.length<2&&(u=!0,f.viscosity.rpm_readings_required="At least 2 paris of rpm and dial_reading required."),l(o,0,200,!f.viscosity.rpm_readings_required)||(u=!0,f["viscosity.pv"]="It should be 0~200"),l(s,0,200,!f.viscosity.rpm_readings_required)||(u=!0,f["viscosity.yp"]="It should be 0~200");for(var g=[],h=0;h<p.length;h+=1){f.viscosity.rpm_readings[h]={};var _=f.viscosity.rpm_readings[h];l(p[h].rpm,0,1e3)||(u=!0,_.rpm="It should be 0~1000"),l(p[h].dial_reading,0,300)||(u=!0,_.dial_reading="It should be 0~300"),-1!==g.indexOf(p[h].rpm)&&(u=!0,_.rpm="Duplicated RPM value"),g.push(p[h].rpm),p[h].originalIndex=h}var b=p.sort((function(t,r){return t.rpm-r.rpm}));return b.forEach((function(t,r){var e=f.viscosity.rpm_readings[t.originalIndex];b[r-1]&&t.dial_reading<b[r-1].dial_reading&&(u=!0,e.dial_reading="Dial Readings should be in increasing order")})),{hasErrors:u,errors:f}};export{y as convertToImperialUnit,v as convertToPrefUnit,f as ctoi,m as ctop,c as isValueEmpty,l as isValueValid,g as validate};
//# sourceMappingURL=FluidCheckUtils.js.map
