'use strict';

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

const index = require('./index-fd2bbf0b.js');
const hardwareBackButton = require('./overlays-de05dc6a.js');
require('./ionic-global-1340f737.js');
require('./helpers-c2496722.js');

const modalSendEmailCss = ".fireenjin-mx-modal-send-email-wrapper{--min-width:300px}fireenjin-mx-modal-send-email ion-item-divider{--padding-start:0px}fireenjin-mx-modal-send-email fireenjin-avatar{margin-left:16px}fireenjin-mx-modal-send-email h5,fireenjin-mx-modal-send-email p{display:block;--ion-color-step-600:#666666;font-size:0.9em}fireenjin-mx-modal-send-email ion-button{display:table;margin-left:0px;margin:0 auto}";

let ModalSendEmail = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.fireenjinTrigger = index.createEvent(this, "fireenjinTrigger", 7);
    this.to = [];
    this.options = [];
    this.hideTemplateSelect = false;
    this.pageTitle = "Send Email";
  }
  onReset(event) {
    var _a;
    if (((_a = event.detail) === null || _a === void 0 ? void 0 : _a.endpoint) === "sendTemplateEmail") {
      this.fireenjinTrigger.emit({ name: "closeModal" });
    }
  }
  async onSuccess(event) {
    var _a;
    if (((_a = event.detail) === null || _a === void 0 ? void 0 : _a.endpoint) === "sendTemplateEmail") {
      this.fireenjinTrigger.emit({ name: "closeModal" });
      this.presentToast();
    }
  }
  async presentToast() {
    const toast = await hardwareBackButton.toastController.create({
      message: "Your emails are on their way.",
      duration: 2000,
    });
    toast.present();
  }
  onBeforeSubmit(formData) {
    return {
      templateId: (formData === null || formData === void 0 ? void 0 : formData.templateId)
        ? formData.templateId
        : this.templateId
          ? this.templateId
          : null,
      from: (formData === null || formData === void 0 ? void 0 : formData.from)
        ? formData.from
        : this.from
          ? this.from
          : "info@thefloodteam.com",
      emails: (formData === null || formData === void 0 ? void 0 : formData.to) ? formData.to : this.to ? this.to : [],
      filters: this.filters ? this.filters : null,
    };
  }
  componentWillLoad() {
    var _a, _b;
    if (((_a = this.to) === null || _a === void 0 ? void 0 : _a.length) && !((_b = this.options) === null || _b === void 0 ? void 0 : _b.length)) {
      this.options = this.to.map((to) => ({
        value: to,
        label: to,
      }));
    }
  }
  render() {
    return [
      index.h("ion-header", null, index.h("ion-toolbar", null, index.h("ion-title", null, this.pageTitle), index.h("ion-buttons", { slot: "end" }, index.h("ion-button", { onClick: () => this.fireenjinTrigger.emit({
          name: "closeModal",
          el: this.modalEl,
          component: "mx-modal-send-email",
        }) }, index.h("ion-icon", { slot: "icon-only", name: "close-circle-outline" }))))),
      index.h("ion-content", { style: {
          "--background": "var(--ion-color-base)",
        } }, index.h("fireenjin-form", { endpoint: "sendTemplateEmail", disableEnterButton: true, beforeSubmit: this.onBeforeSubmit.bind(this) }, index.h("ion-list", { style: {
          contain: "none",
        } }, index.h("fireenjin-input", { name: "subject", label: "Subject", labelPosition: "stacked", placeholder: "Email Subject", value: this.subject }), index.h("fireenjin-input", { name: "from", label: "Email From", labelPosition: "stacked", placeholder: "Email Address to Send From", value: this.from }), index.h("fireenjin-input", { name: "replyTo", label: "Reply To", labelPosition: "stacked", placeholder: "Email Address to Reply", value: this.replyTo }), !this.hideTemplateSelect && (index.h("fireenjin-select", { ref: (el) => (this.templateSelectEl = el), name: "templateId", label: "Template", labelPosition: "stacked", placeholder: "Select Template", value: this.templateId, endpoint: "listTemplates", interface: "action-sheet", optionEl: (result) => (index.h("ion-select-option", { value: result.id }, result.subject)), params: {
          withHtml: true,
        }, resultsKey: "templates", limit: 100 })), index.h("fireenjin-select-tags", { name: "to", label: "Send To", labelPosition: "stacked", placeholder: "Add Emails", allowAdding: true, value: this.to, multiple: true, options: this.options })))),
    ];
  }
  get modalEl() { return index.getElement(this); }
};
ModalSendEmail.style = modalSendEmailCss;

exports.fireenjin_mx_modal_send_email = ModalSendEmail;

//# sourceMappingURL=fireenjin-mx-modal-send-email.cjs.entry.js.map