import { jsx as t, jsxs as S } from "react/jsx-runtime";
import { a as z } from "./index.CfQlFjZU.js";
import { useState as x } from "react";
import { u as A, M as U } from "./modal.BZAvb1Nx.js";
import { S as _ } from "./shared.EdGf6tcG.js";
import { C as O } from "./card.CVCKhKP6.js";
import { s as B, R as F, b as Y, C as j } from "./index.dWlEA7uO.js";
import { a as W, g as L, d as Q } from "./GridRow._ehOXG8R.js";
import "./GridLayouts.DSIvKCIo.js";
import { L as K } from "./LoadingState.BcrOPPws.js";
import { a as X } from "./Pagination.BIPwVSsz.js";
import { P as Z } from "./PageHeader.BwFpx_pz.js";
import { S as q } from "./Search.BMvpFqQc.js";
import { a as J } from "./Status.BXXhAgWr.js";
import { a as ee } from "./Tag.Bk_lQM4l.js";
import { D as te } from "./DataTable.CDOMpN3l.js";
import { B as ae } from "./Button.CpTwUWVr.js";
import { T as I } from "./Typography.a1p6WNM8.js";
import { M as oe } from "./MoreMenu.D8ne9cF5.js";
var ne = /* @__PURE__ */ ((e) => (e.LEGACY_ONCE = "Once", e.SMART_SCHEDULE = "SMART_SCHEDULE", e.ALL_AT_ONCE = "ALL_AT_ONCE", e))(ne || {}), d = /* @__PURE__ */ ((e) => (e.SMS = "SMS", e.EMAIL = "EMAIL", e.SMART_SCHEDULE_EMAIL = "SMART_SCHEDULE_EMAIL", e))(d || {}), l = /* @__PURE__ */ ((e) => (e.DRAFT = "Draft", e.SCHEDULED = "Scheduled", e.STOPPED = "Stopped", e.SENDING = "Sending", e.COMPLETED = "Completed", e.ERRORED = "Errored", e))(l || {});
const se = {
  [l.COMPLETED]: "default",
  [l.DRAFT]: "warning",
  [l.ERRORED]: "error",
  [l.SCHEDULED]: "info",
  [l.SENDING]: "success",
  [l.STOPPED]: "error"
}, le = {
  [d.SMART_SCHEDULE_EMAIL]: "Email",
  [d.EMAIL]: "Email",
  [d.SMS]: "SMS"
}, ie = {
  [d.SMART_SCHEDULE_EMAIL]: "info",
  [d.EMAIL]: "info",
  [d.SMS]: "success"
}, ce = ({
  onDeleteClick: e
}) => {
  const { Modal: r, openModal: c, closeModal: o } = A(), [a, i] = x(null), m = (E) => () => {
    i(E), c();
  }, p = () => {
    a && e(a.id, a.type), i(null), o();
  };
  return {
    CampaignDeleteModal: () => /* @__PURE__ */ t(
      r,
      {
        body: "The campaign will be permanently deleted and you won’t be able to recover it or undo this action.",
        buttons: [
          { label: "Delete", semantic: _.SECONDARY, onClick: p },
          { label: "Keep it", semantic: _.PRIMARY, onClick: o }
        ],
        dismissible: !1,
        heading: a ? `Are you sure you want to delete the campaign "${a.name}"?` : "Are you sure you want to delete the campaign?"
      }
    ),
    closeDeleteModal: () => {
      i(null), o();
    },
    openDeleteModal: m
  };
}, re = ({
  onStopClick: e
}) => {
  const { Modal: r, openModal: c, closeModal: o } = A(), [a, i] = x(null), m = (E) => () => {
    i(E), c();
  }, p = () => {
    a && e(a.id, a.type), i(null), o();
  };
  return {
    CampaignStopModal: () => /* @__PURE__ */ t(
      r,
      {
        body: " ",
        buttons: [
          {
            label: "Keep sending",
            semantic: _.PRIMARY,
            onClick: o
          },
          {
            label: "Stop",
            semantic: _.SECONDARY,
            onClick: p
          }
        ],
        dismissible: !1,
        heading: a ? `Are you sure you want to stop the campaign "${a.name}"?` : "Are you sure you want to stop the campaign?"
      }
    ),
    closeStopModal: () => {
      i(null), o();
    },
    openStopModal: m
  };
}, me = "creator_options_uQGms", de = "creator_option_k7QDG", pe = "creator_title_wGGUG", Ee = "creator_subtitle_QF8gy", M = { options: me, option: de, title: pe, subtitle: Ee }, Ce = ({
  onCreateEmailCampaignClick: e,
  onCreateSmsCampaignClick: r
}) => {
  const {
    Modal: c,
    closeModal: o,
    openModal: a
  } = A();
  return {
    CampaignCreateModal: () => /* @__PURE__ */ t(c, { heading: "Create a new campaign", type: U.ADVANCED, children: /* @__PURE__ */ S("div", { className: M.options, children: [
      /* @__PURE__ */ S(
        O,
        {
          className: M.option,
          elevation: "high",
          interaction: "interactive",
          onClick: e,
          children: [
            /* @__PURE__ */ t(B, { size: 24 }),
            /* @__PURE__ */ t("p", { className: M.title, children: "Email campaign" }),
            /* @__PURE__ */ t("p", { className: M.subtitle, children: "Send email campaigns to any fan segment" })
          ]
        }
      ),
      /* @__PURE__ */ S(
        O,
        {
          className: M.option,
          elevation: "high",
          interaction: "interactive",
          onClick: r,
          children: [
            /* @__PURE__ */ t(F, { size: 24 }),
            /* @__PURE__ */ t("p", { className: M.title, children: "SMS campaign" }),
            /* @__PURE__ */ t("p", { className: M.subtitle, children: "Send SMS messages to any fan segment" })
          ]
        }
      )
    ] }) }),
    closeCampaignCreateModal: o,
    openCampaignCreateModal: a
  };
}, ue = "creator_container_0Xsb6", Se = "creator_title_jyo8r", Me = "creator_body_efbwO", _e = "creator_button_wAg4O", De = "creator_add_nK5zF", y = { container: ue, title: Se, body: Me, button: _e, add: De }, ge = ({
  onCreateClick: e
}) => /* @__PURE__ */ S("div", { className: y.container, children: [
  /* @__PURE__ */ t(I, { className: y.title, variant: "header", size: "small", children: "Nothing Here Yet" }),
  /* @__PURE__ */ t(I, { className: y.body, variant: "body", size: "small", children: "Create a new campaign to get started" }),
  /* @__PURE__ */ t(
    ae,
    {
      className: y.button,
      label: "New Campaign",
      onClick: e,
      prefixIcon: /* @__PURE__ */ t(Y, { size: 24, className: y.add }),
      size: "xsmall",
      semantic: _.PRIMARY
    }
  )
] });
var s = /* @__PURE__ */ ((e) => (e.DELETE = "DELETE", e.EDIT = "EDIT", e.STOP = "STOP", e.VIEW_REPORT = "VIEW_REPORT", e))(s || {});
const k = {
  [l.COMPLETED]: [s.VIEW_REPORT],
  [l.DRAFT]: [
    s.EDIT,
    s.DELETE
  ],
  [l.SCHEDULED]: [
    s.EDIT,
    s.STOP
  ],
  [l.SENDING]: [s.STOP],
  [l.STOPPED]: [s.VIEW_REPORT],
  [l.ERRORED]: []
}, he = {
  [l.COMPLETED]: [s.VIEW_REPORT],
  [l.DRAFT]: [
    s.EDIT,
    s.DELETE
  ],
  [l.SCHEDULED]: [
    s.EDIT,
    s.STOP
  ],
  [l.SENDING]: [s.STOP],
  [l.STOPPED]: [s.VIEW_REPORT],
  [l.ERRORED]: []
}, ye = {
  [d.EMAIL]: k,
  [d.SMART_SCHEDULE_EMAIL]: k,
  [d.SMS]: he
}, Re = "creator_container_dcn8P", Te = "creator_menu_Xh6yZ", be = "creator_dropdown_z-yJj", P = { container: Re, menu: Te, dropdown: be }, Ne = ({
  id: e,
  onDeleteClick: r,
  onEditClick: c,
  onStopClick: o,
  onViewReportClick: a,
  status: i,
  type: m
}) => {
  const p = {
    [s.DELETE]: {
      label: "Delete",
      onClick: () => r(e, m),
      semantic: _.DANGER
    },
    [s.EDIT]: {
      label: "Edit",
      onClick: () => c(e, m)
    },
    [s.STOP]: {
      label: "Stop",
      onClick: () => o(e, m),
      semantic: _.DANGER
    },
    [s.VIEW_REPORT]: {
      label: "View Report",
      onClick: () => a(e, m)
    }
  }, C = ye[m][i].map((E) => p[E]);
  return C.length === 0 ? null : /* @__PURE__ */ t("div", { className: P.container, children: /* @__PURE__ */ t(
    oe,
    {
      alwaysShowIcon: !0,
      dropdownClassName: P.dropdown,
      items: C,
      label: "",
      prefixIcon: /* @__PURE__ */ t(j, { size: 24 }),
      wrapperClassName: P.menu
    }
  ) });
}, Le = (e) => {
  const r = e.toLocaleDateString("en-GB", { weekday: "short" }), c = e.toLocaleDateString("en-GB", { day: "numeric" }), o = e.toLocaleDateString("en-GB", { month: "short" }), a = e.toLocaleDateString("en-GB", { year: "numeric" });
  return `${r} ${c} ${o}, ${a}`;
}, Pe = "creator_container_1QVG-", Ae = "creator_body_Lprt-", fe = "creator_tableHeader_CPSlt", Oe = "creator_tableBody_Ez7Z7", Ie = "creator_tableFooter_fu-o9", ke = "creator_search_4gy5j", xe = "creator_tag_K1jQ-", we = "creator_nameColumn_nLOrU", ve = "creator_statusColumn_al9Qe", Ge = "creator_segmentColumn_n2BTg", He = "creator_openRateColumn_iyqBL", $e = "creator_clickRateColumn_LD7Pw", Ve = "creator_typeColumn_aT5ti", ze = "creator_scheduleColumn_XE8H-", Ue = "creator_optionMenuColumn_Pimrw", Be = "creator_footerText_TX--Y", u = { container: Pe, body: Ae, tableHeader: fe, tableBody: Oe, tableFooter: Ie, search: ke, tag: xe, nameColumn: we, statusColumn: ve, segmentColumn: Ge, openRateColumn: He, clickRateColumn: $e, typeColumn: Ve, scheduleColumn: ze, optionMenuColumn: Ue, footerText: Be };
function w({
  campaigns: e,
  limit: r = 10,
  loading: c = !1,
  offset: o = 0,
  onCreateEmailCampaignClick: a,
  onCreateSmsCampaignClick: i,
  onDeleteClick: m,
  onEditClick: p,
  onNextClick: D,
  onPreviousClick: C,
  onSearch: E,
  onStopClick: R,
  onViewReportClick: T,
  searchTerm: b = "",
  total: N = e.length
}) {
  const h = o + e.length, g = Math.min(h, o + 1);
  return {
    campaigns: e,
    end: h,
    limit: r,
    loading: c,
    offset: o,
    onCreateEmailCampaignClick: a,
    onCreateSmsCampaignClick: i,
    onDeleteClick: m,
    onEditClick: p,
    onNextClick: D,
    onPreviousClick: C,
    onSearch: E,
    onStopClick: R,
    onViewReportClick: T,
    searchTerm: b,
    start: g,
    total: N
  };
}
const Fe = (e) => {
  const {
    campaigns: r,
    end: c,
    limit: o = 10,
    loading: a,
    offset: i = 0,
    onCreateEmailCampaignClick: m,
    onCreateSmsCampaignClick: p,
    onDeleteClick: D,
    onEditClick: C,
    onNextClick: E,
    onPreviousClick: R,
    onSearch: T,
    onStopClick: b,
    onViewReportClick: N,
    start: h,
    total: g
  } = w(e), { CampaignDeleteModal: v, openDeleteModal: G } = ce({
    onDeleteClick: D
  }), { CampaignStopModal: H, openStopModal: $ } = re({
    onStopClick: b
  }), { CampaignCreateModal: V, openCampaignCreateModal: f } = Ce({
    onCreateEmailCampaignClick: m,
    onCreateSmsCampaignClick: p
  });
  return /* @__PURE__ */ S("div", { className: u.container, children: [
    /* @__PURE__ */ t(
      Z,
      {
        button: {
          onClick: f,
          label: "New Campaign"
        },
        title: "Campaigns"
      }
    ),
    /* @__PURE__ */ S(W, { className: u.body, children: [
      /* @__PURE__ */ t(L, { className: u.tableHeader, children: /* @__PURE__ */ t(Q, { className: u.search, children: /* @__PURE__ */ t(
        q,
        {
          label: "Search",
          onChange: (n) => T(n.target.value)
        }
      ) }) }),
      /* @__PURE__ */ t(L, { className: u.tableBody, children: /* @__PURE__ */ t(
        te,
        {
          columns: [
            { style: { width: "27.5%" } },
            { style: { width: "150px" } },
            { style: { width: "27.5%" } },
            { style: { width: "125px" } },
            { style: { width: "175px" } },
            { style: { width: "125px" } },
            { style: { width: "160px" } },
            {
              style: {
                width: "64px",
                paddingLeft: "8px",
                paddingRight: "16px"
              }
            }
          ],
          data: r,
          emptyTableContent: {
            content: /* @__PURE__ */ t(
              ge,
              {
                onCreateClick: f
              }
            )
          },
          head: [
            "Name",
            "Status",
            "Segment",
            "Open rate",
            "Click-through rate",
            "Type",
            "Scheduled send",
            ""
          ],
          isLoading: a,
          row: (n) => [
            n.name,
            /* @__PURE__ */ t(
              J,
              {
                size: "small",
                status: se[n.status],
                text: n.status
              }
            ),
            n.segmentNames.join(", "),
            n.openRate ? `${n.openRate.toFixed(1)}%` : "-",
            n.clickRate ? `${n.clickRate.toFixed(1)}%` : "-",
            /* @__PURE__ */ t("div", { className: u.tag, children: /* @__PURE__ */ t(
              ee,
              {
                text: le[n.type],
                variant: ie[n.type]
              }
            ) }),
            n.scheduledTimestamp ? Le(n.scheduledTimestamp) : "-",
            /* @__PURE__ */ t(
              Ne,
              {
                id: n.id,
                onDeleteClick: G(n),
                onEditClick: C,
                onStopClick: $(n),
                onViewReportClick: N,
                status: n.status,
                type: n.type
              }
            )
          ]
        }
      ) }),
      /* @__PURE__ */ S(L, { className: u.tableFooter, children: [
        a ? /* @__PURE__ */ t(K, { type: "skeleton", size: "large" }) : /* @__PURE__ */ S("p", { className: u.footerText, children: [
          h,
          "-",
          c,
          " of ",
          g,
          " campaigns"
        ] }),
        /* @__PURE__ */ t(
          X,
          {
            isNextDisabled: a || !g || c >= g,
            isPreviousDisabled: a || !g || h === 1,
            onNextClick: () => E(i, o),
            onPreviousClick: () => R(i, o)
          }
        )
      ] })
    ] }),
    /* @__PURE__ */ t(v, {}),
    /* @__PURE__ */ t(H, {}),
    /* @__PURE__ */ t(V, {})
  ] });
}, mt = z(
  Fe,
  w
);
export {
  mt as C,
  ie as a,
  ne as b,
  d as c,
  l as d,
  Fe as e,
  se as s,
  le as t
};
