import { r as registerInstance, d as createEvent, h, B as Build } from './index-33e43734.js';
import { t as toastController } from './overlays-97615cf7.js';
import { g as getHandlebarsHelpers } from './getHandlebarsHelpers-1816c9c1.js';
import { s as state } from './store-163687da.js';
import './ionic-global-bd76bde2.js';
import './helpers-a9270f9e.js';
import './_commonjsHelpers-cca61ea8.js';
import './logic-2eecfe1e.js';
import './index-964da72a.js';
import './index-91eb4513.js';
import './getCache-721d3aa5.js';

const appSignCss = "";

let AppSign = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.fireenjinFetch = createEvent(this, "fireenjinFetch", 7);
    this.fireenjinSubmit = createEvent(this, "fireenjinSubmit", 7);
    this.forceResize = 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 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 [
      h("ion-content", { class: "ion-padding" }, 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", { class: {
          "is-loading": this.loading,
        } }, (Build === null || Build === void 0 ? void 0 : Build.isBrowser) && (h("fireenjin-render-template", { template: (_b = (_a = state === null || state === void 0 ? void 0 : 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 = state === null || state === void 0 ? void 0 : state.templates) === null || _c === void 0 ? void 0 : _c.length)
          ? 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: state === null || state === void 0 ? void 0 : state.job,
          user: state === null || state === void 0 ? void 0 : state.profile,
        }, helpers: getHandlebarsHelpers() })), h("floodteam-signature-pad", { ref: (el) => (this.signaturePadEl = el), style: {
          margin: "0 auto",
          display: "block",
        } })))),
      h("floodteam-navigation-footer", null),
    ];
  }
};
AppSign.style = appSignCss;

export { AppSign as app_sign };

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