"use strict";function i(e,s,r={}){const n={type:"Feature"};return(r.id===0||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=s||{},n.geometry=e,n}function u(e,s,r={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!a(e[0])||!a(e[1]))throw new Error("coordinates must contain numbers");return i({type:"Point",coordinates:e},s,r)}function c(e,s,r={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let o=0;o<t[t.length-1].length;o++)if(t[t.length-1][o]!==t[0][o])throw new Error("First and last Position are not equivalent.")}return i({type:"Polygon",coordinates:e},s,r)}function a(e){return!isNaN(e)&&e!==null&&!Array.isArray(e)}async function l(e){if(!e.trim())return null;const r=await(await fetch(`https://api.phila.gov/ais/v1/search/${encodeURIComponent(e)}?include_units=false`)).json();return r.features&&r.features.length>0?r:null}async function f(e,s){const r=new URLSearchParams({geometry:JSON.stringify({x:e,y:s}),geometryType:"esriGeometryPoint",inSR:"4326",spatialRel:"esriSpatialRelIntersects",outFields:"parcelid,address",returnGeometry:"false",f:"json"}),t=await(await fetch(`https://services.arcgis.com/fLeGjb7u4uXqeF9q/ArcGIS/rest/services/PWD_PARCELS/FeatureServer/0/query?${r}`)).json();if(t.features&&t.features.length>0){const o=t.features[0].attributes;return{parcelId:o.parcelid||null,address:o.address||null}}return null}async function g(e){const s=new URLSearchParams({where:`parcelid = ${e}`,outFields:"parcelid",returnGeometry:"true",outSR:"4326",f:"json"}),n=await(await fetch(`https://services.arcgis.com/fLeGjb7u4uXqeF9q/ArcGIS/rest/services/PWD_PARCELS/FeatureServer/0/query?${s}`)).json();if(n.features&&n.features.length>0){const t=n.features[0],o=t.geometry.rings;return{type:"FeatureCollection",features:[c(o,{parcelid:t.attributes.parcelid})]}}return null}exports.fetchParcelGeometry=g;exports.geocodeAddress=l;exports.point=u;exports.queryParcelAtPoint=f;
