UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) • 35.6 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import{isSome as t}from"../core/arrayUtils.js";import i from"../core/Collection.js";import{deprecateWidget as s}from"../core/deprecate.js";import{addEventListener as o}from"../core/events.js";import{makeHandle as r}from"../core/handleUtils.js";import a from"../core/Logger.js";import{destroyMaybe as n}from"../core/maybe.js";import{debounce as l,isAbortError as c}from"../core/promiseUtils.js";import{watch as d,initial as h,on as p}from"../core/reactiveUtils.js";import{escapeRegExpString as m}from"../core/string.js";import{property as u,subclass as v}from"../core/accessorSupport/decorators.js";import{onLocaleChange as g,getLocaleLanguage as _}from"../intl/locale.js";import w from"../portal/Portal.js";import{defaultUnitPropertyMetadata as y}from"../properties/defaultUnit.js";import b from"../rest/support/Stop.js";import S from"../symbols/SimpleMarkerSymbol.js";import f from"./Search.js";import k from"./Widget.js";import{css as C}from"./Directions/css.js";import{DirectionsSearchTool as D}from"./Directions/DirectionsSearchTool.js";import M from"./Directions/DirectionsViewModel.js";import I from"./Directions/DirectionsVisibleElements.js";import{formatDistance as P,formatDuration as T,DepartureTimeOption as F,getIconName as x}from"./Directions/support/directionsUtils.js";import{isArcGISWorldGeocoder as L,meteredArcGISLocatorUrl as E}from"./Search/support/locatorUtils.js";import{loadCalciteComponents as R}from"./support/componentsUtils.js";import{globalCss as A}from"./support/globalCss.js";import{messageBundle as N,tsx as O}from"./support/widget.js";function B(e){const{branchName:i,displayText:s,exitName:o,intersectingName:r,name:a,towardName:n}=e;if(null==s)return null;const l=[i,o,r,a,n].filter(t).sort((e,t)=>t.length-e.length).map(e=>m(e));if(!l.length)return s;const c=new RegExp(l.join("|"),"g"),d=s.matchAll(c);let h=0;const p=[];for(const{0:t,index:m}of d)p.push(s.slice(h,m),O("span",{class:C.labelEmphasize,key:`maneuver-${m}`},t)),h=m+t.length;return p.push(s.slice(h)),O("span",null,p)}const j="print-preview-closed";let $=class extends k{constructor(e,t){super(e,t),this._activeManeuver=null,this._placeholderStops=new i([new b,new b]),this._portalFolderCombobox=null,this._portalFolders=null,this._portalItemNameInput=null,this._portalUserName=null,this._printPreviewDialog=null,this._sections=null,this._stopsToSearches=new Map,this._editNoticeClosed=!1,this._printPreviewDialogOpen=!1,this._currentFlowItem="primary",this._parentFlowItem="primary",this._saveState="initialized",this._searchTool=null,this.headingLevel=2,this.messages=null,this.messagesUnits=null,this.searchProperties={popupEnabled:!1,resultGraphicEnabled:!1},this.viewModel=new M,this.visibleElements=new I,this._solveRouteDebounced=l(()=>this._solveRoute()),this.announceDeprecation=()=>{s(a.getLogger(this),"Directions","arcgis-directions",{version:"5.0"})}}initialize(){this.addHandles([d(()=>this.viewModel.layer,()=>{try{this.viewModel.load()}catch{}},h),d(()=>this.viewModel.layer?.routeInfo,()=>{this._sections=this._getStopSections()},h),d(()=>this.viewModel.layer?.stops.toArray(),e=>{e&&this.view?.activeTool&&this._searchTool&&this.view.activeTool===this._searchTool&&!e.includes(this._searchTool.stop)&&(this.view.tools.remove(this._searchTool),this._searchTool=null)})])}loadDependencies(){return R({accordion:()=>import("@esri/calcite-components/dist/components/calcite-accordion"),"accordion-item":()=>import("@esri/calcite-components/dist/components/calcite-accordion-item"),action:()=>import("@esri/calcite-components/dist/components/calcite-action"),"action-menu":()=>import("@esri/calcite-components/dist/components/calcite-action-menu"),"block-section":()=>import("@esri/calcite-components/dist/components/calcite-block-section"),button:()=>import("@esri/calcite-components/dist/components/calcite-button"),combobox:()=>import("@esri/calcite-components/dist/components/calcite-combobox"),"combobox-item":()=>import("@esri/calcite-components/dist/components/calcite-combobox-item"),flow:()=>import("@esri/calcite-components/dist/components/calcite-flow"),"flow-item":()=>import("@esri/calcite-components/dist/components/calcite-flow-item"),icon:()=>import("@esri/calcite-components/dist/components/calcite-icon"),input:()=>import("@esri/calcite-components/dist/components/calcite-input"),"input-date-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-date-picker"),"input-time-picker":()=>import("@esri/calcite-components/dist/components/calcite-input-time-picker"),label:()=>import("@esri/calcite-components/dist/components/calcite-label"),list:()=>import("@esri/calcite-components/dist/components/calcite-list"),"list-item":()=>import("@esri/calcite-components/dist/components/calcite-list-item"),loader:()=>import("@esri/calcite-components/dist/components/calcite-loader"),notice:()=>import("@esri/calcite-components/dist/components/calcite-notice"),panel:()=>import("@esri/calcite-components/dist/components/calcite-panel"),switch:()=>import("@esri/calcite-components/dist/components/calcite-switch")})}destroy(){this._stopsToSearches.forEach(n)}get apiKey(){return this.viewModel.apiKey}set apiKey(e){this.viewModel.apiKey=e}get goToOverride(){return this.viewModel.goToOverride}set goToOverride(e){this.viewModel.goToOverride=e}get displayedStops(){return this.effectiveStops.toArray().filter(({locationType:e})=>"waypoint"!==e)}get effectiveStops(){return this.viewModel.layer?.stops??this._placeholderStops}get icon(){return"right"}set icon(e){this._overrideIfSome("icon",e)}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get lastRoute(){return this.viewModel.lastRoute}get layer(){return this.viewModel.layer}set layer(e){this.viewModel.layer=e}get maxStops(){return this.viewModel.maxStops}set maxStops(e){this.viewModel.maxStops=e}get unit(){return this.defaultUnit}set unit(e){this._overrideIfSome("unit",e)}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}acquireSearch(e){const{view:t}=this.viewModel;if(this._stopsToSearches.has(e)){const i=this._stopsToSearches.get(e);return i.view=t,this._overrideDefaultSources(i),i}const i=new f({icon:"",popupEnabled:!1,resultGraphicEnabled:!1,view:t,suppressDeprecationWarning:!0,...this.searchProperties});return this._normalizeSearchSources(i),this.addHandles([p(()=>i.allSources,"change",()=>this._normalizeSearchSources(i)),i.on("search-clear",()=>{e.geometry=null,e.name=null,this.viewModel.layer?.removeResult()}),i.on("select-result",()=>{const t=i.selectedResult;e.geometry=t?.feature.geometry,e.name=t?.name,this._solveRouteDebounced()}),d(()=>i.searchTerm,t=>{e.name=t}),g(()=>this._normalizeSearchSources(i))],i),this._stopsToSearches.set(e,i),i}getDirections(){return this.viewModel.getDirections()}render(){return O("div",{class:this.classes(C.base,A.widget,A.panel)},O("calcite-flow",null,this._renderPrimaryFlowItem(),this._renderDirectionsFlowItem(),this._renderEditFlowItem(),this._renderSaveFlowItem()),this._renderPrintDocument())}save(){return this.viewModel.save()}saveAs(e,t={}){return this.viewModel.saveAs(e,t)}zoomToRoute(){return this.viewModel.zoomToRoute()}_applyLocatorSourceOverrides({allSources:e}){for(const t of e)"url"in t&&t.url&&(t.language=_(),t.locationType??="street",L(t.url)&&this.apiKey&&null==t.apiKey&&(t.apiKey=this.apiKey,t.url=E))}_disposeSearch(e){if(!e||!this._stopsToSearches.has(e))return;const t=this._stopsToSearches.get(e);this.removeHandles(t),t.destroy(),this._stopsToSearches.delete(e)}_getErrorDescription(){switch(this.viewModel.lastError?.name){case"directions-view-model:unable-to-route":return this.messages.errors.unableToRoute;case"directions-view-model:service-metadata-unavailable":return this.messages.errors.unableToLoadServiceMetadata;default:return this.messages.errors.unknownError}}_getNetworkFeatureName(e){switch(e.type){case"stop":switch(e.locationType){case"stop":default:return this.messages.networkFeatures.stops.stop;case"waypoint":return this.messages.networkFeatures.stops.waypoint;case"break":return this.messages.networkFeatures.stops.break}case"point-barrier":return this.messages.networkFeatures.pointBarrier;case"polyline-barrier":return this.messages.networkFeatures.polylineBarrier;case"polygon-barrier":return this.messages.networkFeatures.polygonBarrier}}_getRouteCostSummary(){const e=this.viewModel.layer?.routeInfo;if(!e)return null;const t=e.totalDistance??0,i=e.totalDuration??0,{messagesUnits:s,unit:o}=this;return{distance:P(s,t,o),duration:T(i)}}_getStopCostDescription(e){if(!e.directions.length)return;const{totalDistance:t,totalDuration:i}=e.directions.reduce((e,{lines:t})=>{for(const{distance:i,duration:s}of t)e.totalDistance+=i??0,e.totalDuration+=s??0;return e},{totalDistance:0,totalDuration:0}),{messagesUnits:s,unit:o}=this,r=P(s,t,o);return`${T(i)} (${r})`}_getStopSections(){if(!this.viewModel.layer)return null;const{directionPoints:e,directionLines:t,stops:i}=this.viewModel.layer;if(!e||!t)return null;const s=[];let o=null;for(const r of e){const{objectId:e,stopId:a}=r;if(null!=a){const e=i.find(({objectId:e})=>e===a);o&&o.stop===e||(o={stop:e,directions:[]},s.push(o));continue}if(null==o)continue;const n=t.toArray().filter(({directionPointId:t})=>t===e);0!==n.length&&o.directions.push({directionPoint:r,lines:n})}return s}_handleAddStopClick(){const e=new S;this.viewModel.layer?.stops.add(new b({symbol:e}))}_handleAutoSolveChange({target:e}){this.viewModel.autoSolve=e.checked}_handleCreatePolylineBarrierClick(){this.viewModel.create("polyline-barrier")}_handleClearRouteClick(){this._currentFlowItem="primary",this.viewModel.reset()}_handleCreateStopClick(){this.viewModel.create("stop")}_handleDeleteNetworkFeatureClick(e){this.viewModel.remove(e),this.viewModel.autoSolve&&this._solveRouteDebounced()}_handleDeleteStopClick(e){this.effectiveStops.remove(e),this._disposeSearch(e),this._solveRouteDebounced()}_handleDepartureDateChange({currentTarget:{value:e}}){Array.isArray(e)||(this.viewModel.departureIsoDate=e,this._solveRouteDebounced())}_handleDepartureTimeChange({currentTarget:{value:e}}){this.viewModel.departureIsoTime=e,this._solveRouteDebounced()}_handleDepartureTimeOptionChange({currentTarget:e}){const{selectedItems:t}=e;t.length&&(this.viewModel.departureOption=t[0].value,this._solveRouteDebounced())}_handleDirectionsFlowItemBackClick(e){e.stopPropagation(),this._currentFlowItem="primary"}_handleDirectionTurnItemSelect(e){this._activeManeuver===e?this.zoomToRoute():(this._activeManeuver=e,this.viewModel.centerAt(e.geometry))}_handleDirectionTurnPointerEnter(e){this.viewModel.highlight(e)}_handleDirectionTurnPointerLeave(){this.viewModel.clearHighlights()}_handleEditFlowItemBackClick(e){e.stopPropagation(),this.viewModel.stopEditing(),this._currentFlowItem="primary"}_handleEditingDoneClick(){this.viewModel.stopEditing(),this._currentFlowItem="primary"}_handleEditNoticeClose(){this._editNoticeClosed=!0}_handleEditRouteClick(){this._currentFlowItem="edit",this.viewModel.startEditing()}_handleItemDetailsClick(){const e=this.viewModel.layer?.portalItem;e&&window.open(`${e.portal.url}/home/item.html?id=${e.id}`,"_blank")}_handleLocateStopClick(e){const{view:t}=this;if(!t)return;const i="directions-search-tool";this.removeHandles(i),this._searchTool=new D({stop:e,view:t}),this.addHandles([this._searchTool.on("click",async t=>{if(t.mapPoint&&this._stopsToSearches.has(e)){const i=this._stopsToSearches.get(e),s=await i.search(t.mapPoint),o=s?.results?.[0].results?.[0];if(o){const{feature:t,name:s}=o;i.searchTerm=s,e.geometry=t.geometry}}this.removeHandles(i)}),r(()=>{this._searchTool&&(this.view?.tools.remove(this._searchTool),this._searchTool=null)})],i),t.addAndActivateTool(this._searchTool)}_handleOptimizeStopOrderToggle({target:{expanded:e}}){this.viewModel.routeParameters.findBestSequence=e,e&&this._removeWaypoints(),this._solveRouteDebounced()}_handlePanToStopClick(e){this.viewModel.centerAt(e)}_handlePreserveFirstStopChange({target:{checked:e}}){this.viewModel.routeParameters.preserveFirstStop=e,this._solveRouteDebounced()}_handlePreserveLastStopChange({target:{checked:e}}){this.viewModel.routeParameters.preserveLastStop=e,this._solveRouteDebounced()}_handlePrintPreviewDialogAfterCreate(e){document.body.appendChild(e),e.showModal(),this._printPreviewDialog=e,this.removeHandles(j),this.addHandles([o(e,"close",this._handlePrintPreviewDialogClosed.bind(this)),r(()=>{this._printPreviewDialog&&(document.body.removeChild(this._printPreviewDialog),this._printPreviewDialog=null,this._printPreviewDialogOpen=!1)})],j)}_handlePrintPreviewDialogClick(){this._printPreviewDialogOpen=!0}_handlePrintPreviewDialogCloseClick(){this._printPreviewDialog?.close()}_handlePrintPreviewDialogClosed(){this.removeHandles(j)}_handlePrintPreviewDialogPrintClick(){document.body.classList.add(C.printPreviewMedia),window.print(),document.body.classList.remove(C.printPreviewMedia),this._printPreviewDialog?.close()}_handleResolveRouteClick(){this._solveRouteDebounced()}_handleReverseStopOrderClick(){this._removeWaypoints(),this.effectiveStops.reverse(),this._solveRouteDebounced()}_handleSaveErrorCloseClick(){this._currentFlowItem=this._parentFlowItem}_handleSaveFlowItemBackClick(e){e.stopPropagation(),this._currentFlowItem=this._parentFlowItem}async _handleSaveLayerAs(){const e=w.getDefault();try{await e.signIn()}catch(t){if(c(t)||"identity-manager:user-aborted"===t.name)return;return this._parentFlowItem=this._currentFlowItem,this._currentFlowItem="save",void(this._saveState="connect-to-portal-error")}this._saveState="fetch-portal-information",this._parentFlowItem=this._currentFlowItem,this._currentFlowItem="save",this._portalUserName=e.user?.username;try{this._portalFolders=await(e.user?.fetchFolders())}catch{return void(this._saveState="fetch-portal-information-error")}this._saveState="save-layer"}_handleSaveLayerClick(){this.viewModel.layer?.save()}_handleSaveLayerButtonClick(){this._saveState="saving";const{layer:e}=this;if(!e||!this._portalFolders)return;const t=this._portalItemNameInput?.value,i=this._portalFolderCombobox?.value,s=this._portalFolders.find(({id:e})=>e===i);e.saveAs({title:t},{folder:s}).then(()=>{e.title=t,this._currentFlowItem=this._parentFlowItem}).catch(()=>{this._saveState="saving-error"})}_handleSaveLayerCancelClick(){this._currentFlowItem=this._parentFlowItem}_handleSaveLayerFolderCreate(e){this._portalFolderCombobox=e}_handleSaveLayerNameCreate(e){this._portalItemNameInput=e}_handleSignInClick(){this.viewModel.load().catch(()=>{})}_handleStopListReorder({detail:{dragEl:e,newIndex:t}}){this._removeWaypoints(),this.effectiveStops.reorder(e.value,t),this._solveRouteDebounced()}_handleTravelModeChange({currentTarget:{selectedItems:e}}){e.length&&(this.viewModel.selectedTravelMode=e[0].value,this._solveRouteDebounced())}_handleViewDrivingDirectionsClick(){this._currentFlowItem="directions"}_normalizeSearchSources(e){this._overrideDefaultSources(e),this._applyLocatorSourceOverrides(e)}_overrideDefaultSources(e){for(const t of e.viewModel.defaultSources)t.autoNavigate=!1}_removeWaypoints(){const e=this.viewModel.layer?.stops;if(e){const t=e.filter(({locationType:e})=>"waypoint"===e);e.removeMany(t)}}_renderClearRouteAction(e){return O("calcite-action",{bind:this,icon:"trash",key:"clear-route",onclick:this._handleClearRouteClick,...e,text:this.messages.common.clear,textEnabled:!0})}_renderDeleteStopAction(e){return O("calcite-action",{icon:"trash",onclick:this._handleDeleteStopClick.bind(this,e),slot:"actions-end",text:this.messages.deleteStop,title:this.messages.deleteStop})}_renderDepartureTime(){const{DEPART_AT:e,NOW:t,UNSPECIFIED:i}=F;return O("calcite-label",{class:C.departureTime,key:"departure-time"},this.messages.departureTime,O("calcite-combobox",{bind:this,label:this.messages.departureTime,overlayPositioning:"fixed",selectionMode:"single-persist",topLayerDisabled:this.topLayerDisabled,onCalciteComboboxChange:this._handleDepartureTimeOptionChange},O("calcite-combobox-item",{heading:this.messages.leaveNow,key:t,label:this.messages.leaveNow,selected:this.viewModel.departureOption===t,value:t}),O("calcite-combobox-item",{heading:this.messages.departAt,key:e,label:this.messages.departAt,selected:this.viewModel.departureOption===e,value:e}),O("calcite-combobox-item",{heading:this.messages.timeUnspecified,key:i,label:this.messages.timeUnspecified,selected:this.viewModel.departureOption===i,value:i})))}_renderDepartureTimeOptions(){return this.viewModel.departureOption!==F.DEPART_AT?null:O("div",{class:C.departureTimeOptions},O("calcite-input-date-picker",{bind:this,scale:"s",topLayerDisabled:this.topLayerDisabled,value:this.viewModel.departureIsoDate,onCalciteInputDatePickerChange:this._handleDepartureDateChange}),O("calcite-input-time-picker",{bind:this,scale:"s",value:this.viewModel.departureIsoTime,onCalciteInputTimePickerClose:this._handleDepartureTimeChange}))}_renderDirectionsFlowItem(){if("directions"!==this._currentFlowItem)return null;const e=this._getRouteCostSummary();if(!this._sections||!e)return null;const{distance:t,duration:i}=e,{formattedEta:s}=this.viewModel,o=this._sections.at(0)?.stop.name??"",r=this._sections.at(-1)?.stop.name??"";return O("calcite-flow-item",{bind:this,key:"directions-flow-item",overlayPositioning:"fixed",selected:"directions"===this._currentFlowItem,onCalciteFlowItemBack:this._handleDirectionsFlowItemBackClick},O("div",{class:C.directionsHeader,slot:"header-content"},O("div",{class:C.headerStops},O("span",null,this.messages.from)," ",O("span",{class:C.directionsHeaderStopName},o),O("span",null,this.messages.to)," ",O("span",{class:C.directionsHeaderStopName},r)),O("div",{class:C.flexColumn},O("span",null,`${i} (${t})`),s?O("span",null,s):null)),this._renderRouteLayerActions({slot:"header-menu-actions"}),O("calcite-accordion",{class:C.accordion,iconPosition:"start",selectionMode:"single"},this._sections.map((e,t)=>this._renderDirectionSection(e,t))))}_renderDirectionSection(e,t){const{stop:i,directions:s}=e,{name:o}=i,r=0===t,a=this._getStopCostDescription(e);return O("calcite-accordion-item",{description:a,expanded:r,heading:o??"",key:`stop-${t}`},O("calcite-action",{icon:"zoom-to-object",onclick:this._handlePanToStopClick.bind(this,i),slot:"actions-end",text:this.messages.panToStop,title:this.messages.panToStop}),this._renderDirectionTurns(s))}_renderDirectionTurns(e){return O("calcite-list",{label:this.messages.drivingDirections,selectionMode:"none"},e.map((e,t)=>{const{directionPoint:i,lines:s}=e,o=s[0],{distance:r,duration:a}=o,n=P(this.messagesUnits,r??0,this.unit),l=T(a??0),c=n&&l?`${n} | ${l}`:`${n||l}`,d=B(i),h=x(i.directionPointType);return O("calcite-list-item",{class:C.labelNoBottomMargin,key:`driving-direction-${t}`,onpointerenter:this._handleDirectionTurnPointerEnter.bind(this,o),onpointerleave:this._handleDirectionTurnPointerLeave.bind(this),onCalciteListItemSelect:this._handleDirectionTurnItemSelect.bind(this,o)},O("calcite-icon",{icon:h,slot:"content-start"}),O("div",{slot:"content"},O("calcite-label",{layout:"inline",scale:"s"},d),O("calcite-label",{layout:"inline",scale:"s"},c)))}))}_renderEditNotice(){return this._editNoticeClosed?null:O("div",{class:C.editInformationContainer},O("calcite-notice",{bind:this,closable:!0,kind:"info",open:!0,onCalciteNoticeClose:this._handleEditNoticeClose},O("calcite-label",{scale:"s",slot:"message"},this.messages.editInstructions)))}_renderEditFlowItem(){return"edit"!==this._currentFlowItem?null:O("calcite-flow-item",{bind:this,heading:this.messages.editRoute,headingLevel:this.headingLevel,key:"edit-flow-item",loading:"routing"===this.viewModel.state,selected:"edit"===this._currentFlowItem,onCalciteFlowItemBack:this._handleEditFlowItemBackClick},O("div",{class:C.flexColumn,key:"edit-container"},this._renderEditNotice(),O("div",{class:C.editToolbarContainer},O("calcite-label",{layout:"inline",scale:"s"},this.messages.automaticallySolve,O("calcite-switch",{bind:this,checked:this.viewModel.autoSolve,scale:"s",onCalciteSwitchChange:this._handleAutoSolveChange})),O("div",{class:C.editToolbar},O("calcite-action",{bind:this,disabled:!this.viewModel.layer||this.viewModel.layer.stops.length>=this.maxStops,icon:"flag",onclick:this._handleCreateStopClick,scale:"s",text:this.messages.networkFeatures.stops.stop,textEnabled:!0}),O("calcite-action",{bind:this,icon:"line",onclick:this._handleCreatePolylineBarrierClick,scale:"s",text:this.messages.barrier,textEnabled:!0}),O("calcite-action",{bind:this,class:C.solveRoute,disabled:this.viewModel.autoSolve,icon:"refresh",onclick:this._handleResolveRouteClick,scale:"s",text:this.messages.solve,textEnabled:!0}))),O("div",{class:C.selectedFeatureContainer},O("calcite-list",{label:this.messages.selectedNetworkFeatures,scale:"s",selectionMode:"none"},this.viewModel.selectedNetworkFeatures?.toArray().map((e,t)=>O("calcite-list-item",{description:this._getNetworkFeatureName(e),key:`network-feature-${t}`,label:e.name??e.objectId?.toString()??this.messages.unnamed},O("calcite-action",{icon:"trash",onclick:this._handleDeleteNetworkFeatureClick.bind(this,e),slot:"actions-end",text:this.messages.common.delete}))))),O("div",{class:C.editFooter},this._renderEditFooterContent())))}_renderEditFooterContent(){return this.viewModel.lastError?this._renderErrorNotice():O("calcite-button",{appearance:"outline-fill",bind:this,onclick:this._handleEditingDoneClick,width:"full"},this.messages.common.done)}_renderErrorNotice(){return O("calcite-notice",{icon:"exclamation-mark-circle",kind:"danger",open:!0},O("calcite-label",{class:C.labelNoBottomMargin,slot:"message"},this._getErrorDescription()))}_renderFooter(){if(!this.viewModel.layer)return O("div",{class:C.primaryFooter,key:"footer-missing-layer"},O("calcite-notice",{icon:"information",open:!0},O("calcite-label",{class:C.labelNoBottomMargin,slot:"message"},this.messages.missingLayer)));if("unauthenticated"===this.viewModel.state)return O("div",{class:C.primaryFooterCentered,key:"footer-sign-in"},O("calcite-label",null,this.messages.signInRequired),O("calcite-button",{bind:this,onclick:this._handleSignInClick},this.messages.common.auth.signIn));if("routing"===this.viewModel.state)return O("div",{class:this.classes(C.primaryFooter,C.primaryFooterLoader),key:"footer-routing"},O("calcite-loader",{label:this.messages.solve,scale:"s"}));if("error"===this.viewModel.state)return O("div",{class:C.primaryFooter,key:"footer-service-error"},this._renderErrorNotice());if(!this.viewModel.layer?.routeInfo)return O("div",{class:C.primaryFooter,key:"footer-unsolved-route"},O("calcite-notice",{icon:"information",open:!0},O("calcite-label",{class:C.labelNoBottomMargin,slot:"message"},this.messages.directionsPlaceholder)));const e=this._getRouteCostSummary();if(!e||!this.viewModel.layer?.directionPoints)return O("div",{class:C.primaryFooter,key:"footer-invalid-route"},O("calcite-notice",{icon:"exclamation-mark-triangle",kind:"danger",open:!0},O("calcite-label",{class:C.labelNoBottomMargin,slot:"message"},this.messages.invalidRoute)));const{distance:t,duration:i}=e,{formattedEta:s}=this.viewModel;return O("div",{class:C.routeItem,key:"footer-directions-summary"},O("button",{"aria-busy":"false","aria-label":this.messages.viewDrivingDirections,"aria-live":"polite",bind:this,class:C.routeItemButton,onclick:this._handleViewDrivingDirectionsClick,title:this.messages.viewDrivingDirections,type:"button"},O("div",{class:C.routeItemButtonContent},O("span",{class:C.routeItemLabel},`${i} (${t})`),O("span",{class:C.routeItemDescription},s)),O("calcite-icon",{flipRtl:!0,icon:"chevron-right",scale:"s"})),O("calcite-action-menu",{label:"test"},O("calcite-action",{icon:"ellipsis",key:"route-actions",slot:"trigger",text:"Route actions"}),this._renderRouteLayerActions()))}_renderInteractiveRouteActions(){return O("div",{class:C.actionContainer,key:C.actionContainer},O("calcite-button",{appearance:"outline",bind:this,class:C.addStopButton,disabled:this.effectiveStops.length>=this.maxStops,iconStart:"plus",kind:"neutral",label:this.messages.addStop,onclick:this._handleAddStopClick,title:this.messages.addStop,width:"half"},this.messages.addStop),this.visibleElements.editRouteButton?O("calcite-button",{appearance:"outline",bind:this,class:C.editRouteButton,disabled:"2d"!==this.viewModel.view?.type,iconStart:"pencil",kind:"neutral",label:this.messages.editRoute,onclick:this._handleEditRouteClick,title:this.messages.editRoute,width:"half"},this.messages.editRoute):null)}_renderLocateStopAction(e){if(null!=e.name||null!=e.geometry)return null;const t=this.effectiveStops.indexOf(e),i=!!this.view?.activeTool&&this.view.activeTool===this._searchTool&&this._searchTool.stop===e;return O("calcite-action",{active:i,icon:"crosshair",key:`stop-location-action-${t}`,onclick:this._handleLocateStopClick.bind(this,e),slot:"actions-end",text:this.messages.pickALocationOnTheMap,title:this.messages.pickALocationOnTheMap})}_renderOptimizeStopOrder(){const{routeParameters:e}=this.viewModel,{findBestSequence:t,preserveFirstStop:i,preserveLastStop:s}=e;return O("calcite-block-section",{bind:this,class:C.optimizeSection,text:this.messages.optimizeOrder,toggleDisplay:"switch",onCalciteBlockSectionToggle:this._handleOptimizeStopOrderToggle},t?[O("calcite-label",{class:C.optimizeSwitches,key:"preserve-first-stop",layout:"inline-space-between"},this.messages.preserveFirstStop,O("calcite-switch",{bind:this,checked:i,scale:"s",onCalciteSwitchChange:this._handlePreserveFirstStopChange})),O("calcite-label",{class:C.optimizeSwitches,key:"preserve-last-stop",layout:"inline-space-between"},this.messages.preserveLastStop,O("calcite-switch",{bind:this,checked:s,scale:"s",onCalciteSwitchChange:this._handlePreserveLastStopChange}))]:null)}_renderPrimaryFlowItem(){return O("calcite-flow-item",{key:"primary-flow-item",loading:"initializing"===this.viewModel.state,selected:"primary"===this._currentFlowItem},O("calcite-panel",{class:C.primaryFlowItem,disabled:!this.viewModel.layer||"unauthenticated"===this.viewModel.state||"error"===this.viewModel.state&&!this.viewModel.serviceDescription},this._renderStops(),this._renderInteractiveRouteActions(),this._renderSeparator(),this._renderRouteSolveOptions()),this._renderFooter())}_renderPrintDocument(){if(!this._printPreviewDialogOpen)return null;const e=this._getRouteCostSummary();if(!this._sections||!e)return null;const{distance:t,duration:i}=e,{formattedEta:s}=this.viewModel,o=this._sections.at(0)?.stop.name??"",r=this._sections.at(-1)?.stop.name??"";return O("dialog",{afterCreate:this._handlePrintPreviewDialogAfterCreate,bind:this,class:C.printPreviewDialog},O("div",{class:C.printPreviewContent},O("div",{class:C.printPreviewHeader},O("div",{class:C.printPreviewHeaderLabel},O("div",{class:C.headerStops},O("span",null,this.messages.from)," ",O("span",{class:C.directionsHeaderStopName},o),O("span",null,this.messages.to)," ",O("span",{class:C.directionsHeaderStopName},r))),O("div",{class:this.classes(C.printPreviewHeaderButtons,C.printPreviewHideOnPrint)},O("calcite-button",{autofocus:!0,bind:this,class:C.printPreviewDialogPrint,iconStart:"print",onclick:this._handlePrintPreviewDialogPrintClick},this.messages.common.print),O("calcite-button",{appearance:"outline",bind:this,class:C.printPreviewDialogClose,iconStart:"x-circle",onclick:this._handlePrintPreviewDialogCloseClick},this.messages.common.close))),O("div",{class:C.directionsHeader},O("span",null,`${i} (${t})`),s?O("span",null,s):null),this._sections.map((e,t)=>this._renderPrintSection(e,t))))}_renderPrintManeuver(e,t){const{directionPoint:i,lines:s}=e,{distance:o,duration:r}=s.at(0)??{},a=P(this.messagesUnits,o??0,this.unit),n=T(r??0),l=a&&n?`${a} | ${n}`:`${a||n}`,c=B(i),d=x(i.directionPointType);return O("div",{class:this.classes(C.flexRow,C.printPreviewAvoidPageBreak),key:`direction-${t}`},O("calcite-icon",{icon:d,preload:!0}),O("div",{class:C.flexColumn},O("span",null,c),O("span",null,l)))}_renderPrintRouteAction(e){if(!this.visibleElements.printButton)return null;const t=!this.viewModel.layer?.routeInfo;return O("calcite-action",{bind:this,disabled:t,icon:"print",key:"print-route",onclick:this._handlePrintPreviewDialogClick,...e,text:this.messages.common.print,textEnabled:!0})}_renderPrintSection({stop:e,directions:t},i){return O("div",{class:C.printPreviewSection,key:`section-${i}`},O("span",{class:C.directionsHeaderStopName},e.name??""),t.map((e,t)=>this._renderPrintManeuver(e,t)))}_renderRouteLayerActions(e){return[this._renderClearRouteAction(e),this._renderSaveLayerAction(e),this._renderSaveLayerAsAction(e),this._renderPrintRouteAction(e),this._renderViewItemDetailsAction(e)]}_renderRouteSolveOptions(){return O("div",{class:C.marginInlineMedium,key:"route-solve-options"},this._renderTravelModes(),this._renderDepartureTime(),this._renderDepartureTimeOptions(),this._renderOptimizeStopOrder())}_renderSaveContent(){switch(this._saveState){case"initialized":return this._renderSaveInitialized();case"connect-to-portal":return this._renderSaveProcessing(this.messages.identity.lblSigning);case"connect-to-portal-error":return this._renderSaveError(this.messages.errors.authenticating);case"fetch-portal-information":return this._renderSaveProcessing(this.messages.processing.fetching);case"fetch-portal-information-error":return this._renderSaveError(this.messages.errors.fetching);case"save-layer":return this._renderSaveLayerSettings();case"saving":return this._renderSaveProcessing(this.messages.processing.saving);case"saving-error":return this._renderSaveError(this.messages.errors.saving)}}_renderSaveError(e){return O("calcite-panel",{class:C.paddingMedium,key:"save-layer-error"},O("div",{class:C.saveError},O("calcite-icon",{class:C.saveErrorIcon,icon:"exclamation-mark-triangle",scale:"l",textLabel:this.messages.common.errorMessage}),O("calcite-label",{class:C.saveErrorLabel},e)),O("calcite-button",{appearance:"outline",bind:this,onclick:this._handleSaveErrorCloseClick,slot:"footer-start",width:"full"},this.messages.common.close))}_renderSaveInitialized(){return O("calcite-panel",{class:C.paddingMedium,key:"save-layer-initialized"})}_renderSaveFlowItem(){return"save"!==this._currentFlowItem?null:O("calcite-flow-item",{bind:this,heading:this.messages.saveLayer,headingLevel:this.headingLevel,key:"save-layer-flow-item",selected:"save"===this._currentFlowItem,onCalciteFlowItemBack:this._handleSaveFlowItemBackClick},this._renderSaveContent())}_renderSaveLayerAction(e){if(!this.visibleElements.saveButton)return null;const t=this.viewModel.layer,i=t?.routeInfo,s=t?.portalItem?.itemControl;return O("calcite-action",{bind:this,disabled:!(!!i&&("admin"===s||"update"===s)),icon:"save",key:"save-route",onclick:this._handleSaveLayerClick,...e,text:this.messages.common.save,textEnabled:!0})}_renderSaveLayerAsAction(e){if(!this.visibleElements.saveAsButton)return null;const t=!this.viewModel.layer?.routeInfo;return O("calcite-action",{disabled:t,icon:"save-as",key:"save-as-route",onclick:()=>{this._handleSaveLayerAs()},...e,text:this.messages.common.saveAs,textEnabled:!0})}_renderSaveLayerSettings(){if(null==this.layer||null==this._portalFolders||null==this._portalUserName)return this._renderSaveInitialized();const{stops:e}=this.layer,t=`${e.at(0).name} - ${e.at(-1).name}`,i=[O("calcite-combobox-item",{heading:`${this._portalUserName} (${this.messages.common.home})`,key:C.folderHome,selected:!0,value:C.folderHome}),...this._portalFolders.map(e=>O("calcite-combobox-item",{heading:e.title??"",key:`${C.folder}-${e.id}`,value:e.id}))];return O("calcite-panel",{key:"save-layer-panel"},O("div",{class:C.paddingMedium},O("calcite-label",null,this.messages.layerName,O("calcite-input",{afterCreate:this._handleSaveLayerNameCreate,bind:this,label:this.messages.layerName,value:t})),O("calcite-label",null,this.messages.saveInFolder,O("calcite-combobox",{afterCreate:this._handleSaveLayerFolderCreate,bind:this,label:this.messages.saveInFolder,overlayPositioning:"fixed",selectionMode:"single-persist",topLayerDisabled:this.topLayerDisabled},i))),O("calcite-button",{bind:this,onclick:this._handleSaveLayerButtonClick,slot:"footer-start",width:"full"},this.messages.common.save),O("calcite-button",{appearance:"outline",bind:this,onclick:this._handleSaveLayerCancelClick,slot:"footer-start",width:"full"},this.messages.common.cancel))}_renderSaveProcessing(e){return O("calcite-panel",{class:C.marginInlineMedium,key:"save-layer-processing"},O("calcite-loader",{class:C.saveProcessLoader,label:e,text:e}))}_renderSeparator(){return O("div",{class:C.separator})}_renderStop(e){const t=this.acquireSearch(e);null!=e.name&&(t.searchTerm=e.name);const i=this._renderLocateStopAction(e),s=this.effectiveStops.length>2&&this._renderDeleteStopAction(e);return O("calcite-list-item",{key:e,value:e},i,s,O("div",{class:C.stopItem,slot:"content"},t.render()))}_renderStops(){const e=this.displayedStops;for(const t of this._stopsToSearches.keys())e.includes(t)||this._disposeSearch(t);return O("div",{class:C.stopContainer,key:C.stopContainer},O("calcite-list",{bind:this,class:C.stopList,dragEnabled:!0,label:this.messages.widgetLabel,scale:"s",onCalciteListOrderChange:this._handleStopListReorder},e.map(e=>this._renderStop(e))),2===e.length&&O("calcite-action",{bind:this,icon:"arrow-up-down",onclick:this._handleReverseStopOrderClick,text:this.messages.reverseStops,title:this.messages.reverseStops}))}_renderTravelMode(e){const{id:t,name:i}=e;return O("calcite-combobox-item",{heading:i,key:t,label:i,selected:this.viewModel.selectedTravelMode?.id===t,value:e})}_renderTravelModes(){return this.viewModel.travelModes.length?O("calcite-label",{key:"travel-modes"},this.messages.mode,O("calcite-combobox",{bind:this,label:this.messages.mode,overlayPositioning:"fixed",selectionMode:"single-persist",topLayerDisabled:this.topLayerDisabled,onCalciteComboboxChange:this._handleTravelModeChange},this.viewModel.travelModes.map(e=>this._renderTravelMode(e)))):null}_renderViewItemDetailsAction(e){return this.visibleElements.layerDetails?O("calcite-action",{bind:this,disabled:!this.viewModel.layer?.portalItem,icon:"launch",key:"open-route-details-link",onclick:this._handleItemDetailsClick,...e,text:this.messages.viewLayerDetails,textEnabled:!0}):null}async _solveRoute(){this.viewModel.updateDepartureTime();if((this.viewModel.layer?.stops.filter(({geometry:e})=>!!e).length??0)<2)this.viewModel.clearResults();else try{await this.viewModel.getDirections()}catch{}}};e([u()],$.prototype,"_editNoticeClosed",void 0),e([u()],$.prototype,"_printPreviewDialogOpen",void 0),e([u()],$.prototype,"_currentFlowItem",void 0),e([u()],$.prototype,"_saveState",void 0),e([u()],$.prototype,"_searchTool",void 0),e([u()],$.prototype,"apiKey",null),e([u(y)],$.prototype,"defaultUnit",void 0),e([u()],$.prototype,"goToOverride",null),e([u()],$.prototype,"headingLevel",void 0),e([u()],$.prototype,"displayedStops",null),e([u()],$.prototype,"effectiveStops",null),e([u()],$.prototype,"icon",null),e([u()],$.prototype,"label",null),e([u({readOnly:!0})],$.prototype,"lastRoute",null),e([u()],$.prototype,"layer",null),e([u()],$.prototype,"maxStops",null),e([u(),N("esri/widgets/Directions/t9n/Directions")],$.prototype,"messages",void 0),e([u(),N("esri/core/t9n/Units")],$.prototype,"messagesUnits",void 0),e([u()],$.prototype,"searchProperties",void 0),e([u()],$.prototype,"unit",null),e([u()],$.prototype,"view",null),e([u({type:M})],$.prototype,"viewModel",void 0),e([u({type:I,nonNullable:!0})],$.prototype,"visibleElements",void 0),$=e([v("esri.widgets.Directions")],$);const z=$;export{z as default};