import { Controller } from '@hotwired/stimulus';
import { WpjModal } from '@assets/components/wpj.modal';

const AGE_VERIFICATION_KEY = "age-verified";

const ageVerifyModal = new WpjModal(
   document.querySelector('[data-modal-endpoint="agepopup"]'),
   false
);

export default class extends Controller<HTMLDivElement> {
   static targets = ["simple"];

   initialize() {
      if (window.sessionStorage.getItem(AGE_VERIFICATION_KEY) !== "verified") {
         this.element.style.display = "inline-block";
         ageVerifyModal.create({ endpoint: 'agepopup' });
      }
   }

   verify() {
      window.sessionStorage.setItem(AGE_VERIFICATION_KEY, "verified");
      ageVerifyModal.hide(ageVerifyModal.modal);
   }

   cancel() {
      window.history.back();
   }
}
