crmbonus-component-wake 2.1.39-ngrok → 2.1.41-ngrok

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -66,6 +66,7 @@ export class CrmBonus {
66
66
  }
67
67
  }
68
68
  async componentWillLoad() {
69
+ var _a;
69
70
  this.loading_reprocess = true;
70
71
  window.addEventListener('productRemovedFromCart', async () => {
71
72
  console.log('[CRMBONUS] - productRemovedFromCart');
@@ -81,6 +82,12 @@ export class CrmBonus {
81
82
  await this.reprocess();
82
83
  });
83
84
  });
85
+ (_a = document.getElementById('validarCupom')) === null || _a === void 0 ? void 0 : _a.addEventListener('click', async () => {
86
+ console.log("[CRMBONUS] - cupom sendo submetido!");
87
+ setTimeout(async () => {
88
+ await this.reprocess();
89
+ }, 2000);
90
+ });
84
91
  await this.observerHandle();
85
92
  i18next.changeLanguage(i18next.language);
86
93
  }
@@ -99,6 +106,18 @@ export class CrmBonus {
99
106
  }
100
107
  async observerHandle() {
101
108
  const elements = document.getElementsByTagName('a');
109
+ document.addEventListener('click', (event) => {
110
+ //@ts-ignore
111
+ console.log('Clique detectado em:', event.target.href);
112
+ console.log('Clique detectado em:', event.target);
113
+ //@ts-ignore
114
+ if (['validarCupom'].includes(event.target.id)) {
115
+ setTimeout(async () => {
116
+ await this.reprocess();
117
+ this.observerHandle();
118
+ }, 2000);
119
+ }
120
+ });
102
121
  //@ts-ignore
103
122
  for (let el of elements) {
104
123
  console.log('[el.href]', el.href);
@@ -171,7 +190,6 @@ export class CrmBonus {
171
190
  }, 1500000);
172
191
  }
