/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import e from"../../core/Error.js";import{throwIfAborted as o}from"../../core/promiseUtils.js";import{fetchFullFeaturesByObjectId as i,updateGraphicSymbolWhenRequired as s,swapForEditingSession as t}from"../../views/draw/support/editingSessionUtils.js";async function n(n){const{graphicsLayer:a,graphic:c,signal:p,view:u}=n,d=c.sourceLayer;if(!r(d))throw new e("editing-session:unsupported-layer","The graphic source layer does not support editing sessions.");const l=c.getObjectId();if(null==l)throw new e("editing-session:missing-object-id","The graphic does not have an object id and cannot be used for an editing session.");const g=await i([l],d,u.spatialReference,p);if(o(n),1!==g.length)throw new e("editing-session:feature-not-found","Unable to resolve exactly one feature for the provided graphic.");const f=g[0],h="2d"===u.type?u.scale:null;await s(f,h,p),o(n);const w=await t(a,u,c,f,p),y=()=>w.remove();return{graphic:f,remove:y,[Symbol.asyncDispose]:y}}function r(e){return null!=e&&"object"==typeof e&&"createQuery"in e&&"queryFeatures"in e}export{n as openEditingSession};
