/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
var n=Math.PI,t=Math.sin,r=Math.cos,e=Math.tan,u=Math.asin,o=Math.atan2,a=Math.acos,i=n/180,c=864e5,f=2440588,d=2451545,s={dec:0,ra:0};function M(n){return n.valueOf()/c-.5+f}function h(n){return new Date((n+.5-f)*c)}function l(n){return M(n)-d}var v=23.4397*i;function p(n,u){return o(t(n)*r(v)-e(u)*t(v),r(n))}function N(n,e){return u(t(e)*r(v)+r(e)*t(v)*t(n))}function P(n,u,a){return o(t(n),r(n)*t(u)-e(a)*r(u))}function x(n,e,o){return u(t(e)*t(o)+r(e)*r(o)*r(n))}function E(n,t){return i*(280.16+360.9856235*n)-t}function I(n){return i*(357.5291+.98560028*n)}function O(n){return i*(1.9148*t(n)+.02*t(2*n)+3e-4*t(3*n))}function T(t,r){return t+r+102.9372*i+n}function g(n,t){var r=I(n),e=T(r,O(r));return t||(t={dec:0,ra:0}),t.dec=N(e,0),t.ra=p(e,0),t}var m={PolarException:{NORMAL:0,MIDNIGHT_SUN:1,POLAR_NIGHT:2},getPosition:function(n,t,r,e){var u=i*-r,o=i*t,a=l(n),c=g(a,s),f=E(a,u)-c.ra;return e||(e={azimuth:0,altitude:0}),e.azimuth=P(f,o,c.dec),e.altitude=x(f,o,c.dec),e}},A=[[-.83,"sunrise","sunset"]];m.addTime=function(n,t,r){A.push([n,t,r])};var L=9e-4;function R(t,r){return Math.round(t-L-r/(2*n))}function G(t,r,e){return L+(t+r)/(2*n)+e}function H(n,r,e){return d+n+.0053*t(r)-.0069*t(2*e)}function _(n,e,u){return a((t(n)-t(e)*t(u))/(r(e)*r(u)))}function z(n){var e=i*(134.963+13.064993*n),u=i*(93.272+13.22935*n),o=i*(218.316+13.176396*n)+6.289*i*t(e),a=5.128*i*t(u),c=385001-20905*r(e);return{ra:p(o,a),dec:N(o,a),dist:c}}m.getTimes=function(n,e,u){var o=i*-u,a=i*e,c=R(l(n),o),f=G(0,o,c),d=I(f),s=O(d),M=T(d,s),v=N(M,0),p=H(f,d,M);function P(n){return H(G(_(n,a,v),o,c),d,M)}function x(n){var e=(t(n)-t(a)*t(v))/(r(a)*r(v));return e<-1?m.PolarException.MIDNIGHT_SUN:e>1?m.PolarException.POLAR_NIGHT:m.PolarException.NORMAL}var E,g,L,z,D,S={solarNoon:h(p),nadir:h(p-.5),polarException:m.PolarException.NORMAL};for(E=0,g=A.length;E<g;E+=1)D=p-((z=P((L=A[E])[0]*i))-p),S[L[1]]=h(D),S[L[2]]=h(z);return S.polarException=x(A[0][0]*i),S},m.getMoonPosition=function(n,t,r){var u=i*-r,o=i*t,a=l(n),c=z(a),f=E(a,u)-c.ra,d=x(f,o,c.dec);return d+=.017*i/e(d+10.26*i/(d+5.1*i)),{azimuth:P(f,o,c.dec),altitude:d,distance:c.dist}},m.getMoonFraction=function(n){var e=l(n),u=g(e),i=z(e),c=149598e3,f=a(t(u.dec)*t(i.dec)+r(u.dec)*r(i.dec)*r(u.ra-i.ra)),d=o(c*t(f),i.dist-c*r(f));return(1+r(d))/2};export{m as S};
