/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{ArcadeExecutionError as e}from"../executionError.js";import{shapeExtent as t}from"../kernel.js";import{C as n,B as r,h as i,s as a,m as s}from"../../chunks/languageUtils.js";import o from"../featureset/actions/SpatialFilter.js";import l from"../featureset/sources/Empty.js";import{invokeRemoteGeometryOp as u}from"../geometry/operatorsWorkerConnection.js";function c(a){return async(c,f,p)=>{if(r(p,2,2,c,f),null===(p=n(p))[0]&&null===p[1])return!1;if(s(p[0])){if(i(p[1]))return new o({parentfeatureset:p[0],relation:a,relationGeom:p[1]});if(null===p[1])return new l({parentfeatureset:p[0]});throw new e(c,"InvalidParameter",f)}if(i(p[0])){if(i(p[1])){switch(a){case"esriSpatialRelEnvelopeIntersects":{const e=t(p[0]),n=t(p[1]);return null!=e&&null!=n&&u("intersects",[e.toJSON(),n.toJSON()])}case"esriSpatialRelIntersects":return u("intersects",[p[0].toJSON(),p[1].toJSON()]);case"esriSpatialRelContains":return u("contains",[p[0].toJSON(),p[1].toJSON()]);case"esriSpatialRelOverlaps":return u("overlaps",[p[0].toJSON(),p[1].toJSON()]);case"esriSpatialRelWithin":return u("within",[p[0].toJSON(),p[1].toJSON()]);case"esriSpatialRelTouches":return u("touches",[p[0].toJSON(),p[1].toJSON()]);case"esriSpatialRelCrosses":return u("crosses",[p[0].toJSON(),p[1].toJSON()])}throw new e(c,"InvalidParameter",f)}if(s(p[1]))return new o({parentfeatureset:p[1],relation:a,relationGeom:p[0]});if(null===p[1])return!1;throw new e(c,"InvalidParameter",f)}if(null===p[0]){if(s(p[1]))return new l({parentfeatureset:p[1]});if(i(p[1])||null===p[1])return!1}throw new e(c,"InvalidParameter",f)}}function f(t){"async"===t.mode&&(t.functions.intersects=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelIntersects"))},t.functions.envelopeintersects=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelEnvelopeIntersects"))},t.signatures.push({name:"envelopeintersects",min:2,max:2}),t.functions.contains=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelContains"))},t.functions.overlaps=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelOverlaps"))},t.functions.within=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelWithin"))},t.functions.touches=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelTouches"))},t.functions.crosses=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelCrosses"))},t.functions.relate=function(c,f){return t.standardFunctionAsync(c,f,async(t,p,S)=>{if(S=n(S),r(S,3,3,c,f),i(S[0])&&i(S[1]))return u("relate",[S[0].toJSON(),S[1].toJSON(),a(S[2])]);if(i(S[0])&&null===S[1])return!1;if(i(S[1])&&null===S[0])return!1;if(s(S[0])&&null===S[1])return new l({parentfeatureset:S[0]});if(s(S[1])&&null===S[0])return new l({parentfeatureset:S[1]});if(s(S[0])&&i(S[1]))return new o({parentfeatureset:S[0],relation:"esriSpatialRelRelation",relationGeom:S[1],relationString:a(S[2])});if(s(S[1])&&i(S[0]))return new o({parentfeatureset:S[1],relation:"esriSpatialRelRelation",relationGeom:S[0],relationString:a(S[2])});if(null===S[0]&&null===S[1])return!1;throw new e(c,"InvalidParameter",f)})})}export{f as registerFunctions};