173
192
  async buildAndGetProducts(productsWake) {
174
- console.log();
175
193
  const key = `bc-products:${this.cartWake.id}`;
176
194
  const productsString = JSON.stringify(productsWake);
177
195
  localStorage.setItem(key, productsString);
@@ -1 +1 @@
1
- {"version":3,"file":"crm-bonus.js","sourceRoot":"","sources":["../../../../src/components/crm-bonus/crm-bonus.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,S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a,EAAE,EACxC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,EAChC,YAAY,EAAE,IAAI,CAAC,YAAY,GAC/B,CACH,CAEe,CACrB,CAAA;IACH,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Method, Prop, State, h } from '@stencil/core';\r\nimport { IProduct, IProductWake, ICustomer } from '../../dto/validate.pin.bonus';\r\nimport { CrmBonusService } from '../../services/crmbonus.service';\r\nimport { IPinSent } from '../../components';\r\nimport { defaultStyles, StepFormEnum } from '../../contants';\r\n\r\nimport i18next from '../../i18n/i18n'\r\nimport { buildProductsByWake } from '../../helpers/build.payload.helper';\r\nimport { getCart, getInfoBonusByCartIdAndStoreName } from '../../helpers/cart.helper';\r\nimport { CartWake } from '../../objectvalues/cart.wake';\r\nimport { USED_KEY } from '../../utils/keys.storage';\r\nimport { ReservedInfoDTO } from '../../dto/reserved-info.dto';\r\n\r\n@Component({\r\n tag: 'crm-bonus',\r\n styleUrl: 'crm-bonus.css',\r\n assetsDirs: ['assets'],\r\n // scoped: true\r\n shadow: true\r\n})\r\nexport class CrmBonus {\r\n\r\n private crmBonusService: CrmBonusService = CrmBonusService.getInstance();\r\n\r\n private crmBonusRef: HTMLCrmGiftbackFormElement;\r\n\r\n @Prop() cart;\r\n @Prop() canhidden: boolean = false;\r\n\r\n @State() showModal: boolean = false;\r\n\r\n @State() cartWake: CartWake;\r\n\r\n @State() customer: ICustomer = {\r\n birthDate: \"\",\r\n document: \"\",\r\n name: \"\",\r\n phone: \"\"\r\n };\r\n\r\n @State() loading: boolean = false;\r\n @State() message: string;\r\n @State() phone: number;\r\n @State() canCancel: boolean = false;\r\n @State() amountCancel: string;\r\n @State() sent: IPinSent;\r\n\r\n @State() session: string;\r\n @State() loading_reprocess = false;\r\n @State() styles = defaultStyles;\r\n @State() reservedInfo: ReservedInfoDTO;\r\n\r\n @Method()\r\n async resetBonus() {\r\n console.log('[CRMBONUS] - reset bonus');\r\n\r\n try {\r\n await this.crmBonusRef.processBonus(this.buildProducts(), true);\r\n console.log('[BONUS RESETADO]!!!!!');\r\n } catch (err) {\r\n\r\n this.loading = false;\r\n console.log('[error ao reprocessar bonous]');\r\n await this.crmBonusRef.setStep(StepFormEnum.STEP_PHONE);\r\n } finally {\r\n this.loading = false;\r\n }\r\n }\r\n\r\n @Method()\r\n async setloading() {\r\n this.loading_reprocess = !this.loading_reprocess;\r\n }\r\n\r\n @Method()\r\n async reprocess() {\r\n console.log(\"[CRMBONUS] - reprocess\")\r\n this.loading_reprocess = true\r\n\r\n try {\r\n\r\n const isUse = localStorage.getItem(USED_KEY);\r\n\r\n if (!isUse) return;\r\n\r\n this.cartWake = await getCart();\r\n await this.resetBonus();\r\n } catch (err) {\r\n console.debug('[watchProducts]', err.message);\r\n } finally {\r\n this.loading_reprocess = false\r\n }\r\n }\r\n\r\n async componentWillLoad() {\r\n this.loading_reprocess = true;\r\n window.addEventListener('productRemovedFromCart', async () => {\r\n console.log('[CRMBONUS] - productRemovedFromCart');\r\n await this.reprocess()\r\n });\r\n\r\n window.addEventListener('productAddedToCart', async () => {\r\n console.log('[CRMBONUS] - productAddedToCart');\r\n await this.reprocess();\r\n });\r\n\r\n document.querySelectorAll('form').forEach((el) => {\r\n el.addEventListener(\"submit\", async () => {\r\n console.log(\"[CRMBONUS] - Formulário está sendo submetido!\");\r\n await this.reprocess();\r\n });\r\n });\r\n\r\n await this.observerHandle();\r\n\r\n i18next.changeLanguage(i18next.language);\r\n }\r\n\r\n async componentDidLoad() {\r\n try {\r\n await this.loadSession();\r\n this.handleLoad();\r\n await this.loadConfigStore();\r\n } catch (error) {\r\n console.log('bc:err....')\r\n } finally {\r\n this.loading_reprocess = false;\r\n }\r\n }\r\n\r\n private async observerHandle() {\r\n const elements = document.getElementsByTagName('a');\r\n\r\n //@ts-ignore\r\n for (let el of elements) {\r\n console.log('[el.href]', el.href);\r\n if (el.href.includes('Produto/Delete')) {\r\n el.addEventListener('click', async () => {\r\n console.log('[CRMBONUS] - Produto removido do carrinho');\r\n\r\n setTimeout(async () => {\r\n await this.reprocess();\r\n this.observerHandle();\r\n }, 2000);\r\n\r\n });\r\n }\r\n\r\n if (el.href.includes('Produto/Add')) {\r\n el.addEventListener('click', async () => {\r\n console.log('[CRMBONUS] - Produto adicionado ao carrinho');\r\n setTimeout(async () => {\r\n await this.reprocess();\r\n this.observerHandle();\r\n }, 2000);\r\n });\r\n }\r\n }\r\n }\r\n\r\n async loadConfigStore() {\r\n const [customization, infoBonus] = await Promise.all([\r\n this.crmBonusService.getCustomization(this.cartWake.store.name),\r\n getInfoBonusByCartIdAndStoreName(this.cartWake.id, this.cartWake.store.name)\r\n ]);\r\n\r\n this.reservedInfo = infoBonus;\r\n\r\n if (customization.keepStoreFrontStyle) {\r\n this.styles = null;\r\n }\r\n }\r\n\r\n async fetchCustomer(userId: number, storeName: string) {\r\n try {\r\n return await this.crmBonusService.getCustomer(userId, storeName);\r\n } catch (error) {\r\n console.error('[fetchCustomer] Error fetching customer:', error);\r\n return null;\r\n }\r\n }\r\n\r\n async handleLoad() {\r\n try {\r\n if (this.cartWake.user.id) {\r\n this.fetchCustomer(this.cartWake.user.id, this.cartWake.store.name).then((customer) => {\r\n if (customer) {\r\n this.customer = customer;\r\n }\r\n });\r\n }\r\n\r\n const amount = localStorage.getItem(this.cartWake.id);\r\n\r\n if (amount) {\r\n this.canCancel = true;\r\n this.amountCancel = amount;\r\n }\r\n\r\n await this.buildAndGetProducts(this.cartWake.products);\r\n } catch (error) {\r\n console.log('info customer')\r\n }\r\n }\r\n\r\n async loadSession() {\r\n this.cartWake = this.cart ? new CartWake(JSON.parse(this.cart)) : await getCart();\r\n console.log('[bc:carregou carrinho]');\r\n\r\n this.session = await this.crmBonusService.getToken(this.cartWake.store.name);\r\n console.log('[bc:carregou session]');\r\n setTimeout(() => {\r\n this.loadSession()\r\n }, 1500000)\r\n }\r\n\r\n async buildAndGetProducts(productsWake: IProductWake[]) {\r\n console.log()\r\n\r\n const key = `bc-products:${this.cartWake.id}`;\r\n\r\n const productsString = JSON.stringify(productsWake)\r\n\r\n localStorage.setItem(key, productsString);\r\n\r\n const products_in_cache = JSON.parse(localStorage.getItem(key));\r\n\r\n const products: Array<IProductWake> = []\r\n\r\n for (const product_cart of productsWake) {\r\n\r\n const [pro] = products_in_cache.filter(p => p.ProdutoVarianteId == product_cart.ProdutoVarianteId)\r\n\r\n //const [ajuste = { Valor: 0 }] = pro.Ajustes.filter(aj => aj.Tipo === \"Formula\")\r\n\r\n if (pro) {\r\n products.push({\r\n ...product_cart,\r\n PrecoPor: pro.PrecoPor,\r\n PrecoDe: pro.PrecoDe,\r\n Quantidade: pro.Quantidade,\r\n Ajustes: pro.Ajustes\r\n })\r\n } else {\r\n products.push(product_cart)\r\n }\r\n\r\n }\r\n\r\n this.cartWake.products = products; //cache_products ? JSON.parse(cache_products) : JSON.parse(this.productsInString);\r\n\r\n }\r\n\r\n public async sendPin(phone: string) {\r\n this.loading = true;\r\n this.message = \"\";\r\n\r\n try {\r\n\r\n const _phone = phone.replace(/\\D/g, '');\r\n this.phone = Number(_phone);\r\n\r\n this.sent = await this.crmBonusService.sendPin(this.phone, this.customer.name, this.cartWake.store.name);;\r\n\r\n await this.crmBonusRef.setStep(StepFormEnum.STEP_PIN);\r\n\r\n this.showModal = true;\r\n } catch (error) {\r\n this.message = error?.response?.data?.message\r\n } finally {\r\n this.loading = false\r\n }\r\n }\r\n\r\n public async sendPinName(customerName: string) {\r\n this.loading = true;\r\n this.message = \"\";\r\n\r\n try {\r\n this.customer.name = customerName;\r\n\r\n this.sent = await this.crmBonusService.sendPin(this.phone, this.customer.name, this.cartWake.store.name);\r\n\r\n await this.crmBonusRef.setStep(StepFormEnum.STEP_PIN);\r\n\r\n this.showModal = true;\r\n } catch (error) {\r\n this.message = error?.response?.data?.message\r\n } finally {\r\n this.loading = false\r\n }\r\n }\r\n\r\n buildProducts(): IProduct[] {\r\n return buildProductsByWake(this.cartWake.products);\r\n }\r\n\r\n handleCloseModal() {\r\n this.showModal = false;\r\n }\r\n\r\n save(amount: number) {\r\n localStorage.setItem(this.cartWake.id, amount.toString());\r\n this.canCancel = true;\r\n this.amountCancel = amount.toString()\r\n }\r\n\r\n async cancel() {\r\n this.message = \"\";\r\n this.loading = true;\r\n try {\r\n await this.crmBonusService.cancel(this.cartWake.id);\r\n this.canCancel = false;\r\n\r\n localStorage.removeItem(this.cartWake.id);\r\n } catch (error) {\r\n this.message = \"Não consegui cancelar o bônus, tente novamente!\"\r\n } finally {\r\n this.loading = false;\r\n }\r\n }\r\n\r\n async handleSendPin(phone: string) {\r\n this.message = \"\"\r\n if (!phone) {\r\n this.message = \"Informe seu telefone\";\r\n return;\r\n }\r\n\r\n this.customer.phone = phone;\r\n const _phone = phone.replace(/\\D/g, '');\r\n this.phone = Number(_phone);\r\n\r\n if (this.customer.name) {\r\n return this.sendPin(phone)\r\n }\r\n\r\n await this.crmBonusRef.setStep(StepFormEnum.STEP_NAME);\r\n this.showModal = true;\r\n }\r\n\r\n render() {\r\n\r\n if (this.canhidden) {\r\n return null;\r\n }\r\n\r\n return (\r\n <loading-container loading={this.loading_reprocess} text='carregando...' >\r\n \r\n {\r\n !this.loading_reprocess && (\r\n <crm-giftback-form\r\n customStyles={this.styles}\r\n style={{ position: \"relative\" }}\r\n ref={ref => this.crmBonusRef = ref}\r\n storeName={this.cartWake.store.name}\r\n products={this.buildProducts()}\r\n cartId={this.cartWake.id}\r\n customer={this.customer}\r\n loadProducts={() => this.buildProducts()}\r\n loadAll={() => this.handleLoad()}\r\n reservedInfo={this.reservedInfo}\r\n />\r\n )\r\n }\r\n </loading-container>\r\n )\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"crm-bonus.js","sourceRoot":"","sources":["../../../../src/components/crm-bonus/crm-bon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CAAC,IAAI,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC5B,CAAC;QAED,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QACvD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;IAED,MAAM;QAEJ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,CACL,yBAAmB,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE,IAAI,EAAC,eAAe,IAGpE,CAAC,IAAI,CAAC,iBAAiB,IAAI,CACzB,yBACE,YAAY,EAAE,IAAI,CAAC,MAAM,EACzB,KAAK,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,EAC/B,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,GAAG,GAAG,EAClC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EACnC,QAAQ,EAAE,IAAI,CAAC,aAAa,EAAE,EAC9B,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,EACxB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,YAAY,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa,EAAE,EACxC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,EAChC,YAAY,EAAE,IAAI,CAAC,YAAY,GAC/B,CACH,CAEe,CACrB,CAAA;IACH,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Method, Prop, State, h } from '@stencil/core';\r\nimport { IProduct, IProductWake, ICustomer } from '../../dto/validate.pin.bonus';\r\nimport { CrmBonusService } from '../../services/crmbonus.service';\r\nimport { IPinSent } from '../../components';\r\nimport { defaultStyles, StepFormEnum } from '../../contants';\r\n\r\nimport i18next from '../../i18n/i18n'\r\nimport { buildProductsByWake } from '../../helpers/build.payload.helper';\r\nimport { getCart, getInfoBonusByCartIdAndStoreName } from '../../helpers/cart.helper';\r\nimport { CartWake } from '../../objectvalues/cart.wake';\r\nimport { USED_KEY } from '../../utils/keys.storage';\r\nimport { ReservedInfoDTO } from '../../dto/reserved-info.dto';\r\n\r\n@Component({\r\n tag: 'crm-bonus',\r\n styleUrl: 'crm-bonus.css',\r\n assetsDirs: ['assets'],\r\n // scoped: true\r\n shadow: true\r\n})\r\nexport class CrmBonus {\r\n\r\n private crmBonusService: CrmBonusService = CrmBonusService.getInstance();\r\n\r\n private crmBonusRef: HTMLCrmGiftbackFormElement;\r\n\r\n @Prop() cart;\r\n @Prop() canhidden: boolean = false;\r\n\r\n @State() showModal: boolean = false;\r\n\r\n @State() cartWake: CartWake;\r\n\r\n @State() customer: ICustomer = {\r\n birthDate: \"\",\r\n document: \"\",\r\n name: \"\",\r\n phone: \"\"\r\n };\r\n\r\n @State() loading: boolean = false;\r\n @State() message: string;\r\n @State() phone: number;\r\n @State() canCancel: boolean = false;\r\n @State() amountCancel: string;\r\n @State() sent: IPinSent;\r\n\r\n @State() session: string;\r\n @State() loading_reprocess = false;\r\n @State() styles = defaultStyles;\r\n @State() reservedInfo: ReservedInfoDTO;\r\n\r\n @Method()\r\n async resetBonus() {\r\n console.log('[CRMBONUS] - reset bonus');\r\n\r\n try {\r\n await this.crmBonusRef.processBonus(this.buildProducts(), true);\r\n console.log('[BONUS RESETADO]!!!!!');\r\n } catch (err) {\r\n\r\n this.loading = false;\r\n console.log('[error ao reprocessar bonous]');\r\n await this.crmBonusRef.setStep(StepFormEnum.STEP_PHONE);\r\n } finally {\r\n this.loading = false;\r\n }\r\n }\r\n\r\n @Method()\r\n async setloading() {\r\n this.loading_reprocess = !this.loading_reprocess;\r\n }\r\n\r\n @Method()\r\n async reprocess() {\r\n console.log(\"[CRMBONUS] - reprocess\")\r\n this.loading_reprocess = true\r\n\r\n try {\r\n\r\n const isUse = localStorage.getItem(USED_KEY);\r\n\r\n if (!isUse) return;\r\n\r\n this.cartWake = await getCart();\r\n await this.resetBonus();\r\n } catch (err) {\r\n console.debug('[watchProducts]', err.message);\r\n } finally {\r\n this.loading_reprocess = false\r\n }\r\n }\r\n\r\n async componentWillLoad() {\r\n this.loading_reprocess = true;\r\n window.addEventListener('productRemovedFromCart', async () => {\r\n console.log('[CRMBONUS] - productRemovedFromCart');\r\n await this.reprocess()\r\n });\r\n\r\n window.addEventListener('productAddedToCart', async () => {\r\n console.log('[CRMBONUS] - productAddedToCart');\r\n await this.reprocess();\r\n });\r\n\r\n document.querySelectorAll('form').forEach((el) => {\r\n el.addEventListener(\"submit\", async () => {\r\n console.log(\"[CRMBONUS] - Formulário está sendo submetido!\");\r\n await this.reprocess();\r\n });\r\n });\r\n\r\n document.getElementById('validarCupom')?.addEventListener('click', async () => {\r\n console.log(\"[CRMBONUS] - cupom sendo submetido!\");\r\n setTimeout(async () => {\r\n await this.reprocess();\r\n }, 2000);\r\n });\r\n\r\n await this.observerHandle();\r\n\r\n i18next.changeLanguage(i18next.language);\r\n }\r\n\r\n async componentDidLoad() {\r\n try {\r\n await this.loadSession();\r\n this.handleLoad();\r\n await this.loadConfigStore();\r\n } catch (error) {\r\n console.log('bc:err....')\r\n } finally {\r\n this.loading_reprocess = false;\r\n }\r\n }\r\n\r\n private async observerHandle() {\r\n const elements = document.getElementsByTagName('a');\r\n\r\n document.addEventListener('click', (event) => {\r\n //@ts-ignore\r\n console.log('Clique detectado em:', event.target.href);\r\n console.log('Clique detectado em:', event.target);\r\n \r\n //@ts-ignore\r\n if (['validarCupom'].includes(event.target.id)) {\r\n setTimeout(async () => {\r\n await this.reprocess();\r\n this.observerHandle();\r\n }, 2000);\r\n }\r\n });\r\n\r\n //@ts-ignore\r\n for (let el of elements) {\r\n console.log('[el.href]', el.href);\r\n if (el.href.includes('Produto/Delete')) {\r\n el.addEventListener('click', async () => {\r\n console.log('[CRMBONUS] - Produto removido do carrinho');\r\n\r\n setTimeout(async () => {\r\n await this.reprocess();\r\n this.observerHandle();\r\n }, 2000);\r\n\r\n });\r\n }\r\n\r\n if (el.href.includes('Produto/Add')) {\r\n el.addEventListener('click', async () => {\r\n console.log('[CRMBONUS] - Produto adicionado ao carrinho');\r\n setTimeout(async () => {\r\n await this.reprocess();\r\n this.observerHandle();\r\n }, 2000);\r\n });\r\n }\r\n }\r\n }\r\n\r\n async loadConfigStore() {\r\n const [customization, infoBonus] = await Promise.all([\r\n this.crmBonusService.getCustomization(this.cartWake.store.name),\r\n getInfoBonusByCartIdAndStoreName(this.cartWake.id, this.cartWake.store.name)\r\n ]);\r\n\r\n this.reservedInfo = infoBonus;\r\n\r\n if (customization.keepStoreFrontStyle) {\r\n this.styles = null;\r\n }\r\n }\r\n\r\n async fetchCustomer(userId: number, storeName: string) {\r\n try {\r\n return await this.crmBonusService.getCustomer(userId, storeName);\r\n } catch (error) {\r\n console.error('[fetchCustomer] Error fetching customer:', error);\r\n return null;\r\n }\r\n }\r\n\r\n async handleLoad() {\r\n try {\r\n if (this.cartWake.user.id) {\r\n this.fetchCustomer(this.cartWake.user.id, this.cartWake.store.name).then((customer) => {\r\n if (customer) {\r\n this.customer = customer;\r\n }\r\n });\r\n }\r\n\r\n const amount = localStorage.getItem(this.cartWake.id);\r\n\r\n if (amount) {\r\n this.canCancel = true;\r\n this.amountCancel = amount;\r\n }\r\n\r\n await this.buildAndGetProducts(this.cartWake.products);\r\n } catch (error) {\r\n console.log('info customer')\r\n }\r\n }\r\n\r\n async loadSession() {\r\n this.cartWake = this.cart ? new CartWake(JSON.parse(this.cart)) : await getCart();\r\n console.log('[bc:carregou carrinho]');\r\n\r\n this.session = await this.crmBonusService.getToken(this.cartWake.store.name);\r\n console.log('[bc:carregou session]');\r\n setTimeout(() => {\r\n this.loadSession()\r\n }, 1500000)\r\n }\r\n\r\n async buildAndGetProducts(productsWake: IProductWake[]) {\r\n\r\n const key = `bc-products:${this.cartWake.id}`;\r\n\r\n const productsString = JSON.stringify(productsWake)\r\n\r\n localStorage.setItem(key, productsString);\r\n\r\n const products_in_cache = JSON.parse(localStorage.getItem(key));\r\n\r\n const products: Array<IProductWake> = []\r\n\r\n for (const product_cart of productsWake) {\r\n\r\n const [pro] = products_in_cache.filter(p => p.ProdutoVarianteId == product_cart.ProdutoVarianteId)\r\n\r\n //const [ajuste = { Valor: 0 }] = pro.Ajustes.filter(aj => aj.Tipo === \"Formula\")\r\n\r\n if (pro) {\r\n products.push({\r\n ...product_cart,\r\n PrecoPor: pro.PrecoPor,\r\n PrecoDe: pro.PrecoDe,\r\n Quantidade: pro.Quantidade,\r\n Ajustes: pro.Ajustes\r\n })\r\n } else {\r\n products.push(product_cart)\r\n }\r\n\r\n }\r\n\r\n this.cartWake.products = products; //cache_products ? JSON.parse(cache_products) : JSON.parse(this.productsInString);\r\n\r\n }\r\n\r\n public async sendPin(phone: string) {\r\n this.loading = true;\r\n this.message = \"\";\r\n\r\n try {\r\n\r\n const _phone = phone.replace(/\\D/g, '');\r\n this.phone = Number(_phone);\r\n\r\n this.sent = await this.crmBonusService.sendPin(this.phone, this.customer.name, this.cartWake.store.name);;\r\n\r\n await this.crmBonusRef.setStep(StepFormEnum.STEP_PIN);\r\n\r\n this.showModal = true;\r\n } catch (error) {\r\n this.message = error?.response?.data?.message\r\n } finally {\r\n this.loading = false\r\n }\r\n }\r\n\r\n public async sendPinName(customerName: string) {\r\n this.loading = true;\r\n this.message = \"\";\r\n\r\n try {\r\n this.customer.name = customerName;\r\n\r\n this.sent = await this.crmBonusService.sendPin(this.phone, this.customer.name, this.cartWake.store.name);\r\n\r\n await this.crmBonusRef.setStep(StepFormEnum.STEP_PIN);\r\n\r\n this.showModal = true;\r\n } catch (error) {\r\n this.message = error?.response?.data?.message\r\n } finally {\r\n this.loading = false\r\n }\r\n }\r\n\r\n buildProducts(): IProduct[] {\r\n return buildProductsByWake(this.cartWake.products);\r\n }\r\n\r\n handleCloseModal() {\r\n this.showModal = false;\r\n }\r\n\r\n save(amount: number) {\r\n localStorage.setItem(this.cartWake.id, amount.toString());\r\n this.canCancel = true;\r\n this.amountCancel = amount.toString()\r\n }\r\n\r\n async cancel() {\r\n this.message = \"\";\r\n this.loading = true;\r\n try {\r\n await this.crmBonusService.cancel(this.cartWake.id);\r\n this.canCancel = false;\r\n\r\n localStorage.removeItem(this.cartWake.id);\r\n } catch (error) {\r\n this.message = \"Não consegui cancelar o bônus, tente novamente!\"\r\n } finally {\r\n this.loading = false;\r\n }\r\n }\r\n\r\n async handleSendPin(phone: string) {\r\n this.message = \"\"\r\n if (!phone) {\r\n this.message = \"Informe seu telefone\";\r\n return;\r\n }\r\n\r\n this.customer.phone = phone;\r\n const _phone = phone.replace(/\\D/g, '');\r\n this.phone = Number(_phone);\r\n\r\n if (this.customer.name) {\r\n return this.sendPin(phone)\r\n }\r\n\r\n await this.crmBonusRef.setStep(StepFormEnum.STEP_NAME);\r\n this.showModal = true;\r\n }\r\n\r\n render() {\r\n\r\n if (this.canhidden) {\r\n return null;\r\n }\r\n\r\n return (\r\n <loading-container loading={this.loading_reprocess} text='carregando...' >\r\n\r\n {\r\n !this.loading_reprocess && (\r\n <crm-giftback-form\r\n customStyles={this.styles}\r\n style={{ position: \"relative\" }}\r\n ref={ref => this.crmBonusRef = ref}\r\n storeName={this.cartWake.store.name}\r\n products={this.buildProducts()}\r\n cartId={this.cartWake.id}\r\n customer={this.customer}\r\n loadProducts={() => this.buildProducts()}\r\n loadAll={() => this.handleLoad()}\r\n reservedInfo={this.reservedInfo}\r\n />\r\n )\r\n }\r\n </loading-container>\r\n )\r\n }\r\n}\r\n"]}
@@ -4,14 +4,18 @@ export function buildProductsByWake(productsWake = []) {
4
4
  for (const pw of productsWake) {
5
5
  // let discounts_formula = getDiscountFormula(pw.Ajustes);
6
6
  const hasOriginalPrice = (pw.PrecoDe < pw.PrecoPor);
7
+ const hasDiscountInProduct = (pw.PrecoPor < pw.PrecoDe);
8
+ const existsPromotionProduct = pw.Ajustes.filter(adj => [AjustesTipoEnum.PP].includes(adj.Tipo));
9
+ const promotion_product = (existsPromotionProduct.length > 0);
7
10
  let discounts = getDiscount(pw.Ajustes, hasOriginalPrice);
8
- const price = hasOriginalPrice ? pw.PrecoPor : pw.PrecoDe;
11
+ let price = hasOriginalPrice ? pw.PrecoPor : pw.PrecoDe;
9
12
  const priceOrignal = hasOriginalPrice ? pw.PrecoPor : pw.PrecoDe;
13
+ if (!promotion_product && hasDiscountInProduct) {
14
+ price = pw.PrecoPor;
15
+ }
10
16
  var value = (price * pw.Quantidade);
11
17
  var originalValue = (priceOrignal * pw.Quantidade);
12
18
  var discounts_value = (discounts * -1);
13
- const existsPromotionProduct = pw.Ajustes.filter(adj => [AjustesTipoEnum.PP].includes(adj.Tipo));
14
- const promotion_product = (existsPromotionProduct.length > 0);
15
19
  products.push({
16
20
  sku: pw.SKU,
17
21
  value: value,
@@ -37,13 +41,4 @@ function getDiscount(ajustes = [], hasOriginalPrice) {
37
41
  }
38
42
  return discounts;
39
43
  }
40
- // function getDiscountFormula(ajustes: IAjustes[] = []) {
41
- // let discounts = 0;
42
- // for(const discount of ajustes) {
43
- // if([AjustesTipoEnum.F].includes(discount.Tipo)) {
44
- // discounts += (discount.Valor * -1);
45
- // }
46
- // }
47
- // return discounts;
48
- // }
49
44
  //# sourceMappingURL=build.payload.helper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.payload.helper.js","sourceRoot":"","sources":["../../../src/helpers/build.payload.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAoC,MAAM,2BAA2B,CAAC;AAE9F,MAAM,UAAU,mBAAmB,CAAC,eAAoC,EAAE;IAEtE,MAAM,QAAQ,GAAoB,EAAE,CAAC;IAErC,KAAM,MAAM,EAAE,IAAI,YAAY,EAAG,CAAC;QAE9B,0DA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AACpB,CAAC;AAED,SAAS,WAAW,CAAC,UAAsB,EAAE,EAAE,gBAAyB;IAEpE,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,MAAM,cAAc,GAAG,CAAC,eAAe,CAAC,CAAC,EAAE,eAAe,CAAC,EAAE,CAAC,CAAC;IAE/D,IAAG,CAAC,gBAAgB,EAAE,CAAC;QACnB,cAAc,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,KAAI,MAAM,QAAQ,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAG,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACxC,SAAS,IAAI,QAAQ,CAAC,KAAK,CAAC;QAChC,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC;AAED,0DAA0D;AAE1D,yBAAyB;AAEzB,uCAAuC;AACvC,4DAA4D;AAC5D,kDAAkD;AAClD,YAAY;AACZ,QAAQ;AAER,wBAAwB;AACxB,IAAI","sourcesContent":["import { AjustesTipoEnum, IAjustes, IProduct, IProductWake } from \"../dto/validate.pin.bonus\";\r\n\r\nexport function buildProductsByWake(productsWake: Array<IProductWake> = []): Array<IProduct> {\r\n\r\n const products: Array<IProduct> = [];\r\n\r\n for ( const pw of productsWake ) {\r\n \r\n // let discounts_formula = getDiscountFormula(pw.Ajustes);\r\n\r\n const hasOriginalPrice = (pw.PrecoDe < pw.PrecoPor);\r\n \r\n let discounts = getDiscount(pw.Ajustes, hasOriginalPrice);\r\n\r\n const price = hasOriginalPrice ? pw.PrecoPor : pw.PrecoDe;\r\n const priceOrignal = hasOriginalPrice ? pw.PrecoPor : pw.PrecoDe;\r\n\r\n var value = (price * pw.Quantidade);\r\n var originalValue = (priceOrignal * pw.Quantidade);\r\n\r\n var discounts_value = (discounts * -1)\r\n\r\n const existsPromotionProduct = pw.Ajustes.filter(adj => [AjustesTipoEnum.PP].includes(adj.Tipo))\r\n\r\n const promotion_product = (existsPromotionProduct.length > 0)\r\n\r\n products.push(\r\n {\r\n sku: pw.SKU,\r\n value: value,\r\n originalValue: originalValue,\r\n productVariantId: pw.ProdutoVarianteId.toString(),\r\n quantity: pw.Quantidade,\r\n discount: value < discounts_value ? value : discounts_value,\r\n promotion_product,\r\n }\r\n )\r\n }\r\n\r\n return products;\r\n}\r\n\r\nfunction getDiscount(ajustes: IAjustes[] = [], hasOriginalPrice: boolean) {\r\n \r\n let discounts = 0;\r\n const config_ajustes = [AjustesTipoEnum.P, AjustesTipoEnum.CC];\r\n\r\n if(!hasOriginalPrice) {\r\n config_ajustes.push(AjustesTipoEnum.PP);\r\n }\r\n\r\n for(const discount of ajustes) {\r\n if(config_ajustes.includes(discount.Tipo)) {\r\n discounts += discount.Valor;\r\n }\r\n }\r\n\r\n return discounts;\r\n}\r\n\r\n// function getDiscountFormula(ajustes: IAjustes[] = []) {\r\n \r\n// let discounts = 0;\r\n \r\n// for(const discount of ajustes) {\r\n// if([AjustesTipoEnum.F].includes(discount.Tipo)) {\r\n// discounts += (discount.Valor * -1);\r\n// }\r\n// }\r\n\r\n// return discounts;\r\n// }"]}
1
+ {"version":3,"file":"build.payload.helper.js","sourceRoot":"","sources":["../../../src/helpers/build.payload.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAoC,MAAM,2BAA2B,CAAC;AAE9F,MAAM,UAAU,mBAAmB,CAAC,eAAoC,EAAE;IAEtE,MAAM,QAAQ,GAAoB,EAAE,CAAC;IAErC,KAAM,MAAM,EAAE,IAAI,YAAY,EAAG,CAAC;QAE9B,0DAA0D;QAE1D,MAAM,gBAAgB,GAAG,CAAC,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC;QACpD,MAAM,oBAAoB,GAAG,CAAC,EAAE,CAAC,QAAQ,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC;QACxD,MAAM,sBAAsB,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,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E,EAAE,gBAAyB;IAEpE,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,MAAM,cAAc,GAAG,CAAC,eAAe,CAAC,CAAC,EAAE,eAAe,CAAC,EAAE,CAAC,CAAC;IAE/D,IAAG,CAAC,gBAAgB,EAAE,CAAC;QACnB,cAAc,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,KAAI,MAAM,QAAQ,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAG,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACxC,SAAS,IAAI,QAAQ,CAAC,KAAK,CAAC;QAChC,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC","sourcesContent":["import { AjustesTipoEnum, IAjustes, IProduct, IProductWake } from \"../dto/validate.pin.bonus\";\r\n\r\nexport function buildProductsByWake(productsWake: Array<IProductWake> = []): Array<IProduct> {\r\n\r\n const products: Array<IProduct> = [];\r\n\r\n for ( const pw of productsWake ) {\r\n \r\n // let discounts_formula = getDiscountFormula(pw.Ajustes);\r\n\r\n const hasOriginalPrice = (pw.PrecoDe < pw.PrecoPor);\r\n const hasDiscountInProduct = (pw.PrecoPor < pw.PrecoDe);\r\n const existsPromotionProduct = pw.Ajustes.filter(adj => [AjustesTipoEnum.PP].includes(adj.Tipo))\r\n const promotion_product = (existsPromotionProduct.length > 0)\r\n\r\n let discounts = getDiscount(pw.Ajustes, hasOriginalPrice);\r\n\r\n let price = hasOriginalPrice ? pw.PrecoPor : pw.PrecoDe;\r\n const priceOrignal = hasOriginalPrice ? pw.PrecoPor : pw.PrecoDe;\r\n\r\n if(!promotion_product && hasDiscountInProduct) {\r\n price = pw.PrecoPor;\r\n }\r\n\r\n var value = (price * pw.Quantidade);\r\n var originalValue = (priceOrignal * pw.Quantidade);\r\n\r\n var discounts_value = (discounts * -1); \r\n\r\n products.push(\r\n {\r\n sku: pw.SKU,\r\n value: value,\r\n originalValue: originalValue,\r\n productVariantId: pw.ProdutoVarianteId.toString(),\r\n quantity: pw.Quantidade,\r\n discount: value < discounts_value ? value : discounts_value,\r\n promotion_product,\r\n }\r\n )\r\n }\r\n\r\n return products;\r\n}\r\n\r\nfunction getDiscount(ajustes: IAjustes[] = [], hasOriginalPrice: boolean) {\r\n \r\n let discounts = 0;\r\n const config_ajustes = [AjustesTipoEnum.P, AjustesTipoEnum.CC];\r\n\r\n if(!hasOriginalPrice) {\r\n config_ajustes.push(AjustesTipoEnum.PP);\r\n }\r\n\r\n for(const discount of ajustes) {\r\n if(config_ajustes.includes(discount.Tipo)) {\r\n discounts += discount.Valor;\r\n }\r\n }\r\n\r\n return discounts;\r\n}\r\n"]}
@@ -26,14 +26,18 @@ function buildProductsByWake(productsWake = []) {
26
26
  for (const pw of productsWake) {
27
27
  // let discounts_formula = getDiscountFormula(pw.Ajustes);
28
28
  const hasOriginalPrice = (pw.PrecoDe < pw.PrecoPor);
29
+ const hasDiscountInProduct = (pw.PrecoPor < pw.PrecoDe);
30
+ const existsPromotionProduct = pw.Ajustes.filter(adj => [AjustesTipoEnum.PP].includes(adj.Tipo));
31
+ const promotion_product = (existsPromotionProduct.length > 0);
29
32
  let discounts = getDiscount(pw.Ajustes, hasOriginalPrice);
30
- const price = hasOriginalPrice ? pw.PrecoPor : pw.PrecoDe;
33
+ let price = hasOriginalPrice ? pw.PrecoPor : pw.PrecoDe;
31
34
  const priceOrignal = hasOriginalPrice ? pw.PrecoPor : pw.PrecoDe;
35
+ if (!promotion_product && hasDiscountInProduct) {
36
+ price = pw.PrecoPor;
37
+ }
32
38
  var value = (price * pw.Quantidade);
33
39
  var originalValue = (priceOrignal * pw.Quantidade);
34
40
  var discounts_value = (discounts * -1);
35
- const existsPromotionProduct = pw.Ajustes.filter(adj => [AjustesTipoEnum.PP].includes(adj.Tipo));
36
- const promotion_product = (existsPromotionProduct.length > 0);
37
41
  products.push({
38
42
  sku: pw.SKU,
39
43
  value: value,
@@ -59,15 +63,6 @@ function getDiscount(ajustes = [], hasOriginalPrice) {
59
63
  }
60
64
  return discounts;
61
65
  }
62
- // function getDiscountFormula(ajustes: IAjustes[] = []) {
63
- // let discounts = 0;
64
- // for(const discount of ajustes) {
65
- // if([AjustesTipoEnum.F].includes(discount.Tipo)) {
66
- // discounts += (discount.Valor * -1);
67
- // }
68
- // }
69
- // return discounts;
70
- // }
71
66
 
72
67
  const crmBonusCss = ".container-button{cursor:pointer;padding:5px 5px 5px 14px;}.section-crm{border:1px solid #dbd4d4;text-align:-webkit-center;margin-bottom:20px}.section-cart-crm{margin-top:10px}.section-cart-crm p{padding:0;margin:0px 0px 0px 15px}.button{top:50%;background-color:#6c6c7e;color:#fff;border:none;padding:15px;min-height:30px;min-width:120px;cursor:pointer;margin-left:10px;height:70px}.form-container{width:97%;display:flex;justify-content:space-around}.btn{display:inline-block;padding:6px 12px;margin-bottom:0;font-weight:400;line-height:1.42857143;text-align:center;white-space:nowrap;vertical-align:middle;-ms-touch-action:manipulation;touch-action:manipulation;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background-image:none;border:1px solid transparent;border-radius:0px}.form-container .btnCrm{background:#00162e;border-color:#00162e;width:30%;color:#fff}.message-alert{color:#df4d4d;margin-top:5px}";
73
68
  const CrmBonusStyle0 = crmBonusCss;
@@ -135,6 +130,7 @@ const CrmBonus$1 = /*@__PURE__*/ proxyCustomElement(class CrmBonus extends H {
135
130
  }
136
131
  }
137
132
  async componentWillLoad() {
133
+ var _a;
138
134
  this.loading_reprocess = true;
139
135
  window.addEventListener('productRemovedFromCart', async () => {
140
136
  console.log('[CRMBONUS] - productRemovedFromCart');
@@ -150,6 +146,12 @@ const CrmBonus$1 = /*@__PURE__*/ proxyCustomElement(class CrmBonus extends H {
150
146
  await this.reprocess();
151
147
  });
152
148
  });
149
+ (_a = document.getElementById('validarCupom')) === null || _a === void 0 ? void 0 : _a.addEventListener('click', async () => {
150
+ console.log("[CRMBONUS] - cupom sendo submetido!");
151
+ setTimeout(async () => {
152
+ await this.reprocess();
153
+ }, 2000);
154
+ });
153
155
  await this.observerHandle();
154
156
  instance.changeLanguage(instance.language);
155
157
  }
@@ -168,6 +170,18 @@ const CrmBonus$1 = /*@__PURE__*/ proxyCustomElement(class CrmBonus extends H {
168
170
  }
169
171
  async observerHandle() {
170
172
  const elements = document.getElementsByTagName('a');
173
+ document.addEventListener('click', (event) => {
174
+ //@ts-ignore
175
+ console.log('Clique detectado em:', event.target.href);
176
+ console.log('Clique detectado em:', event.target);
177
+ //@ts-ignore
178
+ if (['validarCupom'].includes(event.target.id)) {
179
+ setTimeout(async () => {
180
+ await this.reprocess();
181
+ this.observerHandle();
182
+ }, 2000);
183
+ }
184
+ });
171
185
  //@ts-ignore
172
186
  for (let el of elements) {
173
187
  console.log('[el.href]', el.href);
@@ -240,7 +254,6 @@ const CrmBonus$1 = /*@__PURE__*/ proxyCustomElement(class CrmBonus extends H {
240
254
  }, 1500000);
241
255
  }
242
256
  async buildAndGetProducts(productsWake) {
243
- console.log();
244
257
  const key = `bc-products:${this.cartWake.id}`;
245
258
  const productsString = JSON.stringify(productsWake);
246
259
  localStorage.setItem(key, productsString);
@@ -1 +1 @@
1
- {"file":"crm-bonus.js","mappings":";;;;;;;;;;;;;;;AAUA,IAAY,eAKX;AALD,WAAY,eAAe;IACvB,iCAAc,CAAA;IACd,uCAAoB,CAAA;IACpB,yCAAsB,CAAA;IACtB,gCAAa,CAAA;AACjB,CAAC,EALW,eAAe,KAAf,eAAe;;SCRX,mBAAmB,CAAC,eAAoC,EAAE;IAEtE,MAAM,QAAQ,GAAoB,EAAE,CAAC;IAErC,KAAM,MAAM,EAAE,IAAI,YAAY,EAAG;;QAI7B,MAAM,gBAAgB,IAAI,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC;QAEpD,IAAI,SAAS,GAAG,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;Q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,EAC9B,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,EACxB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,YAAY,EAAE,MAAM,IAAI,CAAC,aAAa,EAAE,EACxC,OAAO,EAAE,MAAM,IAAI,CAAC,UAAU,EAAE,EAChC,YAAY,EAAE,IAAI,CAAC,YAAY,GAC/B,CACH,CAEe,EACrB;KACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["CrmBonus","i18next"],"sources":["src/dto/validate.pin.bonus.ts","src/helpers/build.payload.helper.ts","src/components/crm-bonus/crm-bonus.css?tag=crm-bonus&encapsulation=shadow","src/components/crm-bonus/crm-bonus.tsx"],"sourcesContent":["export interface IProduct {\r\n productVariantId: string;\r\n sku: string;\r\n value: number;\r\n originalValue: number;\r\n quantity: number;\r\n discount: number;\r\n promotion_product: boolean;\r\n}\r\n\r\nexport enum AjustesTipoEnum {\r\n P = \"Promocao\",\r\n CC = \"ContaCorrente\",\r\n PP = \"PromocaoProduto\",\r\n F = \"Formula\"\r\n}\r\n\r\nexport interface IAjustes {\r\n Tipo: AjustesTipoEnum;\r\n Valor: number;\r\n}\r\n\r\nexport interface IUser {\r\n id: number;\r\n}\r\n\r\nexport interface IStore {\r\n name: string;\r\n}\r\n\r\nexport interface IProductWake {\r\n ProdutoVarianteId: number;\r\n SKU: string;\r\n PrecoPor: number;\r\n PrecoDe: number;\r\n Quantidade: number;\r\n Ajustes: IAjustes[];\r\n}\r\n\r\nexport interface ICustomer {\r\n birthDate: string;\r\n document: string;\r\n name: string;\r\n phone: string;\r\n}\r\n\r\nexport interface IProccesPinBonusDto {\r\n storeName: string;\r\n name: string;\r\n checkoutId: string;\r\n checkoutProducts: Array<IProduct>;\r\n storeId: string;\r\n userId: string;\r\n cellphone: number;\r\n pin: string;\r\n\r\n}\r\n\r\nexport interface IBonus {\r\n hasBonus: boolean;\r\n bonusBalance: number;\r\n totalBonus: number;\r\n minimumPurchase: number;\r\n bonusIds: string;\r\n firstValidityDate: string\r\n history: [\r\n {\r\n validityStart: string;\r\n validityEnd: string;\r\n value: number\r\n },\r\n {\r\n validityStart: string;\r\n validityEnd: string\r\n value: number\r\n }\r\n ]\r\n storeId: number;\r\n userId: number;\r\n cartId: string\r\n calculatedValue: number;\r\n totalValue: number\r\n}\r\n\r\n\r\nexport interface IReserveDTO {\r\n storeName: string;\r\n cartId: string;\r\n grossValue: number;\r\n redeemedBonus: number;\r\n ticket: string;\r\n storeId: string;\r\n userId: number;\r\n}","import { AjustesTipoEnum, IAjustes, IProduct, IProductWake } from \"../dto/validate.pin.bonus\";\r\n\r\nexport function buildProductsByWake(productsWake: Array<IProductWake> = []): Array<IProduct> {\r\n\r\n const products: Array<IProduct> = [];\r\n\r\n for ( const pw of productsWake ) {\r\n \r\n // let discounts_formula = getDiscountFormula(pw.Ajustes);\r\n\r\n const hasOriginalPrice = (pw.PrecoDe < pw.PrecoPor);\r\n \r\n let discounts = getDiscount(pw.Ajustes, hasOriginalPrice);\r\n\r\n const price = hasOriginalPrice ? pw.PrecoPor : pw.PrecoDe;\r\n const priceOrignal = hasOriginalPrice ? pw.PrecoPor : pw.PrecoDe;\r\n\r\n var value = (price * pw.Quantidade);\r\n var originalValue = (priceOrignal * pw.Quantidade);\r\n\r\n var discounts_value = (discounts * -1)\r\n\r\n const existsPromotionProduct = pw.Ajustes.filter(adj => [AjustesTipoEnum.PP].includes(adj.Tipo))\r\n\r\n const promotion_product = (existsPromotionProduct.length > 0)\r\n\r\n products.push(\r\n {\r\n sku: pw.SKU,\r\n value: value,\r\n originalValue: originalValue,\r\n productVariantId: pw.ProdutoVarianteId.toString(),\r\n quantity: pw.Quantidade,\r\n discount: value < discounts_value ? value : discounts_value,\r\n promotion_product,\r\n }\r\n )\r\n }\r\n\r\n return products;\r\n}\r\n\r\nfunction getDiscount(ajustes: IAjustes[] = [], hasOriginalPrice: boolean) {\r\n \r\n let discounts = 0;\r\n const config_ajustes = [AjustesTipoEnum.P, AjustesTipoEnum.CC];\r\n\r\n if(!hasOriginalPrice) {\r\n config_ajustes.push(AjustesTipoEnum.PP);\r\n }\r\n\r\n for(const discount of ajustes) {\r\n if(config_ajustes.includes(discount.Tipo)) {\r\n discounts += discount.Valor;\r\n }\r\n }\r\n\r\n return discounts;\r\n}\r\n\r\n// function getDiscountFormula(ajustes: IAjustes[] = []) {\r\n \r\n// let discounts = 0;\r\n \r\n// for(const discount of ajustes) {\r\n// if([AjustesTipoEnum.F].includes(discount.Tipo)) {\r\n// discounts += (discount.Valor * -1);\r\n// }\r\n// }\r\n\r\n// return discounts;\r\n// }","\r\n.container-button {\r\n /* max-width: 100%; */\r\n cursor: pointer;\r\n padding: 5px 5px 5px 14px;\r\n /* display: flex; */\r\n}\r\n\r\n/* padding: 0 15px 15px;\r\nborder: 1px solid #ddd;\r\nmargin-bottom: 20px; */\r\n\r\n.section-crm {\r\n border: 1px solid #dbd4d4;\r\n /* min-height: 50px; */\r\n text-align: -webkit-center;\r\n margin-bottom: 20px;\r\n}\r\n\r\n.section-cart-crm {\r\n margin-top: 10px;\r\n}\r\n\r\n.section-cart-crm p {\r\n padding: 0;\r\n margin: 0px 0px 0px 15px;\r\n}\r\n\r\n.button {\r\n top: 50%;\r\n background-color: #6c6c7e;\r\n color: #fff;\r\n border: none;\r\n /* border-radius: 10px; */\r\n padding: 15px;\r\n min-height: 30px;\r\n min-width: 120px;\r\n /* font-size: 20px; */\r\n cursor: pointer;\r\n margin-left: 10px;\r\n height: 70px;\r\n}\r\n\r\n.form-container {\r\n width: 97%;\r\n display: flex;\r\n justify-content: space-around;\r\n}\r\n\r\n\r\n.btn {\r\n display: inline-block;\r\n padding: 6px 12px;\r\n margin-bottom: 0;\r\n /* font-size: 14px; */\r\n font-weight: 400;\r\n line-height: 1.42857143;\r\n text-align: center;\r\n white-space: nowrap;\r\n vertical-align: middle;\r\n -ms-touch-action: manipulation;\r\n touch-action: manipulation;\r\n cursor: pointer;\r\n -webkit-user-select: none;\r\n -moz-user-select: none;\r\n -ms-user-select: none;\r\n user-select: none;\r\n background-image: none;\r\n border: 1px solid transparent;\r\n border-radius: 0px;\r\n}\r\n\r\n.form-container .btnCrm {\r\n background: #00162e;\r\n border-color: #00162e;\r\n width: 30%;\r\n color: #fff;\r\n}\r\n\r\n.message-alert {\r\n color: #df4d4d;\r\n margin-top: 5px;\r\n}","import { Component, Method, Prop, State, h } from '@stencil/core';\r\nimport { IProduct, IProductWake, ICustomer } from '../../dto/validate.pin.bonus';\r\nimport { CrmBonusService } from '../../services/crmbonus.service';\r\nimport { IPinSent } from '../../components';\r\nimport { defaultStyles, StepFormEnum } from '../../contants';\r\n\r\nimport i18next from '../../i18n/i18n'\r\nimport { buildProductsByWake } from '../../helpers/build.payload.helper';\r\nimport { getCart, getInfoBonusByCartIdAndStoreName } from '../../helpers/cart.helper';\r\nimport { CartWake } from '../../objectvalues/cart.wake';\r\nimport { USED_KEY } from '../../utils/keys.storage';\r\nimport { ReservedInfoDTO } from '../../dto/reserved-info.dto';\r\n\r\n@Component({\r\n tag: 'crm-bonus',\r\n styleUrl: 'crm-bonus.css',\r\n assetsDirs: ['assets'],\r\n // scoped: true\r\n shadow: true\r\n})\r\nexport class CrmBonus {\r\n\r\n private crmBonusService: CrmBonusService = CrmBonusService.getInstance();\r\n\r\n private crmBonusRef: HTMLCrmGiftbackFormElement;\r\n\r\n @Prop() cart;\r\n @Prop() canhidden: boolean = false;\r\n\r\n @State() showModal: boolean = false;\r\n\r\n @State() cartWake: CartWake;\r\n\r\n @State() customer: ICustomer = {\r\n birthDate: \"\",\r\n document: \"\",\r\n name: \"\",\r\n phone: \"\"\r\n };\r\n\r\n @State() loading: boolean = false;\r\n @State() message: string;\r\n @State() phone: number;\r\n @State() canCancel: boolean = false;\r\n @State() amountCancel: string;\r\n @State() sent: IPinSent;\r\n\r\n @State() session: string;\r\n @State() loading_reprocess = false;\r\n @State() styles = defaultStyles;\r\n @State() reservedInfo: ReservedInfoDTO;\r\n\r\n @Method()\r\n async resetBonus() {\r\n console.log('[CRMBONUS] - reset bonus');\r\n\r\n try {\r\n await this.crmBonusRef.processBonus(this.buildProducts(), true);\r\n console.log('[BONUS RESETADO]!!!!!');\r\n } catch (err) {\r\n\r\n this.loading = false;\r\n console.log('[error ao reprocessar bonous]');\r\n await this.crmBonusRef.setStep(StepFormEnum.STEP_PHONE);\r\n } finally {\r\n this.loading = false;\r\n }\r\n }\r\n\r\n @Method()\r\n async setloading() {\r\n this.loading_reprocess = !this.loading_reprocess;\r\n }\r\n\r\n @Method()\r\n async reprocess() {\r\n console.log(\"[CRMBONUS] - reprocess\")\r\n this.loading_reprocess = true\r\n\r\n try {\r\n\r\n const isUse = localStorage.getItem(USED_KEY);\r\n\r\n if (!isUse) return;\r\n\r\n this.cartWake = await getCart();\r\n await this.resetBonus();\r\n } catch (err) {\r\n console.debug('[watchProducts]', err.message);\r\n } finally {\r\n this.loading_reprocess = false\r\n }\r\n }\r\n\r\n async componentWillLoad() {\r\n this.loading_reprocess = true;\r\n window.addEventListener('productRemovedFromCart', async () => {\r\n console.log('[CRMBONUS] - productRemovedFromCart');\r\n await this.reprocess()\r\n });\r\n\r\n window.addEventListener('productAddedToCart', async () => {\r\n console.log('[CRMBONUS] - productAddedToCart');\r\n await this.reprocess();\r\n });\r\n\r\n document.querySelectorAll('form').forEach((el) => {\r\n el.addEventListener(\"submit\", async () => {\r\n console.log(\"[CRMBONUS] - Formulário está sendo submetido!\");\r\n await this.reprocess();\r\n });\r\n });\r\n\r\n await this.observerHandle();\r\n\r\n i18next.changeLanguage(i18next.language);\r\n }\r\n\r\n async componentDidLoad() {\r\n try {\r\n await this.loadSession();\r\n this.handleLoad();\r\n await this.loadConfigStore();\r\n } catch (error) {\r\n console.log('bc:err....')\r\n } finally {\r\n this.loading_reprocess = false;\r\n }\r\n }\r\n\r\n private async observerHandle() {\r\n const elements = document.getElementsByTagName('a');\r\n\r\n //@ts-ignore\r\n for (let el of elements) {\r\n console.log('[el.href]', el.href);\r\n if (el.href.includes('Produto/Delete')) {\r\n el.addEventListener('click', async () => {\r\n console.log('[CRMBONUS] - Produto removido do carrinho');\r\n\r\n setTimeout(async () => {\r\n await this.reprocess();\r\n this.observerHandle();\r\n }, 2000);\r\n\r\n });\r\n }\r\n\r\n if (el.href.includes('Produto/Add')) {\r\n el.addEventListener('click', async () => {\r\n console.log('[CRMBONUS] - Produto adicionado ao carrinho');\r\n setTimeout(async () => {\r\n await this.reprocess();\r\n this.observerHandle();\r\n }, 2000);\r\n });\r\n }\r\n }\r\n }\r\n\r\n async loadConfigStore() {\r\n const [customization, infoBonus] = await Promise.all([\r\n this.crmBonusService.getCustomization(this.cartWake.store.name),\r\n getInfoBonusByCartIdAndStoreName(this.cartWake.id, this.cartWake.store.name)\r\n ]);\r\n\r\n this.reservedInfo = infoBonus;\r\n\r\n if (customization.keepStoreFrontStyle) {\r\n this.styles = null;\r\n }\r\n }\r\n\r\n async fetchCustomer(userId: number, storeName: string) {\r\n try {\r\n return await this.crmBonusService.getCustomer(userId, storeName);\r\n } catch (error) {\r\n console.error('[fetchCustomer] Error fetching customer:', error);\r\n return null;\r\n }\r\n }\r\n\r\n async handleLoad() {\r\n try {\r\n if (this.cartWake.user.id) {\r\n this.fetchCustomer(this.cartWake.user.id, this.cartWake.store.name).then((customer) => {\r\n if (customer) {\r\n this.customer = customer;\r\n }\r\n });\r\n }\r\n\r\n const amount = localStorage.getItem(this.cartWake.id);\r\n\r\n if (amount) {\r\n this.canCancel = true;\r\n this.amountCancel = amount;\r\n }\r\n\r\n await this.buildAndGetProducts(this.cartWake.products);\r\n } catch (error) {\r\n console.log('info customer')\r\n }\r\n }\r\n\r\n async loadSession() {\r\n this.cartWake = this.cart ? new CartWake(JSON.parse(this.cart)) : await getCart();\r\n console.log('[bc:carregou carrinho]');\r\n\r\n this.session = await this.crmBonusService.getToken(this.cartWake.store.name);\r\n console.log('[bc:carregou session]');\r\n setTimeout(() => {\r\n this.loadSession()\r\n }, 1500000)\r\n }\r\n\r\n async buildAndGetProducts(productsWake: IProductWake[]) {\r\n console.log()\r\n\r\n const key = `bc-products:${this.cartWake.id}`;\r\n\r\n const productsString = JSON.stringify(productsWake)\r\n\r\n localStorage.setItem(key, productsString);\r\n\r\n const products_in_cache = JSON.parse(localStorage.getItem(key));\r\n\r\n const products: Array<IProductWake> = []\r\n\r\n for (const product_cart of productsWake) {\r\n\r\n const [pro] = products_in_cache.filter(p => p.ProdutoVarianteId == product_cart.ProdutoVarianteId)\r\n\r\n //const [ajuste = { Valor: 0 }] = pro.Ajustes.filter(aj => aj.Tipo === \"Formula\")\r\n\r\n if (pro) {\r\n products.push({\r\n ...product_cart,\r\n PrecoPor: pro.PrecoPor,\r\n PrecoDe: pro.PrecoDe,\r\n Quantidade: pro.Quantidade,\r\n Ajustes: pro.Ajustes\r\n })\r\n } else {\r\n products.push(product_cart)\r\n }\r\n\r\n }\r\n\r\n this.cartWake.products = products; //cache_products ? JSON.parse(cache_products) : JSON.parse(this.productsInString);\r\n\r\n }\r\n\r\n public async sendPin(phone: string) {\r\n this.loading = true;\r\n this.message = \"\";\r\n\r\n try {\r\n\r\n const _phone = phone.replace(/\\D/g, '');\r\n this.phone = Number(_phone);\r\n\r\n this.sent = await this.crmBonusService.sendPin(this.phone, this.customer.name, this.cartWake.store.name);;\r\n\r\n await this.crmBonusRef.setStep(StepFormEnum.STEP_PIN);\r\n\r\n this.showModal = true;\r\n } catch (error) {\r\n this.message = error?.response?.data?.message\r\n } finally {\r\n this.loading = false\r\n }\r\n }\r\n\r\n public async sendPinName(customerName: string) {\r\n this.loading = true;\r\n this.message = \"\";\r\n\r\n try {\r\n this.customer.name = customerName;\r\n\r\n this.sent = await this.crmBonusService.sendPin(this.phone, this.customer.name, this.cartWake.store.name);\r\n\r\n await this.crmBonusRef.setStep(StepFormEnum.STEP_PIN);\r\n\r\n this.showModal = true;\r\n } catch (error) {\r\n this.message = error?.response?.data?.message\r\n } finally {\r\n this.loading = false\r\n }\r\n }\r\n\r\n buildProducts(): IProduct[] {\r\n return buildProductsByWake(this.cartWake.products);\r\n }\r\n\r\n handleCloseModal() {\r\n this.showModal = false;\r\n }\r\n\r\n save(amount: number) {\r\n localStorage.setItem(this.cartWake.id, amount.toString());\r\n this.canCancel = true;\r\n this.amountCancel = amount.toString()\r\n }\r\n\r\n async cancel() {\r\n this.message = \"\";\r\n this.loading = true;\r\n try {\r\n await this.crmBonusService.cancel(this.cartWake.id);\r\n this.canCancel = false;\r\n\r\n localStorage.removeItem(this.cartWake.id);\r\n } catch (error) {\r\n this.message = \"Não consegui cancelar o bônus, tente novamente!\"\r\n } finally {\r\n this.loading = false;\r\n }\r\n }\r\n\r\n async handleSendPin(phone: string) {\r\n this.message = \"\"\r\n if (!phone) {\r\n this.message = \"Informe seu telefone\";\r\n return;\r\n }\r\n\r\n this.customer.phone = phone;\r\n const _phone = phone.replace(/\\D/g, '');\r\n this.phone = Number(_phone);\r\n\r\n if (this.customer.name) {\r\n return this.sendPin(phone)\r\n }\r\n\r\n await this.crmBonusRef.setStep(StepFormEnum.STEP_NAME);\r\n this.showModal = true;\r\n }\r\n\r\n render() {\r\n\r\n if (this.canhidden) {\r\n return null;\r\n }\r\n\r\n return (\r\n <loading-container loading={this.loading_reprocess} text='carregando...' >\r\n \r\n {\r\n !this.loading_reprocess && (\r\n <crm-giftback-form\r\n customStyles={this.styles}\r\n style={{ position: \"relative\" }}\r\n ref={ref => this.crmBonusRef = ref}\r\n storeName={this.cartWake.store.name}\r\n products={this.buildProducts()}\r\n cartId={this.cartWake.id}\r\n customer={this.customer}\r\n loadProducts={() => this.buildProducts()}\r\n loadAll={() => this.handleLoad()}\r\n reservedInfo={this.reservedInfo}\r\n />\r\n )\r\n }\r\n </loading-container>\r\n )\r\n }\r\n}\r\n"],"version":3}
1
+ {"file":"crm-bonus.js","mappings":";;;;;;;;;;;;;;;AAUA,IAAY,eAKX;A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AI,CAAC,QAAQ,CAAC,EAAE,EACxB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,YAAY,EAAE,MAAM,IAAI,CAAC,aAAa,EAAE,EACxC,OAAO,EAAE,MAAM,IAAI,CAAC,UAAU,EAAE,EAChC,YAAY,EAAE,IAAI,CAAC,YAAY,GAC/B,CACH,CAEe,EACrB;KACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["CrmBonus","i18next"],"sources":["src/dto/validate.pin.bonus.ts","src/helpers/build.payload.helper.ts","src/components/crm-bonus/crm-bonus.css?tag=crm-bonus&encapsulation=shadow","src/components/crm-bonus/crm-bonus.tsx"],"sourcesContent":["export interface IProduct {\r\n productVariantId: string;\r\n sku: string;\r\n value: number;\r\n originalValue: number;\r\n quantity: number;\r\n discount: number;\r\n promotion_product: boolean;\r\n}\r\n\r\nexport enum AjustesTipoEnum {\r\n P = \"Promocao\",\r\n CC = \"ContaCorrente\",\r\n PP = \"PromocaoProduto\",\r\n F = \"Formula\"\r\n}\r\n\r\nexport interface IAjustes {\r\n Tipo: AjustesTipoEnum;\r\n Valor: number;\r\n}\r\n\r\nexport interface IUser {\r\n id: number;\r\n}\r\n\r\nexport interface IStore {\r\n name: string;\r\n}\r\n\r\nexport interface IProductWake {\r\n ProdutoVarianteId: number;\r\n SKU: string;\r\n PrecoPor: number;\r\n PrecoDe: number;\r\n Quantidade: number;\r\n Ajustes: IAjustes[];\r\n}\r\n\r\nexport interface ICustomer {\r\n birthDate: string;\r\n document: string;\r\n name: string;\r\n phone: string;\r\n}\r\n\r\nexport interface IProccesPinBonusDto {\r\n storeName: string;\r\n name: string;\r\n checkoutId: string;\r\n checkoutProducts: Array<IProduct>;\r\n storeId: string;\r\n userId: string;\r\n cellphone: number;\r\n pin: string;\r\n\r\n}\r\n\r\nexport interface IBonus {\r\n hasBonus: boolean;\r\n bonusBalance: number;\r\n totalBonus: number;\r\n minimumPurchase: number;\r\n bonusIds: string;\r\n firstValidityDate: string\r\n history: [\r\n {\r\n validityStart: string;\r\n validityEnd: string;\r\n value: number\r\n },\r\n {\r\n validityStart: string;\r\n validityEnd: string\r\n value: number\r\n }\r\n ]\r\n storeId: number;\r\n userId: number;\r\n cartId: string\r\n calculatedValue: number;\r\n totalValue: number\r\n}\r\n\r\n\r\nexport interface IReserveDTO {\r\n storeName: string;\r\n cartId: string;\r\n grossValue: number;\r\n redeemedBonus: number;\r\n ticket: string;\r\n storeId: string;\r\n userId: number;\r\n}","import { AjustesTipoEnum, IAjustes, IProduct, IProductWake } from \"../dto/validate.pin.bonus\";\r\n\r\nexport function buildProductsByWake(productsWake: Array<IProductWake> = []): Array<IProduct> {\r\n\r\n const products: Array<IProduct> = [];\r\n\r\n for ( const pw of productsWake ) {\r\n \r\n // let discounts_formula = getDiscountFormula(pw.Ajustes);\r\n\r\n const hasOriginalPrice = (pw.PrecoDe < pw.PrecoPor);\r\n const hasDiscountInProduct = (pw.PrecoPor < pw.PrecoDe);\r\n const existsPromotionProduct = pw.Ajustes.filter(adj => [AjustesTipoEnum.PP].includes(adj.Tipo))\r\n const promotion_product = (existsPromotionProduct.length > 0)\r\n\r\n let discounts = getDiscount(pw.Ajustes, hasOriginalPrice);\r\n\r\n let price = hasOriginalPrice ? pw.PrecoPor : pw.PrecoDe;\r\n const priceOrignal = hasOriginalPrice ? pw.PrecoPor : pw.PrecoDe;\r\n\r\n if(!promotion_product && hasDiscountInProduct) {\r\n price = pw.PrecoPor;\r\n }\r\n\r\n var value = (price * pw.Quantidade);\r\n var originalValue = (priceOrignal * pw.Quantidade);\r\n\r\n var discounts_value = (discounts * -1); \r\n\r\n products.push(\r\n {\r\n sku: pw.SKU,\r\n value: value,\r\n originalValue: originalValue,\r\n productVariantId: pw.ProdutoVarianteId.toString(),\r\n quantity: pw.Quantidade,\r\n discount: value < discounts_value ? value : discounts_value,\r\n promotion_product,\r\n }\r\n )\r\n }\r\n\r\n return products;\r\n}\r\n\r\nfunction getDiscount(ajustes: IAjustes[] = [], hasOriginalPrice: boolean) {\r\n \r\n let discounts = 0;\r\n const config_ajustes = [AjustesTipoEnum.P, AjustesTipoEnum.CC];\r\n\r\n if(!hasOriginalPrice) {\r\n config_ajustes.push(AjustesTipoEnum.PP);\r\n }\r\n\r\n for(const discount of ajustes) {\r\n if(config_ajustes.includes(discount.Tipo)) {\r\n discounts += discount.Valor;\r\n }\r\n }\r\n\r\n return discounts;\r\n}\r\n","\r\n.container-button {\r\n /* max-width: 100%; */\r\n cursor: pointer;\r\n padding: 5px 5px 5px 14px;\r\n /* display: flex; */\r\n}\r\n\r\n/* padding: 0 15px 15px;\r\nborder: 1px solid #ddd;\r\nmargin-bottom: 20px; */\r\n\r\n.section-crm {\r\n border: 1px solid #dbd4d4;\r\n /* min-height: 50px; */\r\n text-align: -webkit-center;\r\n margin-bottom: 20px;\r\n}\r\n\r\n.section-cart-crm {\r\n margin-top: 10px;\r\n}\r\n\r\n.section-cart-crm p {\r\n padding: 0;\r\n margin: 0px 0px 0px 15px;\r\n}\r\n\r\n.button {\r\n top: 50%;\r\n background-color: #6c6c7e;\r\n color: #fff;\r\n border: none;\r\n /* border-radius: 10px; */\r\n padding: 15px;\r\n min-height: 30px;\r\n min-width: 120px;\r\n /* font-size: 20px; */\r\n cursor: pointer;\r\n margin-left: 10px;\r\n height: 70px;\r\n}\r\n\r\n.form-container {\r\n width: 97%;\r\n display: flex;\r\n justify-content: space-around;\r\n}\r\n\r\n\r\n.btn {\r\n display: inline-block;\r\n padding: 6px 12px;\r\n margin-bottom: 0;\r\n /* font-size: 14px; */\r\n font-weight: 400;\r\n line-height: 1.42857143;\r\n text-align: center;\r\n white-space: nowrap;\r\n vertical-align: middle;\r\n -ms-touch-action: manipulation;\r\n touch-action: manipulation;\r\n cursor: pointer;\r\n -webkit-user-select: none;\r\n -moz-user-select: none;\r\n -ms-user-select: none;\r\n user-select: none;\r\n background-image: none;\r\n border: 1px solid transparent;\r\n border-radius: 0px;\r\n}\r\n\r\n.form-container .btnCrm {\r\n background: #00162e;\r\n border-color: #00162e;\r\n width: 30%;\r\n color: #fff;\r\n}\r\n\r\n.message-alert {\r\n color: #df4d4d;\r\n margin-top: 5px;\r\n}","import { Component, Method, Prop, State, h } from '@stencil/core';\r\nimport { IProduct, IProductWake, ICustomer } from '../../dto/validate.pin.bonus';\r\nimport { CrmBonusService } from '../../services/crmbonus.service';\r\nimport { IPinSent } from '../../components';\r\nimport { defaultStyles, StepFormEnum } from '../../contants';\r\n\r\nimport i18next from '../../i18n/i18n'\r\nimport { buildProductsByWake } from '../../helpers/build.payload.helper';\r\nimport { getCart, getInfoBonusByCartIdAndStoreName } from '../../helpers/cart.helper';\r\nimport { CartWake } from '../../objectvalues/cart.wake';\r\nimport { USED_KEY } from '../../utils/keys.storage';\r\nimport { ReservedInfoDTO } from '../../dto/reserved-info.dto';\r\n\r\n@Component({\r\n tag: 'crm-bonus',\r\n styleUrl: 'crm-bonus.css',\r\n assetsDirs: ['assets'],\r\n // scoped: true\r\n shadow: true\r\n})\r\nexport class CrmBonus {\r\n\r\n private crmBonusService: CrmBonusService = CrmBonusService.getInstance();\r\n\r\n private crmBonusRef: HTMLCrmGiftbackFormElement;\r\n\r\n @Prop() cart;\r\n @Prop() canhidden: boolean = false;\r\n\r\n @State() showModal: boolean = false;\r\n\r\n @State() cartWake: CartWake;\r\n\r\n @State() customer: ICustomer = {\r\n birthDate: \"\",\r\n document: \"\",\r\n name: \"\",\r\n phone: \"\"\r\n };\r\n\r\n @State() loading: boolean = false;\r\n @State() message: string;\r\n @State() phone: number;\r\n @State() canCancel: boolean = false;\r\n @State() amountCancel: string;\r\n @State() sent: IPinSent;\r\n\r\n @State() session: string;\r\n @State() loading_reprocess = false;\r\n @State() styles = defaultStyles;\r\n @State() reservedInfo: ReservedInfoDTO;\r\n\r\n @Method()\r\n async resetBonus() {\r\n console.log('[CRMBONUS] - reset bonus');\r\n\r\n try {\r\n await this.crmBonusRef.processBonus(this.buildProducts(), true);\r\n console.log('[BONUS RESETADO]!!!!!');\r\n } catch (err) {\r\n\r\n this.loading = false;\r\n console.log('[error ao reprocessar bonous]');\r\n await this.crmBonusRef.setStep(StepFormEnum.STEP_PHONE);\r\n } finally {\r\n this.loading = false;\r\n }\r\n }\r\n\r\n @Method()\r\n async setloading() {\r\n this.loading_reprocess = !this.loading_reprocess;\r\n }\r\n\r\n @Method()\r\n async reprocess() {\r\n console.log(\"[CRMBONUS] - reprocess\")\r\n this.loading_reprocess = true\r\n\r\n try {\r\n\r\n const isUse = localStorage.getItem(USED_KEY);\r\n\r\n if (!isUse) return;\r\n\r\n this.cartWake = await getCart();\r\n await this.resetBonus();\r\n } catch (err) {\r\n console.debug('[watchProducts]', err.message);\r\n } finally {\r\n this.loading_reprocess = false\r\n }\r\n }\r\n\r\n async componentWillLoad() {\r\n this.loading_reprocess = true;\r\n window.addEventListener('productRemovedFromCart', async () => {\r\n console.log('[CRMBONUS] - productRemovedFromCart');\r\n await this.reprocess()\r\n });\r\n\r\n window.addEventListener('productAddedToCart', async () => {\r\n console.log('[CRMBONUS] - productAddedToCart');\r\n await this.reprocess();\r\n });\r\n\r\n document.querySelectorAll('form').forEach((el) => {\r\n el.addEventListener(\"submit\", async () => {\r\n console.log(\"[CRMBONUS] - Formulário está sendo submetido!\");\r\n await this.reprocess();\r\n });\r\n });\r\n\r\n document.getElementById('validarCupom')?.addEventListener('click', async () => {\r\n console.log(\"[CRMBONUS] - cupom sendo submetido!\");\r\n setTimeout(async () => {\r\n await this.reprocess();\r\n }, 2000);\r\n });\r\n\r\n await this.observerHandle();\r\n\r\n i18next.changeLanguage(i18next.language);\r\n }\r\n\r\n async componentDidLoad() {\r\n try {\r\n await this.loadSession();\r\n this.handleLoad();\r\n await this.loadConfigStore();\r\n } catch (error) {\r\n console.log('bc:err....')\r\n } finally {\r\n this.loading_reprocess = false;\r\n }\r\n }\r\n\r\n private async observerHandle() {\r\n const elements = document.getElementsByTagName('a');\r\n\r\n document.addEventListener('click', (event) => {\r\n //@ts-ignore\r\n console.log('Clique detectado em:', event.target.href);\r\n console.log('Clique detectado em:', event.target);\r\n \r\n //@ts-ignore\r\n if (['validarCupom'].includes(event.target.id)) {\r\n setTimeout(async () => {\r\n await this.reprocess();\r\n this.observerHandle();\r\n }, 2000);\r\n }\r\n });\r\n\r\n //@ts-ignore\r\n for (let el of elements) {\r\n console.log('[el.href]', el.href);\r\n if (el.href.includes('Produto/Delete')) {\r\n el.addEventListener('click', async () => {\r\n console.log('[CRMBONUS] - Produto removido do carrinho');\r\n\r\n setTimeout(async () => {\r\n await this.reprocess();\r\n this.observerHandle();\r\n }, 2000);\r\n\r\n });\r\n }\r\n\r\n if (el.href.includes('Produto/Add')) {\r\n el.addEventListener('click', async () => {\r\n console.log('[CRMBONUS] - Produto adicionado ao carrinho');\r\n setTimeout(async () => {\r\n await this.reprocess();\r\n this.observerHandle();\r\n }, 2000);\r\n });\r\n }\r\n }\r\n }\r\n\r\n async loadConfigStore() {\r\n const [customization, infoBonus] = await Promise.all([\r\n this.crmBonusService.getCustomization(this.cartWake.store.name),\r\n getInfoBonusByCartIdAndStoreName(this.cartWake.id, this.cartWake.store.name)\r\n ]);\r\n\r\n this.reservedInfo = infoBonus;\r\n\r\n if (customization.keepStoreFrontStyle) {\r\n this.styles = null;\r\n }\r\n }\r\n\r\n async fetchCustomer(userId: number, storeName: string) {\r\n try {\r\n return await this.crmBonusService.getCustomer(userId, storeName);\r\n } catch (error) {\r\n console.error('[fetchCustomer] Error fetching customer:', error);\r\n return null;\r\n }\r\n }\r\n\r\n async handleLoad() {\r\n try {\r\n if (this.cartWake.user.id) {\r\n this.fetchCustomer(this.cartWake.user.id, this.cartWake.store.name).then((customer) => {\r\n if (customer) {\r\n this.customer = customer;\r\n }\r\n });\r\n }\r\n\r\n const amount = localStorage.getItem(this.cartWake.id);\r\n\r\n if (amount) {\r\n this.canCancel = true;\r\n this.amountCancel = amount;\r\n }\r\n\r\n await this.buildAndGetProducts(this.cartWake.products);\r\n } catch (error) {\r\n console.log('info customer')\r\n }\r\n }\r\n\r\n async loadSession() {\r\n this.cartWake = this.cart ? new CartWake(JSON.parse(this.cart)) : await getCart();\r\n console.log('[bc:carregou carrinho]');\r\n\r\n this.session = await this.crmBonusService.getToken(this.cartWake.store.name);\r\n console.log('[bc:carregou session]');\r\n setTimeout(() => {\r\n this.loadSession()\r\n }, 1500000)\r\n }\r\n\r\n async buildAndGetProducts(productsWake: IProductWake[]) {\r\n\r\n const key = `bc-products:${this.cartWake.id}`;\r\n\r\n const productsString = JSON.stringify(productsWake)\r\n\r\n localStorage.setItem(key, productsString);\r\n\r\n const products_in_cache = JSON.parse(localStorage.getItem(key));\r\n\r\n const products: Array<IProductWake> = []\r\n\r\n for (const product_cart of productsWake) {\r\n\r\n const [pro] = products_in_cache.filter(p => p.ProdutoVarianteId == product_cart.ProdutoVarianteId)\r\n\r\n //const [ajuste = { Valor: 0 }] = pro.Ajustes.filter(aj => aj.Tipo === \"Formula\")\r\n\r\n if (pro) {\r\n products.push({\r\n ...product_cart,\r\n PrecoPor: pro.PrecoPor,\r\n PrecoDe: pro.PrecoDe,\r\n Quantidade: pro.Quantidade,\r\n Ajustes: pro.Ajustes\r\n })\r\n } else {\r\n products.push(product_cart)\r\n }\r\n\r\n }\r\n\r\n this.cartWake.products = products; //cache_products ? JSON.parse(cache_products) : JSON.parse(this.productsInString);\r\n\r\n }\r\n\r\n public async sendPin(phone: string) {\r\n this.loading = true;\r\n this.message = \"\";\r\n\r\n try {\r\n\r\n const _phone = phone.replace(/\\D/g, '');\r\n this.phone = Number(_phone);\r\n\r\n this.sent = await this.crmBonusService.sendPin(this.phone, this.customer.name, this.cartWake.store.name);;\r\n\r\n await this.crmBonusRef.setStep(StepFormEnum.STEP_PIN);\r\n\r\n this.showModal = true;\r\n } catch (error) {\r\n this.message = error?.response?.data?.message\r\n } finally {\r\n this.loading = false\r\n }\r\n }\r\n\r\n public async sendPinName(customerName: string) {\r\n this.loading = true;\r\n this.message = \"\";\r\n\r\n try {\r\n this.customer.name = customerName;\r\n\r\n this.sent = await this.crmBonusService.sendPin(this.phone, this.customer.name, this.cartWake.store.name);\r\n\r\n await this.crmBonusRef.setStep(StepFormEnum.STEP_PIN);\r\n\r\n this.showModal = true;\r\n } catch (error) {\r\n this.message = error?.response?.data?.message\r\n } finally {\r\n this.loading = false\r\n }\r\n }\r\n\r\n buildProducts(): IProduct[] {\r\n return buildProductsByWake(this.cartWake.products);\r\n }\r\n\r\n handleCloseModal() {\r\n this.showModal = false;\r\n }\r\n\r\n save(amount: number) {\r\n localStorage.setItem(this.cartWake.id, amount.toString());\r\n this.canCancel = true;\r\n this.amountCancel = amount.toString()\r\n }\r\n\r\n async cancel() {\r\n this.message = \"\";\r\n this.loading = true;\r\n try {\r\n await this.crmBonusService.cancel(this.cartWake.id);\r\n this.canCancel = false;\r\n\r\n localStorage.removeItem(this.cartWake.id);\r\n } catch (error) {\r\n this.message = \"Não consegui cancelar o bônus, tente novamente!\"\r\n } finally {\r\n this.loading = false;\r\n }\r\n }\r\n\r\n async handleSendPin(phone: string) {\r\n this.message = \"\"\r\n if (!phone) {\r\n this.message = \"Informe seu telefone\";\r\n return;\r\n }\r\n\r\n this.customer.phone = phone;\r\n const _phone = phone.replace(/\\D/g, '');\r\n this.phone = Number(_phone);\r\n\r\n if (this.customer.name) {\r\n return this.sendPin(phone)\r\n }\r\n\r\n await this.crmBonusRef.setStep(StepFormEnum.STEP_NAME);\r\n this.showModal = true;\r\n }\r\n\r\n render() {\r\n\r\n if (this.canhidden) {\r\n return null;\r\n }\r\n\r\n return (\r\n <loading-container loading={this.loading_reprocess} text='carregando...' >\r\n\r\n {\r\n !this.loading_reprocess && (\r\n <crm-giftback-form\r\n customStyles={this.styles}\r\n style={{ position: \"relative\" }}\r\n ref={ref => this.crmBonusRef = ref}\r\n storeName={this.cartWake.store.name}\r\n products={this.buildProducts()}\r\n cartId={this.cartWake.id}\r\n customer={this.customer}\r\n loadProducts={() => this.buildProducts()}\r\n loadAll={() => this.handleLoad()}\r\n reservedInfo={this.reservedInfo}\r\n />\r\n )\r\n }\r\n </loading-container>\r\n )\r\n }\r\n}\r\n"],"version":3}
@@ -1,2 +1,2 @@
1
- import{p as e,b as o}from"./p-8c362346.js";export{s as setNonce}from"./p-8c362346.js";import{g as n}from"./p-e1255160.js";var t=()=>{const o=import.meta.url;const n={};if(o!==""){n.resourcesUrl=new URL(".",o).href}return e(n)};t().then((async e=>{await n();return o([["p-df80d1b0",[[0,"crm-bonus-note",{cart:[8],cartWake:[32],url:[32],config:[32],bonus:[32],showEdit:[32],styles:[32],infoBonus:[32],loading:[32],info:[32]}]]],["p-7e52727e",[[1,"app-modal",{isOpen:[516,"is-open"],modalTitle:[1,"modal-title"]}]]],["p-1644deef",[[0,"container-empty"]]],["p-ac027576",[[1,"countdown-timer-v2",{downtime:[16],reload:[4],dates:[16],seconds:[32],minutes:[32]}]]],["p-ac1e7c32",[[0,"pedido-finalizado",{cart:[8]}]]],["p-0b369ee2",[[1,"crm-bonus",{cart:[8],canhidden:[4],showModal:[32],cartWake:[32],customer:[32],loading:[32],message:[32],phone:[32],canCancel:[32],amountCancel:[32],sent:[32],session:[32],loading_reprocess:[32],styles:[32],reservedInfo:[32],resetBonus:[64],setloading:[64],reprocess:[64]}],[0,"crm-giftback-form",{storeName:[8,"storename"],cartId:[8,"cart-id"],products:[16],customer:[16],loadProducts:[16],loadAll:[16],customStyles:[8,"custom-styles"],reservedInfo:[16],value:[32],loading:[32],message:[32],phone:[32],pinInfo:[32],step:[32],bonus:[32],sucess:[32],error:[32],config:[32],hasApplyBonus:[32],loadingAllComponent:[32],setStep:[64],processBonus:[64]}],[0,"phone-form",{value:[1],loading:[4],handlerSubmit:[16],config:[16]}],[1,"pin-form",{validate:[16],cancel:[16],resend:[16],sent:[16],loading:[4],phone:[1],config:[16],pin:[32],isVerified:[32],canResend:[32]}],[0,"giftback-info",{cartId:[8,"cart-id"],loading:[4],bonus:[16],reserve:[16],cancel:[16],config:[16],infoBonus:[16],storeName:[1,"store-name"],usedValue:[32],selectedOption:[32],sliderPosition:[32],sliderValuePosition:[32],loadingTime:[32]},null,{bonus:["changedBonus"]}],[4,"loading-container",{loading:[4],text:[1]}],[0,"crm-tooltip",{text:[1],identity:[1]}],[1,"phone-input-mask",{initialValue:[1,"initial-value"],disabled:[4],phone:[32],message:[32],getPhone:[64]}],[0,"crm-button",{txtBtn:[1,"txt-btn"],loading:[4],handleClick:[16]}],[0,"countdown-timer",{downtime:[16],dataCriacao:[1,"data-criacao"],minutos:[2],segundos:[2],tempoRestante:[32]}],[1,"loading-spinner",{size:[1],color:[1]}]]]],e)}));
1
+ import{p as e,b as o}from"./p-8c362346.js";export{s as setNonce}from"./p-8c362346.js";import{g as n}from"./p-e1255160.js";var t=()=>{const o=import.meta.url;const n={};if(o!==""){n.resourcesUrl=new URL(".",o).href}return e(n)};t().then((async e=>{await n();return o([["p-df80d1b0",[[0,"crm-bonus-note",{cart:[8],cartWake:[32],url:[32],config:[32],bonus:[32],showEdit:[32],styles:[32],infoBonus:[32],loading:[32],info:[32]}]]],["p-7e52727e",[[1,"app-modal",{isOpen:[516,"is-open"],modalTitle:[1,"modal-title"]}]]],["p-1644deef",[[0,"container-empty"]]],["p-ac027576",[[1,"countdown-timer-v2",{downtime:[16],reload:[4],dates:[16],seconds:[32],minutes:[32]}]]],["p-ac1e7c32",[[0,"pedido-finalizado",{cart:[8]}]]],["p-60742512",[[1,"crm-bonus",{cart:[8],canhidden:[4],showModal:[32],cartWake:[32],customer:[32],loading:[32],message:[32],phone:[32],canCancel:[32],amountCancel:[32],sent:[32],session:[32],loading_reprocess:[32],styles:[32],reservedInfo:[32],resetBonus:[64],setloading:[64],reprocess:[64]}],[0,"crm-giftback-form",{storeName:[8,"storename"],cartId:[8,"cart-id"],products:[16],customer:[16],loadProducts:[16],loadAll:[16],customStyles:[8,"custom-styles"],reservedInfo:[16],value:[32],loading:[32],message:[32],phone:[32],pinInfo:[32],step:[32],bonus:[32],sucess:[32],error:[32],config:[32],hasApplyBonus:[32],loadingAllComponent:[32],setStep:[64],processBonus:[64]}],[0,"phone-form",{value:[1],loading:[4],handlerSubmit:[16],config:[16]}],[1,"pin-form",{validate:[16],cancel:[16],resend:[16],sent:[16],loading:[4],phone:[1],config:[16],pin:[32],isVerified:[32],canResend:[32]}],[0,"giftback-info",{cartId:[8,"cart-id"],loading:[4],bonus:[16],reserve:[16],cancel:[16],config:[16],infoBonus:[16],storeName:[1,"store-name"],usedValue:[32],selectedOption:[32],sliderPosition:[32],sliderValuePosition:[32],loadingTime:[32]},null,{bonus:["changedBonus"]}],[4,"loading-container",{loading:[4],text:[1]}],[0,"crm-tooltip",{text:[1],identity:[1]}],[1,"phone-input-mask",{initialValue:[1,"initial-value"],disabled:[4],phone:[32],message:[32],getPhone:[64]}],[0,"crm-button",{txtBtn:[1,"txt-btn"],loading:[4],handleClick:[16]}],[0,"countdown-timer",{downtime:[16],dataCriacao:[1,"data-criacao"],minutos:[2],segundos:[2],tempoRestante:[32]}],[1,"loading-spinner",{size:[1],color:[1]}]]]],e)}));
2
2
  //# sourceMappingURL=crmbonus-component-wake.esm.js.map
@@ -0,0 +1,2 @@
1
+ import{r as t,h as i,H as e}from"./p-8c362346.js";import{C as o,U as s,g as n,a,b as r,c,p as d}from"./p-0d09c221.js";import{d as l,S as h,i as p,g as u,M as f}from"./p-b4f52f79.js";import{d as b,a as g}from"./p-af3ba015.js";const m=class{constructor(i){t(this,i);this.downtime=undefined;this.dataCriacao=undefined;this.minutos=6;this.segundos=60;this.tempoRestante=undefined}componentWillLoad(){const t=this.minutos*this.segundos*1e3;const i=new Date(this.dataCriacao);const e=new Date;const o=e.getTime()-i.getTime();if(o>=t){this.tempoRestante=0;this.onTempoEsgotado()}else{this.tempoRestante=t-o;this.startCountdown()}}disconnectedCallback(){clearInterval(this.intervalId)}startCountdown(){this.intervalId=setInterval((()=>{this.tempoRestante-=1e3;if(this.tempoRestante<=0){this.tempoRestante=0;clearInterval(this.intervalId);this.onTempoEsgotado()}}),1e3)}onTempoEsgotado(){console.log("Tempo esgotado! Executando ação...");this.downtime()}render(){const t=Math.floor(this.tempoRestante/6e4);const e=Math.floor(this.tempoRestante%6e4/1e3);const o=`${String(t).padStart(2,"0")}:${String(e).padStart(2,"0")}`;return i("label",{key:"ed1e0654cba5b152adcadb10cf9dfd6909c07a1f"}," ",o)}};var x;(function(t){t["P"]="Promocao";t["CC"]="ContaCorrente";t["PP"]="PromocaoProduto";t["F"]="Formula"})(x||(x={}));function y(t=[]){const i=[];for(const n of t){const t=n.PrecoDe<n.PrecoPor;const a=n.PrecoPor<n.PrecoDe;const r=n.Ajustes.filter((t=>[x.PP].includes(t.Tipo)));const c=r.length>0;let d=v(n.Ajustes,t);let l=t?n.PrecoPor:n.PrecoDe;const h=t?n.PrecoPor:n.PrecoDe;if(!c&&a){l=n.PrecoPor}var e=l*n.Quantidade;var o=h*n.Quantidade;var s=d*-1;i.push({sku:n.SKU,value:e,originalValue:o,productVariantId:n.ProdutoVarianteId.toString(),quantity:n.Quantidade,discount:e<s?e:s,promotion_product:c})}return i}function v(t=[],i){let e=0;const o=[x.P,x.CC];if(!i){o.push(x.PP)}for(const i of t){if(o.includes(i.Tipo)){e+=i.Valor}}return e}const w=".container-button{cursor:pointer;padding:5px 5px 5px 14px;}.section-crm{border:1px solid #dbd4d4;text-align:-webkit-center;margin-bottom:20px}.section-cart-crm{margin-top:10px}.section-cart-crm p{padding:0;margin:0px 0px 0px 15px}.button{top:50%;background-color:#6c6c7e;color:#fff;border:none;padding:15px;min-height:30px;min-width:120px;cursor:pointer;margin-left:10px;height:70px}.form-container{width:97%;display:flex;justify-content:space-around}.btn{display:inline-block;padding:6px 12px;margin-bottom:0;font-weight:400;line-height:1.42857143;text-align:center;white-space:nowrap;vertical-align:middle;-ms-touch-action:manipulation;touch-action:manipulation;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background-image:none;border:1px solid transparent;border-radius:0px}.form-container .btnCrm{background:#00162e;border-color:#00162e;width:30%;color:#fff}.message-alert{color:#df4d4d;margin-top:5px}";const k=w;const I=class{constructor(i){t(this,i);this.crmBonusService=o.getInstance();this.cart=undefined;this.canhidden=false;this.showModal=false;this.cartWake=undefined;this.customer={birthDate:"",document:"",name:"",phone:""};this.loading=false;this.message=undefined;this.phone=undefined;this.canCancel=false;this.amountCancel=undefined;this.sent=undefined;this.session=undefined;this.loading_reprocess=false;this.styles=l;this.reservedInfo=undefined}async resetBonus(){console.log("[CRMBONUS] - reset bonus");try{await this.crmBonusRef.processBonus(this.buildProducts(),true);console.log("[BONUS RESETADO]!!!!!")}catch(t){this.loading=false;console.log("[error ao reprocessar bonous]");await this.crmBonusRef.setStep(h.STEP_PHONE)}finally{this.loading=false}}async setloading(){this.loading_reprocess=!this.loading_reprocess}async reprocess(){console.log("[CRMBONUS] - reprocess");this.loading_reprocess=true;try{const t=localStorage.getItem(s);if(!t)return;this.cartWake=await n();await this.resetBonus()}catch(t){console.debug("[watchProducts]",t.message)}finally{this.loading_reprocess=false}}async componentWillLoad(){var t;this.loading_reprocess=true;window.addEventListener("productRemovedFromCart",(async()=>{console.log("[CRMBONUS] - productRemovedFromCart");await this.reprocess()}));window.addEventListener("productAddedToCart",(async()=>{console.log("[CRMBONUS] - productAddedToCart");await this.reprocess()}));document.querySelectorAll("form").forEach((t=>{t.addEventListener("submit",(async()=>{console.log("[CRMBONUS] - Formulário está sendo submetido!");await this.reprocess()}))}));(t=document.getElementById("validarCupom"))===null||t===void 0?void 0:t.addEventListener("click",(async()=>{console.log("[CRMBONUS] - cupom sendo submetido!");setTimeout((async()=>{await this.reprocess()}),2e3)}));await this.observerHandle();p.changeLanguage(p.language)}async componentDidLoad(){try{await this.loadSession();this.handleLoad();await this.loadConfigStore()}catch(t){console.log("bc:err....")}finally{this.loading_reprocess=false}}async observerHandle(){const t=document.getElementsByTagName("a");document.addEventListener("click",(t=>{console.log("Clique detectado em:",t.target.href);console.log("Clique detectado em:",t.target);if(["validarCupom"].includes(t.target.id)){setTimeout((async()=>{await this.reprocess();this.observerHandle()}),2e3)}}));for(let i of t){console.log("[el.href]",i.href);if(i.href.includes("Produto/Delete")){i.addEventListener("click",(async()=>{console.log("[CRMBONUS] - Produto removido do carrinho");setTimeout((async()=>{await this.reprocess();this.observerHandle()}),2e3)}))}if(i.href.includes("Produto/Add")){i.addEventListener("click",(async()=>{console.log("[CRMBONUS] - Produto adicionado ao carrinho");setTimeout((async()=>{await this.reprocess();this.observerHandle()}),2e3)}))}}}async loadConfigStore(){const[t,i]=await Promise.all([this.crmBonusService.getCustomization(this.cartWake.store.name),a(this.cartWake.id,this.cartWake.store.name)]);this.reservedInfo=i;if(t.keepStoreFrontStyle){this.styles=null}}async fetchCustomer(t,i){try{return await this.crmBonusService.getCustomer(t,i)}catch(t){console.error("[fetchCustomer] Error fetching customer:",t);return null}}async handleLoad(){try{if(this.cartWake.user.id){this.fetchCustomer(this.cartWake.user.id,this.cartWake.store.name).then((t=>{if(t){this.customer=t}}))}const t=localStorage.getItem(this.cartWake.id);if(t){this.canCancel=true;this.amountCancel=t}await this.buildAndGetProducts(this.cartWake.products)}catch(t){console.log("info customer")}}async loadSession(){this.cartWake=this.cart?new r(JSON.parse(this.cart)):await n();console.log("[bc:carregou carrinho]");this.session=await this.crmBonusService.getToken(this.cartWake.store.name);console.log("[bc:carregou session]");setTimeout((()=>{this.loadSession()}),15e5)}async buildAndGetProducts(t){const i=`bc-products:${this.cartWake.id}`;const e=JSON.stringify(t);localStorage.setItem(i,e);const o=JSON.parse(localStorage.getItem(i));const s=[];for(const i of t){const[t]=o.filter((t=>t.ProdutoVarianteId==i.ProdutoVarianteId));if(t){s.push(Object.assign(Object.assign({},i),{PrecoPor:t.PrecoPor,PrecoDe:t.PrecoDe,Quantidade:t.Quantidade,Ajustes:t.Ajustes}))}else{s.push(i)}}this.cartWake.products=s}async sendPin(t){var i,e;this.loading=true;this.message="";try{const i=t.replace(/\D/g,"");this.phone=Number(i);this.sent=await this.crmBonusService.sendPin(this.phone,this.customer.name,this.cartWake.store.name);await this.crmBonusRef.setStep(h.STEP_PIN);this.showModal=true}catch(t){this.message=(e=(i=t===null||t===void 0?void 0:t.response)===null||i===void 0?void 0:i.data)===null||e===void 0?void 0:e.message}finally{this.loading=false}}async sendPinName(t){var i,e;this.loading=true;this.message="";try{this.customer.name=t;this.sent=await this.crmBonusService.sendPin(this.phone,this.customer.name,this.cartWake.store.name);await this.crmBonusRef.setStep(h.STEP_PIN);this.showModal=true}catch(t){this.message=(e=(i=t===null||t===void 0?void 0:t.response)===null||i===void 0?void 0:i.data)===null||e===void 0?void 0:e.message}finally{this.loading=false}}buildProducts(){return y(this.cartWake.products)}handleCloseModal(){this.showModal=false}save(t){localStorage.setItem(this.cartWake.id,t.toString());this.canCancel=true;this.amountCancel=t.toString()}async cancel(){this.message="";this.loading=true;try{await this.crmBonusService.cancel(this.cartWake.id);this.canCancel=false;localStorage.removeItem(this.cartWake.id)}catch(t){this.message="Não consegui cancelar o bônus, tente novamente!"}finally{this.loading=false}}async handleSendPin(t){this.message="";if(!t){this.message="Informe seu telefone";return}this.customer.phone=t;const i=t.replace(/\D/g,"");this.phone=Number(i);if(this.customer.name){return this.sendPin(t)}await this.crmBonusRef.setStep(h.STEP_NAME);this.showModal=true}render(){if(this.canhidden){return null}return i("loading-container",{loading:this.loading_reprocess,text:"carregando..."},!this.loading_reprocess&&i("crm-giftback-form",{customStyles:this.styles,style:{position:"relative"},ref:t=>this.crmBonusRef=t,storeName:this.cartWake.store.name,products:this.buildProducts(),cartId:this.cartWake.id,customer:this.customer,loadProducts:()=>this.buildProducts(),loadAll:()=>this.handleLoad(),reservedInfo:this.reservedInfo}))}static get assetsDirs(){return["assets"]}};I.style=k;const M="input,button{margin:0;padding:10px;}.crm-contaner-button{height:auto;width:auto}.crm-button{height:48px;width:100%;border:1px solid #000;padding:14px 20px;background-color:#000;color:#fff;line-height:20px;font-weight:500;cursor:pointer}";const N=M;const D=class{constructor(i){t(this,i);this.txtBtn=undefined;this.loading=undefined;this.handleClick=undefined}render(){return i("div",{key:"785b4975fb6538dbe2cdb7b99d5801abc72c534a",class:"crm-contaner-button"},i("button",{key:"1e41951aa024e9f3b9b1836e8386bd369d022f76",class:"crm-button",onClick:()=>this.handleClick()},!this.loading?this.txtBtn:i("loading-spinner",{size:"15px",color:"#fff"})))}};D.style=N;const S="*{margin:0;padding:0;box-sizing:border-box}:host{--crmfont-sizebodymd:14px;--crmline-heightbodymd:20px;--crmletter-spacingtitle-md:0px}.container-message{font-weight:400;line-height:var(--crmline-heightbodymd);letter-spacing:var(--crmletter-spacingtitle-md);text-align:left;text-underline-position:from-font;text-decoration-skip-ink:none}.crm-container-form{display:flex;flex-direction:column;justify-content:space-around;height:auto;padding:20px 24px 20px 24px;border:1px solid #CCCC;writing-mode:horizontal-tb;gap:16px;border-top:1px solid #ccc !important;border-bottom:1px solid #ccc !important}.crm-phone-form{display:flex;flex-direction:column;height:100%;gap:16px}.crm-subtitle{font-size:.875rem;line-height:1.25rem}.crm-title{font-weight:700;line-height:20px;color:#262626;}.crm-message-info{color:#619013;font-weight:500;}.crm-message-error{color:#E11D48;font-weight:500;}";const C=S;const j=class{constructor(i){t(this,i);this.crmBonusService=o.getInstance();this.storeName=undefined;this.cartId=undefined;this.products=undefined;this.customer=undefined;this.loadProducts=undefined;this.loadAll=undefined;this.customStyles=undefined;this.reservedInfo=undefined;this.value=undefined;this.loading=false;this.message=undefined;this.phone=undefined;this.pinInfo=undefined;this.step=h.STEP_RESERVE;this.bonus=undefined;this.sucess="";this.error="";this.config=undefined;this.hasApplyBonus=false;this.loadingAllComponent=false}async setStep(t){this.step=t}async processBonus(t=[],i=false){await this.loadProducts();this.sucess="";if(i){this.products=t}const e=localStorage.getItem(c(this.cartId));console.log("[_bonus]",e);if(e){const t=JSON.parse(e);if(!t.storeId||!t.userId){return}this.bonus=t;this.phone=t.phone;this.pinInfo={storeId:t.storeId,userId:t.userId};await this.validateBonus("2018")}}async handleSendPin(t){await this.loadAll();this.message="";if(!t){this.message="Informe seu telefone";return}this.phone=t;this.sendPin()}async componentWillLoad(){this.sucess="";this.error="";this.config=u(this.storeName);const t=this.getPhoneNumberAgain();if(t){this.step=h.STEP_PHONE;return}await this.processBonus()}getPhoneNumberAgain(){const t=localStorage.getItem(c(this.cartId));if(!t)return true;const i=JSON.parse(t);return!i.hasBonus}convertStringToNumber(){var t;const i=(t=this.phone)===null||t===void 0?void 0:t.replace(/\D/g,"");return Number(i)}async sendPin(){var t,i,e;this.loading=true;this.message="";this.sucess="";this.error="";try{const i=this.convertStringToNumber();const e=localStorage.getItem(`bc:${this.phone}`);if(!e){this.pinInfo=await this.crmBonusService.sendPin(i,(t=this.customer)===null||t===void 0?void 0:t.name,this.storeName)}if(e){const t=JSON.parse(e);this.pinInfo={storeId:t.storeId,userId:t.userId};await this.validateBonus("2018")}else{this.step=h.STEP_PIN}}catch(t){this.message=(e=(i=t===null||t===void 0?void 0:t.response)===null||i===void 0?void 0:i.data)===null||e===void 0?void 0:e.message}finally{this.loading=false}}changePhone(){this.sucess="";this.error="";this.step=h.STEP_PHONE}async validateBonus(t){var i,e,o,n,a,r,d,l,p,u,f,b;this.loadingAllComponent=true;await this.loadProducts();const g=localStorage.getItem(s);if(g=="dontUse"){this.step=h.STEP_RESERVE;return}this.loading=true;this.sucess="";this.error="";const m=((i=this.pinInfo)===null||i===void 0?void 0:i.storeId)||((o=(e=this.reservedInfo)===null||e===void 0?void 0:e.metadata)===null||o===void 0?void 0:o.storeId);const x=((n=this.pinInfo)===null||n===void 0?void 0:n.userId)||((r=(a=this.reservedInfo)===null||a===void 0?void 0:a.metadata)===null||r===void 0?void 0:r.userId);const y=(l=(d=this.reservedInfo)===null||d===void 0?void 0:d.metadata)===null||l===void 0?void 0:l.cellphone;const v={pin:t,cellphone:y||this.convertStringToNumber(),storeId:m===null||m===void 0?void 0:m.toString(),userId:x===null||x===void 0?void 0:x.toString(),checkoutId:this.cartId,checkoutProducts:this.products,name:(p=this.customer)===null||p===void 0?void 0:p.name,storeName:this.storeName};try{this.bonus=await this.crmBonusService.validatePinBonus(v);if(!this.bonus.hasBonus){localStorage.setItem(c(this.cartId),JSON.stringify(Object.assign(Object.assign({},this.bonus),{phone:this.phone})));this.loading=false;this.step=h.STEP_NO_BONUS;return}this.sucess="Código validado com sucesso!";localStorage.setItem(c(this.cartId),JSON.stringify(Object.assign(Object.assign({},this.bonus),{phone:this.phone})));localStorage.setItem(`bc:${this.phone}`,JSON.stringify(this.bonus));localStorage.setItem(s,"use");localStorage.setItem(this.cartId,this.bonus.bonusBalance.toString());this.updateMetadata({storeId:Number(m),userId:Number(x)},v.cellphone);console.log("RESERVE",this.bonus);this.step=h.STEP_RESERVE}catch(t){const i=(f=(u=t===null||t===void 0?void 0:t.response)===null||u===void 0?void 0:u.data)===null||f===void 0?void 0:f.response;const e=(b=t===null||t===void 0?void 0:t.response)===null||b===void 0?void 0:b.data;if(i&&i.includes("Pin")){this.error="Código inválido!"}else if([403,500].includes(e.statusCode)){this.error="ocorreu um error, atualize a pagina e tente novamente!"}else{this.error=i;this.step=h.STEP_NO_BONUS}}finally{this.loading=false;this.loadingAllComponent=false}}async updateMetadata(t,i){try{if(this.reservedInfo.isExpired()){console.log("[CRM:updateMetadata]");await d(this.storeName,this.cartId,{createdAt:Date.now(),url:window.location.href,storeId:t.storeId,userId:t.userId,cellphone:i});localStorage.removeItem("bc:time")}else{await d(this.storeName,this.cartId,{url:window.location.href,storeId:t.storeId,userId:t.userId,cellphone:i})}}catch(t){console.error("[CRMBONUS:updateMetadata]: ",t)}}handleCancel(){this.cancel()}async cancel(){this.message="";this.loading=true;try{await this.crmBonusService.cancel(this.cartId);localStorage.setItem(s,"dontUse");await this.updateMetadata({storeId:null,userId:null},null)}catch(t){this.message="Não consegui cancelar o bônus, tente novamente!"}finally{this.loading=false}}async reserveApply(t){this.loading=true;this.message="";try{await this.reserve(t)}catch(t){this.message="ocorreu um error ao solicitar a aplicação do bonus! tente novamente";this.step=h.STEP_NO_BONUS;localStorage.removeItem(this.cartId)}finally{this.loading=false}}async reserve(t){await this.crmBonusService.reserve({redeemedBonus:t,cartId:this.cartId,ticket:this.cartId,grossValue:Number(this.bonus.totalValue),storeName:this.storeName,storeId:this.bonus.storeId.toString(),userId:this.bonus.userId})}render(){return i("div",{key:"a637c864ea60213cb587e7cb45e22a81480a9808",class:"crm-container-form fbits-responsive-carrinho-desconto",style:this.customStyles},i("label",{key:"129e5e186fcb43d3bd96fbe235e03f9f5effb732",class:"crm-title"},this.config.giftbackTitle),this.error&&i("label",{key:"841e97f1998d736e7ba8eb413870ecf5b1fbd1b8",class:"crm-message-error"},this.error),this.step===h.STEP_PHONE&&i("phone-form",{key:"cebcc523fd68ac798038424433cc839e3acfcc45",value:this.customer.phone,config:this.config,loading:this.loading,handlerSubmit:t=>this.handleSendPin(t)}),this.step===h.STEP_PIN&&i("pin-form",{key:"c4d49b98b5e9fd0797797a072fb13ac795cd91f2",config:this.config,phone:this.phone,cancel:()=>this.changePhone(),resend:()=>this.sendPin(),validate:t=>this.validateBonus(t),loading:this.loading},this.sucess&&i("p",{key:"fb7bcc0108152dde62e3f0197b78ee4be76d1c32",class:"crm-message-info"},this.sucess),this.error&&i("p",{key:"502d0ebbdc1bead841dc19d3446d26611850f144",class:"crm-message-error"},this.error)),this.step===h.STEP_RESERVE&&i("giftback-info",{key:"789f2d1b42e5b4d776e01bf96c31f0be4b5a6b71",storeName:this.storeName,infoBonus:this.reservedInfo,config:this.config,loading:this.loading,cancel:()=>this.handleCancel(),bonus:this.bonus,reserve:()=>this.processBonus(),cartId:this.cartId}),this.step===h.STEP_NO_BONUS&&i("div",{key:"5b6db02d4919df3737feedb22c5f4fdf17b0614c",class:"container-message"},p.t("noGiftback",{storename:this.config.giftbackTitle})))}};j.style=C;const A="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlb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xMDg2IDYuODkxMzcgMjEuMjUgMTIgMjEuMjVDMTcuMTA4NiAyMS4yNSAyMS4yNSAxNy4xMDg2IDIxLjI1IDEyQzIxLjI1IDYuODkxMzcgMTcuMTA4NiAyLjc1IDEyIDIuNzVaIiBmaWxsPSIjMUMyNzRDIi8+DQo8L3N2Zz4=";const T=".crm-tooltip-container {\r\n display: flex;\r\n\r\n & img {\r\n width: 16px;\r\n margin-left: 3px;\r\n position: relative;\r\n }\r\n}\r\n\r\n.crm-tooltip {\r\n position: relative;\r\n display: inline-block;\r\n}\r\n\r\n.crm-tooltip .tooltiptext {\r\n visibility: hidden;\r\n background-color: black;\r\n color: #fff;\r\n text-align: center;\r\n padding: 8px 12px;\r\n border-radius: 0px;\r\n position: absolute;\r\n z-index: 1;\r\n min-width: 271px;\r\n top: 100%;\r\n left: 50%;\r\n margin-left: -238px;\r\n}\r\n\r\n@container (max-width: 410px) {\r\n .crm-tooltip .tooltiptext {\r\n margin-left: -14px;\r\n }\r\n\r\n .crm-tooltip #crm-role-description {\r\n margin-left: -151px;\r\n }\r\n}\r\n\r\n@container (max-width: 250px) {\r\n .crm-tooltip .tooltiptext {\r\n margin-left: -201px;\r\n }\r\n}\r\n\r\n.crm-tooltip:hover .tooltiptext {\r\n visibility: visible;\r\n}";const z=T;const P=class{constructor(i){t(this,i);this.text=undefined;this.identity=undefined}render(){return i("div",{key:"01d82d0172ca5f0dbb0b8ea278b4a5d438c13dd5",class:"crm-tooltip-container crm-tooltip"},i("img",{key:"3b632cc38e8ff206402a2bfaadba9f9d2d747095",src:A}),i("span",{key:"08310e35ac945bda0e9356ecad8742698016f262",id:this.identity,class:"tooltiptext"},this.text))}};P.style=z;const U=":host{--text-color:#6D6D5F}.giftback-container{display:flex;flex-direction:column;gap:14px}h3{margin-bottom:8px;color:#333}.container-description{display:flex;align-items:center;gap:5px;margin:0 0 10px 0}.container-description p{font-weight:400;margin:0px}p{color:#000}.value-display h2{color:#6D6D5F;margin:16px 0}input[type='range']{width:100%;margin:12px 0;-webkit-appearance:none;background:#ddd;height:4px;border-radius:4px;outline:none;padding:3px 0px 3px 3px}input[type=\"range\"]::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;width:20px;height:20px;background:rgb(109, 109, 95);border-radius:50%;cursor:pointer}.options{margin:0px 0;display:flex;gap:10px;flex-direction:column}.options label{display:flex;margin:0px 0;color:#333;align-items:center}.options input[type='radio']{margin-right:8px;height:16px;width:16px}.options input[type='radio']{appearance:none;-webkit-appearance:none;margin-right:8px;width:16px;height:16px;border:2px solid #ddd;border-radius:50%;background-color:#fff;cursor:pointer;transition:all 0.3s;padding:0px}.options input[type='radio']:checked{border-color:#000;background-color:#FAFAFA;border:4px solid #000}.info-box{background-color:#f9f9f9;border:1px solid #e0e0e0;border-radius:4px;padding:8px;color:#262626;line-height:20px}.info-icon{cursor:pointer;color:#888}h3{margin-bottom:8px;color:#333}.slider-wrapper{position:relative;margin:21px 0px 0px 0px}.slider{width:100%;-webkit-appearance:none;background:#ddd;height:4px;border-radius:2px;outline:none}.slider::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;width:16px;height:16px;background:var(--text-color);border-radius:50%;cursor:pointer}.slider-value{position:absolute;top:-30px;font-weight:700;color:var(--text-color);transform:translateX(-50%);white-space:nowrap;}.options-option{display:flex}";const E=U;const O=class{constructor(i){t(this,i);this.usedValue=0;this.selectedOption="none";this.cartId=undefined;this.loading=false;this.bonus={totalBonus:0,cartId:"",minimumPurchase:0,bonusBalance:0,calculatedValue:0,firstValidityDate:"",totalValue:0};this.reserve=undefined;this.cancel=undefined;this.config=undefined;this.infoBonus=undefined;this.storeName=undefined;this.sliderPosition=0;this.sliderValuePosition=0;this.loadingTime=false}changedBonus(){this.updateBonus()}updateBonus(){this.usedValue=this.bonus.bonusBalance;this.buildPositionSlider(0,this.bonus.totalBonus)}componentWillLoad(){this.updateBonus();this.selectedOption=localStorage.getItem(s)}handleSliderChange(t){const i=t.target;this.usedValue=parseFloat(i.value);this.buildPositionSlider(parseFloat(i.min),parseFloat(i.max))}componentDidLoad(){var t;if(this.bonus){this._refIinputRange.value=(t=this.bonus)===null||t===void 0?void 0:t.bonusBalance.toString()}}buildPositionSlider(t,i){const e=i*.1;const o=(this.usedValue-t)/(i-t)*100;this.sliderPosition=o;this.sliderValuePosition=o+(this.usedValue<=e?10:0)}async handleOptionChange(t){this.selectedOption=t;localStorage.setItem(s,t);await d(this.storeName,this.cartId,Object.assign(Object.assign({},this.infoBonus.metadata),{createdAt:null}));switch(this.selectedOption){case"use":await this.reserve(this.usedValue);break;case"dontUse":await this.cancel();break}}showTime(){if(!this.infoBonus)return false;return!this.infoBonus.isExpired()}getTime(){var t,i;const e=new Date((i=(t=this.infoBonus)===null||t===void 0?void 0:t.metadata)===null||i===void 0?void 0:i.createdAt);const o=new Date(e);o.setMinutes(o.getMinutes()+6);return{createdAt:e,expiration:o}}async downtime(){await d(this.storeName,this.bonus.cartId,{createdAt:null})}render(){var t,e,o,s,n,a,r;console.log("this.bonus",this.bonus);const c=this.bonus.minimumPurchase-this.bonus.totalValue;const d=p.t("giftDescription",{amount:`${(e=(t=this.bonus)===null||t===void 0?void 0:t.totalBonus)===null||e===void 0?void 0:e.toFixed(2).replace(".",",")}`,custom_name:"Giftback"});const l=b(c);return i("div",{key:"baf90a1de29b3275c1c3cfd31f9d004ca3187a84",class:"giftback-container"},i("div",{key:"57af5fe5b40b3292a275065f577a9444470f8bf0",class:"container-description"},i("p",{key:"fff28c85077c36854f37d5f23f2908fa47197dac",innerHTML:d}),i("crm-tooltip",{key:"b66b1914dfa5e0806f85a9695840fdd4bd52d21e",identity:"crm-role-description",text:p.t("labelUseGiftback",{minimumPurchase:this.bonus.minimumPurchase,expírationDate:g(this.bonus.firstValidityDate)})})),i("div",{key:"e13afe9428744084443697df22048ac05b41ffd0",class:"slider-wrapper"},i("div",{key:"1826a50e4e1b474322dbb0020db0154fe9ed5b80",class:"slider-value",style:{left:`calc(${this.sliderValuePosition}% - 20px)`}},"R$ ",this.usedValue.toFixed(2).replace(".",",")),i("input",{key:"73b42919b8e4e0223dc8490a6190697d1975e96d",ref:t=>this._refIinputRange=t,id:"position_value_id",disabled:true,type:"range",min:"0",max:this.bonus.totalBonus,value:this.usedValue,class:"slider",step:"0.01",onInput:t=>this.handleSliderChange(t),style:{background:`linear-gradient(to right, #6D6D5F ${this.sliderPosition}%, #ddd ${this.sliderPosition}%)`}})),l.isComplete&&i("p",{key:"b9b853490c112bf3e98d14c2ceee25d0b7604983"},p.t("maxAmount")),!l.isComplete&&i("div",{key:"50b23f6c4bde42ca12b077a33f0ffbde25601e3d",class:"container-description"},i("p",{key:"73bfbcc779b8775aecc63050816909ba9120af3e"},"Adicione ",i("strong",{key:"6d5a2ea943a1d3eee80b0f4d0cdda159a300bb25"},"R$ ",c<0?"0,00":c.toFixed(2).replace(".",","))," ao carrinho para atingir o valor máximo!"),i("crm-tooltip",{key:"5a5bbbeb32abd51fbfb84c63d3e7a06f8d459ea0",identity:"crm-max-description",text:p.t("labelamountPartial")})),i("div",{key:"ea3f6aa8f4668b759b912bac36d9780e183a6180",class:"options"},i("div",{key:"6f7f70930c8cd97f1215301d823f8631d071b472",class:"options-option"},i("input",{key:"35b4f8380f34becd4dc94c1bcb1572c2b3401db8",disabled:this.showTime(),type:"radio",name:"giftbackOption",value:"use",checked:this.selectedOption==="use",onChange:()=>this.handleOptionChange("use")}),i("p",{key:"228beeb474e10a67811925bee00e5c1d0f5d64b6"},"Usar o meu ",(o=this.config)===null||o===void 0?void 0:o.giftbackTitle)),i("div",{key:"2a9ad1052f869057d5e36c3eba0cf1a24af88e1b",class:"options-option"},i("input",{key:"3cc3fae293fda510873f9c5f4d906308affca8e1",disabled:this.showTime(),type:"radio",name:"giftbackOption",value:"dontUse",checked:this.selectedOption==="dontUse",onChange:()=>this.handleOptionChange("dontUse")}),i("p",{key:"364f7de414a6f536680f849fe3efdee803d9a596"},"Não usar o meu ",(s=this.config)===null||s===void 0?void 0:s.giftbackTitle))),this.showTime()&&i("div",{key:"8fe525904208e2fc13ebd80615bbe7856cc2dc2c",class:"info-box"},"Após ",i("countdown-timer",{key:"3913bc9060980620654f03a987f62f628d6ee440",dataCriacao:new Date((a=(n=this.infoBonus)===null||n===void 0?void 0:n.metadata)===null||a===void 0?void 0:a.createdAt).toString(),downtime:()=>{window.location.reload()}}),", você poderá alterar sua escolha de usar ou não o Giftback."),!((r=this===null||this===void 0?void 0:this.infoBonus)===null||r===void 0?void 0:r.isBonusProcessed)&&i("div",{key:"aecd80b9920c8b483d38a1c24a6b38ce03d52b64",class:"info-box"},"O Giftback será aplicado na próxima etapa."))}static get watchers(){return{bonus:["changedBonus"]}}};O.style=E;const L=".loading-container{position:absolute;top:0;left:0;width:100%;height:100%;background-color:rgba(0, 0, 0, 0.5);display:flex;justify-content:center;align-items:center;z-index:1000;flex-direction:column;}.loading-container p{margin:6px 0px;color:white;font-size:large}.loading-spinner{width:40px;height:40px;border:5px solid rgba(255, 255, 255, 0.3);border-top:5px solid white;border-radius:50%;animation:spin 1s linear infinite;}@keyframes spin{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}.relative-xy{position:relative}";const B=L;const R=class{constructor(i){t(this,i);this.loading=true;this.text=null}render(){return i("div",{key:"5e323e6b562ee4d770bb2c9f786a23d6b47ce06e",class:"relative-xy"},this.loading&&i("div",{key:"31183c82285ec32c7de0348885d0fd30e4a82502",class:"loading-container"},i("div",{key:"1de235c7594a15e822d044364de0700d3c9e1fa4",class:"loading-spinner"}),this.text&&i("p",{key:"82daa6b96a1e14d83be2fc22fd879b3a41896d0e"},this.text)),i("slot",{key:"09c654783fde15f7b34c4a0804fcec07cfa28b30"}))}};R.style=B;const V=".spinner{display:inline-block;border:4px solid transparent;border-radius:50%;border-top-color:var(--color, #0078d7);animation:spin 1s linear infinite}@keyframes spin{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}";const F=V;const G=class{constructor(i){t(this,i);this.size="50px";this.color="#0078d7"}render(){return i("div",{key:"e1916d264937b0470cd5b1581c87184061b40c3a",class:"spinner",style:{width:this.size,height:this.size,borderColor:`${this.color} transparent transparent transparent`}})}};G.style=F;const $="*{margin:0;padding:0;box-sizing:border-box}:host{--crmfont-sizebodymd:14px;--crmline-heightbodymd:20px;--crmletter-spacingtitle-md:0px}.container-message{font-weight:400;line-height:var(--crmline-heightbodymd);letter-spacing:var(--crmletter-spacingtitle-md);text-align:left;text-underline-position:from-font;text-decoration-skip-ink:none}.crm-container-form{display:flex;flex-direction:column;justify-content:space-around;height:auto;padding:20px 24px 20px 24px;border:1px solid #CCCC;writing-mode:horizontal-tb;gap:16px;border-top:1px solid #ccc !important;border-bottom:1px solid #ccc !important}.crm-phone-form{display:flex;flex-direction:column;height:100%;gap:16px}.crm-subtitle{font-size:.875rem;line-height:1.25rem}.crm-title{font-weight:700;line-height:20px;color:#262626;}.crm-message-info{color:#619013;font-weight:500;}.crm-message-error{color:#E11D48;font-weight:500;}";const Q=$;const _=class{constructor(i){t(this,i);this.value=undefined;this.loading=undefined;this.handlerSubmit=undefined;this.config=undefined}async handlePhone(){const t=await this.phoneInputMask.getPhone();await this.handlerSubmit(t)}render(){var t;return i(e,{key:"b27f64d8464d4c6b259d2d5f0113f55a6f809afb",class:"crm-phone-form"},i("p",{key:"6f279841f43cd7f70f7a1b5340288b9c2d11c551",class:"crm-subtitle"},"Digite o seu celular para verificar se há desconto disponível nessa compra:"),i("phone-input-mask",{key:"7e86f63998a4f35d134b8f4e867a5e5c0b9df20a",initialValue:this.value,ref:t=>this.phoneInputMask=t}),i("crm-button",{key:"462b7cc91f166c8fc588a5c922ba943a6715dca5",txtBtn:((t=this.config)===null||t===void 0?void 0:t.btnApplyBonusLabel)||"Avançar",loading:this.loading,handleClick:()=>this.handlePhone()}))}};_.style=Q;const W="*{margin:0;padding:0;box-sizing:border-box}.phone{display:block;width:100%;height:24px;padding:6px 12px;line-height:1.42857143;color:#555;background-color:#fff;background-image:none;border:1px solid #ccc;border-radius:0px;-webkit-box-shadow:inset 0 1px 1px rgba(0, 0, 0, .075);box-shadow:inset 0 1px 1px rgba(0, 0, 0, .075);-webkit-transition:border-color ease-in-out .15s, -webkit-box-shadow ease-in-out .15s;-o-transition:border-color ease-in-out .15s, box-shadow ease-in-out .15s;transition:border-color ease-in-out .15s, box-shadow ease-in-out .15s}.phone-input-form{width:100%;height:48px;padding:13px 16px 13px 16px;border:1px solid #CCCCCC;}.crm-erro-msg{color:#E11D48;font-weight:500;margin-top:11px}";const Z=W;const J=class{constructor(i){t(this,i);this.phone="";this.message="";this.initialValue=undefined;this.disabled=undefined}componentWillLoad(){this.phone=this.initialValue}formatPhone(t){const i=t.replace(/\D/g,"");const e=i.match(/^(\d{0,2})(\d{0,5})(\d{0,4})$/);if(!e)return t;const o=e[1]?`(${e[1]}`:"";const s=e[2]?`) ${e[2]}`:"";const n=e[3]?` ${e[3]}`:"";return`${o}${s}${n}`}handleInput(t){const i=t.target;this.phone=this.formatPhone(i.value);if(!this.validatePhoneNumber(i.value)){this.message=f}else{this.message=""}console.log("phone",this.phone)}validatePhoneNumber(t){if(t.length<15){return true}const i=/^\(\d{2}\) \d{5} \d{4}$/;return i.test(t)}async getPhone(){return this.phone}render(){return i("div",{key:"bbb0389d0a7ccb8651b8ee20e92dd4cdc94e3617"},i("input",{key:"b36cc9e65314cb786c7f94fee6b4992ba30a82e6",disabled:this.disabled,id:"phone",type:"text",class:"phone-input-form",value:this.phone,onInput:t=>this.handleInput(t),placeholder:"(99) 99999 9999"}),i("p",{key:"81e48cda38cd9a8fc7d753d269425bd4288c57b1",class:"crm-erro-msg"},this.message))}};J.style=Z;const H=":host{display:block}.form-container-pin{display:flex;flex-direction:column;align-items:center}.pin-container{display:flex;justify-content:start;gap:10px}.pin-container input{width:100%;height:48px;text-align:center;border:1px solid #ccc;border-radius:5px}button{padding:10px 20px;background-color:#ddd;border:none;border-radius:5px;cursor:pointer}.success{color:green;margin-top:10px}.button{top:50%;background-color:#6c6c7e;color:#fff;border:none;border-radius:10px;padding:15px;min-height:30px;min-width:120px;cursor:pointer}.button-cancel{top:50%;background-color:#ffffff;color:#1e1c1c;border:1px solid gray;border-radius:10px;padding:10px;min-height:30px;min-width:120px;cursor:pointer}.crm-description{width:100%;display:flex;gap:9px;flex-wrap:wrap}.crm-description a{font-weight:bold;cursor:pointer;text-decoration:underline}.crm-description div{display:flex;gap:5px}";const X=H;const Y="*{margin:0;padding:0;box-sizing:border-box}:host{--crmfont-sizebodymd:14px;--crmline-heightbodymd:20px;--crmletter-spacingtitle-md:0px}.container-message{font-weight:400;line-height:var(--crmline-heightbodymd);letter-spacing:var(--crmletter-spacingtitle-md);text-align:left;text-underline-position:from-font;text-decoration-skip-ink:none}.crm-container-form{display:flex;flex-direction:column;justify-content:space-around;height:auto;padding:20px 24px 20px 24px;border:1px solid #CCCC;writing-mode:horizontal-tb;gap:16px;border-top:1px solid #ccc !important;border-bottom:1px solid #ccc !important}.crm-phone-form{display:flex;flex-direction:column;height:100%;gap:16px}.crm-subtitle{font-size:.875rem;line-height:1.25rem}.crm-title{font-weight:700;line-height:20px;color:#262626;}.crm-message-info{color:#619013;font-weight:500;}.crm-message-error{color:#E11D48;font-weight:500;}";const q=Y;const K=class{constructor(i){t(this,i);this.validate=undefined;this.cancel=undefined;this.resend=undefined;this.sent=undefined;this.loading=false;this.phone=undefined;this.config=undefined;this.pin=["","","",""];this.isVerified=false;this.canResend=false}componentWillLoad(){this.canResend=false}handleInput(t,i){const e=t.target;const o=e.value.slice(0,1);this.pin[i]=o;if(o&&i<this.pin.length-1){const t=e.nextElementSibling;t===null||t===void 0?void 0:t.focus()}this.pin=[...this.pin]}validatePin(){localStorage.removeItem("bc:resend");this.validate(this.pin.join(""))}verifyPin(){const t=this.pin.join("");if(t==="9999"){this.isVerified=true}}handleTimeout(){localStorage.removeItem("bc:resend");this.canResend=true}async handleResend(){await this.resend();this.canResend=false;this.pin=["","","",""];localStorage.removeItem("bc:resend")}buildTime(){const t=localStorage.getItem("bc:resend");if(t){return t}const i=new Date;i.setSeconds(i.getSeconds()+30);localStorage.setItem("bc:resend",i.toString());return i.toString()}render(){var t;return i("div",{key:"3f60e4c74c925daf656092812f40ae0d1f3b5a99",class:"crm-phone-form"},i("label",{key:"d0c023e22ff7eb8978ee6cc0ca4ced8192c53c20",class:"crm-subtitle"},p.t("pin-sutitle")," ",i("strong",{key:"05bb0e2493c99abaa29031a7cc787260266bb417"},"+55 ",this.phone)),i("div",{key:"24c8eb55625f3b880741086c66decd96ecf40044",class:"pin-container"},this.pin.map(((t,e)=>i("input",{type:"text",maxLength:1,value:this.pin[e],onInput:t=>this.handleInput(t,e)})))),i("slot",{key:"02276aa80396d16f779a92a381e75506fa37d56d"}),i("p",{key:"27af068858b3ead8a70b8ec961d367c7beb04d94",class:"crm-description"}," Não recebeu?",!this.canResend&&i("label",{key:"8ef93baf6f92142292078e5e4bcc125ff12b80d7"}," Reenviar em",i("countdown-timer",{key:"f3a0c60c7a88229e37add445886c44b00c60913f",minutos:0,segundos:30,dataCriacao:this.buildTime(),downtime:()=>this.handleTimeout()})," "),this.canResend&&i("div",{key:"2d1b5b028a7085d912acb0d0c696436e8aa75a29"},i("a",{key:"ad9aea2c6f167f1270c75b8dbd2ee79879f7567d",onClick:()=>this.handleResend()},"Reenviar"),i("a",{key:"b0734ab0e472c5cf24fa083c0a712e4f29cf8d79",onClick:()=>this.cancel()},"Trocar número"))),i("crm-button",{key:"39095211d007c871f48971509c3ff52b0f257c29",txtBtn:((t=this.config)===null||t===void 0?void 0:t.btnApplyBonusLabel)||"Avançar",loading:this.loading,handleClick:()=>this.validatePin()}))}};K.style=X+q;export{m as countdown_timer,I as crm_bonus,D as crm_button,j as crm_giftback_form,P as crm_tooltip,O as giftback_info,R as loading_container,G as loading_spinner,_ as phone_form,J as phone_input_mask,K as pin_form};
2
+ //# sourceMappingURL=p-60742512.entry.js.map