import { r as registerInstance, d as createEvent, B as Build, h } from './index-33e43734.js';
import { t as toastController } from './overlays-0a1b9fc7.js';
import { s as state } from './store-be7d1de5.js';
import './ionic-global-bd76bde2.js';
import './helpers-7e937ffa.js';
import './index-91eb4513.js';
import './getHandlebarsHelpers-91de4454.js';
import './_commonjsHelpers-4ed75ef8.js';
import './logic-88140d62.js';
import './index-d4e79b88.js';
import './localforage-9daa31d6.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();
  }
  componentDidLoad() {
    if (!(Build === null || Build === void 0 ? void 0 : Build.isBrowser))
      return;
    try {
      this.templateEl
        .querySelector("fireenjin-render-template")
        .shadowRoot.querySelector(".contract-header")
        .remove();
      this.templateEl
        .querySelector("fireenjin-render-template")
        .shadowRoot.querySelector(".contract-footer")
        .remove();
    }
    catch (e) {
      console.log(e);
    }
  }
  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", { ref: (el) => (this.templateEl = el), class: "fullscreen", templateId: this.templateId, data: {
          timestamp: new Date().toISOString(),
          job: this.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