{"version":3,"file":"main_js-legacy-mX21-N5Q.js","sources":["../../src/utils/config.js","../../src/utils/mounting.js","../../src/utils/currency.js","../../src/utils/tab_channel.js","../../src/utils/analytics.js","../../src/main.entry.js"],"sourcesContent":["// console.log('Processing config.js, looking for element
')\n// console.log(document.getElementsByTagName('body'))\nexport const getConfig = () => {\n // TODO debug here - reload on local with django cms admin breaks JS\n if (document.getElementsByTagName('body').length > 0)\n return document.getElementsByTagName('body')[0].dataset\n\n}\n\nexport const apiUrl = getConfig()?.['publicApiUrl']\nexport const staticUrl = getConfig()?.['publicStaticUrl']\nexport const debug = getConfig()?.['debug'] === 'True'\n\nexport const isAdmin = !!window.isAdmin // converts to bool\n\nexport const sentryConfig = {\n environment: getConfig() && getConfig()['sentryEnvironment'],\n dsn: 'https://64ad78365fb3f30144ab34182637a77d@o1001156.ingest.sentry.io/4506581831974912',\n traceSampleRate: 0.1,\n sendDefaultPii: true,\n}\n\nexport const clarityConfig = {\n projectId: 'jn8ln6mca7',\n upload: 'https://m.clarity.ms/collect',\n track: true,\n content: true,\n}\n\nexport const currentLanguage = document.getElementsByTagName('html')[0].lang\nexport const currentLocale = (() => {\n switch (currentLanguage) {\n case 'fr':\n return 'fr-FR'\n case 'en':\n return 'en-US'\n case 'pt-br':\n return 'pt-BR'\n case 'es':\n return 'es-ES'\n case 'it':\n return 'it-IT'\n case 'de':\n return 'de-DE'\n case 'cs':\n default:\n return 'cs-CZ'\n }\n})()\n\n\nexport const privacyPolicyScopes = {\n // key is used as id for html elements and storage key acquaring\n analytics: {\n title: 'PRIVACY_ANALYTICS_HEADLINE', // translation key\n description: 'PRIVACY_ANALYTICS_DESCRIPTION', // translation key\n storageKey: 'ANALYTICS' // key in object which is saved to localstorage\n },\n clarity: {\n title: 'PRIVACY_CLARITY_HEADLINE',\n description: 'PRIVACY_CLARITY_DESCRIPTION',\n storageKey: 'CLARITY'\n },\n sentry: {\n title: 'PRIVACY_SENTRY_HEADLINE',\n description: 'PRIVACY_SENTRY_DESCRIPTION',\n storageKey: 'SENTRY'\n }\n}\n\n\nexport const CURRENCY_CONFIG = {\n // TODO get from django\n currencies: ['CZK', 'EUR', 'GBP', 'USD'],\n decimalPlaces: 2,\n formatString: '{INTEGER}.{FRACTION} {CURRENCY}',\n groupSize: 3,\n groupDelimeter: ' ',\n customDecimalPlaces: {\n 'CZK': 0\n },\n customFormatString: {\n 'en': {\n default: '{CURRENCY}{INTEGER}.{FRACTION}',\n 'CZK': '{CURRENCY} {INTEGER}.{FRACTION}',\n },\n 'fr': '{INTEGER},{FRACTION} {CURRENCY}',\n 'cs': '{INTEGER},{FRACTION} {CURRENCY}',\n },\n customGroupSize: {\n // 'en': 3\n },\n customGroupDelimeter: {\n 'en': ','\n },\n\n}","import { currentLanguage } from './config'\n\n\n\n// resolve code running after DOMContent loaded\nexport const postDOM = (callable, ...args) => {\n var loaded = false\n const run = () => {\n if (loaded) return\n loaded = true\n callable(...args)\n }\n\n if (document.readyState !== 'loading') run()\n else document.addEventListener('DOMContentLoaded', run)\n}\n\nexport const interpolate = (fmt, obj, named) => {\n if (named) {\n return fmt.replace(/%\\(\\w+\\)s/g, (match)=>String(obj[match.slice(2,-2)]))\n } else {\n return fmt.replace(/%s/g, () => String(obj.shift()))\n }\n}\n\nexport const webTranslate = (ident, count = 1) => {\n // accepts translation ident or id and returns translated\n // text or original input if translation does not exsist\n // this function has python counterpart (templatetags/mancub_cms.py)\n // TODO fallback languages?\n const webTranlations = JSON.parse(document.getElementById('translation-data').textContent)\n // console.log('WebTranslation ' + ident)\n\n if (currentLanguage === 'cs') {\n // languages with multiple plurals (2, 3, 4 is different from 0, 5, 6, ...)\n if (count !== 1) {\n // determine form of plural\n if ([2, 3, 4].includes(count)) {\n // e.g. 4 obrázky\n count = 2\n }\n else {\n // e.g. 5 obrázků\n count = 5\n }\n\n }\n }\n else {\n // languages with single plural (0, 2, 3, 4, 5, 6 are all second form of plural)\n if (count !== 1) count = 2\n }\n\n for (let index = 0; index < webTranlations.length; index++) {\n const translation = webTranlations[index]\n if ((translation.ident === ident || translation.id === ident) && ((translation.count === undefined && count === 1) || translation.count === count)) {\n return translation.translations__text\n }\n }\n // no translation match\n return ident\n}\n\nexport const addSharedAppGlobals = async app => {\n app.config.globalProperties.webTranslate = webTranslate\n app.config.globalProperties.interpolate = interpolate\n\n app.provide('webTranslate', webTranslate)\n app.provide('interpolate', interpolate)\n\n // app.config.globalProperties.gettext = window.gettext\n // app.config.globalProperties.ngettext = window.ngettext\n // app.config.globalProperties.interpolate = window.interpolate\n // app.config.globalProperties.django = window.django\n\n // // TODO switching currencies\n // app.config.globalProperties.currency = window.gettext('CZK')\n //if (process.env.NODE_ENV === 'production') {\n const injectSentry = vueApp => () => {\n vueApp.mixin(getSentry().createTracingMixins({ trackComponents: true }))\n getSentry().attachErrorHandler(vueApp)\n }\n\n const {subscribeSentryInit, getSentry} = (await import('vendor_modules/sentry'))\n if (getSentry()) injectSentry(app)()\n else {\n subscribeSentryInit(injectSentry(app))\n }\n subscribeSentryInit(injectSentry(app))\n\n //}\n return app\n}","// import { sendMessage, MESSAGES } from './tab_channel'\n\nimport { postDOM, webTranslate } from './mounting'\nimport { CURRENCY_CONFIG, currentLanguage } from './config'\n\nconst CURRENCY_COOKIE = 'currency'\n\nconst getCurrencyCookie = () => {\n const cookies = decodeURIComponent(document.cookie).split(';')\n\n const cookie = cookies.find(c => {\n return c.trim().startsWith(CURRENCY_COOKIE + '=')\n })\n return cookie\n // if setting currency cookie is messed up, this will return undefined\n}\n\nexport const getCurrency = () => {\n let cookie = getCurrencyCookie()\n if (cookie) return cookie.split('=')[1]\n}\n\nexport const setCurrency = currency => {\n const originalCurrency = getCurrency()\n // console.log({originalCurrency, currency})\n document.cookie = `${CURRENCY_COOKIE}=${originalCurrency}; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`\n document.cookie = `${CURRENCY_COOKIE}=${currency}; max-age=${60*60*24*365}; path=/`\n // reload all tabs to get changed currency\n // experimental - cause performance issues if many tabs are open\n // sendMessage(MESSAGES.reload)\n}\n\nconst regexToRemoveDecimalsInCZK = /[,.][0-9][0-9]/\n\n/**\n * @deprecated\n */\nexport const formatCurrency2 = ( value, currency, language ) => {\n // helper function for rounding\n // returns formatted price as string\n // TODO read currency decimals from core settings.CURRENCIES_DECIMALS\n\n let res = new Intl.NumberFormat( language, {\n style: 'currency',\n currency: currency,\n roundingMode:'ceil',\n\n }).format(value)\n\n\n if (currency !== 'CZK') return res\n\n return res.replace(regexToRemoveDecimalsInCZK, '')\n}\n\n/**\n * @deprecated\n */\nexport const formatCurrency3 = (value, currency, language) => {\n\n const str = formatCurrency2(value, currency, language)\n\n if (currency === 'CZK') return str\n\n let i = str.length -1\n\n while (!str[i].match(/(\\.|,)/)) {\n i--\n }\n\n const afterDecimal = str.substring(i+1, str.length)\n\n\n return `${str.substring(0,i)}${str[i]}${afterDecimal.match(/[0-9]+/)[0]}${afterDecimal.match(/[^0-9]+/)?.[0] ?? ''}`\n}\n\n/**\n * @deprecated\n */\nexport const formatCurrency = ( value, currency, language ) => {\n // helper function for rounding\n // returns formatted price as string\n // TODO read currency decimals from core settings.CURRENCIES_DECIMALS\n\n let places\n switch (currency) {\n case 'EUR':\n case 'USD':\n case 'GBP':\n places = 2\n break\n case 'CZK':\n places = 0\n break\n default:\n return value\n }\n value = parseFloat(value).toFixed(places).toString()\n switch (language) {\n case 'cs':\n case 'fr':\n // replace decimal dot for a comma\n value = value.replace(/\\./g, ',')\n break\n }\n return value\n}\n\n\n\n\n\nconst getDecimalPlaces = currency => CURRENCY_CONFIG.customDecimalPlaces[currency] ?? CURRENCY_CONFIG.decimalPlaces\n\nconst getGroupSize = locale => CURRENCY_CONFIG.customGroupSize[locale] ?? CURRENCY_CONFIG.groupSize\n\nconst getGroupDelimeter = locale => CURRENCY_CONFIG.customGroupDelimeter[locale] ?? CURRENCY_CONFIG.groupDelimeter\n\n\nconst _splitNumberIntoGroups = (str, groupSize, groupDelimeter) =>\n (str.match(new RegExp(`(\\\\d+?)(?=(\\\\d{${groupSize}})+(?!\\\\d)|$)`, 'g')))?.join(groupDelimeter) ?? str\n\nconst splitNumberIntoGroups = (str, locale) => _splitNumberIntoGroups(str, getGroupSize(locale), getGroupDelimeter(locale))\n\n\n/**\n * @typedef {{\n * integer: String\n * fraction: String | null\n * }} RawPrice\n *\n * @typedef {{\n * omitSymbol: boolean | undefined\n * decimals: number | undefined\n * substituteZero: boolean | string | undefined\n * }} FormatOptions\n * substituteZero == true - return translation of PRICE_ZERO if price is equal 0.0\n * substituteZero: string - return value of substituteZero if price is equal 0.0\n *\n * @callback FormatCurrency\n * @param {number} value\n * @param {String} currency\n * @param {String} locale\n * @param {FormatOptions} options\n */\n\n/**\n *\n * @type {FormatCurrency}\n * @returns {RawPrice}\n */\nconst getRawPrice = (value, currency, locale = currentLanguage, {decimals = undefined}) => {\n const decPlaces = decimals ?? getDecimalPlaces(currency)\n\n const str = value.toFixed(decPlaces)\n\n\n if (decPlaces == 0) {\n\n return {\n integer: splitNumberIntoGroups(str, locale),\n fraction: null,\n }\n }\n\n const [integer, fraction] = str.split('.')\n\n return {\n integer: splitNumberIntoGroups(integer, locale), fraction: fraction,\n }\n}\n\n\n\n/**\n * @param {String} locale\n * @param {String} currency\n * @param {RawPrice & {options: FormatOptions}} args\n */\nconst formatRawPrice = (locale = currentLanguage, currency, {integer, fraction, options = {}}) => {\n let str = CURRENCY_CONFIG.customFormatString[locale] ?? CURRENCY_CONFIG.formatString\n\n if (typeof str === 'object') str = str[currency] ?? str.default\n\n str = str.replace('{CURRENCY}', options.omitSymbol ? '' : webTranslate(currency))\n str = str.replace('{INTEGER}', integer)\n\n\n if (fraction) return str.replace('{FRACTION}', fraction)\n\n // if fraction is not present comma/period is also removed from final string\n str = str.replace(/(\\.|,)\\{FRACTION\\}/, '')\n\n return str\n}\n\n/**\n * @type {FormatCurrency}\n * @return {String}\n */\nexport const getFormatedPrice = (value, currency = getCurrency(), locale = currentLanguage, options = {}) => {\n if (value === 0.0 && options.substituteZero) {\n if (options.substituteZero == true) return webTranslate('PRICE_ZERO')\n else return options.substituteZero\n }\n\n return formatRawPrice(locale, webTranslate(currency), {...getRawPrice(value, currency, locale, options), options})\n}\n\n/**\n * @type {FormatCurrency}\n * @return {String}\n */\nexport const getCurrencyHTML = (value, currency = getCurrency(), locale, options = {}) => {\n if (value === 0.0 && options.substituteZero) {\n if (options.substituteZero == true) return webTranslate('PRICE_ZERO')\n else return options.substituteZero\n }\n const raw = getRawPrice(value, currency, locale, options)\n\n if (raw.fraction) raw.fraction = `${raw.fraction}`\n\n\n return formatRawPrice(locale, webTranslate(currency), {...raw, options})\n}\n\nconst initHook = async () => {\n\n // const {Popover} = await import('bootstrap')\n\n\n // for (const el of document.querySelectorAll('.price-animate')) {\n // el.classList.add('opacity-0')\n // }\n for (const el of document.querySelectorAll('.price-container')) {\n\n const amount_str = el.dataset['agpAmount']?.match(/[0-9]+((\\.|,)[0-9]+)? [A-Z]{3}/)\n if (amount_str === null) continue\n\n const amount = parseFloat(\n // match any digitsequence or 2 digit sequences separated by dot or comma\n amount_str[0]\n )\n el.innerHTML = getCurrencyHTML(amount)\n\n\n\n\n /*\n const amounts = {}\n for (const key of Object.keys(el.dataset)) {\n const currency = key.match(/price([A-Z][a-z]{0,2})/)?.[1]?.toUpperCase()\n if (!currency) continue\n amounts[currency] = parseFloat(el.dataset[key])\n }\n\n\n\n if (el.dataset.pricePopover !== 'true') continue\n\n const content = document.createElement('table')\n\n\n\n new Popover(el, {\n placement: 'left',\n template: '