'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-3e5ae956.js');
const hardwareBackButton = require('./overlays-b3b752a6.js');
const store = require('./store-c1e254ab.js');
require('./ionic-global-81d6a4bb.js');
require('./helpers-905b0d22.js');
require('./index-b020f7d8.js');
require('./getHandlebarsHelpers-93797155.js');
require('./_commonjsHelpers-a5111d61.js');
require('./index-ba857994.js');
require('./localforage-af1b8c0e.js');

const ModalEsign = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.fireenjinSubmit = index.createEvent(this, "fireenjinSubmit", 7);
    this.floodteamCloseModal = index.createEvent(this, "floodteamCloseModal", 7);
    this.jobId = undefined;
    this.templateId = undefined;
    this.headerTitle = "E-sign";
    this.job = undefined;
    this.loading = false;
    this.signed = false;
    this.isLoaded = false;
  }
  onModalPresent() {
    this.isLoaded = true;
  }
  async onChange(event) {
    var _a;
    if (((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.name) === "signature") {
      const signature = await event.target.toDataURL();
      if (signature.length <= 10) {
        alert("Signature is required to submit!");
        return;
      }
      this.loading = true;
      this.fireenjinSubmit.emit({
        endpoint: "signContract",
        data: {
          jobId: this.jobId,
          signature: await event.target.toDataURL(),
          templateId: this.templateId,
        },
      });
    }
  }
  async onSuccess(event) {
    var _a, _b;
    if (((_a = event === null || event === void 0 ? void 0 : event.detail) === null || _a === void 0 ? void 0 : _a.endpoint) === "signContract") {
      this.presentToast();
      this.loading = false;
      this.signed = true;
      this.floodteamCloseModal.emit();
    }
    else if (((_b = event.detail) === null || _b === void 0 ? void 0 : _b.endpoint) === "findJob") {
      this.loading = false;
    }
  }
  async presentToast() {
    const toast = await hardwareBackButton.toastController.create({
      message: `File(s) added successfully to Efile!`,
      duration: 2000,
    });
    toast.present();
  }
  render() {
    setTimeout(() => {
      try {
        this.templateEl.querySelector(".contract-header").remove();
        this.templateEl.querySelector(".contract-footer").remove();
      }
      catch (e) {
        console.log(e);
      }
    }, 1000);
    return [
      index.h("ion-header", null, index.h("ion-toolbar", null, index.h("ion-title", null, this.headerTitle), index.h("ion-buttons", { slot: "end" }, index.h("ion-button", { onClick: () => this.floodteamCloseModal.emit() }, index.h("ion-icon", { slot: "icon-only", name: "close-circle-outline" }))))),
      index.h("ion-content", { class: {
          "ion-padding": true,
          "is-loading": this.loading,
        } }, this.signed ? (index.h("div", { style: {
          width: "90%",
          maxWidth: "500px",
          margin: "0 auto",
        } }, index.h("ion-icon", { name: "checkmark-circle", color: "success", style: {
          height: "150px",
          width: "150px",
          display: "block",
          margin: "30px auto",
        } }), index.h("h1", null, "Signature Submitted!"), index.h("p", null, "Thank you for your time, you can now close this browser tab."))) : (index.h("div", null, index.h("floodteam-template", { ref: (el) => (this.templateEl = el), class: "fullscreen", templateId: this.templateId, data: {
          timestamp: new Date().toISOString(),
          job: this.job,
          user: store.state === null || store.state === void 0 ? void 0 : store.state.profile,
        } })))),
      this.isLoaded && (index.h("floodteam-signature-pad", { class: {
          "is-loading": this.loading,
        }, ref: (el) => (this.signaturePadEl = el) })),
    ];
  }
};

exports.modal_esign = ModalEsign;
