'use strict';

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

const index = require('./index-fd2bbf0b.js');
const index_esm2017 = require('./index.esm2017-f14d2198.js');
const hardwareBackButton = require('./overlays-de05dc6a.js');
const store = require('./store-f2110833.js');
require('./index.esm2017-895d5dfe.js');
require('./global-9027a413.js');
require('./ionic-global-1340f737.js');
require('./helpers-c2496722.js');
require('./index-81aa1bcb.js');
require('./getCache-c039a6ae.js');

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

let ModalSupport = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.floodteamCloseModal = index.createEvent(this, "floodteamCloseModal", 7);
    this.fireenjinFetch = index.createEvent(this, "fireenjinFetch", 7);
    this.fireenjinUpload = index.createEvent(this, "fireenjinUpload", 7);
    this.heading = "Get Help";
    this.ticket = {};
    this.ticketInput = {};
  }
  async onEditorChange() {
    var _a;
    if (!((_a = this.editorEl) === null || _a === void 0 ? void 0 : _a.exportHTML))
      return;
    this.previewHTML = await this.editorEl.exportHTML();
    this.editor = await (await this.editorEl.getInstance()).save();
  }
  async onChange(event) {
    var _a, _b;
    if (((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.name) === "tags") {
      this.ticketInput.tags = ((_b = event === null || event === void 0 ? void 0 : event.target) === null || _b === void 0 ? void 0 : _b.value) ? event.target.value : [];
    }
  }
  onReset(event) {
    var _a;
    if (((_a = event.detail) === null || _a === void 0 ? void 0 : _a.endpoint) === "addSupport") {
      const modalEl = document.querySelector("ion-modal.modal-support");
      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) === "addSupport") {
      const modalSupportEl = document.querySelector("ion-modal.modal-support");
      if (modalSupportEl === null || modalSupportEl === void 0 ? void 0 : modalSupportEl.dismiss) {
        await modalSupportEl.dismiss();
        this.presentToast();
      }
    }
  }
  async presentToast() {
    const toast = await hardwareBackButton.toastController.create({
      message: `Feedback has been sent successfully!`,
      duration: 2000,
    });
    toast.present();
  }
  getExtension(path) {
    var basename = path.split(/[\\/]/).pop(), // extract file name from full path ...
    // (supports `\\` and `/` separators)
    pos = basename.lastIndexOf("."); // get last position of `.`
    if (basename === "" || pos < 1)
      // if file name is empty or ...
      return ""; //  `.` not found (-1) or comes first (0)
    return basename.slice(pos + 1); // extract extension ignoring `.`
  }
  async onPhotoUpload(event) {
    var _a;
    const storageRef = index_esm2017.ref(this.storage, `${new Date().toISOString()}.${this.getExtension((_a = event === null || event === void 0 ? void 0 : event.file) === null || _a === void 0 ? void 0 : _a.name)}`);
    const upload = await index_esm2017.uploadBytes(storageRef, event.file);
    const url = await index_esm2017.getDownloadURL(upload.ref);
    return {
      success: true,
      file: {
        url,
      },
    };
  }
  componentDidLoad() {
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser))
      return;
    this.storage = index_esm2017.getStorage();
  }
  render() {
    var _a, _b, _c, _d, _e;
    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: () => { var _a, _b; return (_b = (_a = this.formEl) === null || _a === void 0 ? void 0 : _a.submit) === null || _b === void 0 ? void 0 : _b.call(_a); }, color: "primary", fill: "solid" }, "Send"), 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-grid", null, index.h("ion-row", null, index.h("ion-col", { class: "ion-padding" }, index.h("ion-text", { color: "medium" }, "Select the type of support you require and then give us a brief summary of your issue and someone will follow up with you."))), index.h("ion-row", null, index.h("ion-col", { class: "ion-padding" }, index.h("ion-card", { style: {
          overflow: "visible",
        } }, index.h("fireenjin-form", { name: "support", endpoint: "addSupport", beforeSubmit: (data) => ({
          ...this.ticketInput,
          ...data,
          userId: this.userId,
          html: this.previewHTML,
          editor: this.editor,
        }), ref: (el) => (this.formEl = el), submitButton: "Submit", resetButton: "Cancel", resetButtonColor: "medium", hideControls: true, disableLoader: true, disableEnterButton: true }, index.h("ion-item", { lines: "inset" }, index.h("fireenjin-avatar", { slot: "start", style: {
          display: "inline-block",
          position: "relative",
          borderRadius: "4px",
          padding: "0 !important",
          overflow: "hidden",
        }, initials: `${((_a = store.state === null || store.state === void 0 ? void 0 : store.state.profile) === null || _a === void 0 ? void 0 : _a.firstName)
          ? (_b = store.state === null || store.state === void 0 ? void 0 : store.state.profile) === null || _b === void 0 ? void 0 : _b.firstName.charAt(0)
          : ""}${((_c = store.state === null || store.state === void 0 ? void 0 : store.state.profile) === null || _c === void 0 ? void 0 : _c.lastName)
          ? (_d = store.state === null || store.state === void 0 ? void 0 : store.state.profile) === null || _d === void 0 ? void 0 : _d.lastName.charAt(0)
          : ""}`, src: (_e = store.state === null || store.state === void 0 ? void 0 : store.state.profile) === null || _e === void 0 ? void 0 : _e.photo }), index.h("fireenjin-select", { name: "type", label: "Type", labelPosition: "stacked", options: [
          { label: "Bug", value: "Bug 🐞" },
          { label: "Feedback", value: "Task ✅" },
        ], value: "Task ✅" })), index.h("fireenjin-editor", { style: { minHeight: "50px" }, autofocus: true, ref: (el) => (this.editorEl = el), uploadCallback: (event) => this.onPhotoUpload(event) }))))))),
    ];
  }
};
ModalSupport.style = modalSupportCss;

exports.modal_support = ModalSupport;

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