'use strict';

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

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

const modalNoteCss = "modal-note fireenjin-editor{width:calc(100% - 75px);margin:0 0 0 60px}modal-note fireenjin-editor .codex-editor__redactor{padding-bottom:0 !important}@media only screen and (max-width: 800px){.modal-note{--width:100%;--max-width:auto}}";

let ModalNote = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.floodteamCloseModal = index.createEvent(this, "floodteamCloseModal", 7);
    this.fireenjinFetch = index.createEvent(this, "fireenjinFetch", 7);
    this.steps = ["note", "options", "preview"];
    this.heading = "Add a Note";
    this.note = {};
    this.noteInput = {};
  }
  async onEditorChange() {
    var _a;
    if (!((_a = this.editorEl) === null || _a === void 0 ? void 0 : _a.exportHTML))
      return;
    this.previewHTML = await this.editorEl.exportHTML();
  }
  async onChange(event) {
    var _a, _b, _c, _d;
    if (((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.name) === "sendAlert") {
      this.noteInput.sendAlert = !!((_b = event === null || event === void 0 ? void 0 : event.detail) === null || _b === void 0 ? void 0 : _b.checked);
    }
    else if (((_c = event === null || event === void 0 ? void 0 : event.target) === null || _c === void 0 ? void 0 : _c.name) === "tags") {
      this.noteInput.tags = ((_d = event === null || event === void 0 ? void 0 : event.target) === null || _d === void 0 ? void 0 : _d.value) ? event.target.value : [];
    }
  }
  onReset(event) {
    var _a;
    if (((_a = event.detail) === null || _a === void 0 ? void 0 : _a.endpoint) === "addNote") {
      const modalEl = document.querySelector("ion-modal.modal-note");
      if (modalEl === null || modalEl === void 0 ? void 0 : modalEl.dismiss) {
        modalEl.dismiss();
      }
    }
  }
  async onSuccess(event) {
    var _a;
    if (((_a = event.detail) === null || _a === void 0 ? void 0 : _a.endpoint) === "addNote") {
      const photoCarouselModalEl = document.querySelector("ion-modal.modal-note");
      if (photoCarouselModalEl === null || photoCarouselModalEl === void 0 ? void 0 : photoCarouselModalEl.dismiss) {
        await photoCarouselModalEl.dismiss();
        this.presentToast();
      }
    }
  }
  async presentToast() {
    const toast = await hardwareBackButton.toastController.create({
      message: `Note has been added successfully!`,
      duration: 2000,
    });
    toast.present();
  }
  render() {
    var _a, _b;
    return [
      index.h("ion-header", null, index.h("ion-toolbar", null, index.h("ion-title", null, this.heading), 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", null, index.h("ion-tabs", { ref: (el) => (this.tabsEl = el) }, index.h("ion-tab-bar", { ref: (el) => (this.tabBarEl = el), slot: "top" }, index.h("ion-tab-button", { tab: "note" }, index.h("ion-icon", { name: "create" }), index.h("ion-label", null, "Note")), index.h("ion-tab-button", { tab: "options" }, index.h("ion-icon", { name: "cog" }), index.h("ion-label", null, "Options")), index.h("ion-tab-button", { tab: "preview" }, index.h("ion-icon", { name: "eye" }), index.h("ion-label", null, "Preview"))), index.h("ion-tab", { tab: "note" }, index.h("ion-content", null, index.h("ion-card", { style: {
          overflow: "visible",
        } }, index.h("fireenjin-form", { name: "note", endpoint: "addNote", beforeSubmit: async (data) => ({
          ...this.noteInput,
          ...data,
          jobId: this.jobId,
          userId: this.userId,
          html: this.previewHTML,
        }), submitButton: "Save", resetButton: "Cancel", resetButtonColor: "medium", disableLoader: true, disableEnterButton: true }, index.h("fireenjin-editor", { ref: (el) => (this.editorEl = el) }))))), index.h("ion-tab", { tab: "options" }, index.h("ion-content", null, index.h("ion-card", { class: "ion-padding", style: {
          overflow: "visible",
        } }, index.h("fireenjin-form", { name: "note", hideControls: true }, index.h("fireenjin-toggle", { label: "Send an Alert", name: "sendAlert", value: !!((_a = this.note) === null || _a === void 0 ? void 0 : _a.alert) }), index.h("fireenjin-select-tags", { name: "tags", label: "Tags", labelPosition: "stacked", value: ((_b = this.note) === null || _b === void 0 ? void 0 : _b.tags) ? this.note.tags : [], allowAdding: true, options: [
          {
            label: "Important",
            value: "important",
          },
          {
            label: "Referral",
            value: "referral",
          },
          {
            label: "Plumber",
            value: "plumber",
          },
          {
            label: "Staff",
            value: "staff",
          },
          {
            label: "Agent",
            value: "agent",
          },
          {
            label: "Property Manager",
            value: "property manager",
          },
          {
            label: "PEU",
            value: "peu",
          },
        ] }))))), index.h("ion-tab", { tab: "preview" }, index.h("ion-content", null, index.h("ion-card", { class: "ion-padding" }, index.h("floodteam-template", { templateId: "fBRGqXAzDw8CwFfJtQgJ", data: {
          html: this.previewHTML ? this.previewHTML : "",
          user: store.state === null || store.state === void 0 ? void 0 : store.state.profile,
          createdAt: new Date(),
        } })))))),
    ];
  }
};
ModalNote.style = modalNoteCss;

exports.modal_note = ModalNote;

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