'use strict';

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

const index = require('./index-fd2bbf0b.js');
const hardwareBackButton = require('./overlays-0248227e.js');
const store = require('./store-d6f21087.js');
require('./ionic-global-1340f737.js');
require('./helpers-c2496722.js');
require('./index-81aa1bcb.js');
require('./getHandlebarsHelpers-7b2b1728.js');
require('./_commonjsHelpers-a5111d61.js');
require('./logic-d8c34975.js');
require('./index-1f381af8.js');
require('./localforage-af1b8c0e.js');

let ModalEsign = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.fireenjinSubmit = index.createEvent(this, "fireenjinSubmit", 7);
    this.floodteamCloseModal = index.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 hardwareBackButton.toastController.create({
      message: `File(s) added successfully to Efile!`,
      duration: 2000,
    });
    toast.present();
  }
  componentDidLoad() {
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.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 [
      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;

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