import { jsx as e, jsxs as a, Fragment as se } from "react/jsx-runtime";
import { C as ae } from "./CardContentStatistic.tc-bsVHZ.js";
import { l as H } from "./index.C1ZfizMq.js";
import { a as ne } from "./index.CfQlFjZU.js";
import { n as l } from "./index.B0wX8xO7.js";
import { u as re, v as le, w as ce, x as oe, y as de, z as me, A as ue, B as pe, C as he } from "./index.dWlEA7uO.js";
import { useMemo as m } from "react";
import { S as ge, M as B } from "./shared.EdGf6tcG.js";
import { a as Z } from "./message.CHKnnsjy.js";
import { a as fe } from "./Tag.Bk_lQM4l.js";
import { u as be, d as j } from "./useFormatDate.DZVq5Yc3.js";
import { u as G } from "./useFormatNumber.B91lpWtw.js";
import { u } from "./useFormatPercent.Cdq7WsHc.js";
import "./ProgressActivity.DYLCzf8q.js";
import "./formInputIcon.module.CU3tuFAI.js";
import "./isEqual.Bk3xqtBB.js";
import { a as ve, g as N, d as c } from "./GridRow._ehOXG8R.js";
import "./GridLayouts.DSIvKCIo.js";
import { C as z } from "./card.CVCKhKP6.js";
import { C as p } from "./CardBody.BTU-WvVF.js";
import { C as h } from "./CardHeader.ZIkhzd4s.js";
import { P as Pe } from "./PageHeader.BwFpx_pz.js";
import { C as Ce } from "./ClicksTable.CW_ctyXL.js";
import { L as g } from "./LoadingState.BcrOPPws.js";
const Ne = "creator_pageHeader_cpsZi", ze = "creator_header_zppli", Se = "creator_stats_OkmBL", De = "creator_details_Zx99F", we = "creator_detailsContent_GXhzh", ye = "creator_detailsSection_bjRqZ", _e = "creator_clicksTable_10rYK", Te = "creator_segments_haEcT", ke = "creator_preview_Yvm3u", Me = "creator_segmentListItem_050-Q", i = { pageHeader: Ne, header: ze, stats: Se, details: De, detailsContent: we, detailsSection: ye, clicksTable: _e, segments: Te, preview: ke, segmentListItem: Me }, A = [
  "primary",
  "default",
  "other",
  "brand",
  "info",
  "success",
  "warning",
  "error"
], xe = ({
  previousPageUrl: S,
  pdfLoading: f = !1,
  isClickStatsLoading: D = !1,
  onExportAsPdf: b,
  onStopCampaign: r,
  campaign: o,
  campaignLoading: w,
  recipientsLoading: y,
  segmentsLoading: _,
  smartSchedule: t,
  stats: s,
  clicks: T,
  campaignPreviewElement: k,
  allAtOnce: M
}) => {
  const x = u(s?.campaignProgressPercent || 0), O = u(s?.openPercent || 0), v = u(s?.clickThroughPercent || 0), R = u(s?.bouncedPercent || 0), P = u(s?.unsubscribedPercent || 0), E = be(s?.emailsSent || 0, {
    maxDecimalDigits: 1
  }), d = G(s?.emailsSent || 0), L = s?.campaignProgressPercent !== void 0 ? x : "-", $ = s?.openPercent !== void 0 ? O : "-", U = s?.clickThroughPercent !== void 0 ? v : "-", V = s?.bouncedPercent !== void 0 ? R : "-", Y = s?.unsubscribedPercent !== void 0 ? P : "-", q = s?.emailsSent !== void 0 ? E : "-", K = s?.emailsSent !== void 0 ? d : "-", I = j(t?.startDate, {
    timeZone: t?.timeZone
  }), C = j(t?.endDate, {
    timeZone: t?.timeZone
  }), Q = G(t?.recipients), W = m(() => {
    const n = [];
    return t?.status !== "Scheduled" && n.push({
      label: "Export as PDF",
      onClick: b,
      prefixIcon: /* @__PURE__ */ e(re, { size: 24 }),
      disabled: f
    }), t?.status === "Scheduled" && n.push({
      label: "Stop Campaign",
      prefixIcon: /* @__PURE__ */ e(le, { size: 24 }),
      onClick: r,
      semantic: ge.DANGER
    }), n;
  }, [t?.status, f, b, r]), X = m(() => {
    let n = "default";
    return t?.status === "Scheduled" && (n = "info"), (t?.status === "Stopped" || t?.status === "Paused") && (n = "error"), t?.status === "Sending" && (n = "success"), {
      size: "large",
      text: t?.status || "",
      status: n
    };
  }, [t?.status]), J = m(() => {
    if (t?.status === "Sending")
      return `This campaign is estimated to complete on ${C}.`;
    if (t?.status === "Scheduled")
      return `This campaign is estimated to complete between ${I} and ${C}.`;
  }, [t?.status, I, C]), ee = m(() => {
    if (t?.status === "Sending" && !s)
      return "Analytics data for this campaign is not ready yet, come back later.";
  }, [t?.status, s]), te = m(() => t?.segments.map((n, ie) => ({
    text: n,
    variant: A[ie % A.length]
  })) || [], [t?.segments]), F = t?.status || "";
  return {
    status: F,
    previousPageUrl: S,
    showCompletion: F === "Sending" && !M || F === "Scheduled",
    menuItems: W,
    statusDetails: X,
    segments: te,
    campaignLoading: !!w,
    recipientsLoading: !!y,
    segmentsLoading: !!_,
    campaignTitle: o?.title,
    subject: o?.subject,
    template: o?.template,
    startDate: I,
    endDate: C,
    recipients: Q,
    clicks: T,
    isClickStatsLoading: D,
    sendingMessage: J,
    campaignPreview: k,
    stats: [
      {
        label: "Campaign progress",
        value: L,
        icon: ce
      },
      {
        label: "Emails sent",
        tooltipValue: K,
        value: q,
        icon: oe
      },
      {
        label: "Open rate",
        value: $,
        icon: de
      },
      {
        label: "Click-through rate",
        value: U,
        icon: me
      },
      {
        label: "Bounced",
        value: V,
        icon: ue
      },
      {
        label: "Unsubscribed",
        value: Y,
        icon: pe
      }
    ],
    dataUnavailableMessage: ee
  };
}, Oe = ({
  previousPageUrl: S,
  menuItems: f,
  startDate: D,
  endDate: b,
  campaignLoading: r,
  recipientsLoading: o,
  segmentsLoading: w,
  campaignTitle: y,
  subject: _,
  template: t,
  recipients: s,
  stats: T,
  isClickStatsLoading: k,
  clicks: M,
  segments: x,
  statusDetails: O,
  sendingMessage: v,
  campaignPreview: R,
  dataUnavailableMessage: P,
  showCompletion: E
}) => /* @__PURE__ */ a(ve, { children: [
  /* @__PURE__ */ a(N, { children: [
    /* @__PURE__ */ e(c, { className: i.pageHeader, children: /* @__PURE__ */ e(
      Pe,
      {
        title: y,
        previousPageUrl: S,
        tagDetails: {
          text: "Email",
          variant: "other"
        },
        statusDetails: O,
        menu: {
          label: "More",
          suffixIcon: /* @__PURE__ */ e(he, { size: 24 }),
          items: f
        },
        loading: r
      }
    ) }),
    /* @__PURE__ */ e(
      l,
      {
        value: v,
        then: /* @__PURE__ */ e(c, { className: i.pageHeader, children: /* @__PURE__ */ e(Z, { semantic: B.INFO, text: v }) })
      }
    ),
    /* @__PURE__ */ e(
      l,
      {
        value: P,
        then: /* @__PURE__ */ e(c, { className: i.pageHeader, children: /* @__PURE__ */ e(
          Z,
          {
            semantic: B.WARNING,
            text: P
          }
        ) })
      }
    )
  ] }),
  /* @__PURE__ */ e("div", { className: i.header, children: /* @__PURE__ */ e("h2", { children: "Performance" }) }),
  /* @__PURE__ */ e(N, { className: i.stats, children: /* @__PURE__ */ e(
    H,
    {
      values: T,
      layout: (d) => /* @__PURE__ */ e(c, { children: /* @__PURE__ */ e(z, { elevation: "medium", interaction: "static", children: /* @__PURE__ */ e(ae, { ...d }) }) })
    }
  ) }),
  /* @__PURE__ */ e("div", { className: i.header, children: /* @__PURE__ */ e("h2", { children: "Details" }) }),
  /* @__PURE__ */ a(N, { className: i.details, children: [
    /* @__PURE__ */ e(c, { children: /* @__PURE__ */ e(
      z,
      {
        elevation: "medium",
        interaction: "static",
        className: i.preview,
        loading: r,
        children: R
      }
    ) }),
    /* @__PURE__ */ e(c, { children: /* @__PURE__ */ e(z, { elevation: "medium", interaction: "static", children: /* @__PURE__ */ a("div", { className: i.detailsContent, children: [
      /* @__PURE__ */ a("div", { className: i.detailsSection, children: [
        /* @__PURE__ */ e(h, { size: "small", children: "Subject" }),
        /* @__PURE__ */ e(
          l,
          {
            value: r,
            then: /* @__PURE__ */ e(g, { type: "wheel", size: "small" }),
            otherwise: /* @__PURE__ */ e(p, { size: "small", children: _ })
          }
        )
      ] }),
      /* @__PURE__ */ a("div", { className: i.detailsSection, children: [
        /* @__PURE__ */ e(h, { size: "small", children: "Template" }),
        /* @__PURE__ */ e(
          l,
          {
            value: r,
            then: /* @__PURE__ */ e(g, { type: "wheel", size: "small" }),
            otherwise: /* @__PURE__ */ e(p, { size: "small", children: t })
          }
        )
      ] }),
      /* @__PURE__ */ a("div", { className: i.detailsSection, children: [
        /* @__PURE__ */ e(h, { size: "small", children: "Schedule" }),
        /* @__PURE__ */ e("div", { children: /* @__PURE__ */ e(
          l,
          {
            value: r,
            then: /* @__PURE__ */ e(g, { type: "wheel", size: "small" }),
            otherwise: /* @__PURE__ */ a(se, { children: [
              /* @__PURE__ */ a(p, { size: "small", children: [
                "Start date: ",
                D
              ] }),
              /* @__PURE__ */ e(
                l,
                {
                  value: E,
                  then: /* @__PURE__ */ a(p, { size: "small", children: [
                    "Estimated completion date: ",
                    b
                  ] })
                }
              )
            ] })
          }
        ) })
      ] })
    ] }) }) }),
    /* @__PURE__ */ e(c, { children: /* @__PURE__ */ e(z, { elevation: "medium", interaction: "static", children: /* @__PURE__ */ a("div", { className: i.detailsContent, children: [
      /* @__PURE__ */ a("div", { className: i.detailsSection, children: [
        /* @__PURE__ */ e(h, { size: "small", children: "Recipients" }),
        /* @__PURE__ */ e(
          l,
          {
            value: o,
            then: /* @__PURE__ */ e(g, { type: "wheel", size: "small" }),
            otherwise: /* @__PURE__ */ e(p, { size: "small", children: s })
          }
        )
      ] }),
      /* @__PURE__ */ a("div", { className: i.detailsSection, children: [
        /* @__PURE__ */ e(h, { size: "small", children: "Segments" }),
        /* @__PURE__ */ e(
          l,
          {
            value: w,
            then: /* @__PURE__ */ e(g, { type: "wheel", size: "small" }),
            otherwise: /* @__PURE__ */ e("ul", { className: i.segments, children: /* @__PURE__ */ e(
              H,
              {
                values: x,
                layout: (d) => /* @__PURE__ */ e("li", { className: i.segmentListItem, children: /* @__PURE__ */ e(fe, { ...d }) })
              }
            ) })
          }
        )
      ] })
    ] }) }) })
  ] }),
  /* @__PURE__ */ e("div", { className: i.header, children: /* @__PURE__ */ e("h2", { children: "Click-through rate" }) }),
  /* @__PURE__ */ e(N, { children: /* @__PURE__ */ e(c, { className: i.clicksTable, children: /* @__PURE__ */ e(Ce, { clicks: M, isLoading: k }) }) })
] }), st = ne(
  Oe,
  xe
);
export {
  st as S,
  xe as u
};
