import { r as registerInstance, B as Build, h, H as Host } from './index-e0adbd54.js';

const EblastFlow = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.paths = {
      default: () => [],
    };
    this.currentPath = "default";
    this.currentStep = "selectTemplate";
    this.locationId = undefined;
    this.endpoint = "sendTemplateEmail";
    this.errors = [];
    this.steps = [];
    this.currentSlideIndex = 0;
  }
  /**
   * Set the path of the flow
   * @param path The path name to change to
   * @returns A list of steps for the current path
   */
  async setPath(path) {
    var _a, _b, _c, _d;
    this.currentPath = path || this.currentPath;
    this.currentStep =
      ((_d = (_c = (_b = (_a = this.paths) === null || _a === void 0 ? void 0 : _a[this.currentPath]) === null || _b === void 0 ? void 0 : _b.call(_a)) === null || _c === void 0 ? void 0 : _c[this.currentSlideIndex]) === null || _d === void 0 ? void 0 : _d.name) ||
        null;
    this.steps = this.paths[this.currentPath]();
    return this.steps;
  }
  onError(event) {
    if (event.detail.endpoint === this.endpoint) {
      setTimeout(() => {
        this.errors = event.detail.error.response.errors.map((err) => err.message);
      }, 100);
    }
  }
  onChange(event) {
    console.log("change", event);
  }
  async onSuccess(event) {
    console.log("success", event);
    this.errors = [];
  }
  async onSlideChange(event) {
    this.currentSlideIndex = await event.target.getActiveIndex();
    await this.setPath();
  }
  onBeforeSubmit(data) {
    return {
      ...data,
    };
  }
  async componentDidLoad() {
    if (!(Build === null || Build === void 0 ? void 0 : Build.isBrowser))
      return;
    await this.setPath();
  }
  render() {
    const unit = 1 / this.steps.length;
    const progress = unit * this.currentSlideIndex;
    return (h(Host, null, this.errors.map((message) => (h("floodteam-error", { message: message }))), !(this.currentSlideIndex >= this.steps.length) && (h("ion-progress-bar", { style: {
        width: "80%",
        margin: "0 auto",
        transition: "opacity ease 500ms",
        opacity: "1",
      }, value: progress })), h("fireenjin-flow", { endpoint: this.endpoint, steps: this.steps, beforeSubmit: this.onBeforeSubmit.bind(this), prevButton: {
        color: "medium",
        fill: "outline",
        label: "Back",
      }, nextButton: {
        color: "primary",
        fill: "solid",
        icon: null,
        label: "Next",
      } }, h("div", { style: { color: "var(--ion-text-color)", padding: "2rem 3rem" } }, h("h1", { class: "ion-padding-horizontal" }, "Success! Emails have been sent. \uD83D\uDCE8"), h("p", { class: "ion-padding-horizontal", style: { color: "var(--ion-color-medium-shade)" } }, "The company has been added to the database and will be synced with Notion.")))));
  }
};

export { EblastFlow as floodteam_eblast_flow };
