/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../chunks/_rollupPluginBabelHelpers","../../../chunks/tslib.es6","../../../core/maybe","../../../core/reactiveUtils","../../../core/accessorSupport/decorators/property","../../../core/arrayUtils","../../../core/has","../../../core/accessorSupport/ensureType","../../../core/accessorSupport/decorators/subclass","../../Widget","../../support/widgetUtils","../../support/jsxFactory"],(function(e,t,s,r,o,i,a,n,c,h,u,l){"use strict";const p={nextPhase:"nextPhase",previousPhase:"previousPhase",currentPhase:"{{value}}"},_="esri-building-phase-picker",d={container:`${_}`,phasesContainer:`${_}__phases-container`,phase:`${_}__phase`,phaseActive:`${_}__phase--active`,phaseCurrent:`${_}__phase--current`,divider:`${_}__divider`,dividerActive:`${_}__divider--active`,arrowLeft:`${_}__arrow-left`,arrowRight:`${_}__arrow-right`};let v=function(t){function o(r,o){var i;return(i=t.call(this,r,o)||this)._phasesContainer=null,i._shouldScrollCurrentPhaseIntoView=!0,i._shouldFocusCurrentPhase=!1,i._onKeyDown=t=>{const{vm:s}=e._assertThisInitialized(i);switch(t.key){case"ArrowDown":case"ArrowLeft":t.stopPropagation(),t.preventDefault(),s.previous(),i._shouldFocusCurrentPhase=!0;break;case"ArrowUp":case"ArrowRight":t.stopPropagation(),t.preventDefault(),s.next(),i._shouldFocusCurrentPhase=!0}},i._onArrowLeftClick=()=>{i.vm.previous()},i._onArrowRightClick=()=>{i.vm.next()},i._onPhasesContainerAfterCreate=e=>{i._phasesContainer=e,requestAnimationFrame(i._scrollOrFocusPhase)},i._scrollOrFocusPhase=()=>{const e=i._phasesContainer;if(i.destroyed||s.isNone(e))return;const t=e.querySelector(`.${d.phaseCurrent}`);if(t){if(i._shouldScrollCurrentPhaseIntoView){const s=e.offsetWidth,r=t.offsetLeft,o=t.offsetWidth;e.scrollLeft=-s/2+r-o/2,i._shouldScrollCurrentPhaseIntoView=!1}i._shouldFocusCurrentPhase&&(t.focus(),i._shouldFocusCurrentPhase=!1)}},i}e._inheritsLoose(o,t);var i=o.prototype;return i.initialize=function(){this.own([r.watch((()=>[this._currentPhase,this._phasesContainer,this.container]),(()=>{this._shouldScrollCurrentPhaseIntoView=!0,requestAnimationFrame(this._scrollOrFocusPhase)}),r.initial)])},i.render=function(){if(this._phases.length<2)return l.tsx("div",{key:"no-phases"});const{vm:e,container:t,messages:r}=this,{previousPhase:o,nextPhase:i}=s.unwrapOr(r,p),a=u.isRTL(t);return l.tsx("div",{class:this.classes("esri-widget",d.container),key:this,onkeydown:this._onKeyDown},l.tsx("button",{type:"button",class:a?d.arrowRight:d.arrowLeft,disabled:!e.hasPrevious,"aria-label":o,title:o,onclick:this._onArrowLeftClick}),l.tsx("div",{class:d.phasesContainer,afterCreate:this._onPhasesContainerAfterCreate},this._renderPhaseButtons()),l.tsx("button",{type:"button",class:a?d.arrowLeft:d.arrowRight,disabled:!e.hasNext,"aria-label":i,title:i,onclick:this._onArrowRightClick}))},i._renderPhaseButtons=function(){const e=this._phases,t=this._currentPhase,r=[];for(let o=0;o<e.length;++o){const i=e[o],a={phase:i,active:!!s.isSome(t)&&i<=t,current:!!s.isSome(t)&&i===t};o>0&&r.push(this._renderDivider(a)),r.push(this._renderPhaseButton(a))}return r},i._renderPhaseButton=function({phase:e,active:t,current:r}){const{vm:o}=this,i=s.unwrap(o.getValueLabel(e));return l.tsx("button",{key:`phase-${e}`,class:this.classes(d.phase,{[d.phaseActive]:t,[d.phaseCurrent]:r}),"aria-label":i,title:i,onclick:()=>o.select(e),type:"button"},e)},i._renderDivider=function({phase:e,active:t}){return l.tsx("div",{key:`phase-divider-${e}`,class:this.classes(d.divider,{[d.dividerActive]:t})})},e._createClass(o,[{key:"_phases",get:function(){return this.vm.allowedValues}},{key:"_currentPhase",get:function(){const{vm:e}=this;return e.enabled?e.value:null}}]),o}(h);t.__decorate([o.property({nonNullable:!0})],v.prototype,"vm",void 0),t.__decorate([o.property()],v.prototype,"messages",void 0),t.__decorate([o.property()],v.prototype,"_phases",null),t.__decorate([o.property()],v.prototype,"_currentPhase",null),t.__decorate([o.property()],v.prototype,"_phasesContainer",void 0),v=t.__decorate([c.subclass("esri.widgets.BuildingExplorer.BuildingPhasePicker.BuildingPhasePicker")],v);return v}));
