{"version":3,"file":"HeaderPersistentBar-CUl33apM-chunk.js","sources":["../../../src/components/header/HeaderPersistentBar.jsx"],"sourcesContent":["import React, { Component, Fragment } from \"react\";\nimport PropTypes from \"prop-types\";\nimport ImageX from \"components/utility/images/ImageX\";\nimport { getDecodedHtml } from \"utils/getDecodedHtml\";\n\nclass HeaderPersistentBar extends Component {\n\tconstructor(props) {\n\t\tsuper(props);\n\t\tthis.state = {\n\t\t\tclosed: false,\n\t\t\tsubmitting: false\n\t\t};\n\t\tthis.containerRef = React.createRef();\n\t}\n\n\tcomponentDidMount() {\n\t\tif (this.props.data && this.props.type === \"bottom\") {\n\t\t\tthis.onResize();\n\t\t\twindow.addEventListener(\"resize\", this.onResize);\n\t\t}\n\n\t\tif (this.props.data !== undefined && this.props.data !== null) {\n\t\t\twindow.dataLayer = window.dataLayer || [];\n\t\t\twindow.dataLayer.push({\n\t\t\t\t\"data-a-lbl\": \"Banner Initiated\",\n\t\t\t\t\"data-a-cat\": \"Redirect Banner\",\n\t\t\t\t\"data-a-act\":\n\t\t\t\t\t\"Visiting \" +\n\t\t\t\t\tthis.props.data.visitingCountryCode +\n\t\t\t\t\t\", Previously \" +\n\t\t\t\t\tthis.props.data.currentCountryCode\n\t\t\t});\n\t\t}\n\t}\n\n\tonResize() {\n\t\tconst bottomPersistentBar = document.querySelector(\".header-persistent-bar-bottom\");\n\t\tconst topPersistentBar = document.querySelector(\".header-persistent-bar-top\");\n\t\tconst firstLogin = document.querySelector(\".header-persistent-bar-without-line\");\n\t\tif (window.innerWidth < 768) {\n\t\t\tif (topPersistentBar && bottomPersistentBar) {\n\t\t\t\tbottomPersistentBar.style.top = \"auto\";\n\t\t\t}\n\t\t} else {\n\t\t\tconst placeholder = document.querySelector(\".header-persistent-bar-bottom-placeholder\");\n\t\t\tplaceholder.insertAdjacentElement(\"afterend\", bottomPersistentBar);\n\t\t\tif (topPersistentBar && bottomPersistentBar && firstLogin) {\n\t\t\t\tbottomPersistentBar.style.top = topPersistentBar.clientHeight + \"px\";\n\t\t\t}\n\t\t}\n\t}\n\tonClose = (e) => {\n\t\te.preventDefault();\n\t\tthis.post(\n\t\t\t\"SESSION\",\n\t\t\t() => {\n\t\t\t\tthis.setState({\n\t\t\t\t\tclosed: true,\n\t\t\t\t\tsubmitting: false\n\t\t\t\t});\n\t\t\t\tthis.adjustStickyHeader(false);\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tthis.setState({\n\t\t\t\t\tclosed: true,\n\t\t\t\t\tsubmitting: false\n\t\t\t\t});\n\t\t\t\tthis.adjustStickyHeader(false);\n\t\t\t}\n\t\t);\n\t};\n\tonCta = (e) => {\n\t\te.preventDefault();\n\t\tthis.post(\n\t\t\t\"PERMANENT\",\n\t\t\t() => {\n\t\t\t\tthis.setState({\n\t\t\t\t\tclosed: true,\n\t\t\t\t\tsubmitting: false\n\t\t\t\t});\n\t\t\t\tthis.adjustStickyHeader(true);\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tthis.setState({\n\t\t\t\t\tclosed: true,\n\t\t\t\t\tsubmitting: false\n\t\t\t\t});\n\t\t\t\tthis.adjustStickyHeader(true);\n\t\t\t}\n\t\t);\n\t};\n\tsetCountryCookie = (e) => {\n\t\tthis.onClose(e);\n\t\tfetch(this.props.data.countryAPIEndpoint, {\n\t\t\tcredentials: \"same-origin\",\n\t\t\tmethod: \"POST\",\n\t\t\theaders: {\n\t\t\t\tAccept: \"application/json\",\n\t\t\t\t\"Content-Type\": \"application/json\"\n\t\t\t},\n\t\t\tbody: JSON.stringify({ countryValue: this.props.data.countryValue })\n\t\t})\n\t\t\t.then((res) => res.json())\n\t\t\t.catch((error) => {\n\t\t\t\tconsole.log(error);\n\t\t\t});\n\t};\n\tadjustStickyHeader(redirect) {\n\t\tconst persistentBar = this.containerRef.current;\n\t\tconst hardHeight = persistentBar.offsetHeight + \"px\";\n\t\tpersistentBar.style.height = hardHeight;\n\t\tsetTimeout(() => {\n\t\t\tif (persistentBar.classList.contains(\"header-persistent-bar-top\")) {\n\t\t\t\tconst firstPlaceholder = document.querySelector(\".sticky-header-placeholder\");\n\t\t\t\tconst firstStickyEl = document.querySelector(\".sticky-header-el\");\n\t\t\t\tif (firstPlaceholder) {\n\t\t\t\t\tfirstPlaceholder.style.height =\n\t\t\t\t\t\tfirstStickyEl.offsetHeight - persistentBar.offsetHeight + \"px\";\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tpersistentBar.style.height = \"0px\";\n\n\t\t\tif (redirect) {\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tif (this.props.data.ctaUrl && this.props.data.ctaUrl.length) {\n\t\t\t\t\t\tif (this.props.data.ctaTarget && this.props.data.ctaTarget.length) {\n\t\t\t\t\t\t\twindow.open(this.props.data.ctaUrl, this.props.data.ctaTarget);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\twindow.location = this.props.data.ctaUrl;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}, 400);\n\t\t\t}\n\t\t}, 50);\n\t}\n\tpost(acceptanceType, success, error) {\n\t\tif (!this.state.submitting) {\n\t\t\tthis.setState({ submitting: true });\n\t\t\tfetch(this.props.data.url, {\n\t\t\t\tcredentials: \"same-origin\",\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\tAccept: \"application/json\",\n\t\t\t\t\t\"Content-Type\": \"application/json\"\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({ notificationId: this.props.data.notificationId, acceptanceType })\n\t\t\t})\n\t\t\t\t.then((res) => res.json())\n\t\t\t\t.then(success)\n\t\t\t\t.catch(error);\n\t\t}\n\t}\n\trender() {\n\t\tif (!this.props.data) {\n\t\t\treturn \"\";\n\t\t}\n\n\t\tconst { color, type, data, dataset } = this.props;\n\t\tconst {\n\t\t\tcountryFlag = false,\n\t\t\tsetCountryCookieText,\n\t\t\tctaText,\n\t\t\tctaUrl,\n\t\t\tvisitingCountryCode,\n\t\t\tcurrentCountryCode\n\t\t} = data;\n\t\tconst { withoutLine = false, publicSite = false } = dataset;\n\t\tlet button = null,\n\t\t\tcloseButton = null,\n\t\t\tbottomPlaceholder = null;\n\t\tif (ctaText && ctaUrl) {\n\t\t\tbutton = data.countryFlag ? (\n\t\t\t\t