PageSourceSearch

https://www.sklep.laboga.pl/application/assets/storefront/chunk-language_and_currency_initializer.BE4wEjz.js

js laboga.pl collected 2026-09-25 09:21:20 UTC 26,184 bytes, 203 lines download raw bytes

1import{b as O,aJ as L,aK as _,p as E,aL as b,aM as N,N as M,C as w}from"./storefrontApp.5Jl33SLO.min.js";import{b as C,U as A,f as d,d as m,$ as r,e as g,t as S}from"./chunk-vendor-lit.NvY0u02.js";import{S as I}from"./chunk-storefront_base_lit_element.BngXaMu.js";import{t as l}from"./chunk-translations_directive.GYGOaCp.js";import{S as U}from"./chunk-storefront_settings_constants.DIF02Gz.js";import{B as D}from"./chunk-btn_controller.BPcEEeZ.js";import{M as $}from"./chunk-modal_constants.RvL-5Lb.js";import"./chunk-vendor-di.Bh23gdA.js";import"./chunk-vendor-rxjs.Dp7kflo.js";import"./chunk-vendor-lodash.CWHFt7Z.js";import"./chunk-vendor-phoenix.cdKS79L.js";import"./chunk-keystrokes_controller.BSiCZ0Y.js";const o="language-and-currency",v={languages:"languages",currencies:"currencies"};class T extends O{constructor({settingsApi:e,userApi:t}){super(),this.moduleName=L.service,this.#e=null,this.#t=e,this.#n=t,this.#e=this.getLanguageAndCurrencyLocalStorage()}#e;#t;#n;async getPreferredLocale(){const e=await this._getCachedUserCountry();if(!e)return null;const n=(this.#t.getAllLocales()??[]).filter(a=>{const s=a.locale.toUpperCase().split("_");return s.length>1?e===s[1]:!1});if(n.length===1)return n[0];if(n.length>1){const a=navigator.languages.map(s=>s.toLowerCase().replaceAll("-","_"));for(const s of a)if(/^[a-z]{2}_[a-z]{2}$/.test(s)){const h=n.find(y=>y.locale.toLowerCase()===s);if(h)return h}else{const h=n.find(y=>y.locale.toLowerCase().startsWith(s));if(h)return h}return n[0]}return null}async getUserCountry(){return await this._getCachedUserCountry()}async _getCachedUserCountry(){const t="none",n=this.#e?.get(_.userCountryCacheTimestamp),a=this.#e?.get(_.userCountryCache);if(n&&a&&Date.now()-Number(n)<216e5)return a!==t?a:null;const{country:s}=await this.#n.getCurrentCountry();return this.#e&&(this.#e.set(_.userCountryCache,s??t),this.#e.set(_.userCountryCacheTimestamp,Date.now().toString())),s}getLanguageAndCurrencyLocalStorage(){const e=this.getApiSync(E),t=e.getStore(b);return t||e.createStore("local",b)}}var F=Object.defineProperty,u=(p,e,t,n)=>{for(var a=void 0,s=p.length-1,i;s>=0;s--)(i=p[s])&&(a=i(e,t,a)||a);return a&&F(e,t,a),a};class c extends I{constructor(){super(),this._modal=C(),this.moduleInstanceId="",this.detectLocaleMismatch=!1,this.shippingCountries=[],this.marketDefaults=[],this.currentShippingCountry=null,this.marketsEnabled=!1,this._$initiallyCheckedLanguageRadio=null,this._$initiallyCheckedCurrencyRadio=null,this._languageRadioListenersAttached=!1,this._countrySelect=C(),this._localeSelect=C(),this._currencySelect=C(),this._countryOptionsList=[],this._localeOptionsList=[],this._currencyOptionsList=[],this._languageAndCurrencyLocalStorage=null,this._storefrontSettingsApi=null,this._userApi=null,this._languageAndCurrencyService=null,this._allLocales=[],this._allCurrencies=[],this._currentLocale=null,this._currentLocaleName=null,this._currentCurrency=null,this._currentCurrencyCode=null,this._localeNamesWithDuplicates=new Set,this._backdropVisible=!1,this._languageAndCurrencySelectsVisible=!1,this._modalOpenedOnce=!1,this._handleLanguageRadioChange=e=>{const t=e.target;this._changeCurrencyOnLanguageRadioChange(t)},this._selectAndFocusOnLanguageRadio=(e,t=!1)=>{requestAnimationFrame(()=>{const n=document.querySelector(`[name="${o}-language-${this.moduleInstanceId}"][data-locale="${e}"]`);if(n){if(n.checked=!0,t){const a=n.dataset.currencyCode;a&&this._selectCurrencyRadioByCode(a)}typeof n.focus=="function"&&n.focus()}})},this._openLanguageAndCurrencyModal=()=>{this._openModal();const e=this._storefrontSettingsApi?.getLocales().locale;!this.marketsEnabled&&e&&this._selectAndFocusOnLanguageRadio(e)},this._closeLanguageAndCurrencyModal=()=>{this._modal.value?.close()},this._handleAfterModalClose=()=>{!this.marketsEnabled&&this._$initiallyCheckedLanguageRadio&&this._$initiallyCheckedCurrencyRadio&&(this._$initiallyCheckedLanguageRadio.checked=!0,this._$initiallyCheckedCurrencyRadio.checked=!0),this._backdropVisible=!1,this.detectLocaleMismatch&&this._setSuppressLocaleMismatch(),this.marketsEnabled&&(this._languageAndCurrencySelectsVisible=!1,this.currentShippingCountry&&this._selectOptionOnRef(this._countrySelect,this.currentShippingCountry.code))},this._removeHiddenAttributeFromSlots=()=>{const e=this.querySelector(`[slot="${v.currencies}"]`),t=this.querySelector(`[slot="${v.languages}"]`);e&&A.show(e),t&&A.show(t)},this._changeLanguageAndCurrency=e=>{e.preventDefault();
1const t=this._findCheckedRadioByName(`${o}-language-${this.moduleInstanceId}`),n=this._findCheckedRadioByName(`${o}-currency-${this.moduleInstanceId}`);if(!t||!n)return;this.detectLocaleMismatch&&this._setSuppressLocaleMismatch();const a=t.dataset.locale!==this._storefrontSettingsApi?.getLocales().locale,s=t.dataset.currencyCode===n.value,i=n.value!==this._storefrontSettingsApi?.getLocales().currency,h=a&&!s||!a&&i;this._redirectToUrl(t.value,a,h?n.value:null)},this._changeDeliveryCountryLanguageAndCurrency=e=>{e.preventDefault(),this.detectLocaleMismatch&&this._setSuppressLocaleMismatch();const t=this._countrySelect.value?.selectedOptions?.[0]?.value??null,n=this._localeSelect.value?.selectedOptions?.[0]?.value??null,a=this._currencySelect.value?.selectedOptions?.[0]?.value??null,s=this._allLocales.find(f=>f.locale===n)?.url??"/",i=!!n&&n!==this._storefrontSettingsApi?.getLocales().locale,h=this._allLocales.find(f=>f.locale===n)?.currencyCode===a,y=!!a&&a!==this._storefrontSettingsApi?.getLocales().currency,R=a&&(i&&!h||!i&&y),k=t&&t!==this.currentShippingCountry?.code;this._redirectToUrl(s,i,R?a:null,k?t:null)},this._redirectToUrl=(e,t=!1,n=null,a=null)=>{const s=new URLSearchParams;t&&s.set("localeChange","true"),n&&s.set("currency",n),a&&s.set("delivery_country",a),window.location.href=`${e}${[...s.keys()].length?`?${s.toString()}`:""}`},this._handleChangeClick=()=>{this._languageAndCurrencySelectsVisible=!0},this._handleCountryChange=e=>{const n=e.target?.selectedOptions?.[0]?.value;n&&this._setLanguageAndCurrencySelectsByMarketDefaults(n)},this._setLanguageAndCurrencySelectsByMarketDefaults=async e=>{const t=this.marketDefaults.find(n=>n.deliveryCountry===e);return t&&(t?.defaultLocale!==this._currentLocale||t?.defaultCurrency!==this._currentCurrency)?(this._languageAndCurrencySelectsVisible=!0,await this.updateComplete,this._selectOptionOnRef(this._localeSelect,t.defaultLocale),this._selectOptionOnRef(this._currencySelect,t.defaultCurrency),!0):(this._languageAndCurrencySelectsVisible=!1,!1)},new D(this,this._openLanguageAndCurrencyModal)}static{this.moduleName=L.component}connectedCallback(){super.connectedCallback(),this._storefrontSettingsApi=this.getApiSync(U.api),this.addEventListener("click",this._openLanguageAndCurrencyModal),this.addEventListener($.closed,this._handleAfterModalClose),this.marketsEnabled||(this._addEventListenersToLanguageRadios(),this._languageRadioListenersAttached=!0,this._removeHiddenAttributeFromSlots(),this._findInitiallyCheckedRadios()),this.detectLocaleMismatch&&this._initializeService()}willUpdate(e){super.willUpdate(e);const t=e.has("shippingCountries")||e.has("currentShippingCountry")||e.has("marketDefaults")||e.has("marketsEnabled");this.marketsEnabled&&t&&this._initMarketsMode()}_initMarketsMode(){this._allLocales=this._storefrontSettingsApi?.getAllLocales()??[],this._allCurrencies=this._storefrontSettingsApi?.getCurrencies()??[],this._currentLocale=this._storefrontSettingsApi?.getLocales().locale??null,this._currentLocaleName=this._allLocales.find(e=>e.locale===this._currentLocale)?.name??null,this._currentCurrency=this._storefrontSettingsApi?.getLocales().currency??null,this._currentCurrencyCode=this._allCurrencies.find(e=>e.code===this._currentCurrency)?.code??null,this._localeNamesWithDuplicates=this._findLocaleNamesWithDuplicates(this._allLocales),this._initCountryOptionsList(),this._initLocaleOptionsList(),this._initCurrencyOptionsList()}_initCountryOptionsList(){this._countryOptionsList=[...this.shippingCountries].sort((e,t)=>e.name.localeCompare(t.name)).map(e=>({value:e.code,content:e.name,selected:this.currentShippingCountry?.code===e.code}))}_initLocaleOptionsList(){this._localeOptionsList=[...this._allLocales].sort((e,t)=>e.name.localeCompare(t.name)).map(e=>({value:e.locale,content:this._getLocaleOptionContent(e),selected:this._currentLocale===e.locale}))}_initCurrencyOptionsList(){this._currencyOptionsList=[...this._allCurrencies].sort((e,t)=>e.code.localeCompare(t.code)).map(e=>({value:e.code,content:e.code,selected:this._currentCurrency===e.code}))}_findLocaleNamesWithDuplicates(e){const t=new Map;return e.forEach(n=>{t.set(n.name,(t.get(n.name)??0)+1)}),new Set([...t.entries()].filter(([,n])=>n>1).map(([n])=>n))}_getLocaleOptionContent(e){return this._localeNamesWithDuplicates.has(e.name)?`${e.localized.name} (${e.localized.region})`:e.localized.name}async _initializeService(){this._storefrontSettingsApi&&(this._userApi=await this.getApi(N.api),this.isConnected&&(this._languageAndCurrencyService=new T({settingsApi:this._storefrontSettingsApi,userApi:this._userApi}),this._languageAndCurrencyLocalStorage=this._languageAndCurrencyService.getLanguageAndCurrencyLocalStorage(),window.self===window.top&&this._checkForLocaleOrShippingCountryMismatch()))}disconnectedCallback(){super.disconnectedCallback();try{this._languageRadioListenersAttached&&(this._removeEventListenersFromLanguageRadios(),this._languageRadioListenersAttached=!1),this.removeEventListener("click",this._openLanguageAndCurrencyModal),this.removeEventListener($.closed,this._handleAfterModalClose)}catch{}}async _checkForLocaleOrShippingCountryMismatch(){const e=await this._languageAndCurrencyService?.getPreferredLocale()??null,t=this._storefrontSettingsApi?.getLocales().locale,n=await this._languageAndCurrencyService?.getUserCountry()??null,a=this.currentShippingCountry?.code===n,s=this.shippingCountries.some(i=>i.code===n);(e&&t&&e.locale!==t||this.marketsEnabled&&n&&!a&&s)&&this._handleLocaleOrShippingCountryMismatch(e,n)}_removeEventListenersFromLanguageRadios(){this._queryAllLanguageRadios().forEac
1h(e=>{e.removeEventListener("change",this._handleLanguageRadioChange)})}async _handleLocaleOrShippingCountryMismatch(e,t){if(this.marketsEnabled&&!e&&!t||!this.marketsEnabled&&!e||this._languageAndCurrencyLocalStorage?.get(_.suppressLocaleMismatch))return;if(new URLSearchParams(window.location.search).has("localeChange")){this._setSuppressLocaleMismatch();return}if(this._openModal(),!this.marketsEnabled&&e)this._selectAndFocusOnLanguageRadio(e.locale,!0);else if(this.marketsEnabled&&(t||e)){const a=this.shippingCountries.some(i=>i.code===t);let s=!1;t&&a&&(this._languageAndCurrencySelectsVisible=!0,await this.updateComplete,await this._selectOptionOnRef(this._countrySelect,t),s=await this._setLanguageAndCurrencySelectsByMarketDefaults(t)),!s&&e&&(this._languageAndCurrencySelectsVisible=!0,await this.updateComplete,await this._selectOptionOnRef(this._localeSelect,e.locale))}}async _selectOptionOnRef(e,t){const n=e.value;if(!n)return;await customElements.whenDefined(n.tagName.toLowerCase()),await n.updateComplete;const a=n.getOption(t);a&&n.select(a)}_selectCurrencyRadioByCode(e){const t=document.querySelector(`[name="${o}-currency-${this.moduleInstanceId}"][value="${e}"]`);t&&(t.checked=!0)}_changeCurrencyOnLanguageRadioChange(e){const t=e.dataset.currencyCode;t&&this._selectCurrencyRadioByCode(t)}_queryAllLanguageRadios(){return document.querySelectorAll(`[name="${o}-language-${this.moduleInstanceId}"]`)}_addEventListenersToLanguageRadios(){this._queryAllLanguageRadios().forEach(e=>{e.addEventListener("change",this._handleLanguageRadioChange)})}_findInitiallyCheckedRadios(){this._$initiallyCheckedLanguageRadio=this._findCheckedRadioByName(`${o}-language-${this.moduleInstanceId}`),this._$initiallyCheckedCurrencyRadio=this._findCheckedRadioByName(`${o}-currency-${this.moduleInstanceId}`)}_openModal(){this._modal.value&&(this._modalOpenedOnce=!0,this._modal.value.open(),this.detectLocaleMismatch&&(this._backdropVisible=!0))}_findCheckedRadioByName(e){return document.querySelector(`[name="${e}"]:checked`)}_setSuppressLocaleMismatch(){this._languageAndCurrencyLocalStorage?.set(_.suppressLocaleMismatch,"true")}render(){const e=`${o}-country-select-${this.moduleInstanceId}`,t=`${o}-locale-select-${this.moduleInstanceId}`,n=`${o}-currency-select-${this.moduleInstanceId}`;return r`
2            <div>
3                ${d(this.detectLocaleMismatch,()=>r`
4                        <div
5                            class="backdrop backdrop_language-and-currency"
6                            ?hidden=${!this._backdropVisible}
7                        ></div>
8                    `)}
9                <h-modal
10                    class="modal-wrapper_s modal_language-and-currency"
11                    ${m(this._modal)}
12                    no-autofocus
13                    hidden
14                >
15                    <h-modal-header>
16                        <h2 class="font_semibold h2">
17                            ${d(this.marketsEnabled,()=>r`${l("Regional settings")}`,()=>r`${l("Region, language and currency settings")}`)}
18                        </h2>
19
20                        <h-modal-close
21                            aria-label="${l("Close window")} ${l("Region, language and currency settings")}"
22                            class="btn btn_icon"
23                        >
24                            <h-icon
25                                icon-name="icon-x"
26                                role="button"
27                                size="xl"
28                                clickable
29                            ></h-icon>
30                        </h-modal-close>
31                    </h-modal-header>
32
33                    <h-modal-body class="language-and-currency__modal-body scrollable">
34                        ${d(this.marketsEnabled,()=>r`
35                                <h-control>
36                                    <h-control-label class="control__label">
37                                        <label
38                                            id="${e}-label"
39                                            class="label"
40                                            for="${e}"
41                                        >
42                                            ${l("Delivery country")}
43                                        </label>
44                                    </h-control-label>
45                                    <h-control-content class="control">
46                                        <h-control-element class="control__element">
47                                            ${d(this._modalOpenedOnce,()=>r`
48                                                    <h-select
49                                                        ${m(this._countrySelect)}
50                                                        class="select"
51                                                        control-name="${e}"
52                                                        control-id="${e}"
53                                                        no-deselect
54                                                        no-placeholder-option
55                                                        assistive-title-id="${e}-label"
56                                                        .optionsList="${this._countryOptionsList}"
57                                                        @change=${this._handleCountryChange}
58                                                    >
59                                                        <h-select-toggler
60                                                            class="select-toggler"
61                                                            aria-labelledby="${e}-label"
62                                                        >
63                                                            <span
64                                                                class="select-toggler__placeholder"
65                                                                slot="placeholder"
66                                                            >
67                                                                ${l("Select")}
68                                                            </span>
69                                                        </h-select-toggler>
70                                                    </h-select>
71                                                `)}
72                                        </h-control-element>
73
74                                        <control-errors></control-errors>
75                                    </h-control-content>
76                                </h-control>
77                                <div class="language-and-currency__language-currency-section">
78                                    ${d(this._languageAndCurrencySelectsVisible,()=>r`
79                                            <h-control>
80                                                <h-control-label class="control__label">
81                                                    <label
82                                                        id="${t}-label"
83                                                        class="label"
84                                                        for="${t}"
85                                                    >
86                                                        ${l("Language")}
87                                                    </label>
88                                                </h-control-label>
89                                                <h-control-content class="control">
90                                                    <h-control-element class="control__element">
91                                                        <h-select
92                                                            ${m(this._localeSelect)}
93                                                            class="select"
94                                                            control-name="${t}"
95                                                            control-id="${t}"
96                                                            no-deselect
97                                                            no-placeholder-option
98                                                            assistive-title-id="${t}-label"
99                                                            .optionsList="${this._localeOptionsList}"
100                                                        >
101                                                            <h-select-toggler
102                                                                class="select-toggler"
103                                                                aria-labelledby="${t}-label"
104                                                            >
105                                                                <span
106                                                                    class="select-toggler__placeholder"
107                                                                    slot="placeholder"
108                                                                >
109                                                                    ${l("Select")}
110                                                                </span>
111                                                            </h-select-toggler>
112                                                        </h-select>
113                                                    </h-control-element>
114
115                                                    <control-errors></control-errors>
116                                                </h-control-content>
117                                            </h-control>
118
119                                            <h-control>
120                                                <h-control-label class="control__label">
121                                                    <label
122                                                        id="${n}-label"
123                                                        class="label"
124                                                        for="${n}"
125                                                    >
126                                                        ${l("Currency")}
127                                                    </label>
128                                                </h-control-label>
129                                                <h-control-content class="control">
130                                                    <h-control-element class="control__element">
131                                                        <h-select
132                                                            ${m(this._currencySelect)}
133                                                            class="select"
134                                                            control-name="${n}"
135                                                            control-id="${n}"
136                                                            no-deselect
137                                                            no-placeholder-option
138                                                            assistive-title-id="${n}-label"
139                                                            .optionsList="${this._currencyOptionsList}"
140                                                        >
141                                                            <h-select-toggler
142                                                                class="select-toggler"
143                                                                aria-labelledby="${n}-label"
144                                                            >
145                                                                <span
146                                                                    class="select-toggler__placeholder"
147                                                                    slot="placeholder"
148                                                                >
149                                                                    ${l("Select")}
150                                                                </span>
151                                                            </h-select-toggler>
152                                                        </h-select>
153                                                    </h-control-element>
154
155                                                    <control-errors></control-errors>
156                                                </h-control-content>
157                                            </h-control>
158                                        `,()=>r`
159                                            <div class="language-and-currency__language-currency-info">
160                                                <span>
161                                                    ${l("Language")}:
162                                                    <span class="language-and-currency__language-currency-info-value">
163                                                        ${this._currentLocaleName}
164                                                    </span>
165                                                    • ${l("Currency")}:
166                                                    <span class="language-and-currency__language-currency-info-value">
167                                                        ${this._currentCurrencyCode}
168                                                    </span>
169                                                </span>
170                                                <button @click=${this._handleChangeClick}>${l("Change")}</button>
171                                            </div>
172                                        `)}
173                                </div>
174                            `,()=>r`
175                                ${this.getSlot("languages")}
175 ${this.getSlot("currencies")}
176                                <p class="helper">
177                                    ${l("Store versions may differ in the availability of products, payment method and delivery countries")}.
178                                </p>
179                            `)}
180                    </h-modal-body>
181
182                    <h-modal-footer>
183                        ${d(this.marketsEnabled,()=>r`<p class="font_size-s">${l("Prices include taxes for the selected country.")}</p>`)}
184                        ${d(!this.marketsEnabled,()=>r`
185                                <button
186                                    class="btn btn_outline"
187                                    @click=${this._closeLanguageAndCurrencyModal}
188                                >
189                                    ${l("Cancel")}
190                                </button>
191                            `)}
192
193                        <button
194                            type="submit"
195                            class="btn btn_primary"
196                            @click=${this.marketsEnabled?this._changeDeliveryCountryLanguageAndCurrency:this._changeLanguageAndCurrency}
197                        >
198                            ${d(this.marketsEnabled,()=>r`${l("Apply")}`,()=>r`${l("Save")}`)}
199                        </button>
200                    </h-modal-footer>
201                </h-modal>
202            </div>
203        `}}u([g({type:Object})],c.prototype,"_modal");u([g({type:Number,attribute:"module-instance-id"})],c.prototype,"moduleInstanceId");u([g({type:Boolean,attribute:"detect-locale-mismatch"})],c.prototype,"detectLocaleMismatch");u([g({type:Array,attribute:"shipping-countries"})],c.prototype,"shippingCountries");u([g({type:Object,attribute:"market-defaults"})],c.prototype,"marketDefaults");u([g({type:Object,attribute:"current-shipping-country"})],c.prototype,"currentShippingCountry");u([g({type:Boolean,attribute:"markets-enabled"})],c.prototype,"marketsEnabled");u([S()],c.prototype,"_backdropVisible");u([S()],c.prototype,"_languageAndCurrencySelectsVisible");u([S()],c.prototype,"_modalOpenedOnce");class J extends M{static{this.featureName=L.feature}async init(){return{cores:[{type:w,instance:[c]}]}}}export{J as LanguageAndCurrencyInitializer};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.