import*as t from"fs";import*as i from"path";import{decode as r}from"geobuf";import e from"@turf/boolean-point-in-polygon";import{point as o}from"@turf/helpers";import f from"pbf";var n=[{tzid:"Etc/GMT-12",left:172.5,right:180},{tzid:"Etc/GMT-11",left:157.5,right:172.5},{tzid:"Etc/GMT-10",left:142.5,right:157.5},{tzid:"Etc/GMT-9",left:127.5,right:142.5},{tzid:"Etc/GMT-8",left:112.5,right:127.5},{tzid:"Etc/GMT-7",left:97.5,right:112.5},{tzid:"Etc/GMT-6",left:82.5,right:97.5},{tzid:"Etc/GMT-5",left:67.5,right:82.5},{tzid:"Etc/GMT-4",left:52.5,right:67.5},{tzid:"Etc/GMT-3",left:37.5,right:52.5},{tzid:"Etc/GMT-2",left:22.5,right:37.5},{tzid:"Etc/GMT-1",left:7.5,right:22.5},{tzid:"Etc/GMT",left:-7.5,right:7.5},{tzid:"Etc/GMT+1",left:-22.5,right:-7.5},{tzid:"Etc/GMT+2",left:-37.5,right:-22.5},{tzid:"Etc/GMT+3",left:-52.5,right:-37.5},{tzid:"Etc/GMT+4",left:-67.5,right:-52.5},{tzid:"Etc/GMT+5",left:-82.5,right:-67.5},{tzid:"Etc/GMT+6",left:-97.5,right:-82.5},{tzid:"Etc/GMT+7",left:-112.5,right:-97.5},{tzid:"Etc/GMT+8",left:-127.5,right:-112.5},{tzid:"Etc/GMT+9",left:-142.5,right:-127.5},{tzid:"Etc/GMT+10",left:-157.5,right:-142.5},{tzid:"Etc/GMT+11",left:-172.5,right:-157.5},{tzid:"Etc/GMT+12",left:-180,right:-172.5}];function d(t){if(-180===t||180===t)return["Etc/GMT+12","Etc/GMT-12"];for(var i=[],r=0;r<n.length;r++){var e=n[r];if(e.left<=t&&e.right>=t)i.push(e.tzid);else if(e.right<t)break}return i}var a,l=require("../data/index.json"),c=i.join(__dirname,"..","data","geo.dat");function h(i){if(a=i&&i.store&&"function"==typeof i.store.get&&"function"==typeof i.store.set?i.store:new Map,i&&i.preload){var r=t.openSync(c,"r");if(r<0)throw new Error("Failed to open geo.dat file");!function(t){!function i(r,e){if(r.pos>=0&&r.len){var o=g(0,r.pos,r.len,t);a.set(e,o)}else"object"==typeof r&&Object.getOwnPropertyNames(r).forEach(function(t){i(r[t],e+t)})}(l.lookup,"")}(r),t.closeSync(r)}}function g(i,e,o,n){void 0===n&&(n=-1);var d=n;if(d<0&&(d=t.openSync(c,"r"))<0)throw new Error("Failed to open geo.dat file");var a=Buffer.alloc(o),l=t.readSync(d,a,0,o,e);if(n<0&&t.closeSync(d),l<o)throw new Error("tried to read "+o+" bytes from geo.dat but only got "+l+" bytes");var h=new f(a);return r(h)}function p(t,i){var r=i;if(isNaN(t)||t>90||t<-90)throw new Error("Invalid latitude: "+t);if(isNaN(i)||i>180||i<-180)throw new Error("Invalid longitude: "+i);if(90===t)return n.map(function(t){return t.tzid});t>=89.9999?t=89.9999:t<=-89.9999&&(t=-89.9999),i>=179.9999?i=179.9999:i<=-179.9999&&(i=-179.9999);for(var f=o([i,t]),c={top:89.9999,bottom:-89.9999,left:-179.9999,right:179.9999,midLat:0,midLon:0},h="",p=l.lookup;;){var m=void 0;if(t>=c.midLat&&i>=c.midLon?(m="a",c.bottom=c.midLat,c.left=c.midLon):t>=c.midLat&&i<c.midLon?(m="b",c.bottom=c.midLat,c.right=c.midLon):t<c.midLat&&i<c.midLon?(m="c",c.top=c.midLat,c.right=c.midLon):(m="d",c.top=c.midLat,c.left=c.midLon),h+=m,!(p=p[m]))return d(r);if(p.pos>=0&&p.len){var u=a.get(h);u||(u=g(0,p.pos,p.len),a.set(h,u));for(var s=[],E=0;E<u.features.length;E++)e(f,u.features[E])&&s.push(u.features[E].properties.tzid);return s.length>0?s:d(r)}if(p.length>0)return p.map(function(t){return l.timezones[t]});if("object"!=typeof p)throw new Error("Unexpected data type");c.midLat=(c.top+c.bottom)/2,c.midLon=(c.left+c.right)/2}}function m(){h({preload:!0})}h();export{p as default,m as preCache,h as setCache};
//# sourceMappingURL=geo-tz.module.js.map
