<script>
  window.addEventListener('message', (event) => {
    const keys = typeof event.data === 'object' ? Object.keys(event.data) : []
    if (event.origin === 'https://app.doerscircle.com' && keys.length === 5 && keys.some(key => ['firstName', 'isPremiumMember', 'itemCount', 'profileImage', 'userId'].includes(key))) {
      // TODO: code here
      // console.log(event.data.firstName)
      // console.log(event.data.isPremiumMember)
      // console.log(event.data.itemCount)
      // console.log(event.data.profileImage)
      // console.log(event.data.userId)
      // const parseCookie = () =>
      //   document.cookie
      //     .split(';')
      //     .map(v => v.split('='))
      //     .reduce((acc, v) => {
      //       acc[decodeURIComponent(v[0].trim())] = decodeURIComponent(v[1].trim())
      //       return acc
      //     }, {})

      // const cookieData = parseCookie()
      // const { distinct_id, $initial_referrer, $initial_referring_domain } = JSON.parse(cookieData['mp_3a77dd6b8dae22320f9415d6e191d5c3_mixpanel'] ?? '{}')
      // if (window.mixpanel && distinct_id) {
      //   if ($initial_referrer && $initial_referring_domain) {
      //     mixpanel.register_once({ $initial_referrer, $initial_referring_domain })
      //   }

      //   if (/^\d{4}\-\d{4}\-\d{4}$/g.test(distinct_id)) mixpanel.identify(distinct_id)
      //   if (mixpanel.get_distinct_id() !== distinct_id) mixpanel.alias(mixpanel.get_distinct_id(), distinct_id)
      // }

      // const elLoggedOut = document.getElementById('main-CTA-buttons')

      // if (!event.data.firstName) {
      //   elLoggedOut.style.display = 'flex'

      //   return
      // } else {
      //   elLoggedOut.style.display = 'none'
      // }

      // const elLoggedIn = document.getElementById('user-data')
      // const elCart = document.getElementById('cart-icon')
      // const elCartCount = document.getElementById('cart-count')
      // const elUserFirstName = document.getElementById('user-first-name')
      // const elUserProfileImage = document.getElementById('profile-image')

      // if (event.data.itemCount) {
      //   elCartCount.innerText = `(${event.data.itemCount})`
      // } else {
      //   elCart.style.display = 'none'
      // }
      // elUserFirstName.innerText = event.data.firstName
      // if (event.data.profileImage) elUserProfileImage.src = event.data.profileImage

      // elLoggedIn.style.display = 'flex'
    }
  })

  // if (['https://app.doerscircle.com/', 'https://sit.doerscircle.com/'].includes(document.referrer)) {
  //   $(function() {
  //     const headerId = `#header-${document.location.pathname.substring(1)}`

  //     // NOTE: https://discourse.webflow.com/t/close-dropdown-menu/74499/14?page=2
  //     $.data($(headerId).parent()[0], '.wDropdown').open = true
  //     $(`${headerId} .link-list__dropdown-icon`).css({transform: 'translate3d(0px, 0px, 0px) scale3d(1, 1, 1) rotateX(0deg) rotateY(0deg) rotateZ(180deg) skew(0deg, 0deg)'})
  //     $(headerId).addClass('w--open')
  //     $(`${headerId}-menu`).addClass('w--open')
  //   })
  // }
</script>
<iframe style="display:none;" src="https://app.doerscircle.com/data/user"></iframe>