{
  "version": 3,
  "sources": ["/cdn/shop/t/7/assets/nocturne-reviews.js?nx=1793709184493"],
  "sourcesContent": ["/**\n * <nocturne-first-review> \u2014 the first visual of sections/nocturne-reviews.liquid, while a product has no\n * review yet. Its card opens the reviews app's own form by clicking the \"write a review\" button of the\n * app's widget, which stays hidden: Judge.me's form opens as a pop-up over the page. A star clicked on the\n * card is passed on as the rating. The widget may be drawn late, so the button is waited for; the older\n * Judge.me widget opens its form inline, so then (or if the app drew nothing) the widget is shown instead.\n */\n(() => {\n  if (customElements.get('nocturne-first-review')) return;\n\n  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));\n\n  // The element, once it shows up (or null after 4 s).\n  async function wait(root, selector) {\n    for (let i = 0; i < 40; i++) {\n      const el = root.querySelector(selector);\n      if (el) return el;\n      await sleep(100);\n    }\n    return null;\n  }\n\n  class NocturneFirstReview extends HTMLElement {\n    connectedCallback() {\n      this.app = this.querySelector('.nx-reviews__app');\n      this.querySelector('[data-write]')?.addEventListener('click', (event) => {\n        this.write(event.target.closest('[data-star]')?.dataset.star);\n      });\n    }\n\n    async write(star) {\n      if (!this.app || this.busy) return;\n      this.busy = true;\n      const button = await wait(this.app, '.jm-action-buttons__button, .jdgm-write-rev-link');\n      if (!button || button.matches('.jdgm-write-rev-link')) {\n        this.app.hidden = false;\n        this.app.scrollIntoView({ behavior: 'smooth', block: 'start' });\n      }\n      button?.click();\n      if (button && star) {\n        // The pop-up redraws its stars a moment after it opens: click the current one until the rating takes.\n        const selector = `.jdgm-write-review-modal__stars [data-alt=\"${star}\"]`;\n        for (let i = 0; i < 20 && !document.querySelector('.jdgm-write-review-modal input[name=\"score\"]')?.value; i++) {\n          await sleep(200);\n          document.querySelector(selector)?.click();\n        }\n      }\n      this.busy = false;\n    }\n  }\n\n  customElements.define('nocturne-first-review', NocturneFirstReview);\n})();\n"],
  "mappings": "CAOC,IAAM,CACL,GAAI,eAAe,IAAI,uBAAuB,EAAG,OAEjD,MAAM,MAAS,IAAO,IAAI,QAAS,SAAY,WAAW,QAAS,EAAE,CAAC,EAGtE,eAAe,KAAK,KAAM,SAAU,CAClC,QAAS,EAAI,EAAG,EAAI,GAAI,IAAK,CAC3B,MAAM,GAAK,KAAK,cAAc,QAAQ,EACtC,GAAI,GAAI,OAAO,GACf,MAAM,MAAM,GAAG,CACjB,CACA,OAAO,IACT,CAEA,MAAM,4BAA4B,WAAY,CAC5C,mBAAoB,CAClB,KAAK,IAAM,KAAK,cAAc,kBAAkB,EAChD,KAAK,cAAc,cAAc,GAAG,iBAAiB,QAAU,OAAU,CACvE,KAAK,MAAM,MAAM,OAAO,QAAQ,aAAa,GAAG,QAAQ,IAAI,CAC9D,CAAC,CACH,CAEA,MAAM,MAAM,KAAM,CAChB,GAAI,CAAC,KAAK,KAAO,KAAK,KAAM,OAC5B,KAAK,KAAO,GACZ,MAAM,OAAS,MAAM,KAAK,KAAK,IAAK,kDAAkD,EAMtF,IALI,CAAC,QAAU,OAAO,QAAQ,sBAAsB,KAClD,KAAK,IAAI,OAAS,GAClB,KAAK,IAAI,eAAe,CAAE,SAAU,SAAU,MAAO,OAAQ,CAAC,GAEhE,QAAQ,MAAM,EACV,QAAU,KAAM,CAElB,MAAM,SAAW,8CAA8C,IAAI,KACnE,QAAS,EAAI,EAAG,EAAI,IAAM,CAAC,SAAS,cAAc,8CAA8C,GAAG,MAAO,IACxG,MAAM,MAAM,GAAG,EACf,SAAS,cAAc,QAAQ,GAAG,MAAM,CAE5C,CACA,KAAK,KAAO,EACd,CACF,CAEA,eAAe,OAAO,wBAAyB,mBAAmB,CACpE,GAAG",
  "names": []
}
