{"version":3,"sources":["webpack:///./LeLab.Web/src/js/locally-dealers.entry.js"],"names":["PageComponent","constructor","node","this","config","companyId","dataset","locallyCompanyId","locale","locallyLocale","btnEndpointUrl","locallyBaseUrl","log","waitForReady","ensureCookieConsent","initLocally","callback","document","readyState","interval","setInterval","clearInterval","window","getCkyConsent","consent","categories","style","display","lcly_config","company_name","company_id","lang","inline","lcly_query","Object","keys","reduce","a","k","push","encodeURIComponent","JSON","stringify","join","appendScript","id","src","s","createElement","async","appendChild","setTimeout","destroy","args"],"mappings":"4FAAA,yBA2GA,IAAIA,IAAc,yBArGlB,MACIC,aAAY,KAAEC,IACVC,KAAKD,KAAOA,EACZC,KAAKC,OAAS,CACVC,UAAWH,EAAKI,QAAQC,iBACxBC,OAAQN,EAAKI,QAAQG,cACrBC,eAAgB,GAAF,OAAKR,EAAKI,QAAQK,eAAlB,mBAGlBR,KAAKS,IAAI,8BAQTT,KAAKU,aAPW,KACPV,KAAKW,uBAEVX,KAAKY,gBAObF,aAAaG,GACT,GAA4B,aAAxBC,SAASC,WACTF,QACG,CACH,MAAMG,EAAWC,YAAY,KACG,aAAxBH,SAASC,aACTG,cAAcF,GACdH,MAEL,MAIXF,sBAEI,IAAKQ,OAAOC,cAAe,OAAO,EAElC,MAAMC,EAAUF,OAAOC,gBAEvB,SAAMC,aAAD,EAACA,EAASC,WAAT,aAENtB,KAAKS,IAAI,mGACTT,KAAKD,KAAKwB,MAAMC,QAAU,QACnB,GAGXZ,cACIZ,KAAKS,IAAI,0CAKT,MAAMgB,EAAc,CAChBC,aAAc,UACdC,WAAY,GAAF,OAAK3B,KAAKC,OAAOC,WAC3B0B,KAAM,GAAF,OAAK5B,KAAKC,OAAOI,QACrBwB,OAAQ,KAGNC,EAAaC,OAAOC,KAAKP,GAC1BQ,QAAO,SAAUC,EAAGC,GAUjB,OATAD,EAAEE,KACEC,mBAAmBF,GACf,IACAE,mBAC8B,iBAAnBZ,EAAYU,IAAsC,OAAnBV,EAAYU,GAC5CG,KAAKC,UAAUd,EAAYU,IAC3BV,EAAYU,KAGvBD,IACR,IACFM,KAAK,KAEJC,EAAe,CAACC,EAAIC,KACtB,MAAMC,EAAI9B,SAAS+B,cAAc,UACjCD,EAAEF,GAAKA,EACPE,EAAEE,OAAQ,EACVF,EAAED,IAAMA,EACR3C,KAAKD,KAAKgD,YAAYH,IAG1BI,WAAW,KACPP,EAAa,gBAAD,UAAqBzC,KAAKC,OAAOM,eAAjC,YAAmDuB,IAC/D9B,KAAKS,IAAI,wCAvFG,KA2FpBwC,UACIjD,KAAKS,IAAL,yCACOT,KAAKD,YACLC,KAAKC,OAGhBQ,IAAIyC,Q","file":"locally-dealers.js","sourcesContent":["import \"./locally-dealers.scss\";\r\nimport { PageComponent } from \"barba\";\r\n\r\nconst reloadTimeoutMs = 1000;\r\nconst cookieConsentLevel = \"necessary\"; // No cookies yet\r\n\r\nclass LocallyDealers {\r\n constructor({ node }) {\r\n this.node = node;\r\n this.config = {\r\n companyId: node.dataset.locallyCompanyId,\r\n locale: node.dataset.locallyLocale,\r\n btnEndpointUrl: `${node.dataset.locallyBaseUrl}/stores/map.js`\r\n };\r\n\r\n this.log(\"LocallyDealers constructor\");\r\n const onReady = () => {\r\n if (!this.ensureCookieConsent()) return;\r\n\r\n this.initLocally();\r\n };\r\n\r\n // Make sure cookieyes has loaded\r\n this.waitForReady(onReady);\r\n }\r\n\r\n waitForReady(callback) {\r\n if (document.readyState === \"complete\") {\r\n callback();\r\n } else {\r\n const interval = setInterval(() => {\r\n if (document.readyState === \"complete\") {\r\n clearInterval(interval);\r\n callback();\r\n }\r\n }, 100);\r\n }\r\n }\r\n\r\n ensureCookieConsent() {\r\n // CookieYes is only available on domain www.devinci.com\r\n if (!window.getCkyConsent) return true;\r\n\r\n const consent = window.getCkyConsent();\r\n\r\n if (!!consent?.categories[cookieConsentLevel]) return true;\r\n\r\n this.log(\"Locally dealer locator will not be activated because the user did not give consent for cookies.\");\r\n this.node.style.display = \"none\";\r\n return false;\r\n }\r\n\r\n initLocally() {\r\n this.log(\"Locally dealer locator initializing...\");\r\n\r\n ////////////////////////////////////////\r\n // Extracted from the locally dealer locator\r\n ////////////////////////////////////////\r\n const lcly_config = {\r\n company_name: \"Devinci\",\r\n company_id: `${this.config.companyId}`,\r\n lang: `${this.config.locale}`,\r\n inline: \"1\"\r\n };\r\n\r\n const lcly_query = Object.keys(lcly_config)\r\n .reduce(function (a, k) {\r\n a.push(\r\n encodeURIComponent(k) +\r\n \"=\" +\r\n encodeURIComponent(\r\n typeof lcly_config[k] === \"object\" && lcly_config[k] !== null\r\n ? JSON.stringify(lcly_config[k])\r\n : lcly_config[k]\r\n )\r\n );\r\n return a;\r\n }, [])\r\n .join(\"&\");\r\n\r\n const appendScript = (id, src) => {\r\n const s = document.createElement(\"script\");\r\n s.id = id;\r\n s.async = true;\r\n s.src = src;\r\n this.node.appendChild(s);\r\n };\r\n\r\n setTimeout(() => {\r\n appendScript(\"lcly-script-0\", `${this.config.btnEndpointUrl}?${lcly_query}`);\r\n this.log(\"Locally dealer locator initialized.\");\r\n }, reloadTimeoutMs);\r\n }\r\n\r\n destroy() {\r\n this.log(`Locally dealer locator destroy`);\r\n delete this.node;\r\n delete this.config;\r\n }\r\n\r\n log(args) {\r\n if (process.env.NODE_ENV !== \"development\") return;\r\n\r\n console.log(args);\r\n }\r\n}\r\n\r\nnew PageComponent(\"[data-locally-dealers]\", LocallyDealers);\r\n"],"sourceRoot":""}