/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../chunks/_rollupPluginBabelHelpers","../kernel","../../chunks/languageUtils","../featureset/actions/SpatialFilter","../featureset/sources/Empty","../../geometry/Geometry","../../geometry/geometryEngineAsync"],(function(e,t,n,r,i,a,s,u){"use strict";function o(e){return e instanceof s}function l(e,l,c,f){return f(e,l,function(){var e=t._asyncToGenerator((function*(e,t,l){if(l.length<2)throw new Error("Missing Parameters");if(null===(l=r.autoCastFeatureToGeometry(l))[0]&&null===l[1])return!1;if(r.isFeatureSet(l[0])){if(l[1]instanceof s)return new i({parentfeatureset:l[0],relation:c,relationGeom:l[1]});if(null===l[1])return new a({parentfeatureset:l[0]});throw new Error("Spatial Relation cannot accept this parameter type")}if(o(l[0])){if(o(l[1])){switch(c){case"esriSpatialRelEnvelopeIntersects":return u.intersects(n.shapeExtent(l[0]),n.shapeExtent(l[1]));case"esriSpatialRelIntersects":return u.intersects(l[0],l[1]);case"esriSpatialRelContains":return u.contains(l[0],l[1]);case"esriSpatialRelOverlaps":return u.overlaps(l[0],l[1]);case"esriSpatialRelWithin":return u.within(l[0],l[1]);case"esriSpatialRelTouches":return u.touches(l[0],l[1]);case"esriSpatialRelCrosses":return u.crosses(l[0],l[1])}throw new Error("Unrecognised Relationship")}if(r.isFeatureSet(l[1]))return new i({parentfeatureset:l[1],relation:c,relationGeom:l[0]});if(null===l[1])return!1;throw new Error("Spatial Relation cannot accept this parameter type")}if(null!==l[0])throw new Error("Spatial Relation cannot accept this parameter type");return r.isFeatureSet(l[1])?new a({parentfeatureset:l[1]}):!(l[1]instanceof s||null===l[1])&&void 0}));return function(t,n,r){return e.apply(this,arguments)}}())}function c(e){"async"===e.mode&&(e.functions.intersects=function(t,n){return l(t,n,"esriSpatialRelIntersects",e.standardFunctionAsync)},e.functions.envelopeintersects=function(t,n){return l(t,n,"esriSpatialRelEnvelopeIntersects",e.standardFunctionAsync)},e.signatures.push({name:"envelopeintersects",min:"2",max:"2"}),e.functions.contains=function(t,n){return l(t,n,"esriSpatialRelContains",e.standardFunctionAsync)},e.functions.overlaps=function(t,n){return l(t,n,"esriSpatialRelOverlaps",e.standardFunctionAsync)},e.functions.within=function(t,n){return l(t,n,"esriSpatialRelWithin",e.standardFunctionAsync)},e.functions.touches=function(t,n){return l(t,n,"esriSpatialRelTouches",e.standardFunctionAsync)},e.functions.crosses=function(t,n){return l(t,n,"esriSpatialRelCrosses",e.standardFunctionAsync)},e.functions.relate=function(t,n){return e.standardFunctionAsync(t,n,(function(e,t,n){if(n=r.autoCastFeatureToGeometry(n),r.pcCheck(n,3,3),o(n[0])&&o(n[1]))return u.relate(n[0],n[1],r.toString(n[2]));if(n[0]instanceof s&&null===n[1])return!1;if(n[1]instanceof s&&null===n[0])return!1;if(r.isFeatureSet(n[0])&&null===n[1])return new a({parentfeatureset:n[0]});if(r.isFeatureSet(n[1])&&null===n[0])return new a({parentfeatureset:n[1]});if(r.isFeatureSet(n[0])&&n[1]instanceof s)return n[0].relate(n[1],r.toString(n[2]));if(r.isFeatureSet(n[1])&&n[0]instanceof s)return n[1].relate(n[0],r.toString(n[2]));if(null===n[0]&&null===n[1])return!1;throw new Error("Illegal Argument")}))})}e.registerFunctions=c,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
