/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{cyclicalDegrees as t}from"./Cyclical.js";import{clamp as n}from"./mathUtils.js";import{convertRotationType as r}from"./quantity.js";import{replace as i}from"./string.js";import{convertUnit as o,adaptiveMetricLengthUnit as e,adaptiveImperialLengthUnit as u,adaptiveMetricVerticalLengthUnit as s,adaptiveImperialVerticalLengthUnit as c,adaptiveMetricAreaUnit as a,adaptiveImperialAreaUnit as m,adaptiveMetricVolumeUnit as f,adaptiveImperialVolumeUnit as b}from"./units.js";import{formatNumber as l}from"../intl/number.js";function g(t,n,r){return t.units[n][r]}function p(t,n,r,i=2,o="abbr"){return`${l(n,{minimumFractionDigits:i,maximumFractionDigits:i,signDisplay:n>0?"never":"exceptZero"})} ${g(t,r,o)}`}function D(t,n,r,i=2,o="abbr"){return`${l(n,{minimumFractionDigits:i,maximumFractionDigits:i,signDisplay:"exceptZero"})} ${g(t,r,o)}`}function x(t,n,r,i=2,u="abbr"){const s=e(n,r);return p(t,o(n,r,s),s,i,u)}function F(t,n,r,i=2,u="abbr"){const s=e(n,r);return D(t,o(n,r,s),s,i,u)}function y(t,n,r,i=2,e="abbr"){const u=s(n,r);return p(t,o(n,r,u),u,i,e)}function d(t,n,r,i=2,e="abbr"){const u=s(n,r);return D(t,o(n,r,u),u,i,e)}function h(t,n,r,i=2,e="abbr"){const s=u(n,r);return p(t,o(n,r,s),s,i,e)}function M(t,n,r,i=2,e="abbr"){const s=u(n,r);return D(t,o(n,r,s),s,i,e)}function $(t,n,r,i=2,e="abbr"){const u=c(n,r);return p(t,o(n,r,u),u,i,e)}function j(t,n,r,i=2,e="abbr"){const u=c(n,r);return D(t,o(n,r,u),u,i,e)}function B(t,n,r,i=2,e="abbr"){const u=a(n,r);return p(t,o(n,r,u),u,i,e)}function w(t,n,r,i=2,e="abbr"){const u=m(n,r);return p(t,o(n,r,u),u,i,e)}function Z(t,n,r,i=2,e="abbr"){const u=f(n,r);return p(t,o(n,r,u),u,i,e)}function S(t,n,r,i=2,e="abbr"){const u=b(n,r);return p(t,o(n,r,u),u,i,e)}function v(t,n,r=2){let i=o(t,n,"degrees"),e=i-Math.floor(i);i-=e,e*=60;let u=e-Math.floor(e);return e-=u,u*=60,`${i.toFixed()}° ${e.toFixed()}' ${u.toFixed(r)}"`}const z=(t,n)=>({style:"unit",unitDisplay:"narrow",unit:"degree",maximumFractionDigits:n,minimumFractionDigits:n,signDisplay:t>0?"never":"exceptZero"});function N(n,i,e,u,s,c=t,a=!0){let m=c.normalize(r(o(n,i,"degrees"),e,u),0,a);const f=z(m,s??2);return m=q(m,f),l(m,f)}function U(t,n,r,i,e=2){r!==i&&(t=-t);const u={style:"unit",unitDisplay:"narrow",unit:"degree",maximumFractionDigits:e,minimumFractionDigits:e,signDisplay:"exceptZero"};let s=o(t,n,"degrees")%360;return s=q(s,u),l(s,u)}const k=new Map;function q(t,n){const r=JSON.stringify(n);let i=k.get(r);return i||(i=new Intl.NumberFormat("en-US",n),k.set(r,i)),/^[-+]?360\.?0*°?$/.test(i.format(t))?0:t}const C=["B","kB","MB","GB","TB"];function G(t,r){let o=0===(r=Math.round(r))?0:Math.floor(Math.log(r)/Math.log(1024));o=n(o,0,C.length-1);const e=l(r/1024**o,{maximumFractionDigits:2});return i(t.units.bytes[C[o]],{fileSize:e})}export{N as formatAngleDegrees,v as formatDMS,p as formatDecimal,G as formatFileSize,w as formatImperialArea,h as formatImperialLength,M as formatImperialRelativeLength,j as formatImperialRelativeVerticalLength,$ as formatImperialVerticalLength,S as formatImperialVolume,B as formatMetricArea,x as formatMetricLength,F as formatMetricRelativeLength,d as formatMetricRelativeVerticalLength,y as formatMetricVerticalLength,Z as formatMetricVolume,U as formatRelativeAngleDegrees,D as formatRelativeDecimal,g as unitName};
