import * as R from "immutable";
import { sendShowCase as I, subscribe as T } from "./embeddable-api.js";
const r = "SEND_SHOW_CASE", _ = "SEND_SHOW_CASE_DONE", n = "SEND_SHOW_CASE_FAILURE", a = "SHOW_CASE_RESET", o = "NEWS_LETTER_SUBSCRIBE", u = "NEWS_LETTER_SUBSCRIBE_DONE", S = "NEWS_LETTER_SUBSCRIBE_FAILURE", c = "NEWS_LETTER_SET_EMAIL", l = "POST_LOADED", O = (e) => (t, s) => {
  t({ type: l });
}, C = R.Map({}), L = (e) => (t, s) => {
  t({ type: c, eMail: e });
}, A = (e) => (t, s) => {
  t({ type: o }), T(e).then((E) => {
    E.status === 500 ? t({ type: S }) : t({ type: u });
  }).catch((E) => {
    t({ type: S });
  });
}, W = (e) => (t, s) => {
  t({ type: r }), I(e).then((E) => {
    E.status === 500 ? t({ type: n }) : t({ type: _ });
  }).catch((E) => {
    t({ type: n });
  });
}, m = (e) => (t, s) => {
  t({ type: a });
}, w = (e = C, t) => {
  switch (t.type) {
    case r:
      return e.setIn(["showCase", "loading"], !0).setIn(["showCase", "status"], null);
    case _:
      return e.setIn(["showCase", "status"], "OK");
    case n:
      return e.setIn(["showCase", "status"], "ERROR");
    case a:
      return e.setIn(["showCase", "status"], null);
    case o:
      return e.setIn(["newsletter", "loading"], !0).setIn(["newsletter", "status"], null);
    case u:
      return e.setIn(["newsletter", "status"], "OK").setIn(["newsletter", "email"], "");
    case S:
      return e.setIn(["newsletter", "status"], "ERROR");
    case c: {
      const { eMail: s } = t;
      return e.setIn(["newsletter", "email"], s);
    }
    case l:
      return e.setIn(["random"], Math.random());
    default:
      return e;
  }
};
export {
  w as default,
  A as newsletterSubscription,
  O as postLoaded,
  m as reset,
  W as sendShowCaseForm,
  L as setEmail
};
