import { r as registerInstance, d as createEvent, h } from './index-33e43734.js';
import { t as toastController } from './overlays-97615cf7.js';
import { s as state } from './store-729235b6.js';
import './ionic-global-bd76bde2.js';
import './helpers-a9270f9e.js';
import './index-91eb4513.js';
import './getCache-f7c123d8.js';
import './_commonjsHelpers-cca61ea8.js';
import './logic-2eecfe1e.js';
import './index-964da72a.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) {
    registerInstance(this, hostRef);
    this.floodteamCloseModal = createEvent(this, "floodteamCloseModal", 7);
    this.fireenjinFetch = 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 toastController.create({
      message: `Note has been added successfully!`,
      duration: 2000,
    });
    toast.present();
  }
  render() {
    var _a, _b;
    return [
      h("ion-header", null, h("ion-toolbar", null, h("ion-title", null, this.heading), h("ion-buttons", { slot: "end" }, h("ion-button", { onClick: () => this.floodteamCloseModal.emit() }, h("ion-icon", { slot: "icon-only", name: "close-circle-outline" }))))),
      h("ion-content", null, h("ion-tabs", { ref: (el) => (this.tabsEl = el) }, h("ion-tab-bar", { ref: (el) => (this.tabBarEl = el), slot: "top" }, h("ion-tab-button", { tab: "note" }, h("ion-icon", { name: "create" }), h("ion-label", null, "Note")), h("ion-tab-button", { tab: "options" }, h("ion-icon", { name: "cog" }), h("ion-label", null, "Options")), h("ion-tab-button", { tab: "preview" }, h("ion-icon", { name: "eye" }), h("ion-label", null, "Preview"))), h("ion-tab", { tab: "note" }, h("ion-content", null, h("ion-card", { style: {
          overflow: "visible",
        } }, 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 }, h("fireenjin-editor", { ref: (el) => (this.editorEl = el) }))))), h("ion-tab", { tab: "options" }, h("ion-content", null, h("ion-card", { class: "ion-padding", style: {
          overflow: "visible",
        } }, h("fireenjin-form", { name: "note", hideControls: true }, h("fireenjin-toggle", { label: "Send an Alert", name: "sendAlert", value: !!((_a = this.note) === null || _a === void 0 ? void 0 : _a.alert) }), 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",
          },
        ] }))))), h("ion-tab", { tab: "preview" }, h("ion-content", null, h("ion-card", { class: "ion-padding" }, h("floodteam-template", { templateId: "fBRGqXAzDw8CwFfJtQgJ", data: {
          html: this.previewHTML ? this.previewHTML : "",
          user: state === null || state === void 0 ? void 0 : state.profile,
          createdAt: new Date(),
        } })))))),
    ];
  }
};
ModalNote.style = modalNoteCss;

export { ModalNote as modal_note };

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