Directions.js 29 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{_ as e}from"../chunks/tslib.es6.js";import"../intl.js";import{deprecatedProperty as t}from"../core/deprecate.js";import{on as s,pausable as r}from"../core/events.js";import o from"../core/Logger.js";import{isNone as i,isSome as n,unwrap as a,unwrapOrValue as l}from"../core/maybe.js";import{watch as c,initial as d,when as u,on as h}from"../core/reactiveUtils.js";import{property as p}from"../core/accessorSupport/decorators/property.js";import"../core/arrayUtils.js";import{cast as v}from"../core/accessorSupport/decorators/cast.js";import{subclass as m}from"../core/accessorSupport/decorators/subclass.js";import{defaultUnitPropertyMetadata as _}from"../properties/defaultUnit.js";import g from"../rest/support/Stop.js";import y from"../symbols/SimpleMarkerSymbol.js";import S from"./Search.js";import w from"./Widget.js";import M from"./Directions/DirectionsViewModel.js";import{SaveLayer as b}from"./Directions/components/SaveLayer.js";import{formatDistance as f,formatDuration as T}from"./Directions/support/directionsUtils.js";import{DepartureTime as C,CSS as k,getIconPath as I}from"./Directions/support/resources.js";import{isArcGISWorldGeocoder as D,meteredArcGISLocatorUrl as P}from"./Search/support/locatorUtils.js";import L from"./support/DatePicker.js";import{Heading as R,incrementHeadingLevel as B}from"./support/Heading.js";import H from"./support/TimePicker.js";import{accessibleHandler as A}from"./support/decorators/accessibleHandler.js";import{messageBundle as x}from"./support/decorators/messageBundle.js";import{tsx as j}from"./support/jsxFactory.js";import"./support/widgetUtils.js";import E from"sortablejs";import{substitute as U}from"../intl/substitute.js";import{formatDate as O,convertDateFormatToIntlOptions as z}from"../intl/date.js";import{formatNumber as $}from"../intl/number.js";const F={departureTime:!0,layerDetails:!0,printButton:!1,saveAsButton:!0,saveButton:!0,stops:!0,traveMode:!0};function N(e){const t=e.getTimezoneOffset(),s=t>0?"-":"+",r=60,o=Math.abs(Math.floor(t/r)),i=Math.abs(Math.floor(t)%r),n={minimumIntegerDigits:2};return`GMT${s}${$(o,n)}${$(i,n)}`}function K(e){return!!e.composedPath?.().find((e=>e.classList?.contains("esri-search__suggestions-list")))}const V="search-term",W="date-time-picker",q=100,Y=500,G="esri.widgets.Directions",J=o.getLogger(G);let Q=class extends w{constructor(e,t){super(e,t),this._autoStopRemovalDelay=q,this._departureTime=C.NOW,this._datePicker=new L,this._newPlaceholderStop=null,this._pointerPressedSearchSuggestionStop=null,this._renderSavePopoverFunction=null,this._saveAsButtonNode=null,this._saveLayer=new b,this._sections=null,this._stopsToSearches=new Map,this._timePicker=new H,this.headingLevel=2,this.iconClass=k.widgetIcon,this.messages=null,this.messagesCommon=null,this.messagesUnits=null,this.searchProperties=null,this.viewModel=new M,this.visibleElements={...F},this._setUpDragAndDropStops=e=>{this._sortable=E.create(e,{draggable:`.${k.validStopRow}`,ghostClass:k.stopRowGhost,handle:`.${k.stopHandle}`,onEnd:this._handleStopInputDragEnd})},this._handleDragHandlePointerDown=()=>this.viewModel.layer.stops.forEach((e=>this._acquireSearch(e).activeMenu="none")),this._handleStopInputDragEnd=({oldIndex:e,newIndex:t,target:s})=>{if(e===t)return;const{children:r}=s,o=r[t],i=r[e],n=t-e<0;s.insertBefore(o,n?i.nextElementSibling:i);const a=this.viewModel.layer.stops;a.reorder(a.getItemAt(e),t);for(const l of a)l.sequence=null;this._getDirections()}}initialize(){this.addHandles([c((()=>this.viewModel.layer.routeInfo),(()=>{this._activeManeuver=null,this._focusedManeuver=null,this._sections=this._getSections(),this.scheduleRender()}),d),u((()=>this.view),((e,t)=>{if(t&&(this._viewClickHandle=null,this.removeHandles(t)),e){const t=this._prepPointerDownUpClick(),r=this._prepViewClick();t.pause(),r.pause(),this.addHandles([s(e.surface,"mousedown",(()=>this._autoStopRemovalDelay=Y)),s(e.surface,"mouseup",(()=>this._autoStopRemovalDelay=q)),t,r],e),this._pointerDownUpHandle=t,this._viewClickHandle=r}}),d),u((()=>i(this.viewModel.serviceDescription)),(()=>{try{this.viewModel.load()}catch{}}),d),c((()=>this._saveLayer.state),(()=>{this.scheduleRender()}))]),this.when((()=>{this.destroyed||(this._renderSavePopoverFunction=this._renderSavePopover.bind(this),this._projector.append(document.body,this._renderSavePopoverFunction))}))}loadDependencies(){return Promise.all([import("@esri/calcite-components/dist/components/calcite-button.js"),import("@esri/calcite-components/dist/components/calcite-link.js"),import("@esri/calcite-components/dist/components/calcite-popover.js")])}destroy(){this._datePicker.destroy(),this._timePicker.destroy();for(const e of this._stopsToSearches.values())e.destroy();this._sortable&&this._sortable.destroy(),n(this._renderSavePopoverFunction)&&this._projector.detach(this._renderSavePopoverFunction)}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 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}set routeServiceUrl(e){t(J,"routeServiceUrl",{replacement:"viewModel.layer.url",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.url=e}get routeServiceUrl(){return t(J,"routeServiceUrl",{replacement:"viewModel.layer.url",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.url}set routeSymbol(e){t(J,"routeSymbol",{replacement:"viewModel.layer.defaultSymbols.directionLines",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.defaultSymbols.directionLines=e}get routeSymbol(){return t(J,"routeSymbol",{replacement:"viewModel.layer.defaultSymbols.directionLines",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.defaultSymbols.directionLines}set stopSymbols(e){t(J,"stopSymbols",{replacement:"viewModel.layer.defaultSymbols.stops",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.defaultSymbols.stops=e}get stopSymbols(){return t(J,"stopSymbols",{replacement:"viewModel.layer.defaultSymbols.stops",version:"4.24",warnOnce:!0}),this.viewModel.legacyLayer.defaultSymbols.stops}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}castVisibleElements(e){return{...F,...e}}getDirections(){return this.viewModel.getDirections()}render(){return j("div",{class:this.classes(k.base,k.scroller)},this._renderPanelContent())}save(){return this.viewModel.layer.save()}saveAs(e,t={}){return this.viewModel.layer.saveAs(e,t)}zoomToRoute(){return this.viewModel.zoomToRoute()}_renderPanelContent(){const{viewModel:{serviceDescription:e,state:t}}=this,s="initializing"===t,r="error"===t&&!e,o="unauthenticated"===t,i={[k.panelContentLoading]:s,[k.panelContentError]:r,[k.panelContentSignIn]:o},n=s?"presentation":"group",a=o?this._renderSignIn():r?this._renderMessage(this._getErrorMessage()):s?this._renderLoader():this._renderReadyContent();return j("div",{class:this.classes(k.panelContent,i),role:n},a)}_renderReadyContent(){return[this._renderStopsContainer(),this._renderTravelModeOptions(),this._renderDepartureTimeControls(),this._renderSaveContainer(),this._renderSectionSplitter(),this._renderDirectionsContainer()]}_renderSignIn(){return j("div",{key:"sign-in",class:k.signInContent},j(R,{class:k.contentTitle,level:this.headingLevel},this.messages.widgetLabel),this._renderPlaceholder(),j(R,{level:B(this.headingLevel)},this.messages.signInRequired),j("button",{class:this.classes(k.button,k.buttonSecondary,k.signInButton),tabIndex:0,onclick:this._handleSignInClick,bind:this,type:"button"},this.messagesCommon.auth.signIn))}_handleSignInClick(){this.viewModel.load().catch((()=>{}))}_renderTravelModeOptions(){if(!this.visibleElements.traveMode)return null;const{selectedTravelMode:e,travelModes:t}=this.viewModel;if(0===t.length)return null;const s=n(e)?e.name:this.messages.travelMode;return j("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(k.travelMode,this._saveLayer.opened&&k.buttonDisabled),key:"esri-directions__travel-mode-controls",role:"group"},j("select",{"aria-label":s,bind:this,class:this.classes(k.travelModeSelect,k.select),key:"esri-directions__travel-mode-options",onchange:this._handleTravelModeChange,title:s},t.map((t=>{const s=n(e)&&t.id===e.id;return j("option",{key:`esri-directions__travel-mode-${t.id}`,"data-mode":t,selected:s,value:t.id},t.name)}))))}_handleTravelModeChange(e){const t=e.currentTarget,s=t.item(t.selectedIndex);this.viewModel.selectedTravelMode=s["data-mode"],this._getDirections()}_renderStopsContainer(){return this.visibleElements.stops?j("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(k.section,this._saveLayer.opened&&k.buttonDisabled),key:"esri-directions__stops-container",role:"group"},this._renderStops()):null}_renderDepartureTimeControls(){if(!this.visibleElements.departureTime)return null;const e=this._departureTime,{messages:t}=this,s=t.departureTime;return j("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(k.departureTime,this._saveLayer.opened&&k.buttonDisabled),key:"esri-directions__departure-time-controls",role:"group"},j("select",{"aria-label":s,bind:this,class:this.classes(k.departureTimeSelect,k.select),onchange:this._handleDepartureOptionChange,title:s},j("option",{value:C.NOW,selected:e===C.NOW},t.leaveNow),j("option",{value:C.DEPART_BY,selected:e===C.DEPART_BY},t.departBy),j("option",{value:C.UNSPECIFIED,selected:e===C.UNSPECIFIED},t.timeUnspecified)),e===C.DEPART_BY?this._renderTimeControls():null)}_renderStops(){const e=this.viewModel.layer.stops;let t=0;for(const o of this._stopsToSearches.keys())e.includes(o)||this._disposeSearch(o);for(const o of e){const e=this._acquireSearch(o);"none"!==e.activeMenu&&(t+=1),n(o.name)&&(e.searchTerm=o.name)}const s=e.toArray().map(((s,r)=>{const o=e.length,a=r>1&&i(s.geometry),l={[k.stopsIcon]:r>=0&&r<o-1,[k.lastStopIcon]:r===o-1},c={[k.lastStopIconContainer]:r===o-1},d={[k.validStopRow]:!a},u=e.getItemAt(r+1),h=u&&n(u.geometry),p=r===o-1,v=r===o-2,m=2===o&&0===r||o>2&&!p&&!v||o>2&&v&&h||o>2&&p&&i(s.geometry),_=o<3,g=this._acquireSearch(s),{messages:y}=this,{removeStop:S,reverseStops:w,unlocated:M}=y,b=U(y.stopLabelTemplate,{number:r+1,label:n(s.geometry)?s.name:M}),f=`${this.id}__stop--${r}`,T=!!g.searchTerm&&!!g.selectedResult&&n(s.geometry)&&g.selectedResult.name===s.name,C={zIndex:"none"!==g.activeMenu?""+t--:""};return j("li",{"aria-label":b,afterCreate:this._handleStopFieldCreation,bind:this,class:this.classes(k.stopRow,d),id:f,key:r,"data-stop-index":r,styles:C},j("div",{class:k.stopHandle},j("span",{"aria-hidden":"true",class:this.classes(k.stopIcon,k.handleIcon,k.stopHandleIcon,k.interactiveStopIcon),onpointerdown:this._handleDragHandlePointerDown}),j("div",{bind:this,"aria-labelledby":f,class:this.classes(k.stopIconContainer,c),"data-stop-index":r,onclick:this._handleStopIconClick,onkeydown:this._handleStopIconClick,role:"button"},j("span",{class:this.classes(k.stopIcon,l),tabindex:T?"0":null}))),j("div",{class:k.stopInput},g.render()),j("div",{class:k.stopOptions,role:"group"},j("div",{"aria-label":S,class:k.removeStopButton,bind:this,"data-stop-index":r,hidden:_,onkeydown:this._handleRemoveStop,onclick:this._handleRemoveStop,role:"button",tabIndex:0,title:S},j("span",{"aria-hidden":"true",class:this.classes(k.stopIcon,k.removeStop,k.removeStopIcon,k.interactiveStopIcon)}),j("span",{class:k.screenReaderText},"removeStopTitle")),j("div",{"aria-label":w,class:k.reverseStops,bind:this,hidden:m,onkeydown:this._handleReverseStops,onclick:this._handleReverseStops,role:"button",tabIndex:0,title:w},j("span",{"aria-hidden":"true",class:this.classes(k.stopIcon,k.reverseStopIcon,k.interactiveStopIcon)}),j("span",{class:k.screenReaderText},"removeStopTitle"))))})),r=this._renderAddStop();return j("div",null,j("ol",{class:k.stops,role:"group",afterCreate:this._setUpDragAndDropStops},s),r)}_renderAddStop(){const{stops:e}=this.viewModel.layer,t=e.filter((({geometry:e})=>n(e))),s=e.at(-1);return t.length>1&&t.length<this.maxStops&&n(s)&&n(s.geometry)?j("div",{class:k.toolbarSection},j("div",{class:k.toolbarButtons},j("calcite-button",{appearance:"outline",class:k.addStopButton,color:"neutral",scale:"s",round:!0,"icon-start":"plus",key:k.addStopButton,onclick:()=>{this._addNewPlaceholder()},text:this.messages.addStop,width:"full"},this.messages.addStop))):null}_handleStopIconClick(e){const t=e.currentTarget["data-stop-index"],s=this.viewModel.layer.stops.getItemAt(t);s&&n(s.geometry)&&this._centerAtStop(s)}_handleClearRouteClick(){this.viewModel.reset()}_centerAtStop(e){this.viewModel.centerAt(e)}_handleStopFieldCreation(e){const t=this._newPlaceholderStop;if(!t)return;const s=e["data-stop-index"],r=this.viewModel.layer.stops.getItemAt(s);if(t===r){const e=this._acquireSearch(r);e.when((()=>{this.renderNow(),e.focus()}))}this._newPlaceholderStop=null}_handleStopInputBlur(e,t){if(this._saveLayer.opened)return;this.removeHandles(V);if(!!e.selectedResult&&n(t.geometry)&&n(e.selectedResult?.feature.geometry)&&t.geometry===e.selectedResult?.feature.geometry)return void this._pointerDownUpHandle.pause();const s=i(t.geometry)&&i(e.selectedResult?.feature.geometry),r=n(t.geometry)&&n(e.selectedResult?.feature.geometry)&&t.geometry!==e.selectedResult.feature.geometry;if((s||r)&&"none"===e.activeMenu&&e.searchTerm)return e.search(),void this._pointerDownUpHandle.pause();e.searchTerm||(this._viewClickHandle.resume(),clearTimeout(this._autoStopRemovalTimeoutId),this._autoStopRemovalTimeoutId=setTimeout((()=>{this.destroyed||(this._viewClickHandle.pause(),"searching"!==e.viewModel.state?this._pointerPressedSearchSuggestionStop||(n(t.geometry)&&(t.geometry=null,this._getDirections()),this.scheduleRender()):this._pointerDownUpHandle.pause())}),this._autoStopRemovalDelay))}_handleStopInputFocus(e,t){if(this._pointerDownUpHandle.resume(),this.hasHandles(V))return;const{view:s}=this,r=s.cursor;this.addHandles([{remove(){s.cursor=r}},c((()=>e.searchTerm),(t=>{e.destroyed||(s.cursor=t.length?r:"copy")}),d)],V),this._activeStop=t}_prepViewClick(){const{view:e}=this.viewModel,t=r(e,"click",this._handleViewClick.bind(this)),s=r(e.surface,"click",(()=>{clearTimeout(this._autoStopRemovalTimeoutId),s.pause()}));return{remove(){s.remove(),t.remove()},pause(){s.pause(),t.pause()},resume(){s.resume(),t.resume()}}}_prepPointerDownUpClick(){const e=r(document,"pointerdown",(e=>{this._pointerPressedSearchSuggestionStop=K(e)?this._activeStop:null})),t=r(document,"pointerup",(e=>{this._pointerDownUpHandle.pause();const t=K(e),s=this._activeStop;t||s!==this._pointerPressedSearchSuggestionStop||this._removeStop(s),this.scheduleRender(),this._pointerPressedSearchSuggestionStop=t?s:null}));return{remove(){t.remove(),e.remove()},pause(){t.pause(),e.pause()},resume(){e.resume()}}}_handleViewClick(e){e.stopPropagation();const t=this._stopsToSearches.get(this._activeStop);t&&!t.searchTerm&&(t.search(e.mapPoint).then((e=>{const s=e.results[0].results[0],{feature:r,name:o}=s;this._activeStop.geometry=r.geometry,this._activeStop.name=o,t.searchTerm=o})),this.scheduleRender()),this._viewClickHandle.pause(),clearTimeout(this._autoStopRemovalTimeoutId)}_addNewPlaceholder(){if(this._pointerDownUpHandle.pause(),this._newPlaceholderStop)return;const e=new g({symbol:new y});this.viewModel.layer.stops.add(e),this._newPlaceholderStop=e}_handleReverseStops(){this._reverseStops()}_reverseStops(){this.viewModel.layer.stops.reverse();for(const e of this.viewModel.layer.stops)e.sequence=null;this._getDirections()}_handleRemoveStop(e){const t=e.currentTarget["data-stop-index"],s=this.viewModel.layer.stops.getItemAt(t);this._removeStop(s),(n(s.geometry)||i(this.viewModel.layer.routeInfo))&&this._getDirections()}_removeStop(e){this.viewModel.layer.stops.length<=2||(this._disposeSearch(e),this.viewModel.layer.stops.remove(e))}_handleDepartureOptionChange(e){const t=e.currentTarget,s=t.item(t.selectedIndex);s.value===C.NOW?(this._departureTime=C.NOW,this.viewModel.departureTime=C.NOW,this.removeHandles(W),this._getDirections()):s.value===C.DEPART_BY?(this._departureTime=C.DEPART_BY,this.addHandles(c((()=>[this._datePicker.value,this._timePicker.value]),(()=>{this._updateDepartureTime(),this._getDirections()}),d),W)):(this._departureTime=C.UNSPECIFIED,this.viewModel.departureTime=null,this._getDirections())}_updateDepartureTime(){const e=this._datePicker.value,t=this._timePicker.value;e&&t&&(this.viewModel.departureTime=new Date(e.getFullYear(),e.getMonth(),e.getDate(),t.getHours(),t.getMinutes()))}_renderTimeControls(){return j("div",{class:k.departureTimeControls,key:"esri-directions__time-controls",role:"group"},this._datePicker.render(),this._timePicker.render())}_renderSectionSplitter(){return j("div",{class:k.sectionSplitter})}_renderSaveContainer(){const{saveButton:e,saveAsButton:t,printButton:s,layerDetails:r}=this.visibleElements;return e||t||s||r?j("div",{class:k.saveSection,key:k.saveSection},this._renderSaveButtons(),this._renderRouteLayerDetailsLink()):null}_renderSaveButtons(){const{saveButton:e,saveAsButton:t,printButton:s}=this.visibleElements;return e||t||s?j("div",{class:k.saveButtons,key:k.saveButtons},this._renderSaveButton(),this._renderSaveAsButton(),this._renderPrintButton()):null}_renderSaveButton(){if(!this.visibleElements.saveButton)return null;const e=this.viewModel.layer.portalItem?.itemControl,t=n(this.viewModel.layer.routeInfo)&&("admin"===e||"update"===e);return j("calcite-button",{appearance:"outline",class:k.saveButton,color:"blue",disabled:!t,"icon-start":"save",key:k.saveButton,onclick:()=>{this._handleSaveButtonClick()},text:this.messagesCommon.save,width:"full"},this.messagesCommon.save)}_renderSaveAsButton(){if(!this.visibleElements.saveAsButton)return null;const e=i(this.viewModel.layer.routeInfo);return j("div",{class:k.saveAsButtonPopover,key:k.saveAsButtonPopover},j("calcite-button",{afterCreate:e=>{this._saveAsButtonNode=e},appearance:"outline",class:k.saveAsButton,color:"blue",disabled:e,"icon-start":"duplicate",key:k.saveAsButton,onclick:()=>this._handleSaveAsButtonClick(),text:this.messagesCommon.saveAs,width:"full"},this.messagesCommon.saveAs))}_renderSavePopover(){return j("calcite-popover",{label:this._saveLayer.label,open:this._saveLayer.opened,"overlay-positioning":"fixed",referenceElement:a(this._saveAsButtonNode)},this._saveLayer.render())}_handleSaveAsButtonClick(){this._saveLayer.opened?this._saveLayer.close():this._saveLayer.open(this.viewModel.layer)}_renderPrintButton(){return this.visibleElements.printButton?j("calcite-button",{appearance:"outline",class:k.printButton,color:"blue","icon-start":"print",key:k.printButton,text:this.messagesCommon.print}):null}_renderRouteLayerDetailsLink(){if(!this.visibleElements.layerDetails)return null;const{portalItem:e}=this.viewModel.layer;if(!e)return null;const{id:t,portal:{url:s}}=e,r=`${s}/home/item.html?id=${t}`;return j("calcite-link",{class:k.layerDetailsLink,href:r,key:k.layerDetailsLink,target:"_blank"},this.messages.viewLayerDetails)}_handleSaveButtonClick(){this.viewModel.layer.save()}_renderDirectionsContainer(){return j("div",{class:this.classes(k.directionsSection,k.section),key:"esri-directions__container"},this._renderDirectionsContainerContent())}_renderLoader(){return j("div",{class:k.loader,key:"loader"})}_renderWarningCard(){return j("div",{class:k.warningCard,role:"alert"},j("div",{class:k.warningHeader},j("span",{class:k.warningIcon,"aria-hidden":"true"}),j(R,{class:k.warningHeading,level:this.headingLevel},this.messagesCommon.warning)),j("div",{class:k.warningMessage},this._getErrorMessage()))}_renderDirectionsContainerContent(){const{viewModel:{layer:e,state:t}}=this,s="routing"===t;return"error"===t?this._renderWarningCard():s?this._renderLoader():n(e.directionLines)?j("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(k.summary,this._saveLayer.opened&&k.buttonDisabled),key:"esri-directions__summary",role:"group"},this._renderCosts(),this._renderRouteActions(),this._renderManeuverSections()):j("div",{key:"esri-directions__placeholder",class:k.emptyContent},this._renderPlaceholder(),j(R,{class:k.message,level:this.headingLevel},this.messages.directionsPlaceholder))}_renderPlaceholder(){return j("svg",{class:k.emptyIllustration,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256"},j("path",{fill:"currentcolor",d:"M192 36c-15.477 0-24 6.034-24 16.99v45.822l24 24 24-24v-45.82C216 42.033 207.477 36 192 36zm20 61.155l-20 20-20-20V52.99c0-8.62 6.73-12.99 20-12.99s20 4.37 20 12.99zM192 52a12 12 0 1 0 12 12 12.013 12.013 0 0 0-12-12zm0 20a8 8 0 1 1 8-8 8.008 8.008 0 0 1-8 8zM92 140.99C92 130.035 83.477 124 68 124s-24 6.034-24 16.99v45.822l24 24 24-24zm-4 44.165l-20 20-20-20V140.99c0-8.62 6.73-12.99 20-12.99s20 4.37 20 12.99zM68 140a12 12 0 1 0 12 12 12.013 12.013 0 0 0-12-12zm0 20a8 8 0 1 1 8-8 8.008 8.008 0 0 1-8 8zm84-44h16v4h-16zm-24 80h4v12h-12v-4h8zm0-28h4v16h-4zm0-52h12v4h-8v8h-4zm0 24h4v16h-4zm-36 64h16v4H92z"}))}_renderMessage(e){return j(R,{level:this.headingLevel},e)}_renderRouteActions(){return j("div",{class:k.routeActions},j("button",{"aria-label":this.messages.clearRoute,class:this.classes(k.clearRouteButton,k.button,k.buttonTertiary),tabIndex:0,onclick:this._handleClearRouteClick,bind:this,type:"button"},this.messages.clearRoute))}_getSections(){const{directionPoints:e,directionLines:t,stops:s}=this.viewModel.layer;if(i(e)||i(t))return null;const r=[];let o=null;for(const a of e){const{objectId:e,stopId:l}=a;if(n(l)){const e=s.find((e=>e.objectId===l)),t=0===r.length;(i(o)||o.stop!==e)&&(o={stop:e,directions:[],open:t},r.push(o));continue}if(i(o))continue;const c=t.find((t=>t.directionPointId===e));i(c)||o.directions.push({directionPoint:a,directionLine:c})}return r}_renderManeuverSections(){return i(this._sections)?null:j("div",{class:k.maneuvers,role:"group"},this._sections.map(((e,t)=>{const{open:s}=e;let r;e.directions.length>0&&s&&(r=j("ol",{class:k.maneuverList},e.directions.map((e=>this._renderManeuver(e)))));const o=a(this._sections).length>2,i=t===a(this._sections).length-1,n={[k.collapsibleSection]:o},l={[k.openIcon]:!s,[k.closeIcon]:s};let c;if(o&&!i){const t=s?this.messagesCommon.close:this.messagesCommon.open;c=j("header",{class:this.classes(k.maneuverSectionHeader,k.maneuverSectionToggle),key:k.maneuverSectionHeader},j("div",{"aria-expanded":s.toString(),"aria-label":t,bind:this,class:k.maneuverSectionHeaderButton,"data-maneuver-section":e,onkeydown:this._handleSectionToggle,onclick:this._handleSectionToggle,role:"button",tabIndex:0,title:t},j(R,{class:k.maneuverSectionTitle,level:this.headingLevel},e.stop.name),j("span",{"aria-hidden":"true",class:this.classes(l)})))}else c=j("header",{class:k.maneuverSectionHeader,key:k.maneuverSectionHeader},j(R,{class:k.maneuverSectionTitle,level:this.headingLevel},e.stop.name));return j("section",{class:this.classes(k.maneuverSection,n),key:t},c,r)})))}_handleSectionToggle(e){const t=e.currentTarget["data-maneuver-section"];t.open=!t.open}_renderCosts(){const e=this._getCostSummary(),{directionPoints:t}=this.viewModel.layer;if(i(t)||i(e))return null;const s=t.getItemAt(t.length-1).arrivalTime,{distance:r,duration:o}=e,{eta:a,etaTemplate:l,primaryCosts:c,secondaryCosts:d,zoomToRoute:u}=this.messages,h=z("short-time"),p=n(s)?`<strong>${O(s,h)}</strong>`:null,v=n(s)?`${N(s)}`:null,m=U(l,{time:p,gmt:v});return j("div",{"aria-label":u,bind:this,class:k.directionCosts,onkeydown:this._handleSummaryInteraction,onclick:this._handleSummaryInteraction,role:"button",tabIndex:0,title:u},j("div",{class:k.costsDetails,role:"group"},j("div",{class:k.primaryCosts,title:c},o),j("div",{class:k.verticalSplitter}),j("div",{class:k.secondaryCosts,title:d},r)),j("div",{innerHTML:m,title:a}))}_handleSummaryInteraction(){this._activeManeuver=null,this._focusedManeuver=null,this.viewModel.clearHighlights(),this.zoomToRoute()}_getErrorMessage(){const{messages:e,viewModel:{lastError:t}}=this;if(n(t))switch(t.name){case"directions-view-model:unable-to-route":return e.errors.unableToRoute;case"directions-view-model:service-metadata-unavailable":return e.errors.unableToLoadServiceMetadata}return e.errors.unknownError}_normalizeSearchSources(e){this._overrideDefaultSources(e),this._applyLocatorSourceOverrides(e)}_overrideDefaultSources(e){e.viewModel.defaultSources.forEach((e=>{e.autoNavigate=!1}))}_applyLocatorSourceOverrides({allSources:e}){for(const t of e)"url"in t&&t.url&&(t.locationType??(t.locationType="street"),D(t.url)&&this.apiKey&&null==t.apiKey&&(t.apiKey=this.apiKey,t.url=P))}_acquireSearch(e){const{view:t}=this.viewModel;if(this._stopsToSearches.has(e)){const s=this._stopsToSearches.get(e);return s.view=t,this._overrideDefaultSources(s),s}const s=new S({view:t,resultGraphicEnabled:!1,popupEnabled:!1,...this.searchProperties});return this._normalizeSearchSources(s),this.addHandles([h((()=>s.allSources),"change",(()=>this._normalizeSearchSources(s))),s.on("select-result",(()=>{e.geometry=s.selectedResult.feature.geometry,e.name=s.selectedResult.name,this._getDirections()})),s.on("search-focus",(()=>this._handleStopInputFocus(s,e))),s.on("search-blur",(()=>this._handleStopInputBlur(s,e))),s.on("search-clear",(()=>{e.geometry=null,e.name=null,this._activeStop=e,this.viewModel.layer.removeResult()})),c((()=>s.searchTerm),(t=>{e.name=t}))],s),this._stopsToSearches.set(e,s),s}_disposeSearch(e){if(this._stopsToSearches.has(e)){const t=this._stopsToSearches.get(e);this.removeHandles(t),t.destroy(),this._stopsToSearches.delete(e)}}_renderManeuver(e){const{directionPoint:t,directionLine:s}=e,{distance:r,duration:o}=s,{messages:i,messagesUnits:a,unit:c}=this,d=f(a,l(r,0),c),u=T(l(o,0)),h=d&&u?`${d}&nbsp;&middot;&nbsp;${u}`:`${d}${u}`,p=this._getFormattedManeuverText(t),{objectId:v,directionPointType:m}=t,_=I(m),g=`esri-directions__maneuver-${v}`,y=`esri-directions__intermediate-costs-${v}`,S={[k.maneuverActive]:this._activeManeuver===s};return j("li",{"aria-labelledby":`${g} ${y}`,bind:this,class:this.classes(k.maneuver,S),"data-maneuver":s,key:s,onclick:this._handleManeuverClick,onkeydown:this._handleManeuverClick,onfocus:this._handleManeuverFocus,onmouseover:this._handleManeuverMouseOver,onmouseout:this._handleManeuverMouseOut,onblur:this._handleManeuverBlur,tabIndex:0},n(_)&&j("img",{alt:"",class:k.maneuverIcon,src:_}),j("div",{class:k.maneuverCostsContainer},j("span",{id:g,innerHTML:l(p,"")}),j("div",{class:k.maneuverCosts},j("div",{class:k.horizontalSplitter}),j("div",{"aria-hidden":"true",id:y,class:k.intermediateCost,innerHTML:h,title:i.intermediateCosts}))))}_handleManeuverClick(e){const t=e.currentTarget["data-maneuver"];if(this._activeManeuver===t)return this._activeManeuver=null,void this.zoomToRoute();this._activeManeuver=t;const{geometry:s}=t;this.viewModel.centerAt(s),this.viewModel.highlight(t)}_handleManeuverMouseOver(e){if(this._activeManeuver||this._focusedManeuver)return;const t=e.currentTarget["data-maneuver"];this.viewModel.highlight(t)}_handleManeuverMouseOut(){this._activeManeuver||this._focusedManeuver||this.viewModel.clearHighlights()}_handleManeuverBlur(){this._activeManeuver||(this._focusedManeuver=null,this.viewModel.clearHighlights())}_handleManeuverFocus(e){if(this._activeManeuver)return;const t=e.currentTarget["data-maneuver"];this._focusedManeuver=t,this.viewModel.highlight(t)}_getFormattedManeuverText(e){const{displayText:t,name:s,intersectingName:r}=e;if(i(t))return"";let o=t;return n(s)&&o.includes(s)&&(o=o.replace(s,`<strong>${s}</strong>`)),n(r)&&o.includes(r)&&(o=o.replace(r,`<strong>${r}</strong>`)),o}_getCostSummary(){const{messagesUnits:e,unit:t,viewModel:s}=this,{routeInfo:r}=s.layer;if(i(r))return null;const o=l(r.totalDistance,0),n=l(r.totalDuration,0);return{distance:f(e,o,t),duration:T(n)}}async _getDirections(){if(!(this.viewModel.layer.stops.filter((e=>n(e.geometry))).length<2))try{await this.viewModel.getDirections()}catch{}}};e([p()],Q.prototype,"apiKey",null),e([p(_)],Q.prototype,"defaultUnit",void 0),e([p()],Q.prototype,"goToOverride",null),e([p()],Q.prototype,"headingLevel",void 0),e([p()],Q.prototype,"iconClass",void 0),e([p()],Q.prototype,"label",null),e([p({readOnly:!0})],Q.prototype,"lastRoute",null),e([p()],Q.prototype,"layer",null),e([p()],Q.prototype,"maxStops",null),e([p(),x("esri/widgets/Directions/t9n/Directions")],Q.prototype,"messages",void 0),e([p(),x("esri/t9n/common")],Q.prototype,"messagesCommon",void 0),e([p(),x("esri/core/t9n/Units")],Q.prototype,"messagesUnits",void 0),e([p()],Q.prototype,"routeServiceUrl",null),e([p()],Q.prototype,"routeSymbol",null),e([p()],Q.prototype,"searchProperties",void 0),e([p()],Q.prototype,"stopSymbols",null),e([p()],Q.prototype,"unit",null),e([p()],Q.prototype,"view",null),e([p({type:M})],Q.prototype,"viewModel",void 0),e([p()],Q.prototype,"visibleElements",void 0),e([v("visibleElements")],Q.prototype,"castVisibleElements",null),e([A()],Q.prototype,"_handleStopIconClick",null),e([A()],Q.prototype,"_handleClearRouteClick",null),e([A()],Q.prototype,"_handleReverseStops",null),e([A()],Q.prototype,"_handleRemoveStop",null),e([A()],Q.prototype,"_handleSectionToggle",null),e([A()],Q.prototype,"_handleSummaryInteraction",null),e([A()],Q.prototype,"_handleManeuverClick",null),Q=e([m(G)],Q);const X=Q;export{X as default};