import { r as registerInstance, d as createEvent, h, e as getElement } from './index-33e43734.js';
import { t as toastController } from './overlays-97615cf7.js';
import './ionic-global-bd76bde2.js';
import './helpers-a9270f9e.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) {
    registerInstance(this, hostRef);
    this.fireenjinTrigger = 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 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 [
      h("ion-header", null, h("ion-toolbar", null, h("ion-title", null, this.pageTitle), h("ion-buttons", { slot: "end" }, h("ion-button", { onClick: () => this.fireenjinTrigger.emit({
          name: "closeModal",
          el: this.modalEl,
          component: "mx-modal-send-email",
        }) }, h("ion-icon", { slot: "icon-only", name: "close-circle-outline" }))))),
      h("ion-content", { style: {
          "--background": "var(--ion-color-base)",
        } }, h("fireenjin-form", { endpoint: "sendTemplateEmail", disableEnterButton: true, beforeSubmit: this.onBeforeSubmit.bind(this) }, h("ion-list", { style: {
          contain: "none",
        } }, h("fireenjin-input", { name: "subject", label: "Subject", labelPosition: "stacked", placeholder: "Email Subject", value: this.subject }), h("fireenjin-input", { name: "from", label: "Email From", labelPosition: "stacked", placeholder: "Email Address to Send From", value: this.from }), h("fireenjin-input", { name: "replyTo", label: "Reply To", labelPosition: "stacked", placeholder: "Email Address to Reply", value: this.replyTo }), !this.hideTemplateSelect && (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) => (h("ion-select-option", { value: result.id }, result.subject)), params: {
          withHtml: true,
        }, resultsKey: "templates", limit: 100 })), 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 getElement(this); }
};
ModalSendEmail.style = modalSendEmailCss;

export { ModalSendEmail as fireenjin_mx_modal_send_email };

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