'use strict';

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

const index = require('./index-ee190ee0.js');
const hardwareBackButton = require('./overlays-6a64deff.js');
const store = require('./store-5a3b44dc.js');
const isAdmin = require('./isAdmin-95517cef.js');
const getLocationOptions = require('./getLocationOptions-daa56051.js');
const getCompanyOptions = require('./getCompanyOptions-d3ba5a4b.js');
const getUserRoleOptions = require('./getUserRoleOptions-63303496.js');
require('./ionic-global-542e0609.js');
require('./helpers-905b0d22.js');
require('./index-4901314f.js');
require('./getHandlebarsHelpers-8ef28401.js');
require('./_commonjsHelpers-a5111d61.js');
require('./index-ba857994.js');
require('./localforage-af1b8c0e.js');

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

const ModalSendEmail = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.floodteamCloseModal = index.createEvent(this, "floodteamCloseModal", 7);
    this.toOptions = [];
    this.ccOptions = [];
    this.bccOptions = [];
    this.formData = {};
    this.to = [];
    this.role = undefined;
    this.bccs = [];
    this.ccs = [];
    this.subject = undefined;
    this.replyTo = undefined;
    this.from = "info@thefloodteam.com";
    this.attachments = [];
    this.templateId = undefined;
    this.users = [];
    this.templateFilter = undefined;
    this.hideTemplateSelect = false;
    this.filters = undefined;
    this.payload = undefined;
    this.job = undefined;
    this.templateData = {};
    this.notes = undefined;
    this.isEblast = false;
    this.dryRun = false;
  }
  onChange(event) {
    var _a;
    if (((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.name) === "templateId") {
      this.templateId = event.target.value;
    }
  }
  async onSuccess(event) {
    var _a;
    if (((_a = event.detail) === null || _a === void 0 ? void 0 : _a.endpoint) === "sendTemplateEmail") {
      const sendEmailModalEl = document.querySelector("ion-modal.modal-send-email-wrapper");
      if (sendEmailModalEl === null || sendEmailModalEl === void 0 ? void 0 : sendEmailModalEl.dismiss) {
        await sendEmailModalEl.dismiss();
        this.presentToast();
      }
    }
  }
  async presentToast() {
    const toast = await hardwareBackButton.toastController.create({
      message: "Your emails are on their way.",
      duration: 2000,
    });
    toast.present();
  }
  componentWillLoad() {
    if (!(index.Build === null || index.Build === void 0 ? void 0 : index.Build.isBrowser))
      return;
    this.toOptions = (this.users || []).map((user) => ({
      label: (user === null || user === void 0 ? void 0 : user.email) ||
        `${user === null || user === void 0 ? void 0 : user.firstName} ${user === null || user === void 0 ? void 0 : user.lastName} has no Email on File.`,
      value: user === null || user === void 0 ? void 0 : user.email,
      disabled: !(user === null || user === void 0 ? void 0 : user.email),
    }));
    if (this.to)
      this.toOptions = [
        ...this.toOptions,
        ...this.to.map((to) => ({
          label: to,
          value: to,
          disabed: false,
        })),
      ];
    this.bccOptions = (this.users || []).map((user) => ({
      label: (user === null || user === void 0 ? void 0 : user.email) ||
        `${user === null || user === void 0 ? void 0 : user.firstName} ${user === null || user === void 0 ? void 0 : user.lastName} has no Email on File.`,
      value: user === null || user === void 0 ? void 0 : user.email,
      disabled: !(user === null || user === void 0 ? void 0 : user.email),
    }));
    if (this.bccs)
      this.bccOptions = [
        ...this.bccOptions,
        ...this.bccs.map((bcc) => ({
          label: bcc,
          value: bcc,
          disabed: false,
        })),
      ];
    this.ccOptions = (this.users || []).map((user) => ({
      label: (user === null || user === void 0 ? void 0 : user.email) ||
        `${user === null || user === void 0 ? void 0 : user.firstName} ${user === null || user === void 0 ? void 0 : user.lastName} has no Email on File.`,
      value: user === null || user === void 0 ? void 0 : user.email,
      disabled: !(user === null || user === void 0 ? void 0 : user.email),
    }));
    if (this.ccs)
      this.ccOptions = [
        ...this.ccOptions,
        ...this.ccs.map((cc) => ({
          label: cc,
          value: cc,
          disabed: false,
        })),
      ];
    this.formData = {
      isEblast: this.isEblast || false,
      dryRun: this.dryRun || false,
      data: { ...(this.templateData || {}), notes: this.notes },
      filters: this.filters || null,
      attachments: this.attachments,
      ccs: this.ccs,
      bccs: this.bccs,
      from: this.from,
      emails: this.to,
      templateId: this.templateId,
    };
  }
  render() {
    var _a;
    return [
      index.h("ion-header", null, index.h("ion-toolbar", null, index.h("ion-title", null, "Send Email"), index.h("ion-buttons", { slot: "end" }, index.h("ion-button", { onClick: () => this.formEl.submit(), color: "primary", fill: "solid" }, "Send"), index.h("ion-button", { onClick: () => this.floodteamCloseModal.emit(), style: {
          "--color": "var(--ion-text-color)",
          "--color-hover": "var(--ion-color-danger",
        } }, 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", { ref: (el) => (this.formEl = el), endpoint: "sendTemplateEmail", formData: this.formData, disableEnterButton: true, hideControls: true }, index.h("ion-grid", null, index.h("ion-row", null, index.h("ion-col", { size: "12", sizeMd: "7" }, !this.hideTemplateSelect && (index.h("fireenjin-select", { interface: "action-sheet", ref: (el) => (this.templateSelectEl = el), name: "templateId", label: "Template", labelPosition: "stacked", placeholder: "Select Message Template", value: this.templateId, options: (store.state.templates || [])
          .filter((template) => !(template === null || template === void 0 ? void 0 : template.partial) &&
          (template === null || template === void 0 ? void 0 : template.type) === "email" &&
          (!this.templateFilter ||
            this.templateFilter(template)))
          .map((template) => ({
          label: template === null || template === void 0 ? void 0 : template.subject,
          value: template === null || template === void 0 ? void 0 : template.id,
        })) })), index.h("fireenjin-select-tags", { name: "emails", label: "Send To", labelPosition: "stacked", placeholder: "Add Emails", allowAdding: true, value: this.to, options: this.toOptions }), index.h("fireenjin-select-tags", { name: "ccs", label: "CCs", labelPosition: "stacked", placeholder: "Add CCs", allowAdding: true, value: this.ccs, options: this.ccOptions }), this.isEblast && isAdmin.isAdmin() && (index.h("fireenjin-select", { interface: "action-sheet", name: "filters.locationId", label: "Send to Location", labelPosition: "stacked", placeholder: "Select a Location", value: this.filters.locationId, options: [...getLocationOptions.getLocationOptions(), { label: "All", value: null }] })), this.isEblast && isAdmin.isAdmin() && (index.h("fireenjin-select", { interface: "action-sheet", name: "filters.role", label: "Send to User Type", labelPosition: "stacked", placeholder: "Select Role", value: this.filters.role, options: getUserRoleOptions.getUserRoleOptions() })), this.isEblast && isAdmin.isAdmin() && (index.h("fireenjin-select", { name: "filters.companyId", label: "Send to Company", labelPosition: "stacked", placeholder: "Select a Company", value: this.filters.companyId, options: getCompanyOptions.getCompanyOptions() })), this.isEblast && (index.h("fireenjin-select-tags", { name: "filters.tags", value: ((_a = this.filters) === null || _a === void 0 ? void 0 : _a.tags) || [], label: "Send by Tags", labelPosition: "stacked", placeholder: "Add tags", allowAdding: true, options: getCompanyOptions.getUserTagOptions() }))), index.h("ion-col", { size: "12", sizeMd: "5" }, this.templateId && (index.h("floodteam-template", { id: "email-preview", zoom: 0.3, templateId: this.templateId, data: this.payload || {
          job: this.job || null,
        } })))), index.h("ion-row", null, index.h("ion-col", null, index.h("fireenjin-chip-bar", null, (this.attachments || []).map((url) => {
        var _a, _b, _c, _d, _e, _f;
        return (index.h("ion-chip", null, index.h("ion-icon", { name: "document", class: "ft-icon-style" }), index.h("ion-label", null, decodeURI(((_f = (_e = (_d = (_c = (_b = (_a = url === null || url === void 0 ? void 0 : url.split) === null || _a === void 0 ? void 0 : _a.call(url, "/")) === null || _b === void 0 ? void 0 : _b.pop) === null || _c === void 0 ? void 0 : _c.call(_b)) === null || _d === void 0 ? void 0 : _d.split) === null || _e === void 0 ? void 0 : _e.call(_d, "?")) === null || _f === void 0 ? void 0 : _f[0]) ||
            "No File Name"))));
      }))))), index.h("ion-accordion-group", null, index.h("ion-accordion", null, index.h("ion-item", { slot: "header" }, index.h("ion-label", null, "Advanced")), index.h("ion-grid", { slot: "content" }, index.h("ion-row", null, index.h("ion-col", null, index.h("fireenjin-input", { name: "subject", label: "Subject", labelPosition: "stacked", placeholder: "Email Subject", value: this.subject }))), index.h("ion-row", null, index.h("ion-col", null, index.h("ion-item", { class: "ion-padding-bottom" }, index.h("ion-label", { position: "stacked" }, "Additional Notes"), index.h("ion-textarea", { style: {
          border: "2px solid #bebebe",
          "--padding-start": "15px",
          "--padding-end": "15px",
        }, name: "data.notes", placeholder: "Enter notes here", inputmode: "text", spellcheck: true, rows: 4, autocapitalize: "sentences", maxlength: 400 })))), index.h("ion-row", null, index.h("ion-col", null, index.h("fireenjin-select-tags", { name: "bccs", label: "BCCs", labelPosition: "stacked", placeholder: "Add BCCs", allowAdding: true, value: this.bccs, options: this.bccOptions }))), index.h("ion-row", null, index.h("ion-col", null, index.h("fireenjin-input", { name: "from", label: "Email From", labelPosition: "stacked", placeholder: "Email Address to Send From", value: this.from })), index.h("ion-col", null, index.h("fireenjin-input", { name: "replyTo", label: "Reply To", labelPosition: "stacked", placeholder: "Email Address to Reply", value: this.replyTo })))))))),
    ];
  }
};
ModalSendEmail.style = modalSendEmailCss;

exports.modal_send_email = ModalSendEmail;
