1import{L as f,bY as U,bZ as nt,R as u,u as o,g as T,c as S,l as ct,aM as g,s as lt,bX as ut,b as E,J as P,aN as L,ae as D,ac as k,ab as x,i as dt,N as ht,b8 as pt,H as yt,e as mt,T as _t,p as ft,aa as gt,r as At,C as Ut}from"./storefrontApp.DHj_rTVq.min.js";import{W as vt}from"./chunk-webapi_http_api.Dc6SyDs.js";import{A as B}from"./chunk-additional_field_mapper.BGljDzk.js";import{A as St}from"./chunk-address_mapper.CYefj1h.js";import{A as H}from"./chunk-availability_notifier_events.8Zgo8zG.js";import{U as q}from"./chunk-user_events.DVe_9j8.js";import{m as p}from"./chunk-vendor-rxjs.Dp7kflo.js";import{w as b,g as V,s as z,c as Y,i as Et,h as Mt,u as It,q as Nt}from"./chunk-index.esm.nYUWi4A.js";import{w as Ot,$ as K,t as $t,e as Tt}from"./chunk-vendor-lit.NvY0u02.js";import{S as j}from"./chunk-storefront_base_lit_element.BDgKmPq.js";import{o as v}from"./chunk-observable_directive.eGckMWP.js";import{o as Ft}from"./chunk-vendor-lodash.CWHFt7Z.js";import{t as F}from"./chunk-translations_directive.DFKTlKG.js";import{S as bt}from"./chunk-storefront_settings_constants.DIF02Gz.js";import"./chunk-vendor-di.Bh23gdA.js";import"./chunk-vendor-phoenix.cdKS79L.js";class C{constructor({points:t,level:e,level_discount:s,next_level:i}){this.points=t,this.achievedDiscountLevelPoints=e||null,this.currentDiscount=s||null,this.hasNextDiscountLevel=!!i,this.nextDiscountLevelPoints=typeof i=="number"?i:null}static create(t){return new C(t)}}class Ct{toModel(t){return C.create(t)}}var G;G=f;const Rt=class Q{constructor({address_book_id:t,address_name:e,shipping_default:s,default:i,...a}){this[G]=!0;const n=new St;this.id=t,this.addressName=e,this.isDefault=i,this.isShippingDefault=s,this.address=n.toModel(a)}static create(t){return new Q(t)}};let Pt=Rt;class R{toModel(t){return Pt.create(t)}toUserAddressDTO(t){return{city:t.address.city,company_name:t.address.companyName,country_code:t.address.country,country_id:t.address.countryId,firstname:t.address.firstName,lastname:t.address.lastName,pesel:t.address.personalId,phone:t.address.phone,state:t.address.state,street_1:t.address.street,street_2:t.address.streetAdditional,tax_id:t.address.taxId,zip_code:t.address.zipCode,address_book_id:t.id,address_name:t.addressName,default:t.isDefault,shipping_default:t.isShippingDefault}}toUserEditDataAddressDTO(t){return{name:t.firstName,surname:t.lastName,phone:t.phone,coname:t.companyName,nip:Number(t.taxId),pesel:t.personalId,other_address:t.street,city:t.city,zip:t.zipCode,state:t.state,country:t.country}}}var W;W=f;const Lt=class J{constructor({additional_fields:t,billing_address:e,email:s,firstname:i,groups:a,lastname:n,newsletter:d,registered:y,shipping_address:l,user_id:m,notification_stock_ids:_,loyalty:h,favourites:M,basketId:I}){this[W]=!0;const N=new B,A=new R,O=new Ct;this.addresses={billing:e?A.toModel(e):null,shipping:l?A.toModel(l):null},this.userId=m,this.email=s,this.firstName=i,this.lastName=n,this.additionalFields=t.map($=>N.toModel($)),this.groups=a,this.isNewsletterSubscriber=d,this.isRegistered=y,this.notificationsStockIds=_,this.loyalty=h?O.toModel(h):null,this.favourites=M,this.basketId=I}static create(t){return new J(t)}};let Dt=Lt;class kt{#t;#e;constructor(){this.#t=new B,this.#e=new R}toModel(t){return Dt.create(t)}toUserDTO(t){return{additional_fields:t.additionalFields.map(e=>this.#t.toAdditionalFieldDTO(e)),billing_address:t.addresses.billing?this.#e.toUserAddressDTO(t.addresses.billing):null,shipping_address:t.addresses.shipping?this.#e.toUserAddressDTO(t.addresses.shipping):null,email:t.email,firstname:t.firstName,groups:t.groups,lastname:t.lastName,newsletter:t.isNewsletterSubscriber,registered:t.isRegistered,user_id:t.userId,notification_stock_ids:t.notificationsStockIds,loyalty:t.loyalty,favourites:t.favourites,basketId:t.basketId}}toUserEditDataDTO(t){return{additional_fields:t.additionalFields.map(e=>this.#t.toAdditionalFieldDTO(e)),billing_address:t.addresses.billing?this.#e.toUserEditDataAddressDTO(t.addresses.billing.address):null,email:t.email,firstname:t.firstName,groups:t.groups,lastname:t.lastName,newsletter:t.isNewsletterSubscriber,registered:t.isRegistered,shipping_address:t.addresses.shipping?this.#e.toUserEditDataAddressDTO(t.addresses.shipping.address):null,user_id:t.userId}}}var X;X=f;const xt=class Z{constructor({confirm:t,date:e,is_digital:s,is_overpayment:i,is_paid:a,is_underpayment:n,order_id:d,registered:y,status:l,sum:m,sum_float:_,total_products:h}){this[X]=!0,this.confirm=t,this.date=e,this.isDigital=s,this.isOverpayment=i,this.isPaid=a,this.isUnderpayment=n,this.id=d,this.registered=y,this.sum=m,this.sumFloat=_,this.totalProducts=h,this.status={statusId:l.status_id,translation:{name:l.translation.name,langId:l.translation.lang_id},type:l.type}}static create(t){return new Z(t)}};let Ht=xt;class qt{toModel(t){return Ht.create(t)}toDTO(t){return{confirm:t.confirm,date:t.date,is_digital:t.isDigital,is_overpayment:t.isOverpayment,is_paid:t.isPaid,is_underpayment:t.isUnderpayment,order_id:t.id,registered:t.registered,status:{status_id:t.status.statusId,translation:{name:t.status.translation.name,lang_id:t.status.translation.langId},type:t.status.type},sum:t.sum,sum_float:t.sumFloat,total_products:t.totalProducts}}}var w;w=f;const Bt=class c{constructor(t){this[w]=!0,this.confirm=t.confirm,this.date=t.date,this.isDigital=t.is_digital,this.isOverpayment=t.is_overpayment,this.isPaid=t.is_paid,this.isUnderpayment=t.is_underpayment,this.id=t.order_id,this.registered=t.registered,this.sum=t.sum,this.sumFloat=t.sum_float,this.totalProducts=t.total_products,this.paid=t.paid,this.paidFloat=t.paid_float,this.productsCost=t.products_cost,this.productsCostFloat=t.products_cost_float,this.discounts=t.discounts,this.discountsFloat=t.discounts_float,this.shippingVatValue=t.shipping_vat_value,this.currencyId=t.currency_id,this.currency=t.currency,this.status=c.mapStatus(t.status),this.payment=c.mapPayment(t.payment),this.shipping=c.mapShipping(t.shipping),this.billingAddress=c.mapAddress(t.billing_address),this.deliveryAddress=c.mapAddress(t.delivery_address),this.products=t.products.map(c.mapProduct),this.parcels=t.parcels.map(c.mapParcel),this.additionalFields=t.additional_fields.map(c.mapAdditionalField)}static mapStatus(t){return{statusId:t.status_id,translation:{name:t.translation.name,langId:t.translation.lang_id},type:t.type}}static mapPayment(t){return{paymentId:t.payment_id,type:t.type,name:t.name,translation:{name:t.translation.name,description:t.translation.description,langId:t.translation.lang_id},isStarted:t.is_started,isFinished:t.is_finished,isProcessing:t.is_processing}}static mapShipping(t){return{shippingId:t.shipping_id,vatValue:t.vat_value,vatName:t.vat_name,cost:t.cost,costFloat:t.cost_float,translation:t.translation?{name:t.translation.name,description:t.translation.description,langId:t.translation.lang_id}:void 0}}static mapAddress(t){return{name:t.name,surname:t.surname,street:t.street,house:t.house,local:t.local,coname:t.coname,nip:t.nip,pesel:t.pesel,phone:t.phone,otherAddress:t.other_address,city:t.city,zip:t.zip,state:t.state,country:t.country,type:t.type}}static mapProduct(t){return{productId:t.product_id,stockId:t.stock_id,code:t.code,pkwiu:t.pkwiu,name:t.name,promoDesc:t.promo_desc,producerName:t.producer_name,producerSite:t.producer_site,ean:t.ean,discountPerc:t.discount_perc,quantity:t.quantity,price:t.price,priceFloat:t.price_float,sum:t.sum,sumFloat:t.sum_float,taxValue:t.tax_value,taxName:t.tax_name,deliveryTime:t.delivery_time,deliveryTimeHours:t.delivery_time_hours,weight:t.weight,unit:{name:t.unit.name,floatingPoint:t.unit.floating_point},textOptions:t.text_options,fileOptions:t.file_options,image:t.image}}static mapParcel(t){return{url:t.url,code:t.code,date:t.date}}static mapAdditionalField(t){return{fieldId:t.field_id,name:t.name,type:t.type,locate:t.locate,req:t.req,fieldValue:t.field_value,value:t.value}}static create(t){return new c(t)}};let Vt=Bt;class zt{toModel(t){return Vt.create(t)}}class Yt{user(){return"/user/"}userAddress(){return"/user/address?limit=50"}userOrders(){return"/user/orders?limit=50"}userOrderDetail(t){return`/user/orders/${t}`}updateUser(){return"/user/"}addAddress(){return"/user/address/"}updateAddress(t){return`/user/address/${t}`}removeAddress(t){return`/user/address/${t}`}getCurrentCountry(){return"/user/country/get-current/"}}var tt;tt=f;const Kt=class et{constructor({country:t}){this[tt]=!0,this.country=t}static create(t){return new et(t)}};let jt=Kt;class st{toModel(t){return jt.create(t)}}class Gt extends vt{#t;#e;#i;#s;#r;#a;constructor(t){super(t),this.#t=new Yt,this.#e=new kt,this.#i=new st,this.#s=new R,this.#r=new qt,this.#a=new zt}
1getUser(){const t={url:this.#t.user(),method:u.get,cacheOptions:{type:nt,ttlInMs:U}};return this.fetch(t,{decorators:[o.status,o.flashMessages],callback:({data:e,...s})=>({...s,data:this.#e.toModel(e)})})}getUserAddresses(){const t={url:this.#t.userAddress(),method:u.get,cacheOptions:{type:T.local,ttlInMs:U}};return this.fetch(t,{callback:e=>({...e,data:{...e.data,list:e.data.list.map(s=>this.#s.toModel(s))}}),decorators:[o.status,o.flashMessages]})}async getUserOrders(){const t={url:this.#t.userOrders(),method:u.get,cacheOptions:{type:T.local,ttlInMs:U}};return this.fetch(t,{decorators:[o.status,o.flashMessages],callback:({data:e,...s})=>({...s,data:{...e,list:e.list.map(i=>this.#r.toModel(i))}})})}async getUserOrderDetails(t){const e={url:this.#t.userOrderDetail(t),method:u.get,cacheOptions:{type:T.local,ttlInMs:U}};return this.fetch(e,{decorators:[o.status,o.flashMessages],callback:({data:s,...i})=>({...i,data:this.#a.toModel(s)})})}async updateUser(t){const e={url:this.#t.updateUser(),method:u.put,data:this.#e.toUserEditDataDTO(t)};return this.fetch(e,{decorators:[o.status,o.flashMessages]})}async addAddress(t){const e={url:this.#t.addAddress(),method:u.put,data:this.#s.toUserAddressDTO(t)};return this.fetch(e,{decorators:[o.status,o.flashMessages]})}async updateAddress(t,e){const s={url:this.#t.updateAddress(t),method:u.put,data:this.#s.toUserAddressDTO(e)};return this.fetch(s,{decorators:[o.status,o.flashMessages]})}async removeAddress(t){const e={url:this.#t.removeAddress(t),method:u.delete};return this.fetch(e,{decorators:[o.status,o.flashMessages]})}async getUserCurrentCountry(){const t={url:this.#t.getCurrentCountry(),method:u.get};return this.fetch(t,{callback:({data:e,...s})=>({...s,data:this.#i.toModel(e)})})}}const Qt={user:null},Wt=()=>S({name:g.store},ct(Qt));class Jt{#t;constructor(t){this.#t=t}getUser(){return this.#t.getValue().user}selectUser$(){return this.#t.pipe(lt(t=>t.user))}updateUser(t){this.#t.update(ut("user",t))}clearUser(){this.updateUser(null)}}class Xt extends E{#t;#e;#i;#s;#r;#a;constructor({userRepository:t,authenticationApi:e,userHttpApi:s,storeFactoryApi:i,featureSystemApi:a,settingsApi:n}){super(),this.#e=t,this.#t=e,this.#i=s,this.#s=i,this.#r=a,this.#a=n,this.#t.selectIsAuthorized$().subscribe(d=>{if(!d){this.hasUser()&&(this._removeFavouriteProductsFromLocalStorage(),this._clearUser());return}this._fetchUser().then(async()=>{this._addFavouriteProductsToLocalStorage(),this._handleUserBasket()})}),this._setupEvents()}async _handleUserBasket(){const t=this.getUser();t?.basketId&&(await this._waitForBasketFeature(),this.eventBus.emit(new P(q.hasBasket,t.basketId)))}async _waitForBasketFeature(){this.isFeatureRegistered(L.feature)||await this.#r.registerDynamic(L.feature)}async _fetchUser(){try{const{response:t}=this.#i.getUser(),{data:e}=await t;this._updateUser(e)}catch(t){console.error(t)}}_setupEvents(){this.eventBus.on(H.subscribed,({body:t})=>{t&&this._addProductNotification(t)}),this.eventBus.on(H.unsubscribed,({body:t})=>{t&&this._removeProductNotification(t)}),this.eventBus.on(D.added,({body:t})=>{t&&this._addProductToFavourites(t)}),this.eventBus.on(D.removed,({body:t})=>{t&&this._removeProductFromFavourites(t)})}getUser(){return this.#e.getUser()}hasUser(){return this.getUser()!==null}selectUser$(){return this.#e.selectUser$()}isProductNotificationPossible(t){const e=this.getUser();return e?!e.notificationsStockIds.includes(t):!1}selectIsProductNotificationPossible$(t){return this.selectUser$().pipe(p(e=>e===null||!e.notificationsStockIds.includes(t)))}getLoyalty(){return this.#e.getUser()?.loyalty||null}getFavourites(){const t=this.#e.getUser();if(!t)throw new Error("User is not logged in");return t.favourites}selectLoyalty$(){return this.selectUser$().pipe(p(t=>t?.loyalty||null))}getLoyaltyPoints(){return this.#e.getUser()?.loyalty?.points||0}selectLoyaltyPoints$(){return this.selectUser$().pipe(p(t=>t?.loyalty?.points||0))}async getCurrentCountry(){try{const{response:t}=await this.#i.getUserCurrentCountry(),{data:e}=await t;return e}catch(t){return console.error("Failed to fetch user country:",t),new st().toModel({country:null})}}_updateUser(t){this.#e.updateUser(t),this.eventBus.emit(new P(q.updated,this.getUser()))}_clearUser(){this.#e.clearUser()}_addProductNotification(t){const e=this.getUser();e&&(e.notificationsStockIds.push(t),this._updateUser({...e}))}_removeProductNotification(t){const e=this.getUser();if(e){const s=e.notificationsStockIds.indexOf(t);e.notificationsStockIds.splice(s,1),this._updateUser({...e})}}_addProductToFavourites(t){const e=this.getUser();e&&(e.favourites=[...e.favourites,t],this._updateUser({...e}))}_removeProductFromFavourites(t){const e=this.getUser();e&&(e.favourites=e.favourites.filter(s=>s!==t),this._updateUser({...e}))}_addFavouriteProductsToLocalStorage(){const t=this.getFavourites();this._getFavouritesStore().setObject(k,t)}_removeFavouriteProductsFromLocalStorage(){this._getFavouritesStore().remove(k)}_getFavouritesStore(){const t=this.#s.getStore(x.store);return t||this.#s.createStore("local",x.store)}}const Zt=({storeName:r="UserOrdersStore"}={})=>S({name:r},b());class wt{#t;constructor(t){this.#t=t}get(){return this.#t.query(V())}select$(){return this.#t.pipe(z())}set(t){this.#t.update(Y(t))}}
1class te extends E{#t;#e;#i;#s;#r;constructor({userOrdersRepository:t,userHttpApi:e,flashMessengerApi:s,translationsApi:i,authenticationApi:a}){super(),this.#t=t,this.#e=e,this.#i=s,this.#s=i,this.#r=a}async get(){return await this._fetchOrdersIfEmpty(),this.#t.get()}async select$(){return await this._fetchOrdersIfEmpty(),this.#t.select$()}async _fetchOrdersIfEmpty(){this._hasAnyOrders()||await this._fetch()}_set(t){this.#t.set(t)}_hasAnyOrders(){return this.#t.get().length>0}async _fetch(){try{const{response:t}=await this.#e.getUserOrders(),{data:e}=await t;this._set(e.list)}catch(t){this.#i.addFlashMessage({type:"error",content:this.#s.translate("Failed to fetch user orders")}),console.error(t)}}}const ee=({storeName:r="UserOrderDetailsStore"}={})=>S({name:r},b({idKey:"id"}));class se{#t;constructor(t){this.#t=t}get(t){return this.#t.query(Et(t))??null}select$(t){return this.#t.pipe(Mt(t),p(e=>e??null))}set(t){this.#t.update(It(t))}has(t){return this.#t.query(Nt(t))}}class ie extends E{#t;#e;#i;#s;constructor({userOrderDetailsRepository:t,userHttpApi:e,flashMessengerApi:s,translationsApi:i}){super(),this.#t=t,this.#e=e,this.#i=s,this.#s=i}async get(t){return await this._fetchOrderDetailIfNotCached(t),this.#t.get(t)}async select$(t){return await this._fetchOrderDetailIfNotCached(t),this.#t.select$(t)}async _fetchOrderDetailIfNotCached(t){this._hasOrderDetail(t)||await this._fetch(t)}_set(t){this.#t.set(t)}_hasOrderDetail(t){return this.#t.has(t)}async _fetch(t){try{const{response:e}=await this.#e.getUserOrderDetails(t),{data:s}=await e;this._set(s)}catch(e){this.#i.addFlashMessage({type:"error",content:this.#s.translate("Failed to fetch order details")}),console.error(e)}}}const re=({storeName:r="UserAddressesStore"}={})=>S({name:r},b());class ae{#t;constructor(t){this.#t=t}get(){return this.#t.query(V())}select$(){return this.#t.pipe(z())}set(t){this.#t.update(Y(t))}}class oe extends E{#t;#e;#i;#s;#r;constructor({userAddressesRepository:t,userHttpApi:e,flashMessengerApi:s,translationsApi:i,authenticationApi:a}){super(),this.#t=t,this.#e=e,this.#i=s,this.#s=i,this.#r=a}async get(){return await this._fetchOrdersIfEmpty(),this.#t.get()}async select$(){return await this._fetchOrdersIfEmpty(),this.#t.select$()}async _fetchOrdersIfEmpty(){this._hasAnyAddresses()||await this._fetch()}_set(t){this.#t.set(t)}_hasAnyAddresses(){return this.#t.get().length>0}async _fetch(){try{const{response:t}=await this.#e.getUserAddresses(),{data:e}=await t;this._set(e.list)}catch(t){this.#i.addFlashMessage({type:"error",content:this.#s.translate("Failed to fetch user addresses")}),console.error(t)}}}class ne extends dt{constructor({userService:t,userOrdersService:e,userOrderDetailsService:s,userAddressesService:i}){super(),this.moduleName=g.api,this.#t=t,this.#e=e,this.#i=s,this.#s=i}#t;#e;#i;#s;getUser(){return this.#t.getUser()}hasUser(){return this.#t.hasUser()}selectUser$(){return this.#t.selectUser$()}async getOrders(){return this.#e.get()}async selectOrders$(){return this.#e.select$()}async getOrderDetails(t){return this.#i.get(t)}async selectOrderDetails$(t){return this.#i.select$(t)}async getAddresses(){return this.#s.get()}async selectAddresses$(){return this.#s.select$()}isProductNotificationPossible(t){return this.#t.isProductNotificationPossible(t)}selectIsProductNotificationPossible$(t){return this.#t.selectIsProductNotificationPossible$(t)}getLoyalty(){return this.#t.getLoyalty()}selectLoyalty$(){return this.#t.selectLoyalty$()}getLoyaltyPoints(){return this.#t.getLoyaltyPoints()}selectLoyaltyPoints$(){return this.#t.selectLoyaltyPoints$()}async getCurrentCountry(){return this.#t.getCurrentCountry()}}var ce=Object.defineProperty,le=(r,t,e,s)=>{for(var i=void 0,a=r.length-1,n;a>=0;a--)(n=r[a])&&(i=n(t,e,i)||i);return i&&ce(t,e,i),i};
1class it extends j{static{this.moduleName="user-loyalty-points"}constructor(){super(),this.getApi(g.api).then(t=>{this._userApi=t,this._loyaltyPoints$=this._userApi.selectLoyaltyPoints$()})}render(){return K`${this._loyaltyPoints$?v(this._loyaltyPoints$):Ot}`}}le([$t()],it.prototype,"_loyaltyPoints$");var ue=Object.defineProperty,de=(r,t,e,s)=>{for(var i=void 0,a=r.length-1,n;a>=0;a--)(n=r[a])&&(i=n(t,e,i)||i);return i&&ue(t,e,i),i};class rt extends j{constructor(){super(),this.href="",this._userApi=this.getApiSync(g.api),this._userEmail$=this._userApi.selectUser$().pipe(p(t=>t?.email)),this._emailFirstLetter$=this._userEmail$.pipe(p(t=>Ft(t?t[0]:"K")))}static{this.moduleName="user-info"}render(){return K` <a 2 class="user-menu__user user-menu__link user-menu__link_no-underline link link_secondary link_no-underline" 3 href="${this.href}" 4 aria-label="${F("Hello")}, ${v(this._userEmail$)}, ${F("go to the customer panel")}" 5 > 6 <div 7 class="user-menu__user-icon" 8 aria-hidden="true" 9 > 10 ${v(this._emailFirstLetter$)} 11 </div> 12 <div> 13 <p class="p_no-margin user-menu__user-text">${F("Hello")},</p> 14 <p class="user-menu__user-text user-menu__user-text_secondary">${v(this._userEmail$)}</p> 15 </div> 16 </a>`}}de([Tt({type:String})],rt.prototype,"href");class $e extends ht{static{this.featureName=g.feature}async init(){const t=await this.getApi(pt.api),e=this.getApiSync(yt),s=this.getApiSync(mt.api),i=this.getApiSync(_t.api),a=new Gt(e),n=this.getApiSync(ft),d=this.getApiSync(gt),y=await this.getApi(bt.api),l=Wt(),m=new Jt(l),_=new Xt({userRepository:m,userHttpApi:a,authenticationApi:t,storeFactoryApi:n,featureSystemApi:d,settingsApi:y}),h=Zt(),M=new wt(h),I=new te({userOrdersRepository:M,userHttpApi:a,flashMessengerApi:s,translationsApi:i,authenticationApi:t}),N=ee(),A=new se(N),O=new ie({userOrderDetailsRepository:A,userHttpApi:a,flashMessengerApi:s,translationsApi:i}),$=re(),at=new ae($),ot=new oe({userAddressesRepository:at,userHttpApi:a,flashMessengerApi:s,translationsApi:i,authenticationApi:t});return{cores:[{type:At.api,instance:[new ne({userService:_,userOrdersService:I,userOrderDetailsService:O,userAddressesService:ot})]},{type:Ut,instance:[it,rt]}]}}}export{$e as UserInitializer};
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.