{"version":3,"file":"video_controller-QilVyl19.js","sources":["../../../app/javascript/controllers/video_controller.js"],"sourcesContent":["import { Modal } from 'tailwindcss-stimulus-components'\nimport { Controller } from 'stimulus'\n\nexport default class extends Modal {\n static targets = ['hide', 'video', 'container']\n\n initialize() {\n this.pauseVideo = this.pauseVideo.bind(this)\n super.initialize()\n }\n\n disconnect() {\n if (this.hasVideoTarget) {\n this.videoTarget.removeEventListener('load', this.pauseVideo)\n }\n\n super.disconnect()\n }\n\n close(t) {\n super.close(t)\n this.dispatch('closed')\n\n if (this.hasVideoTarget) {\n // this.videoTarget.pause()\n\n if (this.videoTarget.contentWindow === null) {\n this.videoTarget.addEventListener('load', this.pauseVideo)\n } else {\n this.pauseVideo()\n }\n\n this.videoTarget.contentWindow.blur()\n this.videoTarget.blur()\n }\n\n // Remove iframe when modal closes\n this.containerTarget.innerHTML = ''\n }\n\n open(t) {\n super.open(t)\n this.dispatch('opened')\n\n if (this.hasVideoTarget) {\n // this.videoTarget.play()\n\n if (this.videoTarget.contentWindow === null) {\n this.videoTarget.addEventListener('load', this.pauseVideo)\n } else {\n this.pauseVideo()\n }\n }\n\n // Create and insert iframe only when modal opens\n const iframe = document.createElement('iframe')\n iframe.setAttribute(\n 'src',\n 'https://www.youtube.com/embed/jpZkPKzGrgU?autoplay=1&theme=light&color=white&autohide=0&modestbranding=1&showinfo=0&rel=0&enablejsapi=1'\n )\n iframe.setAttribute('frameborder', '0')\n iframe.setAttribute('allow', 'autoplay; encrypted-media')\n iframe.setAttribute('class', 'w-full aspect-[1/0.526] -mb-px')\n iframe.setAttribute('data-video-target', 'video')\n\n this.containerTarget.innerHTML = ''\n this.containerTarget.appendChild(iframe)\n }\n\n hideTargetConnected() {\n this.close()\n this.hideTarget.remove()\n\n if (this.hasVideoTarget) {\n // this.videoTarget.pause()\n if (this.videoTarget.contentWindow === null) {\n this.videoTarget.addEventListener('load', this.pauseVideo)\n } else {\n this.pauseVideo()\n }\n }\n }\n\n pauseVideo() {\n this.videoTarget.contentWindow.postMessage(\n '{\"event\":\"command\",\"func\":\"pauseVideo\",\"args\":\"\"}',\n '*'\n )\n\n this.videoTarget.contentWindow.blur()\n this.videoTarget.blur()\n }\n}\n"],"names":["video_controller","Modal","t","iframe","__publicField"],"mappings":"4QAGe,MAAKA,UAASC,CAAM,CAGjC,YAAa,CACX,KAAK,WAAa,KAAK,WAAW,KAAK,IAAI,EAC3C,MAAM,WAAU,CACpB,CAEE,YAAa,CACP,KAAK,gBACP,KAAK,YAAY,oBAAoB,OAAQ,KAAK,UAAU,EAG9D,MAAM,WAAU,CACpB,CAEE,MAAMC,EAAG,CACP,MAAM,MAAMA,CAAC,EACb,KAAK,SAAS,QAAQ,EAElB,KAAK,iBAGH,KAAK,YAAY,gBAAkB,KACrC,KAAK,YAAY,iBAAiB,OAAQ,KAAK,UAAU,EAEzD,KAAK,WAAU,EAGjB,KAAK,YAAY,cAAc,KAAI,EACnC,KAAK,YAAY,KAAI,GAIvB,KAAK,gBAAgB,UAAY,EACrC,CAEE,KAAKA,EAAG,CACN,MAAM,KAAKA,CAAC,EACZ,KAAK,SAAS,QAAQ,EAElB,KAAK,iBAGH,KAAK,YAAY,gBAAkB,KACrC,KAAK,YAAY,iBAAiB,OAAQ,KAAK,UAAU,EAEzD,KAAK,WAAU,GAKnB,MAAMC,EAAS,SAAS,cAAc,QAAQ,EAC9CA,EAAO,aACL,MACA,yIACN,EACIA,EAAO,aAAa,cAAe,GAAG,EACtCA,EAAO,aAAa,QAAS,2BAA2B,EACxDA,EAAO,aAAa,QAAS,gCAAgC,EAC7DA,EAAO,aAAa,oBAAqB,OAAO,EAEhD,KAAK,gBAAgB,UAAY,GACjC,KAAK,gBAAgB,YAAYA,CAAM,CAC3C,CAEE,qBAAsB,CACpB,KAAK,MAAK,EACV,KAAK,WAAW,OAAM,EAElB,KAAK,iBAEH,KAAK,YAAY,gBAAkB,KACrC,KAAK,YAAY,iBAAiB,OAAQ,KAAK,UAAU,EAEzD,KAAK,WAAU,EAGvB,CAEE,YAAa,CACX,KAAK,YAAY,cAAc,YAC7B,oDACA,GACN,EAEI,KAAK,YAAY,cAAc,KAAI,EACnC,KAAK,YAAY,KAAI,CACzB,CACA,CAxFEC,EADkBJ,EACX,UAAU,CAAC,OAAQ,QAAS,WAAW"}