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MS,OAAOS,WACxBC,WAAYnB,EAAMS,OAAOyB,WAAa,CAAClC,EAAMS,OAAOyB,YAAc,GAClEd,SAAU,SAAFI,OAAWxB,EAAMS,OAAOY,gBAChCE,IAAKE,SAASU,KACdR,MAAO3B,EAAMS,OAAOmB,OACpBC,MAAO3C,EAAec,EAAMS,OAAOI,MAAO,GAAI,CAAEjB,sBAAuB,IACvEwC,eAAgBlD,EAAec,EAAMS,OAAO4B,iBAAkB,GAAI,CAAEzC,sBAAuB,IAC3FkC,UAAW9B,EAAMS,OAAOsB,YAG1B9B,OAAO+B,QAAQC,KAAK,CAAC,QAAS,iBAAkBnB,IAEhDb,OAAO+B,QAAQC,KAAK,CAAC,kBAAmB,CACtCK,MAAOxB,EAAKC,KACZwB,OAAQzB,EAAKG,UACbE,WAAYL,EAAKK,WACjBqB,SAAU1B,EAAKM,SACfqB,IAAK3B,EAAKS,IACVmB,SAAU,CACRf,MAAOb,EAAKa,MACZE,MAAOf,EAAKe,MACZO,eAAgBtB,EAAKsB,kBAG3B,IAUAnC,OAAO+B,QAAU/B,OAAO+B,SAAW,E","sources":["webpack://lange/./scripts/common/utils.ts","webpack://lange/./scripts/integrations/common.ts","webpack://lange/./scripts/integrations/klaviyo/index.ts"],"sourcesContent":["export function formatCurrency(val: number, fallbackValue = '-', options = {}) {\n  if (isNaN(val)) {\n    return fallbackValue;\n  }\n\n  const currencyFormatter = new Intl.NumberFormat('en-US', {\n    style: 'currency',\n    currency: 'USD',\n    minimumFractionDigits: val % 1 === 0 ? 0 : 2,\n    maximumFractionDigits: 2,\n    ...options\n  });\n\n  return currencyFormatter.format(val);\n}\n","/**\n * Appends a script element in the head that loads its url async.\n *\n * @todo set crossorigin or other attributes?\n *\n * @param url The script url to load\n * @returns A promise that resolves to a load event or rejects with an error event\n */\nexport function loadScript(url: string) {\n  return new Promise<Event>((resolve, reject) => {\n    const script = document.createElement('script');\n    script.async = true;\n    script.addEventListener('load', resolve);\n    script.addEventListener('error', reject);\n    document.head.append(script);\n    script.src = url;\n  });\n}\n\n/**\n * Search the queue for events that have already fired. For each event, search for whether we have a\n * listener for the event. If found, directly dispatch the event to the listener. This fixes the\n * issue where the script that loads the registry does not add its event listeners until after the\n * event has fired.\n *\n * Then register event listeners for each key of the registry.\n *\n * We cannot restrict the type of parameters to the callback because we have some special callbacks\n * such as the callback for the global error event. However, most of the time the callback is just\n * one parameter, event of type Event.\n *\n * @param registry An event registry\n */\nexport function setupRegistry(registry: Record<string, (...args: unknown[])=> void>) {\n  for (const event of window.ofir.queue) {\n    const listener = registry[event?.type];\n    if (listener) {\n      listener(event);\n    }\n  }\n\n  for (const eventType in registry) {\n    addEventListener(eventType, registry[eventType]);\n  }\n}\n","import { formatCurrency } from '../../common/utils';\nimport * as common from '../common';\n\nfunction onAddToCart(event: OfirCustomEvents.AddToCartEvent) {\n  if (typeof event.detail !== 'object' || event.detail === null) {\n    return;\n  }\n\n  // Ignore failed adds\n  if (!event.detail.success) {\n    return;\n  }\n\n  for (const lineItem of event.detail.items) {\n    const price = lineItem.price ? lineItem.price / 100 : 0;\n    const item = {\n      Name: lineItem.product_title,\n      ProductID: lineItem.product_id,\n      Categories: <string[]>[],\n      ImageURL: lineItem.featured_image.url,\n      URL: `${location.origin}${lineItem.url}`,\n      Brand: lineItem.vendor,\n      Price: formatCurrency(price, '', { minimumFractionDigits: 2 }),\n      VariantID: lineItem.variant_id\n    };\n\n    window._learnq.push(['track', 'Added to Cart', item]);\n  }\n}\n\nfunction onViewItem(event: WindowEventMap['ofir-view-item']) {\n  if (typeof event.detail !== 'object' || event.detail === null) {\n    return;\n  }\n\n  const item = {\n    Name: event.detail.product_title,\n    ProductID: event.detail.product_id,\n    Categories: event.detail.collection ? [event.detail.collection] : [],\n    ImageURL: `https:${event.detail.featured_image}`,\n    URL: location.href,\n    Brand: event.detail.vendor,\n    Price: formatCurrency(event.detail.price, '', { minimumFractionDigits: 2 }),\n    CompareAtPrice: formatCurrency(event.detail.compare_at_price, '', { minimumFractionDigits: 2 }),\n    VariantID: event.detail.variant_id\n  };\n\n  window._learnq.push(['track', 'Viewed Product', item]);\n\n  window._learnq.push(['trackViewedItem', {\n    Title: item.Name,\n    ItemId: item.ProductID,\n    Categories: item.Categories,\n    ImageUrl: item.ImageURL,\n    Url: item.URL,\n    Metadata: {\n      Brand: item.Brand,\n      Price: item.Price,\n      CompareAtPrice: item.CompareAtPrice\n    }\n  }]);\n}\n\nconst registry = <Record<string, (...args: unknown[])=> void>>{\n  'ofir-add-to-cart': onAddToCart,\n  'ofir-view-item': onViewItem\n};\n\ncommon.setupRegistry(registry);\n\n// @ts-ignore\nwindow._learnq = window._learnq || [];\n"],"names":["formatCurrency","val","fallbackValue","options","isNaN","Intl","NumberFormat","_extends","style","currency","minimumFractionDigits","maximumFractionDigits","format","registry","event","window","ofir","queue","listener","type","eventType","addEventListener","common","detail","success","lineItem","items","price","item","Name","product_title","ProductID","product_id","Categories","ImageURL","featured_image","url","URL","concat","location","origin","Brand","vendor","Price","VariantID","variant_id","_learnq","push","collection","href","CompareAtPrice","compare_at_price","Title","ItemId","ImageUrl","Url","Metadata"],"sourceRoot":""}