{"version":3,"sources":["checkout/vipps/vipps-buy-product-dialog.ts"],"names":["html","render","createRef","ref","determineTranslation","toLocalFixed","VippsBuyProductDialog","HTMLElement","constructor","onDecision","super","this","translations","en","title","youAlreadyHaveCart","cart","wouldYou","buyAll","onlyThis","totalPrice","no","template","dialog","labels","data","cartLink","cartSum","handleBuyAllClick","bind","productPrice","handleBuyOnlyThisClick","show","value","showModal","e","preventDefault","VippsBuyDecision","WholeCart","close","OnlyThisProduct","setOnDecision","connectedCallback","customElements","define"],"mappings":"OAASA,KAAMC,MAAwB,KAAV,kBACpBC,UAAWC,GAAoC,KAAzB,iCACtBC,oBAAqD,KAAzB,iCAC5BC,YAA2C,KAAvB,8BACtB,oCAGMC,8BAA8BC,YACvCC,YAAoBC,GAChBC,MAAK,EADWC,KAAAF,WAAAA,EAaZE,KAAAC,aAAe,CACnBC,GAAI,CACAC,MAAO,kCACPC,mBAAoB,+BACpBC,KAAM,gBACNC,SAAU,2FACVC,OAAQ,kBACRC,SAAU,wBACVC,WAAY,c,EAEhBC,GAAI,CACAP,MAAO,8BACPC,mBAAoB,0BACpBC,KAAM,eACNC,SAAU,gFACVC,OAAQ,kBACRC,SAAU,uBACVC,WAAY,a,GAQZT,KAAAW,SAAW,GAAgCtB;sBACjCG,IAAIQ,KAAKY,MAAM,cAAcZ,KAAKa,OAAOV;;kCAE7BH,KAAKa,OAAOT,+BAA+BU,EAAKC,aAAaf,KAAKa,OAAOR;kBACzFL,KAAKa,OAAOP;;;uDAGyBN,KAAKa,OAAOJ,yCAAyCf,aAAaoB,EAAKE,QAAS,CAAC;8EAC1DhB,KAAKiB,kBAAkBC,KAAKlB,IAAI,MAAMA,KAAKa,OAAON;;;uDAGzEP,KAAKa,OAAOJ,yCAAyCf,aAAaoB,EAAKK,aAAc,CAAC;oFACzDnB,KAAKoB,uBAAuBF,KAAKlB,IAAI,MAAMA,KAAKa,OAAOL;;;;;MAiC/HR,KAAAY,OAASrB,UAAS,EAjFtBS,KAAKa,OAASpB,qBAAqBO,KAAKC,YAAY,CACxD,CAGOoB,KAAKP,GACRd,KAAKV,OAAOwB,CAAI,EAChBd,KAAKY,OAAOU,OAAOC,UAAS,CAChC,CAkDQN,kBAAkBO,GACtBA,EAAEC,eAAc,EAEZzB,KAAKF,YACLE,KAAKF,WAAW4B,iBAAiBC,SAAS,EAG9C3B,KAAKY,OAAOU,OAAOM,MAAK,CAC5B,CAEQR,uBAAuBI,GAC3BA,EAAEC,eAAc,EAEZzB,KAAKF,YACLE,KAAKF,WAAW4B,iBAAiBG,eAAe,EAGpD7B,KAAKY,OAAOU,OAAOM,MAAK,CAC5B,CAQQtC,OAAOwB,GACXxB,OAAOU,KAAKW,SAASG,CAAI,EAAGd,IAAI,CACpC,CAEO8B,cAAchC,GACjBE,KAAKF,WAAaA,CACtB,CAGAiC,qB,CAUJ,IAAYL,iBAAZ,CAAA,SAAYA,GACRA,EAAA,OAAA,SACAA,EAAA,UAAA,aACAA,EAAA,gBAAA,cACH,EAJWA,iBAAAA,kBAAgB,EAAA,EAM5BM,eAAeC,OAAO,2BAA4BtC,qBAAqB,SA/G1DA,sBAyGD+B,gBAM4D","file":"vipps-buy-product-dialog.js","sourcesContent":["import { html, render } from \"lit-html\";\r\nimport { createRef, ref } from \"lit-html/directives/ref\";\r\nimport { determineTranslation } from \"../../utils/language.js\";\r\nimport { toLocalFixed } from \"../../utils/number.js\";\r\nimport \"../../website/cms-dialog.js\";\r\nimport { CmsDialog } from \"../../website/cms-dialog.js\";\r\n\r\nexport class VippsBuyProductDialog extends HTMLElement {\r\n constructor(private onDecision: (decision: VippsBuyDecision) => void) {\r\n super();\r\n this.labels = determineTranslation(this.translations);\r\n }\r\n\r\n /* #region Public */\r\n public show(data: IVippsBuyProductData) {\r\n this.render(data);\r\n this.dialog.value?.showModal();\r\n }\r\n /* #endregion */\r\n\r\n /* #region Translations */\r\n private translations = {\r\n en: {\r\n title: \"Pay with Vipps express checkout\",\r\n youAlreadyHaveCart: \"You already have products in\",\r\n cart: \"shopping cart\",\r\n wouldYou: \"Would you like to buy all products in cart including this product, or just this product?\",\r\n buyAll: \"Buy all in cart\",\r\n onlyThis: \"Buy only this product\",\r\n totalPrice: \"Total price:\"\r\n },\r\n no: {\r\n title: \"Betal med Vipps hurtigkasse\",\r\n youAlreadyHaveCart: \"Du har allerede varer i\",\r\n cart: \"handlekurven\",\r\n wouldYou: \"Vil du kjøpe alle varer i handlekurven inklusiv denne, eller kun denne varen?\",\r\n buyAll: \"Kjøp alle varer\",\r\n onlyThis: \"Kjøp kun denne varen\",\r\n totalPrice: \"Total pris:\"\r\n }\r\n };\r\n\r\n private labels: { [key: string]:any };\r\n /* #endregion */\r\n\r\n /* #region Markup */\r\n private template = (data: IVippsBuyProductData) => html`\r\n \r\n
\r\n

${this.labels.youAlreadyHaveCart} ${this.labels.cart}
\r\n ${this.labels.wouldYou}

\r\n
\r\n
\r\n

${this.labels.totalPrice} ${toLocalFixed(data.cartSum, 2)}

\r\n \r\n
\r\n
\r\n

${this.labels.totalPrice} ${toLocalFixed(data.productPrice, 2)}

\r\n \r\n
\r\n
\r\n
\r\n
\r\n `;\r\n /* #endregion */\r\n\r\n /* #region Event handlers */\r\n private handleBuyAllClick(e: MouseEvent) {\r\n e.preventDefault();\r\n\r\n if (this.onDecision) {\r\n this.onDecision(VippsBuyDecision.WholeCart);\r\n }\r\n\r\n this.dialog.value?.close();\r\n }\r\n\r\n private handleBuyOnlyThisClick(e: MouseEvent) {\r\n e.preventDefault();\r\n\r\n if (this.onDecision) {\r\n this.onDecision(VippsBuyDecision.OnlyThisProduct);\r\n }\r\n\r\n this.dialog.value?.close();\r\n }\r\n\r\n /* #endregion */\r\n\r\n /* #region Private */\r\n\r\n private dialog = createRef();\r\n\r\n private render(data: IVippsBuyProductData) {\r\n render(this.template(data), this);\r\n }\r\n\r\n public setOnDecision(onDecision) {\r\n this.onDecision = onDecision;\r\n }\r\n /* #endregion */\r\n\r\n connectedCallback() { }\r\n}\r\n\r\nexport interface IVippsBuyProductData {\r\n cartLink: string;\r\n cartCount: number;\r\n cartSum: number;\r\n productPrice: number;\r\n}\r\n\r\nexport enum VippsBuyDecision {\r\n Cancel = \"cancel\",\r\n WholeCart = \"whole-cart\",\r\n OnlyThisProduct = \"only-product\"\r\n}\r\n\r\ncustomElements.define(\"vipps-buy-product-dialog\", VippsBuyProductDialog);"]}