/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import a from"./M536RNIN.js";import{a as h}from"./ONARC6AZ.js";import{b as D}from"./HVT2WBVC.js";import{E as I,F as v,G as b,h as L,i as n,q as f}from"./FFF5HUPM.js";import"./EXBEKVP5.js";export default $arcgis.t(([r,m,{a:p,c:$,d:S,e:g,f:u}])=>{var y=L`:host{display:block;background-color:var(--calcite-color-foreground-1);color:var(--calcite-color-text-1);min-width:200px}:host calcite-dropdown{width:100%}:host calcite-button{--calcite-color-brand: var(--calcite-color-text-3);--calcite-color-brand-hover: var(--calcite-color-text-3)}`,w=class extends b{constructor(){super(...arguments),this.trigger=I(),this.t9nData=null,this.isLoaded=!1,this.icon="language",this.locales=[],this.selectedLanguage=null,this.calciteDropdownOverlayPositioning="absolute",this.selectedLanguageUpdated=f()}static{this.properties={t9nData:16,isLoaded:16,icon:1,portalItem:0,view:0,locales:0,defaultLocale:1,selectedLanguage:1,calciteDropdownOverlayPositioning:1}}static{this.styles=y}async refresh(){try{let e=await u(this.portalItem),t=await g(e);this.t9nData=t;let a={locale:this.selectedLanguage,data:t[this.selectedLanguage]};this.selectedLanguageUpdated.emit(a)}catch{}}async load(){try{this.portalItemResource=await u(this.portalItem);let e=await g(this.portalItemResource);this.t9nData=e??{}}catch{this.t9nData={},console.error("NO PORTAL ITEM RESOURCE AVAILABLE."),this.isLoaded=!0}finally{this.userLocale=this.defaultLocale;let e=new URLSearchParams(window.location.search).get("locale"),t=this.locales?.map(o=>o?.locale)?.filter(o=>o===e)?.length>0,a=$(this.portalItem.portal),c=this.locales?.map(o=>o?.locale)?.filter(o=>o===a)?.length>0;this.selectedLanguage=t?e:c?a:this.userLocale;let i=this.selectedLanguage;if(i!==this.userLocale&&(this.calciteDropdownItemSelectCallback(i)(),this.selectedLanguageUpdated.emit({locale:i,data:this.t9nData?.[i]??null})),this.view){let o=this.view.map;this.defaultWebMapId=o?.portalItem?.id??"";let l=this.locales?.filter(s=>s?.webmap&&s?.webmap!==this.defaultWebMapId&&s?.locale===this.selectedLanguage)?.[0]?.webmap;l&&(this.view.map=new m({portalItem:{id:l}}))}this.isLoaded=!0}}calciteDropdownItemSelectCallback(e){return async()=>{if(!this.isLoaded)return;this.selectedLanguage=e;let{selectedLanguage:t,t9nData:a,userLocale:c}=this,i=this.locales.find(s=>s.locale===t);a&&i&&t!==c&&(i.data=a[e]);let o=new URLSearchParams(window.location.search),l=S(this.selectedLanguage);if(r.setLocale(l),o.set("locale",l),this.view){let s=this.locales.filter(d=>d.locale===t)?.[0]?.webmap;if(s)this.view.map=new m({portalItem:{id:s}});else{let d=this.view?.map?.portalItem?.id;d&&this.defaultWebMapId!==d&&(this.view.map=new m({portalItem:{id:this.defaultWebMapId}}))}}document.documentElement.setAttribute("lang",l),r.prefersRTL()?document.documentElement.setAttribute("dir","rtl"):document.documentElement.setAttribute("dir","ltr"),window.history.replaceState({},"",decodeURIComponent(`${window.location.pathname}?${o}`)),this.selectedLanguageUpdated.emit(i)}}getSelectedLanguageText(e){let t=Object.keys(p.partial).includes(e),a=p[t?"partial":"full"],c=a[e];if(!t&&c==null){let l=r.normalizeMessageBundleLocale(e);c=a[l]}let{language:i,translated:o}=c;return`${i} - ${o}`}render(){let e=this.renderTrigger(),t=this.renderDropdownItems(),a=this.renderDefaultLocale();return n`<calcite-dropdown @calciteDropdownBeforeOpen=${()=>{this.trigger.value&&(this.trigger.value.iconEnd="chevron-up")}} @calciteDropdownBeforeClose=${()=>{this.trigger.value&&(this.trigger.value.iconEnd="chevron-down")}} .overlayPositioning=${this.calciteDropdownOverlayPositioning} width-scale=m>${e}<calcite-dropdown-group>${a}${t}</calcite-dropdown-group></calcite-dropdown>`}renderDefaultLocale(){let{userLocale:e}=this;return h(`default-${e}`,n`<calcite-dropdown-item @calciteDropdownItemSelect=${this.calciteDropdownItemSelectCallback(e)} .selected=${this.selectedLanguage===this.userLocale}>${this.getSelectedLanguageText(e)}</calcite-dropdown-item>`)}renderTrigger(){return n`<calcite-button slot=trigger .iconStart=${this.icon} icon-end=chevron-down width=full appearance=outline ${v(this.trigger)}>${this.getSelectedLanguageText(this.selectedLanguage)}</calcite-button>`}renderDropdownItems(){return this.locales?.map(e=>e.locale)?.map(e=>this.renderDropdownItem(e))}renderDropdownItem(e){let t=this.getSelectedLanguageText(e),a=e===this.selectedLanguage;return h(e,n`<calcite-dropdown-item .selected=${a} @calciteDropdownItemSelect=${this.calciteDropdownItemSelectCallback(e)}>${t}</calcite-dropdown-item>`)}};D("instant-apps-language-switcher",w);return w},"intl","WebMap",a)