import r from"@babel/runtime/helpers/defineProperty";import n from"corva-convert-units";import{sortBy as t,uniqBy as e,mapValues as i}from"lodash";import{IMPERIAL_UNITS as o,METRIC_UNITS as u,UNIT_DEFINITIONS as c,UNIT_TYPES_DEFINITIONS_MAP as a}from"./constants/units.js";function l(r,n){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(r);n&&(e=e.filter((function(n){return Object.getOwnPropertyDescriptor(r,n).enumerable}))),t.push.apply(t,e)}return t}function s(n){for(var t=1;t<arguments.length;t++){var e=null!=arguments[t]?arguments[t]:{};t%2?l(Object(e),!0).forEach((function(t){r(n,t,e[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(e)):l(Object(e)).forEach((function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(e,r))}))}return n}var v={imperial:o,metric:u,custom:s({},o)},f=[],m={},d=function(){return c},p=function(){return v.custom};var b=function(r){var n,t=r.userUnits,e=void 0===t?{}:t,u=r.companyUnits,c=void 0===u?{}:u,a=r.companyCustomUnitSystem,l=void 0===a?{}:a,d=r.userCustomUnitSystem,p=void 0===d?{}:d,b=r.companyCustomUnits;v.custom=s(s(s(s(s({},o),c),l),e),p),b&&(m=i(b||{},(function(r,n){var t=r.measures;return{display:r.name,imperial:n,measures:t.map((function(r){return{abbr:r.abbr,display:r.name,measure:r.abbr,plural:r.name,singular:r.name,system:"custom"}})),metric:n,origin:n,type:n}}))),n=v.custom,f.forEach((function(r){return r(n)}))};function g(){return v.custom}function y(r){return f.push(r),function(){f=f.filter((function(n){return n!==r}))}}var h=function(r){return v.custom[r]},O=function(r){var e,i=a[r];return i?t(n().list(i.origin),"abbr"):(null===(e=m[r])||void 0===e?void 0:e.measures)||[]},j=function(r){var n=O(r);return e(n,"abbr")},P=function(){return"custom"},w=function(r){var t,e,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,o=null===(t=a[r])||void 0===t?void 0:t.origin,u=n(void 0,o),c=u.getUnit,l=u.describe;if(null===i&&(i=v.custom[r]),c(i))return l(i).display;var s=null===(e=O(r).find((function(r){return r.measure===i})))||void 0===e?void 0:e.display;return s||i},U=function(r){return v.imperial[r]},D=function(r,t,e){var i,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,u=arguments.length>4&&void 0!==arguments[4]?arguments[4]:2;if(!r||!e||e===o||m[t])return r;if(null===o&&(!(o=h(t))||e===o))return r;var c=null===(i=a[t])||void 0===i?void 0:i.origin,l=n(r,c).from(e).to(o);return Number.isFinite(l)?Math.round(l*Math.pow(10,u))/Math.pow(10,u):l},S=function(r,n,t,e){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:2;return r.map((function(r){var u=D(r.get(n),t,e,i,o);return r.set(n,u)}))},C=function(r,n){return r.map((function(r){return n.reduce((function(r,n){var t=n.key,e=n.unitType,i=n.from,o=n.to,u=n.precision,c=r.get(t),a=D(c,e,i,o,u);return r.set(t,a)}),r)}))},E=function(){for(var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=arguments.length>1?arguments[1]:void 0,t=arguments.length>2?arguments[2]:void 0,e=arguments.length>3?arguments[3]:void 0,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null,o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:2,u=0;u<r.length;u+=1)r[u][n]=D(r[u][n],t,e,i,o);return r},M=function(r){var t,e=null===(t=a[r])||void 0===t?void 0:t.origin;return m[r]?w(r):n(void 0,e).describe(h(r)).singular},k=function(r){var t,e=null===(t=a[r])||void 0===t?void 0:t.origin;return m[r]?w(r):n(void 0,e).describe(h(r)).plural},x=function(r){var t,e=null===(t=a[r])||void 0===t?void 0:t.origin;return n(void 0,e).describe(r)};export{E as convertArray,S as convertImmutables,C as convertImmutablesByBatch,D as convertValue,d as getAllUnitTypes,U as getDefaultImperialUnit,p as getDefaultUnits,j as getUniqueUnitsByType,x as getUnitDescription,w as getUnitDisplay,k as getUnitPlural,h as getUnitPreference,M as getUnitSingular,P as getUnitSystem,O as getUnitsByType,g as getUserUnits,y as subscribeForUserUnitsUpdates,b as updateUserUnits};
