import{validation}from"../../Validation.js";import{featuresToArray,isFeatureSet}from"./tools.js";import{isArcGisApiVersion3x}from"./ArcGisApiVersion.js";function removeAttributes(e,t){const i=e.attributes;for(const s of t)delete i[s];isArcGisApiVersion3x?e.setAttributes(i):e.attributes=i}class RemoveFeatureSetFields{execute(e,t){const i=featuresToArray(validation.exists("features",e.features)),s=validation.array("fields",e.fields,[]);var r=validation.boolean("removeEmptyFields",e.removeEmptyFields,!1);const o={};for(const d of i){var a,l=d.attributes;if(null!=l&&(removeAttributes(d,s),r))for(const c in l)c in o||(o[c]=!1),o[c]||null!=(a=l[c])&&""!==a&&(o[c]=!0)}let f=[];if(r&&(f=Object.keys(o).filter(e=>!o[e]&&-1===s.indexOf(e)),0<f.length))for(const m of i){var n=m.attributes;null!=n&&removeAttributes(m,f)}if(isFeatureSet(e.features)){const v=e.features,A=[...s,...f];if(v.fields&&(v.fields=v.fields.filter(e=>-1===A.indexOf(e.name))),v.fieldAliases){var u=v.fieldAliases;for(const F of A)delete v.fieldAliases[F];v.fieldAliases=u}}u=i.slice(0);return{feature:u[0],features:u}}}RemoveFeatureSetFields.action="gcx:wf:arcgis::RemoveFeatureSetFields",RemoveFeatureSetFields.suite="gcx:wf:builtin";export{RemoveFeatureSetFields};