import { r as registerInstance, d as createEvent, h } from './index-33e43734.js';
import { t as toastController } from './overlays-97615cf7.js';
import { s as state } from './store-729235b6.js';
import './ionic-global-bd76bde2.js';
import './helpers-a9270f9e.js';
import './index-91eb4513.js';
import './getCache-f7c123d8.js';
import './_commonjsHelpers-cca61ea8.js';
import './logic-2eecfe1e.js';
import './index-964da72a.js';

let ModalEsign = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.fireenjinSubmit = createEvent(this, "fireenjinSubmit", 7);
    this.floodteamCloseModal = createEvent(this, "floodteamCloseModal", 7);
    this.headerTitle = "E-sign";
    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 toastController.create({
      message: `File(s) added successfully to Efile!`,
      duration: 2000,
    });
    toast.present();
  }
  render() {
    return [
      h("ion-header", null, h("ion-toolbar", null, h("ion-title", null, this.headerTitle), h("ion-buttons", { slot: "end" }, h("ion-button", { onClick: () => this.floodteamCloseModal.emit() }, h("ion-icon", { slot: "icon-only", name: "close-circle-outline" }))))),
      h("ion-content", { class: {
          "ion-padding": true,
          "is-loading": this.loading,
        } }, this.signed ? (h("div", { style: {
          width: "90%",
          maxWidth: "500px",
          margin: "0 auto",
        } }, h("ion-icon", { name: "checkmark-circle", color: "success", style: {
          height: "150px",
          width: "150px",
          display: "block",
          margin: "30px auto",
        } }), h("h1", null, "Signature Submitted!"), h("p", null, "Thank you for your time, you can now close this browser tab."))) : (h("div", null, h("floodteam-template", { class: "fullscreen", templateId: this.templateId, data: {
          timestamp: new Date().toISOString(),
          job: state === null || state === void 0 ? void 0 : state.job,
          user: state === null || state === void 0 ? void 0 : state.profile,
        } })))),
      this.isLoaded && (h("floodteam-signature-pad", { class: {
          "is-loading": this.loading,
        }, ref: (el) => (this.signaturePadEl = el) })),
    ];
  }
};

export { ModalEsign as modal_esign };

//# sourceMappingURL=modal-esign.entry.js.map