/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import n from"../core/Error.js";import{l as e,i as t,e as r,P as o,a as i,f as l,g as u,h as a,j as s}from"../chunks/pe.js";import c from"./Point.js";import d from"./SpatialReference.js";import{parseNumber as f}from"../intl/number.js";function _(){return t()}function S(){return s()}function E(){return e()}function g(n,e){const t=k(e),o=n.replaceAll(/[\u00B0\u00BA]/g,"^").replaceAll("′","'").replaceAll("″",'"'),i=[];return r.dmsToGeog(t,1,[o],i)?new c(i[0][0],i[0][1],e||d.WGS84):null}function w(n){return n&&_()?f(n)??g(`0° 0' 0" N | ${n}`)?.longitude??g(`0 N | ${n}`)?.longitude??null:null}function m(n){return n&&_()?f(n)??g(`${n} | 0° 0' 0" E`)?.latitude??g(`${n} | 0 E`)?.latitude??null:null}function T(n,e,t){const r=[],o=h(t);if(-1===o)return console.warn(`invalid conversionMode: ${t}`),null;const i=k(e);return a.mgrsToGeogExtended(i,1,[n],o,r)?new c(r[0][0],r[0][1],e||d.WGS84):null}function P(n,e){const t=[];!e&&/\(.+27/.test(n)&&(e=d.GCS_NAD_1927);const r=k(e);return l.usngToGeog(r,1,[n],t)?new c(t[0][0],t[0][1],e||d.WGS84):null}function G(n,e,t){const r=[],o=A(t);if(-1===o)return console.warn(`invalid conversionMode: ${t}`),null;const i=k(e);return u.utmToGeog(i,1,[n],o,r)?new c(r[0][0],r[0][1],e||d.WGS84):null}function p(n,e,t=0){const o=[[n.x,n.y]],i=[],l=k(n.spatialReference);let u=0;switch(e){case"dd":u=r.geogToDd(l,1,o,t,i);break;case"ddm":u=r.geogToDdm(l,1,o,t,i);break;case"dms":u=r.geogToDms(l,1,o,t,i);break;default:return console.warn(`invalid format: ${e}`),null}return u?i[0]:null}function M(n,e,t=0,r=!1){const o=[[n.x,n.y]],i=[],l=k(n.spatialReference);let u=h(e);if(-1===u)return console.warn(`invalid conversionMode: ${e}`),null;r&&(u|=a.PE_MGRS_ADD_SPACES);return a.geogToMgrsExtended(l,1,o,t,!1,u,i)?i[0]:null}function v(n,e=0,t=!1){const r=[[n.x,n.y]],o=[],i=k(n.spatialReference);return l.geogToUsng(i,1,r,e,!1,t,o)?o[0]:null}function R(n,e,t=!1){const r=[[n.x,n.y]],o=[],i=k(n.spatialReference);let l=A(e);if(-1===l)return console.warn(`invalid conversionMode: ${e}`),null;t&&(l|=u.PE_UTM_OPTS_ADD_SPACES);return u.geogToUtm(i,1,r,l,o)?o[0]:null}function k(e){if(e??=d.WGS84,e.wkid){const t=o.geogcs(e.wkid);if(!t)throw new n("coordinate-formatter:invalid-spatial-reference","wkid is not valid");return t}const t=e.wkt2??e.wkt;if(t){const e=o.fromString(i.PE_TYPE_GEOGCS,t);if(!e)throw new n("coordinate-formatter:invalid-spatial-reference","wkt is not valid");return e}throw new n("coordinate-formatter:invalid-spatial-reference","wkid and wkt are missing")}function h(n){switch(n){case"automatic":return a.PE_MGRS_STYLE_AUTO;case"new-180-in-zone-01":return a.PE_MGRS_STYLE_NEW|a.PE_MGRS_180_ZONE_1_PLUS;case"new-180-in-zone-60":return a.PE_MGRS_STYLE_NEW;case"old-180-in-zone-01":return a.PE_MGRS_STYLE_OLD|a.PE_MGRS_180_ZONE_1_PLUS;case"old-180-in-zone-60":return a.PE_MGRS_STYLE_OLD;default:return-1}}function A(n){switch(n){case"latitude-band-indicators":return u.PE_UTM_OPTS_NONE;case"north-south-indicators":return u.PE_UTM_OPTS_NS;default:return-1}}export{m as fromLatitude,g as fromLatitudeLongitude,w as fromLongitude,T as fromMgrs,P as fromUsng,G as fromUtm,_ as isLoaded,S as isSupported,E as load,p as toLatitudeLongitude,M as toMgrs,v as toUsng,R as toUtm};
