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G,MAAAe,GAAS,MAAMpC,EAAA,GAAiB,QAC/B,OAAAK,EACLI,EACAY,EACAnB,EACCmC,GAAcL,EAAKI,EAAOC,CAAS,GAAKJ,EAAQI,CAAS,EAC5D,EAyBA,uBAtB6B,MAC7BpB,EACAC,IAIG,CACG,MAAAkB,GAAS,MAAMpC,EAAA,GAAiB,QAC/B,OAAAgB,EACLC,EACAC,EACAhB,EACCmC,GAAcL,EAAKI,EAAOC,CAAS,GAAKJ,EAAQI,CAAS,EAC1DlB,CAAA,CACF,CAQA,CAEJ","names":["parseNumber","number","strg","decimal","GET_BESTPRICE","isShopFunction","fischer","enableTrackingFunction","enableTrackingShopFunction","getPriceForTrackingFunction","productIdUnpadded","qty","getBestPriceQuery","productId","result","bestPrice","_a","_b","_c","error","trackAddMultipleToCartFunction","cartId","productsWithQuantity","sendEvent","items","quantity","item","totalPrice","currency","captureException","useTracking","useFischer","useEventHub","enableTracking","enableTrackingShop","isShop","load","refetch","useLazyQuery","DUMMY","query","variables"],"ignoreList":[],"sources":["../../src/utils/parseNumber.ts","../../src/composables/tracking.ts"],"sourcesContent":["export default (number: string | number) => {\n  let strg = number.toString() || '';\n  let decimal = '.';\n\n  strg = strg.replace(/[^0-9$.,]/g, '');\n  if (strg.indexOf(',') > strg.indexOf('.')) decimal = ',';\n  if ((strg.match(new RegExp(`\\\\${decimal}`, 'g')) || []).length > 1) decimal = '';\n  strg = strg.replace(new RegExp(`[^0-9$${decimal}]`, 'g'), '');\n  strg = strg.replace(',', '.');\n\n  return parseFloat(strg);\n};\n","import { captureException } from '@sentry/browser';\nimport { useLazyQuery } from '@vue/apollo-composable';\nimport DUMMY from 'gql/dummy.gql';\nimport parseNumber from 'utils/parseNumber';\n\nimport type { FischerPlugin } from '@/lib/fischerPlugin';\n\nimport { useEventHub } from './eventHub';\nimport { useFischer } from './fischerPlugin';\n\n// @ts-ignore\nconst GET_BESTPRICE = () => import('gql/getBestPrice.gql');\n\nexport type TrackingEventItem = {\n  currency?: string;\n  item_name?: string;\n  item_id?: string;\n  item_brand?: string;\n  item_list_name?: string;\n  item_list_id?: string;\n  index?: number;\n  item_variant?: string;\n  price?: number;\n  productPrice?: number;\n  productId?: string;\n  quantity?: number;\n  cart_id?: number | string;\n};\n\nexport const isShopFunction = (fischer: FischerPlugin): boolean =>\n  fischer.shop.isClosedShop() || fischer.shop.isOnlineShop();\n\nexport const enableTrackingFunction = (fischer: FischerPlugin): boolean =>\n  fischer.enableAnalytics();\n\nexport const enableTrackingShopFunction = (fischer: FischerPlugin): boolean =>\n  isShopFunction(fischer) || fischer.shop.isRetailConnectCart();\n\nexport const getPriceForTrackingFunction = async (\n  productIdUnpadded: string,\n  qty: number = 0,\n  fischer: FischerPlugin,\n  getBestPriceQuery: (variables: {\n    baseSiteId: string;\n    accessToken: string;\n    productCode: string;\n    qty: number;\n    language: string;\n    expired: boolean;\n    userId: string;\n  }) => Promise<{ data?: any } | undefined>,\n): Promise<{\n  price: number | undefined;\n  quantity: number;\n  currency: string;\n  totalPrice: number | undefined;\n}> => {\n  if (isShopFunction(fischer) && productIdUnpadded) {\n    try {\n      const productId = productIdUnpadded.padStart(6, '0');\n      const result = await getBestPriceQuery({\n        baseSiteId: fischer.baseSiteId(),\n        accessToken: fischer.user.accessToken(),\n        productCode: productId,\n        qty: qty,\n        language: fischer.siteLanguage(),\n        expired: true,\n        userId: fischer.user.id(),\n      });\n\n      const bestPrice = result?.data?.getBestPrice;\n      if (\n        bestPrice &&\n        bestPrice.price?.valueFormatted &&\n        bestPrice.price?.totalValueFormatted &&\n        bestPrice.initialQuantity\n      ) {\n        return {\n          currency: bestPrice.price.currencyIso,\n          price: parseNumber(bestPrice.price.valueFormatted) / bestPrice.initialQuantity,\n          quantity: bestPrice.initialQuantity || '1',\n          totalPrice: parseNumber(bestPrice.price.totalValueFormatted),\n        };\n      }\n\n      return { price: undefined, quantity: qty, currency: '', totalPrice: undefined };\n    } catch (error) {\n      // eslint-disable-next-line no-console\n      console.trace('error getting best price', error, productIdUnpadded, qty);\n    }\n  }\n\n  return { price: undefined, quantity: qty, currency: '', totalPrice: undefined };\n};\n\nexport const trackAddMultipleToCartFunction = async (\n  cartId: number | string,\n  productsWithQuantity: {\n    id: string;\n    quantity: number;\n  }[],\n  fischer: FischerPlugin,\n  getBestPriceQuery: Parameters<typeof getPriceForTrackingFunction>[3],\n  sendEvent: (\n    type: string,\n    data: {\n      cartId: string | number;\n      items: TrackingEventItem[];\n    },\n  ) => Promise<void>,\n) => {\n  try {\n    if (!(enableTrackingFunction(fischer) && enableTrackingShopFunction(fischer))) {\n      return;\n    }\n\n    const itemsWithNull: (TrackingEventItem | null)[] = await Promise.all(\n      productsWithQuantity.map(async ({ id: productId, quantity }: any) => {\n        try {\n          const item: TrackingEventItem = {\n            productId,\n            quantity,\n          };\n          const { totalPrice, currency } = await getPriceForTrackingFunction(\n            productId,\n            quantity,\n            fischer,\n            getBestPriceQuery,\n          );\n          if (totalPrice) {\n            item.productPrice = totalPrice;\n            item.currency = currency;\n          }\n          return item;\n        } catch (error) {\n          console.error('could not get info on product', productId, quantity, error);\n          return null;\n        }\n      }),\n    );\n    const items = itemsWithNull.filter((item) => item) as TrackingEventItem[];\n\n    if (items.length) {\n      sendEvent('add_to_cart', {\n        cartId,\n        items,\n      });\n    }\n  } catch (error) {\n    console.error(error);\n    captureException(error);\n  }\n};\n\nexport const useTracking = () => {\n  const fischer = useFischer();\n  const { sendEvent } = useEventHub();\n\n  const enableTracking = () => enableTrackingFunction(fischer);\n\n  const enableTrackingShop = () => enableTrackingShopFunction(fischer);\n\n  const isShop = () => isShopFunction(fischer);\n\n  type getPriceForTrackingParams = Parameters<typeof getPriceForTrackingFunction>;\n  const { load, refetch } = useLazyQuery(DUMMY);\n  const getPriceForTracking = async (\n    productId: getPriceForTrackingParams[0],\n    quantity: getPriceForTrackingParams[1],\n  ) => {\n    const query = (await GET_BESTPRICE()).default;\n    return getPriceForTrackingFunction(\n      productId,\n      quantity,\n      fischer,\n      (variables) => load(query, variables) || refetch(variables),\n    );\n  };\n\n  const trackAddMultipleToCart = async (\n    cartId: number | string,\n    productsWithQuantity: {\n      id: string;\n      quantity: number;\n    }[],\n  ) => {\n    const query = (await GET_BESTPRICE()).default;\n    return trackAddMultipleToCartFunction(\n      cartId,\n      productsWithQuantity,\n      fischer,\n      (variables) => load(query, variables) || refetch(variables),\n      sendEvent,\n    );\n  };\n\n  return {\n    enableTracking,\n    enableTrackingShop,\n    isShop,\n    getPriceForTracking,\n    trackAddMultipleToCart,\n  };\n};\n"],"file":"assets/tracking-jEMpK71t.js"}