import { Component, Event, Listen, h, Build, } from "@stencil/core";
import { toastController } from "@ionic/core";
export class ModalScanner {
  onReset(event) {
    var _a;
    if (((_a = event.detail) === null || _a === void 0 ? void 0 : _a.endpoint) === "bulkUpdateUsers") {
      const sendEmailModalEl = document.querySelector("ion-modal.modal-scanner");
      if (sendEmailModalEl === null || sendEmailModalEl === void 0 ? void 0 : sendEmailModalEl.dismiss) {
        sendEmailModalEl.dismiss();
      }
    }
  }
  async onSuccess(event) {
    var _a;
    if (((_a = event.detail) === null || _a === void 0 ? void 0 : _a.endpoint) === "bulkUpdateUsers") {
      const sendEmailModalEl = document.querySelector("ion-modal.modal-scanner");
      if (sendEmailModalEl === null || sendEmailModalEl === void 0 ? void 0 : sendEmailModalEl.dismiss) {
        await sendEmailModalEl.dismiss();
        this.presentToast();
      }
    }
  }
  async presentToast() {
    const toast = await toastController.create({
      message: `Scanning...`,
      duration: 2000,
    });
    toast.present();
  }
  onScanSuccess(decodedText, decodedResult) {
    // Handle on success condition with the decoded text or result.
    console.log(`Scan result: ${decodedText}`, decodedResult);
    // ...
    this.qrCodeScanner.clear();
    // ^ this will stop the scanner (video feed) and clear the scan area.
  }
  componentDidLoad() {
    if (!(Build === null || Build === void 0 ? void 0 : Build.isBrowser))
      return;
    setTimeout(() => {
      this.qrCodeScanner = new window.Html5QrcodeScanner("reader", {
        fps: 10,
        qrbox: 250,
      });
      this.qrCodeScanner.render(this.onScanSuccess.bind(this));
    }, 100);
  }
  render() {
    return [
      h("ion-header", null,
        h("ion-toolbar", null,
          h("ion-title", null, "Scan QR Code"),
          h("ion-buttons", { slot: "end" },
            h("ion-button", { onClick: () => this.floodteamCloseModal.emit(), style: {
                "--color": "var(--ion-text-color)",
                "--color-hover": "var(--ion-color-danger",
              } },
              h("ion-icon", { slot: "icon-only", name: "close-circle-outline" }))))),
      h("ion-content", null,
        h("div", { id: "reader" })),
    ];
  }
  static get is() { return "modal-scanner"; }
  static get originalStyleUrls() { return {
    "$": ["modal-scanner.css"]
  }; }
  static get styleUrls() { return {
    "$": ["modal-scanner.css"]
  }; }
  static get events() { return [{
      "method": "floodteamCloseModal",
      "name": "floodteamCloseModal",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }]; }
  static get listeners() { return [{
      "name": "fireenjinReset",
      "method": "onReset",
      "target": "body",
      "capture": false,
      "passive": false
    }, {
      "name": "fireenjinSuccess",
      "method": "onSuccess",
      "target": "body",
      "capture": false,
      "passive": false
    }]; }
}
