{"version":3,"sources":["estore/cart/views/cart-sidebar-v1.ts"],"names":["html","render","nothing","OrderDiscountProgressBar","FreeShippingProgressBar","SiteCartController","Locale","determineTranslation","cartEventSubscriber","CartSidebarOrderLines","CartSidebarTotalSummary","CartSidebarV1","HTMLElement","constructor","super","this","translations","En","heading","shoppingCartIsEmpty","btnRemoveAll","btnCheckout","No","labels","mainTemplate","sidebarTemplate","close","_siteCartInfo","products","length","_clearCart","bind","CssClasses","FontSizeSmall","_orderLinesTable","emptyMessageTemplate","window","globalSettings","freeShippingMessageSettings","_freeShippingProgressBar","_orderDiscountProgressBar","_totalSummary","cartSettings","detailedCartPageUrl","_getDisabledState","_isOpened","_siteCartController","_toggledById","getAttribute","_toggledBy","document","querySelector","Error","addEventListener","toggle","setAttribute","body","classList","remove","style","setProperty","open","removeAttribute","scrollCompensation","innerWidth","documentElement","getBoundingClientRect","width","add","clearCart","_updateView","_onSiteCartChanged","topic","data","setData","freeShippingInfo","connectedCallback","isConnected","onSiteCartChanged","disconnectedCallback","removeEventListener","customElements","define"],"mappings":"OAASA,KAAMC,OAAQC,YAAe,kBAE7BC,6BAAgC,0CAChCC,4BAA+B,yCAC/BC,uBAA0B,oCAC1BC,WAAc,8CACdC,yBAA4B,oCAC5BC,wBAA2B,sDAC3BC,0BAA6B,4DAC7BC,4BAA+B,6DAE3BC,sBAAsBC,YAC/BC,cAKI,GAJAC,QAgDIC,KAAAC,aAAgC,EACnCV,OAAOW,IAAI,CACRC,QAAS,gBACTC,oBAAqB,0BACrBC,aAAc,aACdC,YAAa,eAEhBf,OAAOgB,IAAK,CACTJ,QAAS,iBACTC,oBAAqB,uBACrBC,aAAc,iBACdC,YAAa,kBAGbN,KAAAQ,OAAShB,qBAAqBQ,KAAKC,cAInCD,KAAAS,aAAe,IAAMxB;+BACFe,KAAKU;uCACG,GAAkBV,KAAKW;MAGlDX,KAAAU,gBAAkB,IAAMzB;;;sBAGde,KAAKQ,OAAOL;+CACa,GAAkBH,KAAKW,oCAAo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zBd,SACCvC,KAAK8B,UACL9B,KAAKW,QAELX,KAAK8C,OAwELjB,oBACJ,OAA4C,EAArC7B,KAAKY,cAAcC,SAASC,OAAa,GAAK,WAGjDC,aACJf,KAAK+B,oBAAoBuB,YAGrBC,cACJrE,OAAOc,KAAKS,eAAgBT,MAGxBwD,yBAAyBC,EAAeC,GAC5C1D,KAAKY,cAAgB8C,EACrB1D,KAAKwB,yBAAyBmC,QAAQD,EAAKE,kBAC3C5D,KAAKuD,cAIFM,oBACA7D,KAAK8D,aACJrE,oBAAoBsE,kBAAkB/D,KAAKwD,mBAAmBxC,KAAKhB,OAI3EgE,uBACQhE,KAAKkC,YACLlC,KAAKkC,WAAW+B,oBAAoB,QAASjE,KAAKuC,OAAOvB,KAAKhB,QAmB1E,IAAKiB,WAdLiD,eAAeC,OAAO,kBAAmBvE,gBAcpCqB,WAAAA,YAAU,IACX,cAAA,eAnKSrB","file":"cart-sidebar-v1.js","sourcesContent":["import { html, render, nothing } from \"lit-html\";\nimport { IDetailedCartInfo, IDetailedCartInfoForUi } from \"../interfaces/detailed-cart-info.js\";\nimport { OrderDiscountProgressBar } from \"./order-discount-progress-bar.js\";\nimport { FreeShippingProgressBar } from \"./free-shipping-progress-bar.js\";\nimport { SiteCartController } from \"../site-cart-controller.js\";\nimport { Locale } from \"../../../common/interfaces/locate.js\";\nimport { determineTranslation } from \"../../../utils/language.js\";\nimport { cartEventSubscriber } from \"../../../common/pubsub/cart-event-pub-sub.js\";\nimport { CartSidebarOrderLines } from \"./cat-sidebar-v1-parts/cart-sidebar-order-lines.js\";\nimport { CartSidebarTotalSummary } from \"./cat-sidebar-v1-parts/cart-sidebar-total-summary.js\";\n//The Vipps checkout button was not defined by BA+Desinger to be used in sitecart sidebar! Don't add it here!\nexport class CartSidebarV1 extends HTMLElement {\n constructor() {\n super();\n\n this._toggledById = this.getAttribute('toggledBy');\n\n if (!this._toggledById) {\n return;\n }\n\n this._toggledBy = document.querySelector(this._toggledById);\n\n if (!this._toggledBy) {\n throw Error('Can not find element which controls CmsSiteCardSidebar');\n }\n\n this._toggledBy.addEventListener('click', this.toggle.bind(this));\n }\n\n /* #region Public */\n public close() : void {\n this.setAttribute('hidden', '');\n document.body.classList.remove('cart-sidebar-v1-is-shown');\n document.body.style.setProperty('--scrollbar-compensate', '0px');\n }\n\n public open() : void {\n this.removeAttribute(\"hidden\");\n const windowWidth = window.innerWidth;\n const documentWidth = document.documentElement.getBoundingClientRect().width;\n\n let scrollCompensation = windowWidth - documentWidth;\n\n if(scrollCompensation > 0) {\n document.body.style.setProperty('--scrollbar-compensate', `${scrollCompensation}px`);\n }\n\n document.body.classList.add('cart-sidebar-v1-is-shown');\n }\n\n public toggle() : void {\n if (this._isOpened) {\n this.close();\n } else {\n this.open();\n }\n }\n /* #endregion */\n\n /* #region Translations */\n private translations: ITranslationSet = {\n [Locale.En]:{\n heading: \"Shopping cart\",\n shoppingCartIsEmpty: \"Shopping cart is empty!\",\n btnRemoveAll: \"Remove all\",\n btnCheckout: \"Go to cart\",\n },\n [Locale.No]: {\n heading: \"Min handlekurv\",\n shoppingCartIsEmpty: \"Handlekurven er tom!\",\n btnRemoveAll: \"Tøm handlekurv\",\n btnCheckout: \"Gå til kassen\",\n }\n };\n private labels = determineTranslation(this.translations) as ISiteCartSidebarLabels;\n /* #endregion */\n\n /* #region Markup */\n private mainTemplate = () => html`\n
${this.sidebarTemplate()}
\n
this.close()}>
\n `;\n\n private sidebarTemplate = () => html`\n
\n
\n

${this.labels.heading}

\n \n
\n ${this._siteCartInfo.products.length > 0 ? html`\n
\n \n
\n ` : nothing }\n
\n ${this._siteCartInfo.products.length > 0 ? this._orderLinesTable : this.emptyMessageTemplate() }\n \n `;\n\n private emptyMessageTemplate = () => html`\n
${this.labels.shoppingCartIsEmpty}
\n `;\n /* #endregion */\n\n /* #region Private */\n private _toggledById?: string;\n private _toggledBy?: HTMLElement;\n private _isOpened: boolean = false;\n private _siteCartController = new SiteCartController();\n private _siteCartInfo: IDetailedCartInfoForUi;\n private _orderLinesTable = new CartSidebarOrderLines();\n private _totalSummary = new CartSidebarTotalSummary();\n private _freeShippingProgressBar = new FreeShippingProgressBar();\n private _orderDiscountProgressBar = new OrderDiscountProgressBar();\n\n private _getDisabledState() {\n return this._siteCartInfo.products.length > 0 ? '' : 'disabled';\n }\n\n private _clearCart(){\n this._siteCartController.clearCart();\n }\n\n private _updateView() {\n render(this.mainTemplate(), this);\n }\n\n private async _onSiteCartChanged(topic: string, data: IDetailedCartInfo){\n this._siteCartInfo = data;\n this._freeShippingProgressBar.setData(data.freeShippingInfo);\n this._updateView();\n }\n /* #endregion */\n\n public connectedCallback() {\n if(this.isConnected){\n cartEventSubscriber.onSiteCartChanged(this._onSiteCartChanged.bind(this));\n }\n }\n\n disconnectedCallback() : void {\n if (this._toggledBy) {\n this._toggledBy.removeEventListener('click', this.toggle.bind(this));\n }\n }\n}\n\ncustomElements.define('cart-sidebar-v1', CartSidebarV1);\n\n/* #region Local interfaces */\ninterface ISiteCartSidebarLabels{\n heading: string;\n shoppingCartIsEmpty: string;\n btnRemoveAll: string;\n btnCheckout: string;\n}\n\ninterface ITranslationSet {\n [key:string]: ISiteCartSidebarLabels\n}\n\nenum CssClasses {\n FontSizeSmall = 'fs-sm',\n}\n/* #endregion */"]}