/* COPYRIGHT Esri - https://js.arcgis.com/1.2/LICENSE.txt */
import c from"./T2ZUVHM7.js";import a from"./HUJP6DFF.js";import{a as L}from"./XN2LWKJE.js";import"./4BPRM7CL.js";import"./NIL6NWG5.js";import{b}from"./ODCCVHGI.js";import{F as m,G as u,H as v,J as f,h as y,i as p,r as d,u as M}from"./42WFQ3AX.js";import"./3QPJ2JCA.js";export default $arcgis.t(([E,C,F,k,A,T,x,I,h,,{d:w,e:V}])=>{var P=y`@layer{
/** @license
 * Copyright 2025 Esri
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

:host {
  display: block;
}

/* Override to hide Editor settings panel collapsible */
.hide-editor-toolbar .esri-editor__panel-toolbar {
  display: none !important;
}

/* Override to reduce the padding of panel content*/
.esri-editor__panel-content {
  padding-block: 0px !important;
}

/* Override to hide header */
.esri-editor .esri-item-list__group__header {
  display: none !important;
}

/* Override to hide the create feature heading title */
.esri-editor__panel-content__section .esri-widget__heading {
  display: none !important;
}

/* Override to reduce padding for the template filter*/
.esri-editor .esri-item-list__filter-container--sticky {
  padding-block: 0px !important;
  padding-inline: 10px !important;
}

.search-widget {
  width: 92% !important;
  margin: 5px 14px 20px 14px;
}

.display-none {
  display: none !important;
}

.hide-map {
  height: 1%;
  visibility: hidden;
}

.show-map {
  padding: 10px !important;
  position: absolute !important;
  bottom: 0;
  height: auto !important;
  width: calc(100% - 22px);
}

.notice-msg {
  padding: 10px;
  width: calc(100% - 20px);
}

.edit-location-btn {
  margin: 5px;
  display: flex;
}

/* override the padding of the feature form */
.esri-editor__panel-content {
  padding-block: 10px !important;
}

/* overide css for editor widget in case of mobile */
@media only screen and (max-width: 600px) {
  .esri-editor__panel-content {
    padding-block: 0 !important;
    min-height: 0 !important;
  }
}
}`,g=class extends v{constructor(){super(...arguments),this.customizeSubmit=!1,this.enableSearch=!1,this.enableSnapping=!1,this.floorLevel="",this.isMobile=!1,this.selectedLayerId="",this.showGuidingMsg=!0,this.submitNewReportsMessage="",this.updateMapPosition=!1,this.reportingArea=!1,this.reportingAreaLayer="",this.reportingAreaMessage="",this.showSketchWidgets=!1,this.allowMultipleCreation=!1,this.popupEnabled=!1,this.showLayerVisibilityMsg=!1,this._currentPage="templatePicker",this._editorLoading=!1,this._inValidGeomtryDrawn=!1,this._translations=L({name:"create-feature",blocking:!0}),this._addingAttachment=!1,this._calciteNotice=m(),this._isSubmitBtnClicked=!1,this._mapViewContainer=m(),this._searchDiv=m(),this._guidingMessageRefNode=m(),this.success=d(),this.fail=d(),this.drawComplete=d(),this.editingLocation=d(),this.editingAttachment=d(),this.progressStatus=d(),this.modeChanged=d()}static{this.properties={customizeSubmit:[5,{},{type:Boolean}],enableSearch:[5,{},{type:Boolean}],enableSnapping:[5,{},{type:Boolean}],floorLevel:1,formElements:1,isMobile:[5,{},{type:Boolean}],mapView:[0,{},{attribute:!1}],searchConfiguration:[0,{},{attribute:!1}],selectedLayerId:1,showGuidingMsg:[5,{},{type:Boolean}],submitNewReportsMessage:1,updateMapPosition:[5,{},{type:Boolean}],reportingArea:[5,{},{type:Boolean}],reportingAreaLayer:1,reportingAreaMessage:1,showSketchWidgets:[5,{},{type:Boolean}],allowMultipleCreation:[5,{},{type:Boolean}],popupEnabled:[5,{},{type:Boolean}],showLayerVisibilityMsg:[5,{},{type:Boolean}],_currentPage:[16,{},{state:!0}],_editorLoading:[16,{},{state:!0}],_inValidGeomtryDrawn:[16,{},{state:!0}],_translations:[16,{},{state:!0}]}}static{this.styles=P}static{this.shadowRootOptions=M}willUpdate(e){e.has("mapView")&&this.hasUpdated&&this.mapViewWatchHandler(),e.has("isMobile")&&this.hasUpdated&&this.isMobileHandler(),e.has("_editorLoading")&&(this.hasUpdated||this._editorLoading!==!1)&&this._editorLoadingWatchHandler(this._editorLoading)}async mapViewWatchHandler(){this.mapView&&await this.mapView.when(async()=>{await this.init()})}async isMobileHandler(){this.modeChanged.emit()}async _editorLoadingWatchHandler(e){if(e){if(this._container?.classList.add("display-none"),this._selectedLayer?.isTable){if(this._selectedLayer.templates&&this._editor){let t=this._selectedLayer.templates[0],r={layer:this._selectedLayer,template:t};await this._editor.startCreateFeaturesWorkflowAtFeatureCreation(r),await this.hideEditorsElements()}}else await this.startCreate();this._container?.classList.remove("display-none"),this._editorLoading=!1}}async submit(){this._editor?.viewModel?.featureFormViewModel&&(this._isSubmitBtnClicked=!0,this._editor.viewModel.featureFormViewModel.submit())}async refresh(e){this._editor&&(e?await this._setFloorLevel(e):this.reportingArea&&this.reportingAreaLayer&&this._currentPage!=="drawing"?await this.queryIntersectingFeatures():this._currentPage!=="drawing"&&(this._inValidGeomtryDrawn=!1,this.drawComplete.emit(this._inValidGeomtryDrawn)))}async showForm(){this.progressStatus.emit(100),this._container?.classList.remove("display-none"),this._mapViewContainer.value?.classList?.replace("show-map","hide-map"),this._currentPage="featureForm"}async loaded(){await this.init()}async updated(){if(this.isMobile&&this.updateMapPosition){let e=this._currentPage==="drawing"?80:30,t=this.enableSearch?this._searchDiv.value?.offsetHeight:0;await this._calciteNotice.value?.componentOnReady();let i=(this._calciteNotice.value?.offsetHeight||0)+t+e;this._mapViewContainer.value&&(this._mapViewContainer.value.style.top=`${i}px`)}this.reportingAreaMessage&&this._guidingMessageRefNode.value?.children[0]&&(this._guidingMessageRefNode.value.children[0].style.margin="0px")}disconnectedCallback(){super.disconnectedCallback(),this._editor&&(this._editor.viewModel.sketchViewModel&&this._editor.viewModel.sketchViewModel?.destroy(),this._editor.destroy(),this.enableSnapping&&this.mapView?.ui.view&&((this.mapView?.ui.view).grid=null))}render(){let e=this._currentPage==="drawing"||this._currentPage==="editing"?"":"display-none",t=this._editorLoading?"":"display-none",r=this._editorLoading?"display-none":"",i=this.isMobile&&this.updateMapPosition?"show-map":"display-none",s=this._inValidGeomtryDrawn?"danger":"success",l=this._inValidGeomtryDrawn?"exclamation-mark-triangle":"lightbulb",a=this.showLayerVisibilityMsg&&this._currentPage==="templatePicker",n=this.showGuidingMsg||a,o=this._translations.chooseCategoryMsg;return this._inValidGeomtryDrawn?o=this.reportingAreaMessage||this._translations.reportOutsideAreaMessage:this._currentPage==="drawing"||this._currentPage==="editing"?o=this._translations.provideLocationMsg:this._currentPage==="featureForm"?o=this._translations.provideDetailsMsg:a&&(o=this._translations.enableFeatureTemplatesMessage),p`${n&&p`<calcite-notice class="notice-msg" .icon=${l} .kind=${s} open ${u(this._calciteNotice)}><div slot=message .innerHTML=${o??""} ${u(this._guidingMessageRefNode)}></div></calcite-notice>`||""}<calcite-loader class=${f(t)} label scale=s></calcite-loader>${this._currentPage==="featureForm"&&this.isMobile&&p`<calcite-button appearance=transparent class="edit-location-btn" icon-start=pin @click=${this.editLocation}>${this._translations.editLocationLabel}</calcite-button>`||""}<div class=${f(r)} id=feature-form></div>${this.enableSearch&&p`<div class=${`search-widget ${e} ${r}`} id=search-widget-ref ${u(this._searchDiv)}></div>`||""}<div class=${f(i)} ${u(this._mapViewContainer)}></div>`}async init(){this.mapView&&this.selectedLayerId&&(this._updatedMapView=this.mapView,await(this.isMobile&&this.updateMapPosition?this.createMobileMapView():this._loadWidgets()))}async createMobileMapView(){this._mapViewContainer.value&&this.mapView&&(this._mapViewContainer.value.classList.add("hide-map"),await new T({map:this.mapView.map,container:this._mapViewContainer.value,zoom:this.mapView.zoom,center:this.mapView.center,popupEnabled:this.popupEnabled}).when(e=>{this._updatedMapView=e;let t=new x({view:this._updatedMapView});t&&this._updatedMapView.ui.add(t,"top-left"),this._loadWidgets()},e=>{console.log(e)}))}async _loadWidgets(){await this.createEditorWidget(),this.enableSearch&&await this.createSearchWidget()}async createEditorWidget(){this._editor&&this._editor.destroy();let e=[];this._container=document.createElement("div"),this._container?.classList.add("display-none"),this.enableSnapping||this._container.classList.add("hide-editor-toolbar");let t=this._updatedMapView&&await V(this._updatedMapView),r=this.mapView&&await w(this.mapView,this.selectedLayerId);if(r&&(this._selectedLayer=r,!this._selectedLayer?.isTable&&t&&t.forEach(i=>{e.push({layer:i,enabled:i?.type==="feature"&&i?.id===this.selectedLayerId,addEnabled:!0,updateEnabled:!1,deleteEnabled:!1})})),this._editor=new E({view:this._updatedMapView,layerInfos:e,visibleElements:{settingsMenu:this.enableSnapping,snappingControls:this.enableSnapping,createFeaturesSection:!0,editFeaturesSection:!1,flow:!0,sketch:this.showSketchWidgets&&this._selectedLayer?.geometryType!=="point"},container:this._container}),this._mapViewContainer.value?this.el.insertBefore(this._container,this._mapViewContainer.value):this.el.appendChild(this._container),this._selectedLayer?.isTable&&(this._editorLoading=!0),this._editor){let i=h.watch(()=>this._editor?.viewModel.state,o=>{o==="adding-attachment"||o==="editing-attachment"?(this._addingAttachment=!0,this.editingAttachment.emit(!0)):this._addingAttachment&&(this.editingAttachment.emit(!1),this._addingAttachment=!1)});i&&this._editor.viewModel.addHandles(i);let s=h?.watch(()=>this._editor?.viewModel.featureTemplatesViewModel.state,o=>{o==="ready"&&this._editor?.viewModel?.activeWorkflow?.type!=="create-features"&&(this.progressStatus.emit(50),this._editorLoading=!0)});s&&this._editor.viewModel.addHandles(s);let l=h?.watch(()=>this._editor?.viewModel.featureFormViewModel?.state,o=>{o==="ready"&&this._editor?.viewModel.featureFormViewModel&&this._currentPage!=="editing"&&(this._mapViewContainer.value?.classList?.replace("show-map","hide-map"),this._editor.viewModel.featureFormViewModel.addHandles(this._editor.viewModel.featureFormViewModel.on("submit",this.submitted.bind(this))),setTimeout(()=>{this._setFloorLevel(this.floorLevel)},50),!this.allowMultipleCreation&&this._editor.activeWorkflow&&(this._editor.activeWorkflow.data.creationInfo.maxFeatures=1),this._currentPage="featureForm",this.progressStatus.emit(100),this.drawComplete.emit(!1))});l&&this._editor.viewModel.addHandles(l);let a=h.watch(()=>this._editor?.viewModel.state,o=>{o==="creating-features"&&this._editor?.viewModel.featureFormViewModel&&this._editor.viewModel.featureFormViewModel.state==="disabled"&&(this._mapViewContainer.value?.classList?.replace("hide-map","show-map"),this._selectedLayer&&!this._selectedLayer.isTable&&(this._currentPage="drawing"))});a&&this._editor.viewModel.addHandles(a),this._editor.on("sketch-create",async o=>{o.detail.state==="complete"&&(this._drawnGeometry=o.detail.graphic?.geometry,this.reportingArea&&this.reportingAreaLayer&&await this.queryIntersectingFeatures())});let n;this._editor.on("sketch-update",o=>{clearTimeout(n),n=window.setTimeout(async()=>{this._drawnGeometry=o.detail.graphics[0].geometry,this.reportingArea&&this.reportingAreaLayer&&await this.queryIntersectingFeatures()},50)})}}async queryIntersectingFeatures(){let e=this.mapView&&await w(this.mapView,this.reportingAreaLayer);if(e){let t=e.createQuery();t.geometry=this._drawnGeometry,t.spatialRelationship="intersects";let i=await e.queryFeatureCount(t)===0;this._inValidGeomtryDrawn=i,this.drawComplete.emit(this._inValidGeomtryDrawn)}}editLocation(){this.progressStatus.emit(75),this.editingLocation.emit(),this._container?.classList.add("display-none"),this._mapViewContainer.value?.classList.replace("hide-map","show-map"),this._currentPage="editing"}async startCreate(){return await this.hideEditorsElements(),new Promise((e,t)=>{if(this._editor?.viewModel.featureTemplatesViewModel.items?.length){let r=this._editor.viewModel.featureTemplatesViewModel.items[0].items;this._editor.viewModel.featureTemplatesViewModel.addHandles(this._editor.viewModel.featureTemplatesViewModel.on("select",()=>{this.progressStatus.emit(75),setTimeout(()=>{this.hideEditorsElements().then(()=>{e({})},s=>t(s))},700)})),r.length===1&&this._editor.viewModel.featureTemplatesViewModel.select(r[0]);let i=r.length>1;this.hideEditorsElements().then(()=>{i&&e({})},s=>i&&t(s))}})}async createSearchWidget(){if(this._updatedMapView){let e={view:this._updatedMapView};if(this.searchConfiguration&&(e={...this._getSearchConfig(this.searchConfiguration,this._updatedMapView)}),this._search=new I(e),!this._search)return;this._search.container="search-widget-ref",this._search.popupEnabled=!1,this._search.resultGraphicEnabled=!1;let t;this._search.viewModel.addHandles(this._search.on("search-complete",i=>{i.results[0].results&&i.results[0].results[0]&&(i.results[0].results[0].extent&&this._updatedMapView?.goTo(i.results[0].results[0].extent),this._selectedLayer?.geometryType==="point"&&(t=i.results[0].results[0]?.feature.geometry))}));let r=h.watch(()=>this._search?.viewModel.state,i=>{i==="ready"&&setTimeout(()=>{if(this._editor?.viewModel.sketchViewModel?.createGraphic&&t){let s=t.clone(),a=this._editor.viewModel.sketchViewModel.createGraphic.set("geometry",t).clone();this._editor.viewModel.sketchViewModel.addGraphic(a),this._editor.viewModel.sketchViewModel.emit("create",{graphic:a,state:"complete",toolEventInfo:null,type:"create"}),this._editor.viewModel.sketchViewModel.update(s),this.hideEditorsElements()}else if(this._editor?.viewModel.sketchViewModel&&this._editor.viewModel.sketchViewModel.updateGraphics.length>0&&t){let s=this._editor?.viewModel.sketchViewModel?.updateGraphics.getItemAt(0);s&&(s.set("geometry",t),this._editor?.viewModel.sketchViewModel?.update(s),this.hideEditorsElements())}},100)});r&&this._search.viewModel.addHandles(r)}}_getSearchConfig(e,t){let r="includeDefaultSources",i=e.sources;return i&&i?.length>0?(e[r]=!1,i.forEach(s=>{if(s.hasOwnProperty("layer")){let a=s,n=a.layer?.id,o=n?t.map?.findLayerById(n):"",c=a?.layer?.url;o?a.layer=o:c&&(a.layer=new F(c))}}),i?.forEach(s=>{if(s.hasOwnProperty("locator")){let a=s;if(a?.name==="ArcGIS World Geocoding Service"){let n=a.outFields||["Addr_type","Match_addr","StAddr","City"];a.outFields=n,a.singleLineFieldName="SingleLine"}a.url=a.url,delete a.url}})):e={...e,includeDefaultSources:!0},e}async _setFloorLevel(e){if(!e)return;let t=this._selectedLayer,r=t?.floorInfo?.floorField;if(r){let i=t.fields.find(s=>s.name===r);if(i&&!t?.formTemplate)this._editor?.viewModel.featureFormViewModel&&(this._editor.viewModel.featureFormViewModel.setValue(i.name,e),i.editable=!1);else if(t.formTemplate&&this.formElements){let s=new C({expression:`'${e}'`,name:"floor-info-test",title:"Floor Info",returnType:"string"}),l=new k({label:r,editableExpression:"false",fieldName:r,input:{type:"text-box",maxLength:50,minLength:0},valueExpression:s.name});this._updatedMapView?.map.editableLayers.forEach(a=>{let n=this.formElements.orgElements,o=this.formElements.orgExpressionInfos,c=[...n];if(c.push(l),a.type==="feature"){let _=a,S=new A({title:_?.formTemplate?.title,description:_?.formTemplate?.description,elements:c,expressionInfos:[s].concat(o)});a.formTemplate=S}})}}}async hideEditorsElements(){this.customizeSubmit&&(await this.timeout(700),this.el.querySelector(".esri-editor")?.querySelectorAll("calcite-flow-item")?.forEach(e=>{let t=e.shadowRoot?.querySelector("calcite-panel")?.shadowRoot?.querySelector("article");t?.querySelector("header")?.setAttribute("style","display: none"),t?.querySelector("footer")?.setAttribute("style","display: none")}))}async submitted(e){if(e.invalid.length){this._isSubmitBtnClicked=!1;return}if(this._isSubmitBtnClicked){this._isSubmitBtnClicked=!1;try{this._editor?.activeWorkflow&&(await this._editor.activeWorkflow.commit(),this._editor.viewModel.failures?.length&&this._editor.viewModel.failures.some(t=>{if(t.error)throw t.error}))}catch(t){this.fail.emit(t);return}this.success.emit()}}async timeout(e){return new Promise(t=>setTimeout(t,e))}};b("create-feature",g);return g},"widgets/Editor","form/ExpressionInfo","layers/FeatureLayer","form/elements/FieldElement","form/FormTemplate","views/MapView","widgets/Home","widgets/Search","core/reactiveUtils",a,c)