/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{createTask as t}from"../../../core/asyncUtils.js";import{throwIfAborted as r,throwIfNotAbortError as e,isAborted as s,isAbortError as i}from"../../../core/promiseUtils.js";import{whenOnce as a}from"../../../core/reactiveUtils.js";import{diff as o}from"../../../core/accessorSupport/diffUtils.js";import{isGraphicsLayer as n,isSceneLayer as c}from"../../../layers/support/layerUtils.js";import{getDisplayedSymbol as l}from"../../../symbols/support/symbolUtils.js";import{GraphicState as u}from"../../3d/layers/graphics/GraphicState.js";async function y(t,e,s,i){const a=e.createQuery();a.objectIds=t,a.outFields=["*"],a.returnM=e.capabilities.data.supportsM,a.returnZ=e.capabilities.data.supportsZ,a.returnGeometry=!0,c(e)&&null!=e.infoFor3D||(a.outSpatialReference=s),!c(e)&&e.capabilities?.data.supportsTrueCurve&&(a.returnTrueCurves=!0);const o=await e.queryFeatures(a,{signal:i});return r(i),o.features}async function p(t,e,s){const i=await l(t,{useSourceLayer:!0,ignoreGraphicSymbol:!0,scale:e});r(s);null!=o(t.symbol,i)&&(t.symbol=i)}async function d(o,c,l,u,y){r(y),o.graphics.includes(u)||o.add(u);const p=l.sourceLayer,d=l.layer??p,b=l.getObjectId();let h=null,w=null;function g(e){return h?.abort(),n(d)?(l.visible=e,Promise.resolve()):(h=t(async t=>{const i=await m(c,d);if(r(t),i&&!c.destroyed&&!i.destroyed)try{null!=b&&"number"==typeof b&&"setVisibility"in i&&i.setVisibility?.(b,e)}catch(a){if(s(t)||c.destroyed||i.destroyed)return;throw a}}),h.promise)}async function v(){return w||(w=(async()=>{try{await g(!0);const t=c.destroyed?null:await m(c,d).catch(()=>{});t&&!t.destroyed&&await a(()=>!t.updating)}catch(t){if(t&&!i(t))throw t}finally{o.remove(u)}})(),c.addUpdatingPromise(w).catch(e),w)}try{await f(c,u,y),r(y),g(!1).catch(e)}catch(S){throw await v(),S}const j=async()=>v();return{remove:j,[Symbol.asyncDispose]:()=>j()}}async function m(t,r){if(!r||"building-component"===r.type)return;const e="subtype-sublayer"===r.type?r.parent:r;return e?t.whenLayerView(e):void 0}async function f(t,r,e){if("3d"===t.type){const s=new u({graphic:r}),i=t.trackGraphicState(s);try{await a(()=>s.displaying||s.error,e)}finally{i.remove()}}else await a(()=>r.visible,e)}export{y as fetchFullFeaturesByObjectId,d as swapForEditingSession,p as updateGraphicSymbolWhenRequired};
