// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("require ../chunks/tslib.es6 ../intl ../core/events ../core/handleUtils ../core/maybe ../core/reactiveUtils ../core/string ../core/accessorSupport/decorators/property ../core/accessorSupport/decorators/cast ../core/RandomLCG ../core/has ../core/accessorSupport/decorators/subclass ../properties/defaultUnit ../rest/support/Stop ../symbols/SimpleMarkerSymbol ./Search ./Widget ./Directions/css ./Directions/DirectionsViewModel ./Directions/components/SaveLayer ./Directions/support/directionsUtils ./Search/support/locatorUtils ../chunks/componentsUtils ./support/globalCss ./support/Heading ./support/legacyIcon ./support/decorators/accessibleHandler ./support/decorators/messageBundle ./support/jsxFactory ./support/widgetUtils ../intl/number".split(" "), function(va,C,vc,wa,Vb,ub,Y,Wb,K,Xb,wc,xc,Yb,Zb,$b,ac,bc,cc,h,vb,dc,T,wb,ec,R,ma,ba,ra,cb,m,yc,fc){function xb(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(e){return Object.getOwnPropertyDescriptor(a,e).enumerable}));c.push.apply(c,d)}return c}function ca(a){for(var b=1;b=b;if(!e)return d;if(d===ka())break;d=na(d,!1)}return!1}function ya(a,b,c,d){for(var e= 0,f=0,g=a.children;fc.right+10||a.clientY>d.bottom&&a.clientX>d.left:a.clientY>c.bottom+10||a.clientX>d.right&&a.clientY>d.top}function mc(a,b,c,d,e,f,g,k){a=d?a.clientY:a.clientX;var l=d?c.height:c.width,p=d?c.top:c.left;c=d?c.bottom:c.right;d=!1;if(!g)if(k&&Rap+l*f/2:ac-Ra)return-Ka}else if(a>p+l*(1-e)/2&&ac-l*f/2)return a>p+l/2?1:-1;return 0}function nc(a){Sa.length=0;a=a.getElementsByTagName("input");for(var b=a.length;b--;){var c=a[b];c.checked&&Sa.push(c)}}function Ta(a){return setTimeout(a,0)}function Ua(){I.forEach(function(a){clearInterval(a.pid)});I=[]}function ib(){}function jb(){}function oc(a){const {branchName:b,displayText:c,exitName:d,intersectingName:e,name:f,objectId:g,towardName:k}=a;if(null==c)return null;a=[b,d,e,f,k].filter(Boolean).sort((q,r)=>r.length-q.length).map(q=> Wb.escapeRegExpString(q));if(!a.length)return c;a=new RegExp(a.join("|"),"g");a=c.matchAll(a);let l=0;const p=[];for(const {0:q,index:r}of a)p.push(c.slice(l,r),m.tsx("span",{class:h.css.maneuverPlaceName},q)),l=r+q.length;p.push(c.slice(l));return m.tsx("span",{id:`${h.css.maneuver}-${g}`},p)}function Jb(a){return!!a.composedPath?.().find(b=>b.classList?.contains("esri-search__suggestions-list"))}function pc(a){a=new Date(a);return new Date(a.getUTCFullYear(),a.getUTCMonth(),a.getUTCDate())}function kb(a){return a?.["data-stop-index"]} var ja=ia(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),Ga=ia(/Edge/i),Kb=ia(/firefox/i),Ia=ia(/safari/i)&&!ia(/chrome/i)&&!ia(/android/i),La=ia(/iP(ad|od|hone)/i),Lb=ia(/chrome/i)&&ia(/android/i),yb={capture:!1,passive:!1},zb=/\s+/g,Ea,W="Sortable"+(new Date).getTime(),Aa=[],lb={initializeByDefault:!0},Ha={mount:function(a){for(var b in lb)!lb.hasOwnProperty(b)||b in a||(a[b]=lb[b]);Aa.forEach(function(c){if(c.pluginName===a.pluginName)throw"Sortable: Cannot mount plugin ".concat(a.pluginName, " more than once");});Aa.push(a)},pluginEvent:function(a,b,c){var d=this;this.eventCanceled=!1;c.cancel=function(){d.eventCanceled=!0};var e=a+"Global";Aa.forEach(function(f){if(b[f.pluginName]){if(b[f.pluginName][e])b[f.pluginName][e](ca({sortable:b},c));if(b.options[f.pluginName]&&b[f.pluginName][a])b[f.pluginName][a](ca({sortable:b},c))}})},initializePlugins:function(a,b,c,d){Aa.forEach(function(f){var g=f.pluginName;if(a.options[g]||f.initializeByDefault)f=new f(a,b,a.options),f.sortable=a,f.options= a.options,a[g]=f,ha(c,f.defaults)});for(var e in a.options)a.options.hasOwnProperty(e)&&(d=this.modifyOption(a,e,a.options[e]),"undefined"!==typeof d&&(a.options[e]=d))},getEventProperties:function(a,b){var c={};Aa.forEach(function(d){"function"===typeof d.eventProperties&&ha(c,d.eventProperties.call(b[d.pluginName],a))});return c},modifyOption:function(a,b,c){var d;Aa.forEach(function(e){a[e.pluginName]&&e.optionListeners&&"function"===typeof e.optionListeners[b]&&(d=e.optionListeners[b].call(a[e.pluginName], c))});return d}},qc=["evt"],S=function(a,b){var c=2=c.gridTemplateColumns.split(" ").length?"vertical":"horizontal":e&&f["float"]&&"none"!==f["float"]?(c="left"===f["float"]?"left":"right", !a||"both"!==b.clear&&b.clear!==c?"horizontal":"vertical"):e&&("block"===f.display||"flex"===f.display||"table"===f.display||"grid"===f.display||g>=d&&"none"===c[Qb]||a&&"none"===c[Qb]&&g+k>d)?"vertical":"horizontal"},rc=function(a,b,c){var d=c?a.left:a.top,e=c?a.right:a.bottom;a=c?a.width:a.height;var f=c?b.left:b.top,g=c?b.right:b.bottom;b=c?b.width:b.height;return d===f||e===g||d+a/2===f+b/2},sc=function(a,b){var c;Pa.some(function(d){var e=d[W].options.emptyInsertThreshold;if(e&&!eb(d)){var f= H(d),g=b>=f.top-e&&b<=f.bottom+e;if(a>=f.left-e&&a<=f.right+e&&g)return c=d}});return c},Ib=function(a){function b(e,f){return function(g,k,l,p){var q=g.options.group.name&&k.options.group.name&&g.options.group.name===k.options.group.name;if(null==e&&(f||q))return!0;if(null==e||!1===e)return!1;if(f&&"clone"===e)return e;if("function"===typeof e)return b(e(g,k,l,p),f)(g,k,l,p);g=(f?g:k).options.group.name;return!0===e||"string"===typeof e&&e===g||e.join&&-1=Math.floor(this.options.touchStartThreshold/(this.nativeDraggable&&window.devicePixelRatio||1))&&this._disableDelayedDrag()},_disableDelayedDrag:function(){n&&gb(n);clearTimeout(this._dragStartTimer); this._disableDelayedDragEvents()},_disableDelayedDragEvents:function(){var a=this.el.ownerDocument;w(a,"mouseup",this._disableDelayedDrag);w(a,"touchend",this._disableDelayedDrag);w(a,"touchcancel",this._disableDelayedDrag);w(a,"mousemove",this._delayedDragTouchMoveHandler);w(a,"touchmove",this._delayedDragTouchMoveHandler);w(a,"pointermove",this._delayedDragTouchMoveHandler)},_triggerDragStart:function(a,b){b=b||"touch"==a.pointerType&&a;!this.nativeDraggable||b?this.options.supportPointer?x(document, "pointermove",this._onTouchMove):b?x(document,"touchmove",this._onTouchMove):x(document,"mousemove",this._onTouchMove):(x(n,"dragend",this),x(D,"dragstart",this._onDragStart));try{document.selection?Ta(function(){document.selection.empty()}):window.getSelection().removeAllRanges()}catch(c){}},_dragStarted:function(a,b){Ba=!1;if(D&&n){S("dragStarted",this,{evt:b});this.nativeDraggable&&x(document,"dragover",tc);var c=this.options;!a&&U(n,c.dragClass,!1);U(n,c.ghostClass,!0);u.active=this;a&&this._appendGhost(); O({sortable:this,name:"start",originalEvent:b})}else this._nulling()},_emulateDragOver:function(){if(aa){this._lastX=aa.clientX;this._lastY=aa.clientY;Mb();for(var a=document.elementFromPoint(aa.clientX,aa.clientY),b=a;a&&a.shadowRoot;){a=a.shadowRoot.elementFromPoint(aa.clientX,aa.clientY);if(a===b)break;b=a}n.parentNode[W]._isOutsideThisEl(a);if(b){do{if(b[W]){var c=void 0;if((c=b[W]._onDragOver({clientX:aa.clientX,clientY:aa.clientY,target:a,rootEl:b}))&&!this.options.dragoverBubble)break}a=b}while(b= b.parentNode)}Nb()}},_onTouchMove:function(a){if(ta){var b=this.options,c=b.fallbackTolerance,d=b.fallbackOffset;b=a.touches?a.touches[0]:a;var e=v&&xa(v,!0),f=v&&e&&e.a,g=v&&e&&e.d,k=La&&N&&Cb(N);f=(b.clientX-ta.clientX+d.x)/(f||1)+(k?k[0]-ob[0]:0)/(f||1);d=(b.clientY-ta.clientY+d.y)/(g||1)+(k?k[1]-ob[1]:0)/(g||1);if(!u.active&&!Ba){if(c&&Math.max(Math.abs(b.clientX-this._lastX),Math.abs(b.clientY-this._lastY)){this._sortable= u.create(c,{draggable:`.${h.css.validStopRow}`,ghostClass:h.css.stopRowGhost,handle:`.${h.css.stopHandle}`,onEnd:this._handleStopInputDragEnd})};this._handleDragHandlePointerDown=()=>this.viewModel.layer?.stops.forEach(c=>this.acquireSearch(c).activeMenu="none");this._handleStopInputDragEnd=({oldIndex:c,newIndex:d,target:e})=>{if(c!==d&&null!=d&&null!=c){var {children:f}=e,g=f[c];e.insertBefore(f[d],0>d-c?g.nextElementSibling:g);({stops:e}=this.viewModel.layer);e.reorder(e.at(c),d);for(const k of e)k.sequence= null;this._solveRoute()}}}initialize(){this.addHandles([Y.watch(()=>this.viewModel.layer?.routeInfo,()=>{this._focusedManeuver=this._activeManeuver=null;this._sections=this._getSections();this.scheduleRender()},Y.initial),Y.when(()=>[this.view,this.view?.surface],([a,b],c)=>{if(c=c?.[0])this._viewClickHandle=null,c&&this.removeHandles(c);if(a&&b){c=this._prepPointerDownUpClick();const d=this._prepViewClick();c.pause();d.pause();this.addHandles([wa.on(b,"mousedown",()=>this._autoStopRemovalDelay=500), wa.on(b,"mouseup",()=>this._autoStopRemovalDelay=100),c,d],a);this._pointerDownUpHandle=c;this._viewClickHandle=d}},Y.initial),Y.when(()=>null==this.viewModel.serviceDescription,()=>{try{this.viewModel.load()}catch{}},Y.initial),Y.watch(()=>this._saveLayer.state,()=>{this.scheduleRender()})]);this.when(()=>{!this.destroyed&&this.visibleElements.saveAsButton&&(this._renderSavePopoverFunction=this._renderSavePopover.bind(this),this._projector.append(document.body,this._renderSavePopoverFunction))})}loadDependencies(){return ec.loadCalciteComponents({button:()=> new Promise((a,b)=>va(["../chunks/calcite-button"],a,b)),icon:()=>new Promise((a,b)=>va(["../chunks/calcite-icon"],a,b)),"input-date-picker":()=>new Promise((a,b)=>va(["../chunks/calcite-input-date-picker"],a,b)),"input-time-picker":()=>new Promise((a,b)=>va(["../chunks/calcite-input-time-picker"],a,b)),link:()=>new Promise((a,b)=>va(["../chunks/calcite-link"],a,b)),popover:()=>new Promise((a,b)=>va(["../chunks/calcite-popover"],a,b))})}destroy(){for(const a of this._stopsToSearches.values())a.destroy(); this._sortable?.destroy();null!=this._renderSavePopoverFunction&&this._projector.detach(this._renderSavePopoverFunction)}get apiKey(){return this.viewModel.apiKey}set apiKey(a){this.viewModel.apiKey=a}get goToOverride(){return this.viewModel.goToOverride}set goToOverride(a){this.viewModel.goToOverride=a}get icon(){return"right"}set icon(a){this._overrideIfSome("icon",a)}get label(){return this.messages?.widgetLabel??""}set label(a){this._overrideIfSome("label",a)}get lastRoute(){return this.viewModel.lastRoute}get layer(){return this.viewModel.layer}set layer(a){this.viewModel.layer= a}get maxStops(){return this.viewModel.maxStops}set maxStops(a){this.viewModel.maxStops=a}get unit(){return this.defaultUnit}set unit(a){this._overrideIfSome("unit",a)}get view(){return this.viewModel.view}set view(a){this.viewModel.view=a}castVisibleElements(a){return{...Ub,...a}}acquireSearch(a){const {view:b}=this.viewModel;if(this._stopsToSearches.has(a)){const d=this._stopsToSearches.get(a);d.view=b;this._overrideDefaultSources(d);return d}const c=new bc({view:b,resultGraphicEnabled:!1,popupEnabled:!1, ...this.searchProperties});this._normalizeSearchSources(c);this.addHandles([Y.on(()=>c.allSources,"change",()=>this._normalizeSearchSources(c)),c.on("select-result",()=>{a.geometry=c.selectedResult?.feature.geometry;a.name=c.selectedResult?.name;this._solveRoute()}),c.on("search-focus",()=>this._handleStopInputFocus(c,a)),c.on("search-blur",()=>this._handleStopInputBlur(c,a)),c.on("search-clear",()=>{a.geometry=null;a.name=null;this._activeStop=a;this.viewModel.layer?.removeResult()}),Y.watch(()=> c.searchTerm,d=>{a.name=d})],c);this._stopsToSearches.set(a,c);return c}getDirections(){return this.viewModel.getDirections()}render(){return m.tsx("div",{class:this.classes(h.css.base,R.globalCss.widget,R.globalCss.panel,h.css.scroller)},this._renderPanelContent())}save(){return this.viewModel.save()}saveAs(a,b={}){return this.viewModel.saveAs(a,b)}zoomToRoute(){return this.viewModel.zoomToRoute()}_renderPanelContent(){const {layer:a,serviceDescription:b,state:c}=this.viewModel;var d="initializing"=== c;const e="error"===c&&!b,f="unauthenticated"===c,g={[h.css.panelContentLoading]:d,[h.css.panelContentError]:e||!a,[h.css.panelContentSignIn]:f},k=d?"presentation":"group";d=a?f?this._renderSignIn():e?this._renderMessage(this._getErrorMessage()):d?this._renderLoader():this._renderReadyContent():this._renderMessage(this.messages.missingLayer);return m.tsx("div",{class:this.classes(h.css.panelContent,g),role:k},d)}_renderReadyContent(){return[this._renderStopsContainer(),this._renderTravelModeOptions(), this._renderDepartureTimeControls(),this._renderSaveContainer(),this._renderSectionSplitter(),this._renderDirectionsContainer()]}_renderSignIn(){return m.tsx("div",{class:h.css.signInContent,key:"sign-in"},m.tsx(ma.Heading,{class:h.css.contentTitle,level:this.headingLevel},this.messages.widgetLabel),this._renderPlaceholder(),m.tsx(ma.Heading,{level:ma.incrementHeadingLevel(this.headingLevel)},this.messages.signInRequired),m.tsx("button",{bind:this,class:this.classes(R.globalCss.button,R.globalCss.buttonSecondary, h.css.signInButton),onclick:this._handleSignInClick,tabIndex:0,type:"button"},this.messagesCommon.auth.signIn))}_handleSignInClick(){this.viewModel.load().catch(()=>{})}_renderTravelModeOptions(){if(!this.visibleElements.traveMode)return null;const {selectedTravelMode:a,travelModes:b}=this.viewModel;if(0===b.length)return null;const c=null!=a?a.name:this.messages.travelMode;return m.tsx("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(h.css.travelMode,this._saveLayer.opened&& R.globalCss.buttonDisabled),key:"esri-directions__travel-mode-controls",role:"group"},m.tsx("select",{"aria-label":c,bind:this,class:this.classes(h.css.travelModeSelect,R.globalCss.select),key:"esri-directions__travel-mode-options",onchange:this._handleTravelModeChange,title:c},b.map((d,e)=>m.tsx("option",{"data-mode":d,key:`esri-directions__travel-mode-${e}`,selected:a===d,value:`${e}`},d.name))))}_handleTravelModeChange(a){var b=a.currentTarget;a=this.viewModel;b=b.item(b.selectedIndex)?.["data-mode"]; a.selectedTravelMode=b;this._solveRoute()}_renderStopsContainer(){return this.visibleElements.stops?m.tsx("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(h.css.section,this._saveLayer.opened&&R.globalCss.buttonDisabled),key:"esri-directions__stops-container",role:"group"},this._renderStops()):null}_renderDepartureTimeControls(){if(!this.visibleElements.departureTime)return null;const {messages:{departAt:a,departureTime:b,leaveNow:c,timeUnspecified:d},viewModel:{departureOption:e}}= this;return m.tsx("div",{"aria-disabled":this._saveLayer.opened.toString(),class:this.classes(h.css.departureTime,this._saveLayer.opened&&R.globalCss.buttonDisabled),key:"esri-directions__departure-time-controls",role:"group"},m.tsx("select",{"aria-label":b,bind:this,class:this.classes(h.css.departureTimeSelect,R.globalCss.select),onchange:this._handleDepartureOptionChange,title:b},m.tsx("option",{selected:e===T.DepartureTimeOption.NOW,value:T.DepartureTimeOption.NOW},c),m.tsx("option",{selected:e=== T.DepartureTimeOption.DEPART_AT,value:T.DepartureTimeOption.DEPART_AT},a),m.tsx("option",{selected:e===T.DepartureTimeOption.UNSPECIFIED,value:T.DepartureTimeOption.UNSPECIFIED},d)),e===T.DepartureTimeOption.DEPART_AT?this._renderTimeControls():null)}_renderStops(){const {stops:a}=this.viewModel.layer;let b=0;for(var c of this._stopsToSearches.keys())a.includes(c)||this._disposeSearch(c);for(var d of a)c=this.acquireSearch(d),"none"!==c.activeMenu&&(b+=1),null!=d.name&&(c.searchTerm=d.name);d=a.toArray().map((e, f)=>{var g=a.length;const k={[ba.legacyIcon.radioUnchecked]:0<=f&&fg;r=this.acquireSearch(e);({messages:y}=this);const {removeStop:E,reverseStops:J,unlocated:z}=y;var M=null!=e.geometry&&null!=e.name?e.name:z,P=fc.formatNumber(f+1);y=`${y.stopLabel} ${P} (${M})`; M=`${this.id}__stop--${f}`;e=!!r.searchTerm&&!!r.selectedResult&&null!=e.geometry&&r.selectedResult.name===e.name;P={zIndex:"none"!==r.activeMenu?`${b--}`:""};return m.tsx("li",{afterCreate:this._handleStopFieldCreation,"aria-label":y,bind:this,class:this.classes(h.css.stopRow,p),"data-stop-index":f,id:M,key:f,styles:P},m.tsx("div",{class:h.css.stopHandle},m.tsx("span",{"aria-hidden":"true",class:this.classes(h.css.stopIcon,ba.legacyIcon.handleVertical,h.css.stopHandleIcon,h.css.interactiveStopIcon), onpointerdown:this._handleDragHandlePointerDown}),m.tsx("div",{"aria-labelledby":M,bind:this,class:this.classes(h.css.stopIconContainer,l),"data-stop-index":f,onclick:this._handleStopIconClick,onkeydown:this._handleStopIconClick,role:"button"},m.tsx("span",{class:this.classes(h.css.stopIcon,k),tabIndex:e?0:void 0}))),m.tsx("div",{class:h.css.stopInput},r.render()),m.tsx("div",{class:h.css.stopOptions,role:"group"},m.tsx("div",{"aria-label":E,bind:this,class:h.css.removeStopButton,"data-stop-index":f, hidden:g,onclick:this._handleRemoveStop,onkeydown:this._handleRemoveStop,role:"button",tabIndex:0,title:E},m.tsx("span",{"aria-hidden":"true",class:this.classes(h.css.stopIcon,h.css.removeStop,ba.legacyIcon.trash,h.css.interactiveStopIcon)}),m.tsx("span",{class:ba.legacyIcon.fontFallbackText},"removeStopTitle")),m.tsx("div",{"aria-label":J,bind:this,class:h.css.reverseStops,hidden:q,onclick:this._handleReverseStops,onkeydown:this._handleReverseStops,role:"button",tabIndex:0,title:J},m.tsx("span", {"aria-hidden":"true",class:this.classes(h.css.stopIcon,ba.legacyIcon.upDownArrows,h.css.interactiveStopIcon)}),m.tsx("span",{class:ba.legacyIcon.fontFallbackText},"removeStopTitle"))))});c=this._renderAddStop();return m.tsx("div",null,m.tsx("ol",{afterCreate:this._setUpDragAndDropStops,class:h.css.stops,role:"group"},d),c)}_renderAddStop(){var a=this.viewModel.layer?.stops;if(!a)return null;const b=a.filter(({geometry:c})=>null!=c);a=a.at(-1);return 1{this._addNewPlaceholder()},round:!0,scale:"s",width:"full"},this.messages.addStop))):null}_handleStopIconClick(a){a=kb(a.currentTarget);a=null!=a?this.viewModel.layer?.stops.at(a):void 0;a?.geometry&&this._centerAtStop(a)}_handleClearRouteClick(){this.viewModel.reset()}_centerAtStop(a){this.viewModel.centerAt(a)}_handleStopFieldCreation(a){const b= this._newPlaceholderStop;if(b){a=kb(a);a=null!=a?this.viewModel.layer?.stops.at(a):void 0;if(b===a){const c=this.acquireSearch(a);c.when(()=>{this.renderNow();c.focus()})}this._newPlaceholderStop=null}}_handleStopInputBlur(a,b){if(!this._saveLayer.opened)if(this.removeHandles("search-term"),a.selectedResult&&null!=b.geometry&&null!=a.selectedResult?.feature.geometry&&b.geometry===a.selectedResult?.feature.geometry)this._pointerDownUpHandle?.pause();else{var c=null!=b.geometry&&null!=a.selectedResult?.feature.geometry&& b.geometry!==a.selectedResult?.feature.geometry;(null==b.geometry&&null==a.selectedResult?.feature.geometry||c)&&"none"===a.activeMenu&&a.searchTerm?(a.search(),this._pointerDownUpHandle?.pause()):a.searchTerm||(this._viewClickHandle?.resume(),clearTimeout(this._autoStopRemovalTimeoutId),this._autoStopRemovalTimeoutId=setTimeout(()=>{this.destroyed||(this._viewClickHandle?.pause(),"searching"===a.viewModel.state?this._pointerDownUpHandle?.pause():this._pointerPressedSearchSuggestionStop||(null!=b.geometry&& (b.geometry=null,this._solveRoute()),this.scheduleRender()))},this._autoStopRemovalDelay))}}_handleStopInputFocus(a,b){this._pointerDownUpHandle?.resume();const {view:c}=this;if(!this.hasHandles("search-term")&&c){var d=c.cursor;this.addHandles([Vb.makeHandle(()=>{c.cursor=d}),Y.watch(()=>a.searchTerm,e=>{a.destroyed||(c.cursor=e.length?d:"copy")},Y.initial)],"search-term");this._activeStop=b}}_prepViewClick(){const {view:a}=this.viewModel;ub.assertIsSome(a);ub.assertIsSome(a.surface);const b=wa.pausable(a, "click",this._handleViewClick.bind(this)),c=wa.pausable(a.surface,"click",()=>{clearTimeout(this._autoStopRemovalTimeoutId);c.pause()});return{remove(){c.remove();b.remove()},pause(){c.pause();b.pause()},resume(){c.resume();b.resume()}}}_prepPointerDownUpClick(){const a=wa.pausable(document,"pointerdown",c=>{this._pointerPressedSearchSuggestionStop=Jb(c)?this._activeStop:null}),b=wa.pausable(document,"pointerup",c=>{this._pointerDownUpHandle?.pause();c=Jb(c);const d=this._activeStop;c||d!==this._pointerPressedSearchSuggestionStop|| this._removeStop(d);this.scheduleRender();this._pointerPressedSearchSuggestionStop=c?d:null});return{remove(){b.remove();a.remove()},pause(){b.pause();a.pause()},resume(){a.resume()}}}_handleViewClick(a){a.stopPropagation();const b=this._activeStop,c=b?this._stopsToSearches.get(b):null;b&&c&&!c.searchTerm&&(c.search(a.mapPoint).then(d=>{if(d=d?.results[0].results){var {feature:e,name:f}=d[0];b.geometry=e.geometry;b.name=f;c.searchTerm=f}}),this.scheduleRender());this._viewClickHandle?.pause();clearTimeout(this._autoStopRemovalTimeoutId)}_addNewPlaceholder(){this._pointerDownUpHandle?.pause(); if(!this._newPlaceholderStop){var a=new $b({symbol:new ac});this.viewModel.layer?.stops.add(a);this._newPlaceholderStop=a}}_handleReverseStops(){this._reverseStops()}_reverseStops(){const a=this.viewModel.layer?.stops??[];a.reverse();for(const b of a)b.sequence=null;this._solveRoute()}_handleRemoveStop(a){var {layer:b}=this.viewModel;if(b&&(a=kb(a.currentTarget),null!=a)){var {stops:c,routeInfo:d}=b;b=c.at(a);this._removeStop(b);null==b.geometry&&null!=d||this._solveRoute()}}_removeStop(a){const {stops:b}= this.viewModel.layer;!a||2>=b.length||(this._disposeSearch(a),b.remove(a))}_handleDepartureOptionChange(a){a=a.currentTarget;a=a.item(a.selectedIndex);this.viewModel.departureOption=a.value;this._solveRoute()}_renderTimeControls(){return this.viewModel.departureIsoDate&&this.viewModel.departureIsoTime?m.tsx("div",{class:h.css.departureTimeControls,key:h.css.departureTimeControls,role:"group"},m.tsx("div",{class:h.css.departureDateTimePickers},m.tsx("calcite-input-date-picker",{valueAsDate:pc(this.viewModel.departureIsoDate), onCalciteInputDatePickerChange:({target:a})=>{this.viewModel.departureIsoDate=a.value;this._solveRoute()}}),m.tsx("calcite-input-time-picker",{value:this.viewModel.departureIsoTime,onCalciteInputTimePickerChange:({target:a})=>{this.viewModel.departureIsoTime=a.value;this._solveRoute()}}))):null}_renderSectionSplitter(){return m.tsx("div",{class:h.css.sectionSplitter})}_renderSaveContainer(){const {saveButton:a,saveAsButton:b,printButton:c,layerDetails:d}=this.visibleElements;return a||b||c||d?m.tsx("div", {class:h.css.saveSection,key:h.css.saveSection},this._renderSaveButtons(),this._renderRouteLayerDetailsLink()):null}_renderSaveButtons(){const {saveButton:a,saveAsButton:b,printButton:c}=this.visibleElements;return a||b||c?m.tsx("div",{class:h.css.saveButtons,key:h.css.saveButtons},this._renderSaveButton(),this._renderSaveAsButton(),this._renderPrintButton()):null}_renderSaveButton(){if(!this.visibleElements.saveButton)return null;const {portalItem:a,routeInfo:b}=this.viewModel.layer,c=a?.itemControl; return m.tsx("calcite-button",{appearance:"outline",class:h.css.saveButton,disabled:!(null!=b&&("admin"===c||"update"===c)),iconStart:"save",key:h.css.saveButton,label:this.messagesCommon.save,onclick:()=>{this._handleSaveButtonClick()},width:"full"},this.messagesCommon.save)}_renderSaveAsButton(){return this.visibleElements.saveAsButton?m.tsx("div",{class:h.css.saveAsButtonPopover,key:h.css.saveAsButtonPopover},m.tsx("calcite-button",{afterCreate:a=>{this._saveAsButtonNode=a},appearance:"outline", class:h.css.saveAsButton,disabled:null==this.viewModel.layer.routeInfo,iconStart:"duplicate",key:h.css.saveAsButton,label:this.messagesCommon.saveAs,onclick:()=>this._handleSaveAsButtonClick(),width:"full"},this.messagesCommon.saveAs)):null}_renderSavePopover(){return m.tsx("calcite-popover",{class:h.css.savePopover,label:this._saveLayer.label,open:this._saveLayer.opened,overlayPositioning:"fixed",referenceElement:this._saveAsButtonNode,triggerDisabled:!0},this._saveLayer.render())}_handleSaveAsButtonClick(){this._saveLayer.opened? this._saveLayer.close():this._saveLayer.open(this.viewModel.layer)}_renderPrintButton(){return this.visibleElements.printButton?m.tsx("calcite-button",{appearance:"outline",class:h.css.printButton,iconStart:"print",key:h.css.printButton,label:this.messagesCommon.print}):null}_renderRouteLayerDetailsLink(){if(!this.visibleElements.layerDetails)return null;const {portalItem:a}=this.viewModel.layer;if(!a)return null;const {id:b,portal:{url:c}}=a;return m.tsx("calcite-link",{class:h.css.layerDetailsLink, href:`${c}/home/item.html?id=${b}`,key:h.css.layerDetailsLink,target:"_blank"},this.messages.viewLayerDetails)}_handleSaveButtonClick(){this.viewModel.layer.save()}_renderDirectionsContainer(){return m.tsx("div",{class:this.classes(h.css.directionsSection,h.css.section),key:"esri-directions__container"},this._renderDirectionsContainerContent())}_renderLoader(){return m.tsx("div",{class:h.css.loader,key:"loader"})}_renderWarningCard(){return m.tsx("div",{class:h.css.warningCard,role:"alert"},m.tsx("div", {class:h.css.warningHeader},m.tsx("span",{"aria-hidden":"true",class:ba.legacyIcon.noticeTriangle}),m.tsx(ma.Heading,{class:h.css.warningHeading,level:this.headingLevel},this.messagesCommon.warning)),m.tsx("div",{class:h.css.warningMessage},this._getErrorMessage()))}_renderDirectionsContainerContent(){const {layer:a,state:b}=this.viewModel,c="routing"===b;return"error"===b?this._renderWarningCard():c?this._renderLoader():null!=a.directionLines?m.tsx("div",{"aria-disabled":this._saveLayer.opened.toString(), class:this.classes(h.css.summary,this._saveLayer.opened&&R.globalCss.buttonDisabled),key:h.css.summary,role:"group"},this._renderCosts(),this._renderRouteActions(),this._renderManeuverSections()):m.tsx("div",{class:R.globalCss.empty,key:"esri-directions__placeholder"},this._renderPlaceholder(),m.tsx(ma.Heading,{class:h.css.message,level:this.headingLevel},this.messages.directionsPlaceholder))}_renderPlaceholder(){return m.tsx("svg",{class:R.globalCss.emptyIllustration,viewBox:"0 0 256 256",xmlns:"http://www.w3.org/2000/svg"}, m.tsx("path",{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", fill:"currentcolor"}))}_renderMessage(a){return m.tsx(ma.Heading,{class:h.css.messageHeading,level:this.headingLevel},a)}_renderRouteActions(){return m.tsx("div",{class:h.css.routeActions},m.tsx("button",{"aria-label":this.messages.clearRoute,bind:this,class:this.classes(h.css.clearRouteButton,R.globalCss.button,R.globalCss.buttonTertiary),onclick:this._handleClearRouteClick,tabIndex:0,type:"button"},this.messages.clearRoute))}_getSections(){var {layer:a}=this.viewModel;if(!a)return null;const {directionPoints:b, directionLines:c,stops:d}=a;if(null==b||null==c)return null;a=[];let e=null;for(const g of b){const {objectId:k,stopId:l}=g;if(null!=l){var f=d.find(({objectId:q})=>q===l);const p=0===a.length;if(null==e||e.stop!==f)e={stop:f,directions:[],open:p},a.push(e)}else null!=e&&(f=c.find(({directionPointId:p})=>p===k),null!=f&&e.directions.push({directionPoint:g,directionLine:f}))}return a}_renderManeuverSections(){return null==this._sections?null:m.tsx("div",{class:h.css.maneuvers,role:"group"},this._sections.map((a, b)=>{const {open:c}=a;let d;0this._renderManeuver(l))));var e=2 {b.autoNavigate=!1})}_applyLocatorSourceOverrides({allSources:a}){for(const b of a)if("url"in b&&b.url){let c;(c=b).locationType??(c.locationType="street");wb.isArcGISWorldGeocoder(b.url)&&this.apiKey&&null==b.apiKey&&(b.apiKey=this.apiKey,b.url=wb.meteredArcGISLocatorUrl)}}_disposeSearch(a){if(a&&this._stopsToSearches.has(a)){var b=this._stopsToSearches.get(a);this.removeHandles(b);b.destroy();this._stopsToSearches.delete(a)}}_renderManeuver(a){const {directionPoint:b,directionLine:c}=a,{distance:d, duration:e}=c,{messages:f,messagesUnits:g,unit:k}=this;a=T.formatDistance(g,d??0,k);var l=T.formatDuration(e??0);a=a&&l?`${a} · ${l}`:`${a}${l}`;l=oc(b);const {objectId:p,directionPointType:q}=b,r=T.getIconName(q),y=`${h.css.intermediateCost}-${p}`;return m.tsx("li",{"aria-labelledby":`${`${h.css.maneuver}-${p}`} ${y}`,bind:this,class:this.classes(h.css.maneuver,{[h.css.maneuverActive]:this._activeManeuver===c}),"data-maneuver":c,key:c,onblur:this._handleManeuverBlur,onclick:this._handleManeuverClick, onfocus:this._handleManeuverFocus,onkeydown:this._handleManeuverClick,onmouseout:this._handleManeuverMouseOut,onmouseover:this._handleManeuverMouseOver,tabIndex:0},m.tsx("calcite-icon",{alt:"",class:h.css.maneuverIcon,icon:r}),m.tsx("div",{class:h.css.maneuverCostsContainer},l,m.tsx("div",{class:h.css.maneuverCosts},m.tsx("div",{class:h.css.horizontalSplitter}),m.tsx("div",{"aria-hidden":"true",class:h.css.intermediateCost,id:y,innerHTML:a,title:f.intermediateCosts}))))}_handleManeuverClick(a){if(a= a.currentTarget?.["data-maneuver"])if(this._activeManeuver===a)this._activeManeuver=null,this.zoomToRoute();else{this._activeManeuver=a;var {geometry:b}=a;this.viewModel.centerAt(b);this.viewModel.highlight(a)}}_handleManeuverMouseOver(a){this._activeManeuver||this._focusedManeuver||(a=a.currentTarget?.["data-maneuver"])&&this.viewModel.highlight(a)}_handleManeuverMouseOut(){this._activeManeuver||this._focusedManeuver||this.viewModel.clearHighlights()}_handleManeuverBlur(){this._activeManeuver||(this._focusedManeuver= null,this.viewModel.clearHighlights())}_handleManeuverFocus(a){!this._activeManeuver&&(a=a.currentTarget?.["data-maneuver"])&&(this._focusedManeuver=a,this.viewModel.highlight(a))}_getCostSummary(){const {messagesUnits:a,unit:b,viewModel:c}=this;var {routeInfo:d}=c.layer;if(null==d)return null;var e=d.totalDuration??0;d=T.formatDistance(a,d.totalDistance??0,b);e=T.formatDuration(e);return{distance:d,duration:e}}async _solveRoute(){this.viewModel.updateDepartureTime();const a=this.viewModel.layer?.stops.filter(({geometry:b})=> null!=b);if(a&&!(2>a.length))try{await this.viewModel.getDirections()}catch{}}};C.__decorate([K.property()],B.prototype,"apiKey",null);C.__decorate([K.property(Zb.defaultUnitPropertyMetadata)],B.prototype,"defaultUnit",void 0);C.__decorate([K.property()],B.prototype,"goToOverride",null);C.__decorate([K.property()],B.prototype,"headingLevel",void 0);C.__decorate([K.property()],B.prototype,"icon",null);C.__decorate([K.property()],B.prototype,"label",null);C.__decorate([K.property({readOnly:!0})],B.prototype, "lastRoute",null);C.__decorate([K.property()],B.prototype,"layer",null);C.__decorate([K.property()],B.prototype,"maxStops",null);C.__decorate([K.property(),cb.messageBundle("esri/widgets/Directions/t9n/Directions")],B.prototype,"messages",void 0);C.__decorate([K.property(),cb.messageBundle("esri/t9n/common")],B.prototype,"messagesCommon",void 0);C.__decorate([K.property(),cb.messageBundle("esri/core/t9n/Units")],B.prototype,"messagesUnits",void 0);C.__decorate([K.property()],B.prototype,"searchProperties", void 0);C.__decorate([K.property()],B.prototype,"unit",null);C.__decorate([K.property()],B.prototype,"view",null);C.__decorate([K.property({type:vb})],B.prototype,"viewModel",void 0);C.__decorate([K.property()],B.prototype,"visibleElements",void 0);C.__decorate([Xb.cast("visibleElements")],B.prototype,"castVisibleElements",null);C.__decorate([ra.accessibleHandler()],B.prototype,"_handleStopIconClick",null);C.__decorate([ra.accessibleHandler()],B.prototype,"_handleClearRouteClick",null);C.__decorate([ra.accessibleHandler()], B.prototype,"_handleReverseStops",null);C.__decorate([ra.accessibleHandler()],B.prototype,"_handleRemoveStop",null);C.__decorate([ra.accessibleHandler()],B.prototype,"_handleSectionToggle",null);C.__decorate([ra.accessibleHandler()],B.prototype,"_handleSummaryInteraction",null);C.__decorate([ra.accessibleHandler()],B.prototype,"_handleManeuverClick",null);return B=C.__decorate([Yb.subclass("esri.widgets.Directions")],B)});