import{__decorate}from"tslib";import Collection from"@arcgis/core/core/Collection";import{validation}from"../../Validation.js";import{MapProvider}from"./MapProvider.js";import{inline,featuresToArray}from"./tools.js";import{isArcGisApiVersion3x}from"./ArcGisApiVersion.js";import{activate}from"../../Hooks.js";import FeatureLayer from"@arcgis/core/layers/FeatureLayer";let AddFeatureLayer=class{execute(e,r,a){const t=featuresToArray(validation.exists("features",e.features)),o=validation.string("displayName",e.displayName,validation.never),s=validation.array("fields",e.fields,validation.never),n=a.create();return inline(n.load(),function(){let r=void 0;if(isArcGisApiVersion3x){var a=s.filter(e=>"esriFieldTypeOID"===e.type)[0];if(a&&a.name){let e;switch(t[0].geometry.type){case"point":case"multipoint":e="esriGeometryPoint";break;case"polygon":case"extent":e="esriGeometryPolygon";break;case"polyline":e="esriGeometryPolyline"}var a={layerDefinition:{geometryType:e,fields:s,objectIdField:a.name,drawingInfo:{renderer:{type:"simple",symbol:t[0].symbol}}},featureSet:{features:t,geometryType:e}},i={id:o};r=new FeatureLayer(a,i),n.map.addLayer(r)}return{layer:r}}i=s.filter(e=>"oid"===e.type)[0];if(i&&i.name){const e=new Collection;e.addMany(t),r=new FeatureLayer({fields:s,objectIdField:i.name,title:o,source:e}),n.view.map.add(r)}return{layer:r}})}};AddFeatureLayer.action="gcx:wf:arcgis::AddFeatureLayer",AddFeatureLayer.suite="gcx:wf:builtin",AddFeatureLayer=__decorate([activate(MapProvider)],AddFeatureLayer);export{AddFeatureLayer};