'use strict';

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

const index = require('./index-cba1c3ae.js');
const hardwareBackButton = require('./overlays-e0a7d0eb.js');
const store = require('./store-49e3b933.js');
require('./ionic-global-01cd0200.js');
require('./helpers-c2496722.js');
require('./getHandlebarsHelpers-7b2b1728.js');
require('./_commonjsHelpers-a5111d61.js');
require('./logic-d8c34975.js');
require('./index-1f381af8.js');
require('./localforage-af1b8c0e.js');

const appSignCss = "";

const AppSign = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.fireenjinFetch = index.createEvent(this, "fireenjinFetch", 7);
    this.fireenjinSubmit = index.createEvent(this, "fireenjinSubmit", 7);
    this.forceResize = index.createEvent(this, "forceResize", 7);
    this.loading = false;
    this.signed = false;
  }
  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, _c, _d;
    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;
    }
    else if (((_b = event.detail) === null || _b === void 0 ? void 0 : _b.endpoint) === "findTemplate") {
      this.template = ((_d = (_c = event.detail) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.template)
        ? event.detail.data.template
        : null;
    }
  }
  async fetchJob() {
    if (!this.jobId)
      return;
    this.fireenjinFetch.emit({
      endpoint: "findJob",
      params: {
        id: this.jobId,
        withPayments: false,
        withUsers: true,
        withSites: false,
        withPayModel: false,
        withPhotos: false,
        withEfiles: false,
        withPayables: false,
        withReadings: false,
      },
    });
  }
  async presentToast() {
    const toast = await hardwareBackButton.toastController.create({
      message: `File(s) added successfully to Efile!`,
      duration: 2000,
    });
    toast.present();
  }
  componentDidLoad() {
    {
      this.fetchJob();
      setTimeout(() => {
        this.forceResize.emit({});
      }, 1000);
    }
  }
  render() {
    var _a;
    return [
      index.h("ion-content", { class: "ion-padding" }, index.h("floodteam-title-bar", { back: ((_a = store.state === null || store.state === void 0 ? void 0 : store.state.session) === null || _a === void 0 ? void 0 : _a.uid) ? `/jobs/${this.jobId}` : "/" }, "E-Sign"), 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", { style: {
          position: "relative",
        }, class: {
          "is-loading": this.loading,
        } }, index.h("floodteam-template", { style: {
          padding: "60px 2em",
        }, disablePositioning: true, templateId: this.templateId, data: {
          timestamp: new Date().toISOString(),
          job: store.state.job,
          user: store.state === null || store.state === void 0 ? void 0 : store.state.profile,
        } }), index.h("floodteam-signature-pad", { ref: (el) => (this.signaturePadEl = el) })))),
      index.h("floodteam-navigation-footer", null),
    ];
  }
};
AppSign.style = appSignCss;

exports.app_sign = AppSign;
