/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../chunks/_rollupPluginBabelHelpers","../../chunks/tslib.es6","../../core/maybe","../../core/Logger","../../core/accessorSupport/ensureType","../../core/arrayUtils","../../core/has","../../core/accessorSupport/set","../../core/accessorSupport/decorators/subclass","./CreateWorkflowData","./Edits","./Workflow","./workflowUtils"],(function(e,t,r,a,o,i,n,s,l,u,c,d,f){"use strict";var w;let p=w=function(t){function a(e){var r;return(r=t.call(this,e)||this).type="create",r}return e._inheritsLoose(a,t),a.create=function(t,r,a){const o=new w({data:new u({edits:new c.Edits,viewModel:t}),onCommit:(i=e._asyncToGenerator((function*(e){yield a(e.creationInfo.layer,{addFeatures:[e.edits.feature]})})),function(e){return i.apply(this,arguments)})});var i;return o._set("steps",this._createWorkflowSteps(o,r)),o},a._createWorkflowSteps=function(t,a="awaiting-feature-creation-info"){const{data:o,handles:i}=t,n=new Map,s={"awaiting-feature-creation-info":()=>({id:"awaiting-feature-creation-info",setUp(){var t=this;return e._asyncToGenerator((function*(){o.creationInfo=null,o.edits.feature=null,o.viewModel.featureTemplatesViewModel.select(null),i.add(o.viewModel.featureTemplatesViewModel.on("select",(({item:e})=>{o.creationInfo={layer:e.layer,template:e.template},o.viewModel.activeWorkflow.next()})),t.id)}))()},tearDown(){var t=this;return e._asyncToGenerator((function*(){i.remove(t.id)}))()}}),"awaiting-feature-to-create":()=>({id:"awaiting-feature-to-create",setUp(){var t=this;return e._asyncToGenerator((function*(){i.add(yield f.setUpFeatureAdd(o.viewModel.sketchViewModel,o.creationInfo,(e=>{o.edits.feature=e,o.viewModel.activeWorkflow.next()}),n),t.id)}))()},tearDown(){var t=this;return e._asyncToGenerator((function*(){i.remove(t.id)}))()}}),"editing-new-feature":()=>({id:"editing-new-feature",setUp(){var t=this;return e._asyncToGenerator((function*(){const a=o.edits.feature,s=a.sourceLayer,l=o.viewModel,u=l.sketchViewModel,c=f.findLayerInfo(l.layerInfos,s),d=null==c?void 0:c.formTemplate,{spatialReference:w}=l.view;l.featureFormViewModel.set({feature:a,formTemplate:d,spatialReference:w}),u.allowDeleteKey=!1;const p=f.getVisualVariableAttributes(a);yield f.startUpdatingFeature(u,a,s,p,n);const v=u.on("update",function(){var t=e._asyncToGenerator((function*(e){const t=e.graphics[0];if("complete"===e.state)return f.startUpdatingFeature(u,t,s,p,n);yield f.visualVariableInteractiveUpdate(u.view,t,e,p,n);const a=t.attributes;if(r.isSome(p.rotation)){const{field:e}=p.rotation;l.featureFormViewModel.setValue(e,a[e])}if(r.isSome(p.size)){const{field:e}=p.size;l.featureFormViewModel.setValue(e,a[e])}}));return function(e){return t.apply(this,arguments)}}());i.add([o.viewModel.featureFormViewModel.on("value-change",e._asyncToGenerator((function*(){o.edits.updateAttributes(o.viewModel.featureFormViewModel.getValues()),a.attributes=o.edits.feature.attributes,"3d"===u.view.type&&(yield f.updateGraphicSymbolWhenRequired(a,n))}))),v],t.id)}))()},tearDown(t){var r=this;return e._asyncToGenerator((function*(){t.cancelled&&o.viewModel.sketchViewModel.layer.removeAll(),i.remove(r.id)}))()}})},l=f.createWorkflowSteps(["awaiting-feature-creation-info","awaiting-feature-to-create","editing-new-feature"],a,s);return f.avoidFeatureTemplateSelectionWithOnlyOneItem(o,l)},a}(d);p=w=t.__decorate([l.subclass("esri.widgets.Editor.CreateWorkflow")],p);return p}));
