/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import e from"../../Graphic.js";import{makeHandle as r,handlesGroup as t}from"../../core/handleUtils.js";import"../../core/has.js";import{throwIfAborted as o}from"../../core/promiseUtils.js";import{watch as a}from"../../core/reactiveUtils.js";import{showProgressCursor as c}from"./workflowUtils.js";async function s({view:s,data:i,signal:l,next:m,cancel:p}){const{creationInfo:u}=i;if(!u)return r();if(!n(u))return r();const{layer:f}=u,y=null!=u.geometryToPlace;if(u.geometryToPlace=null,y)return p(),r();const{Upload:d}=await import("./Upload.js");o(l);const g=new d;i.upload=g;let h=null;const j=()=>h?.remove(),w=t([a(()=>g.state,r=>{switch(r){case"default":case"error":j();break;case"pending":j(),h=c(s);break;case"success":{u.maxFeatures=1;const{result:r}=g;"georeferenced"===r?.type||"georeferenced-reprojected"===r?.type?(u.geometryToPlace=r.mesh,u.initialFeature=new e({geometry:r.mesh,sourceLayer:f}),"3d"===s.type&&s.goTo({target:r.mesh},{animate:!0}).catch(()=>{})):u.geometryToPlace=r?.mesh,j(),m();break}}}),r(()=>{g.cancel(),j()})]);return g.uploadTo(f),w}function n(e){const r=e?.layer;return"scene"===r?.type}export{s as handleModelUpload,n as isModelUpload};
