'use strict';

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

const index = require('./index-fd2bbf0b.js');
const hardwareBackButton = require('./overlays-de05dc6a.js');
const getHandlebarsHelpers = require('./getHandlebarsHelpers-118ee216.js');
const store = require('./store-f2110833.js');
require('./ionic-global-1340f737.js');
require('./helpers-c2496722.js');
require('./_commonjsHelpers-a5111d61.js');
require('./logic-d8c34975.js');
require('./index-6307644b.js');
require('./index-81aa1bcb.js');
require('./getCache-c039a6ae.js');

const appSignCss = "";

let 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, _e;
    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) === "findJob") {
      this.loading = false;
    }
    else if (((_c = event.detail) === null || _c === void 0 ? void 0 : _c.endpoint) === "findTemplate") {
      this.template = ((_e = (_d = event.detail) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.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, _b, _c;
    return [
      index.h("ion-content", { class: "ion-padding" }, 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", { class: {
          "is-loading": this.loading,
        } }, (index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser) && (index.h("fireenjin-render-template", { template: (_b = (_a = store.state === null || store.state === void 0 ? void 0 : store.state.templates) === null || _a === void 0 ? void 0 : _a.find) === null || _b === void 0 ? void 0 : _b.call(_a, (template) => (template === null || template === void 0 ? void 0 : template.id) === this.templateId), partials: ((_c = store.state === null || store.state === void 0 ? void 0 : store.state.templates) === null || _c === void 0 ? void 0 : _c.length)
          ? store.state.templates
            .filter((template) => !!(template === null || template === void 0 ? void 0 : template.partial))
            .map((partial) => ({
            html: (partial === null || partial === void 0 ? void 0 : partial.html) || "",
            id: (partial === null || partial === void 0 ? void 0 : partial.id) || null,
          }))
          : [], data: {
          timestamp: new Date().toISOString(),
          job: store.state === null || store.state === void 0 ? void 0 : store.state.job,
          user: store.state === null || store.state === void 0 ? void 0 : store.state.profile,
        }, helpers: getHandlebarsHelpers.getHandlebarsHelpers() })), index.h("floodteam-signature-pad", { ref: (el) => (this.signaturePadEl = el), style: {
          margin: "0 auto",
          display: "block",
        } })))),
      index.h("floodteam-navigation-footer", null),
    ];
  }
};
AppSign.style = appSignCss;

exports.app_sign = AppSign;

//# sourceMappingURL=app-sign.cjs.entry.js.map