import C, { Component as ce, useState as k, useRef as j, useEffect as I, useCallback as z, useMemo as Z } from "react";
import { jsxs as o, jsx as t, Fragment as H } from "react/jsx-runtime";
var ee = {
  color: void 0,
  size: void 0,
  className: void 0,
  style: void 0,
  attr: void 0
}, W = C.createContext && /* @__PURE__ */ C.createContext(ee), de = ["attr", "size", "title"];
function ue(e, r) {
  if (e == null) return {};
  var a = he(e, r), n, i;
  if (Object.getOwnPropertySymbols) {
    var l = Object.getOwnPropertySymbols(e);
    for (i = 0; i < l.length; i++)
      n = l[i], !(r.indexOf(n) >= 0) && Object.prototype.propertyIsEnumerable.call(e, n) && (a[n] = e[n]);
  }
  return a;
}
function he(e, r) {
  if (e == null) return {};
  var a = {};
  for (var n in e)
    if (Object.prototype.hasOwnProperty.call(e, n)) {
      if (r.indexOf(n) >= 0) continue;
      a[n] = e[n];
    }
  return a;
}
function L() {
  return L = Object.assign ? Object.assign.bind() : function(e) {
    for (var r = 1; r < arguments.length; r++) {
      var a = arguments[r];
      for (var n in a)
        Object.prototype.hasOwnProperty.call(a, n) && (e[n] = a[n]);
    }
    return e;
  }, L.apply(this, arguments);
}
function K(e, r) {
  var a = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var n = Object.getOwnPropertySymbols(e);
    r && (n = n.filter(function(i) {
      return Object.getOwnPropertyDescriptor(e, i).enumerable;
    })), a.push.apply(a, n);
  }
  return a;
}
function T(e) {
  for (var r = 1; r < arguments.length; r++) {
    var a = arguments[r] != null ? arguments[r] : {};
    r % 2 ? K(Object(a), !0).forEach(function(n) {
      me(e, n, a[n]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(a)) : K(Object(a)).forEach(function(n) {
      Object.defineProperty(e, n, Object.getOwnPropertyDescriptor(a, n));
    });
  }
  return e;
}
function me(e, r, a) {
  return r = ge(r), r in e ? Object.defineProperty(e, r, { value: a, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = a, e;
}
function ge(e) {
  var r = fe(e, "string");
  return typeof r == "symbol" ? r : r + "";
}
function fe(e, r) {
  if (typeof e != "object" || !e) return e;
  var a = e[Symbol.toPrimitive];
  if (a !== void 0) {
    var n = a.call(e, r);
    if (typeof n != "object") return n;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return (r === "string" ? String : Number)(e);
}
function te(e) {
  return e && e.map((r, a) => /* @__PURE__ */ C.createElement(r.tag, T({
    key: a
  }, r.attr), te(r.child)));
}
function v(e) {
  return (r) => /* @__PURE__ */ C.createElement(pe, L({
    attr: T({}, e.attr)
  }, r), te(e.child));
}
function pe(e) {
  var r = (a) => {
    var {
      attr: n,
      size: i,
      title: l
    } = e, u = ue(e, de), h = i || a.size || "1em", c;
    return a.className && (c = a.className), e.className && (c = (c ? c + " " : "") + e.className), /* @__PURE__ */ C.createElement("svg", L({
      stroke: "currentColor",
      fill: "currentColor",
      strokeWidth: "0"
    }, a.attr, n, u, {
      className: c,
      style: T(T({
        color: e.color || a.color
      }, a.style), e.style),
      height: h,
      width: h,
      xmlns: "http://www.w3.org/2000/svg"
    }), l && /* @__PURE__ */ C.createElement("title", null, l), e.children);
  };
  return W !== void 0 ? /* @__PURE__ */ C.createElement(W.Consumer, null, (a) => r(a)) : r(ee);
}
function ve(e) {
  return v({ attr: { viewBox: "0 0 512 512" }, child: [{ tag: "path", attr: { d: "M257 120.471c7.083 0 23.911 4.479 23.911 4.479 45.589 10.447 77.678 52.439 77.678 99.85V352.412l9.321 9.364 7.788 7.823H136.302l7.788-7.823 9.321-9.364V224.8c0-47.41 32.089-89.403 77.678-99.85 0 0 18.043-4.479 23.911-4.479M256 48c-17.602 0-31.059 13.518-31.059 31.2v14.559c-59.015 13.523-103.53 67.601-103.53 131.041v114.4L80 380.8v20.8h352v-20.8l-41.411-41.6V224.8c0-63.44-44.516-117.518-103.53-131.041V79.2c0-17.682-13.457-31.2-31.059-31.2zm41.411 374.4h-82.823c0 22.881 18.633 41.6 41.412 41.6s41.411-18.719 41.411-41.6z" }, child: [] }] })(e);
}
const Ue = ({
  unreadCount: e,
  onClick: r,
  className: a = "",
  disabled: n = !1
}) => {
  const i = (c) => c === 0 ? "" : c > 99 ? "99+" : c.toString(), l = (c) => {
    n || (c.key === "Enter" || c.key === " ") && (c.preventDefault(), r());
  }, u = i(e), h = e > 0;
  return /* @__PURE__ */ o(
    "button",
    {
      type: "button",
      className: `
        relative inline-flex items-center justify-center
        rounded-full
        text-[var(--widget-text-secondary)] hover:text-[var(--widget-text)]
        bg-transparent hover:bg-[var(--widget-bg-hover)]
        border-0 cursor-pointer
        transition-colors duration-300
        focus:outline-none focus:ring-1 focus:ring-[var(--widget-primary)] focus:ring-offset-1
        disabled:opacity-70 disabled:cursor-not-allowed
        w-10 h-10
        mx-widget-bell
        ${a}
      `,
      onClick: r,
      onKeyDown: l,
      disabled: n,
      "aria-label": h ? `Notifications (${e} unread)` : "Notifications",
      "aria-expanded": !1,
      "aria-haspopup": "dialog",
      "data-testid": "bell-component",
      "data-mx-widget": "bell",
      children: [
        /* @__PURE__ */ o("div", { className: "relative inline-flex items-center justify-center text-align-center", children: [
          /* @__PURE__ */ t(ve, { className: "w-6 h-6" }),
          h && /* @__PURE__ */ t(
            "span",
            {
              className: `
              absolute
              flex items-center justify-center
              w-[16px] h-[16px]
              text-[10px] font-bold leading-none
              text-[var(--widget-text)] bg-red-500
              rounded-full
              border border-white dark:border-gray-900
              shadow-sm
              pointer-events-none
              text-align-center
            `,
              "aria-hidden": "true",
              "data-testid": "unread-badge",
              style: { marginTop: "-25px", marginRight: "-25px" },
              children: u
            }
          )
        ] }),
        /* @__PURE__ */ t("span", { className: "sr-only", children: h ? `${e} unread notifications` : "No unread notifications" })
      ]
    }
  );
};
class q extends ce {
  constructor(r) {
    super(r), this.state = {
      hasError: !1,
      error: null
    };
  }
  static getDerivedStateFromError(r) {
    return {
      hasError: !0,
      error: r
    };
  }
  componentDidCatch(r, a) {
    const { componentName: n = "Unknown Component", onError: i } = this.props;
    i && i(r, a);
  }
  render() {
    return this.state.hasError ? this.props.fallback ? this.props.fallback : /* @__PURE__ */ t(
      "div",
      {
        className: "p-2 text-sm text-gray-500 bg-gray-50 border border-gray-200 rounded",
        "data-testid": "component-error-fallback",
        children: /* @__PURE__ */ o("span", { children: [
          "Unable to load ",
          this.props.componentName || "component"
        ] })
      }
    ) : this.props.children;
  }
}
function V(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" }, child: [] }, { tag: "path", attr: { d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z" }, child: [] }] })(e);
}
function be(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" }, child: [] }, { tag: "path", attr: { d: "M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" }, child: [] }] })(e);
}
function xe(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" }, child: [] }, { tag: "path", attr: { d: "M15.5 14h-.79l-.28-.27A6.471 6.471 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" }, child: [] }] })(e);
}
function re(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0V0z" }, child: [] }, { tag: "path", attr: { d: "M19.14 12.94c.04-.3.06-.61.06-.94 0-.32-.02-.64-.07-.94l2.03-1.58a.49.49 0 0 0 .12-.61l-1.92-3.32a.488.488 0 0 0-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54a.484.484 0 0 0-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.05.3-.09.63-.09.94s.02.64.07.94l-2.03 1.58a.49.49 0 0 0-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z" }, child: [] }] })(e);
}
function We(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" }, child: [] }, { tag: "path", attr: { d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z" }, child: [] }] })(e);
}
function we(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" }, child: [] }, { tag: "path", attr: { d: "M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z" }, child: [] }] })(e);
}
function ye(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" }, child: [] }, { tag: "path", attr: { d: "M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4-8 5-8-5V6l8 5 8-5v2z" }, child: [] }] })(e);
}
function ae(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" }, child: [] }, { tag: "path", attr: { d: "m20.54 5.23-1.39-1.68C18.88 3.21 18.47 3 18 3H6c-.47 0-.88.21-1.16.55L3.46 5.23C3.17 5.57 3 6.02 3 6.5V19c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6.5c0-.48-.17-.93-.46-1.27zM12 17.5 6.5 12H10v-2h4v2h3.5L12 17.5zM5.12 5l.81-1h12l.94 1H5.12z" }, child: [] }] })(e);
}
function Ne(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" }, child: [] }, { tag: "path", attr: { d: "M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z" }, child: [] }, { tag: "path", attr: { d: "M12.5 7H11v6l5.25 3.15.75-1.23-4.5-2.67z" }, child: [] }] })(e);
}
function ke(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" }, child: [] }, { tag: "path", attr: { d: "M17 1.01 7 1c-1.1 0-2 .9-2 2v18c0 1.1.9 2 2 2h10c1.1 0 2-.9 2-2V3c0-1.1-.9-1.99-2-1.99zM17 19H7V5h10v14z" }, child: [] }] })(e);
}
function Ce(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" }, child: [] }, { tag: "path", attr: { d: "m21.41 11.58-9-9C12.05 2.22 11.55 2 11 2H4c-1.1 0-2 .9-2 2v7c0 .55.22 1.05.59 1.42l9 9c.36.36.86.58 1.41.58.55 0 1.05-.22 1.41-.59l7-7c.37-.36.59-.86.59-1.41 0-.55-.23-1.06-.59-1.42zM5.5 7C4.67 7 4 6.33 4 5.5S4.67 4 5.5 4 7 4.67 7 5.5 6.33 7 5.5 7z" }, child: [] }] })(e);
}
function Me(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" }, child: [] }, { tag: "path", attr: { d: "M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z" }, child: [] }] })(e);
}
function ne(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" }, child: [] }, { tag: "path", attr: { d: "M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" }, child: [] }] })(e);
}
function ze(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" }, child: [] }, { tag: "path", attr: { d: "m12 8-6 6 1.41 1.41L12 10.83l4.59 4.58L18 14z" }, child: [] }] })(e);
}
function je(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" }, child: [] }, { tag: "path", attr: { d: "M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z" }, child: [] }] })(e);
}
function Ke(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" }, child: [] }, { tag: "path", attr: { d: "M17.65 6.35A7.958 7.958 0 0 0 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08A5.99 5.99 0 0 1 12 18c-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z" }, child: [] }] })(e);
}
function Ee(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" }, child: [] }, { tag: "path", attr: { d: "M20 2H4c-1.1 0-1.99.9-1.99 2L2 22l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zM9 11H7V9h2v2zm4 0h-2V9h2v2zm4 0h-2V9h2v2z" }, child: [] }] })(e);
}
function G(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { d: "M12 22c1.1 0 2-.9 2-2h-4a2 2 0 0 0 2 2zm6-6v-5c0-3.07-1.64-5.64-4.5-6.32V4c0-.83-.67-1.5-1.5-1.5s-1.5.67-1.5 1.5v.68C7.63 5.36 6 7.92 6 11v5l-2 2v1h16v-1l-2-2z" }, child: [] }] })(e);
}
function He(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0z" }, child: [] }, { tag: "path", attr: { d: "M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z" }, child: [] }, { tag: "path", attr: { d: "M14 17H7v-2h7v2zm3-4H7v-2h10v2zm0-4H7V7h10v2z" }, child: [] }] })(e);
}
function ie(e) {
  return v({ attr: { viewBox: "0 0 24 24" }, child: [{ tag: "path", attr: { fill: "none", d: "M0 0h24v24H0V0z" }, child: [] }, { tag: "path", attr: { d: "M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 14H4V8l8 5 8-5v10zm-8-7L4 6h16l-8 5z" }, child: [] }] })(e);
}
const Le = ({ onRetry: e, error: r }) => /* @__PURE__ */ o("div", { className: "p-3 text-center", "data-testid": "notifications-fallback", children: [
  /* @__PURE__ */ t("div", { className: "text-[var(--widget-text-tertiary)] mb-2", children: /* @__PURE__ */ t(V, { className: "w-12 h-12 mx-auto" }) }),
  /* @__PURE__ */ t("p", { className: "text-sm text-[var(--widget-text-secondary)] mb-3", children: r ? "Failed to load notifications" : "No notifications available" }),
  e && /* @__PURE__ */ t(
    "button",
    {
      type: "button",
      className: "text-sm text-[var(--widget-primary)] hover:text-[var(--widget-primary-hover)] font-medium transition-colors",
      onClick: e,
      children: "Try again"
    }
  )
] }), J = ({ onRetry: e, onBack: r }) => /* @__PURE__ */ o("div", { className: "p-3 text-center", "data-testid": "preferences-fallback", children: [
  /* @__PURE__ */ t("div", { className: "text-[var(--widget-text-tertiary)] mb-2", children: /* @__PURE__ */ t(re, { className: "w-12 h-12 mx-auto" }) }),
  /* @__PURE__ */ t("p", { className: "text-sm text-[var(--widget-text-secondary)] mb-3", children: "Unable to load preferences" }),
  /* @__PURE__ */ o("div", { className: "space-x-2", children: [
    e && /* @__PURE__ */ t(
      "button",
      {
        type: "button",
        className: "text-sm text-[var(--widget-primary)] hover:text-[var(--widget-primary-hover)] font-medium transition-colors",
        onClick: e,
        children: "Try again"
      }
    ),
    r && /* @__PURE__ */ t(
      "button",
      {
        type: "button",
        className: "text-sm text-[var(--widget-text-secondary)] hover:text-[var(--widget-text)] font-medium transition-colors",
        onClick: r,
        children: "Back"
      }
    )
  ] })
] }), qe = ({ onRetry: e, error: r }) => /* @__PURE__ */ o(
  "div",
  {
    className: "p-3 text-center bg-[var(--widget-warning)]/10 border border-[var(--widget-warning)]/20 rounded-lg",
    "data-testid": "sdk-connection-fallback",
    children: [
      /* @__PURE__ */ t("div", { className: "text-[var(--widget-warning)] mb-2", children: /* @__PURE__ */ t(we, { className: "w-12 h-12 mx-auto" }) }),
      /* @__PURE__ */ t("p", { className: "text-sm text-[var(--widget-warning)] mb-3 font-medium", children: "Connection to notification service failed" }),
      r && process.env.NODE_ENV === "development" && /* @__PURE__ */ t("p", { className: "text-xs text-[var(--widget-warning)] mb-3 font-mono opacity-80", children: r }),
      e && /* @__PURE__ */ t(
        "button",
        {
          type: "button",
          className: "text-sm font-medium bg-[var(--widget-warning)]/20 text-[var(--widget-warning)] hover:bg-[var(--widget-warning)]/30 px-3 py-1 rounded transition-colors",
          onClick: e,
          children: "Retry connection"
        }
      )
    ]
  }
), Ge = ({ message: e = "Loading..." }) => /* @__PURE__ */ o("div", { className: "p-3 text-center", "data-testid": "loading-fallback", children: [
  /* @__PURE__ */ t("div", { className: "w-6 h-6 border-2 border-[var(--widget-primary)] border-t-transparent rounded-full animate-spin mx-auto mb-2" }),
  /* @__PURE__ */ t("p", { className: "text-sm text-[var(--widget-text-secondary)]", children: e })
] }), Te = (e, r) => {
  switch (r) {
    case "all":
      return e;
    case "unread":
      return e.filter((a) => !a.isRead);
    default:
      if (r.startsWith("tag:")) {
        const a = r.substring(4);
        return e.filter((n) => n.tags.includes(a));
      }
      return e;
  }
}, Se = (e, r) => {
  if (!r.trim())
    return e;
  const a = r.toLowerCase().trim();
  return e.filter((n) => {
    const i = n.subject.toLowerCase(), l = n.body.toLowerCase(), u = n.tags.join(" ").toLowerCase();
    return i.includes(a) || l.includes(a) || u.includes(a);
  });
}, Oe = (e, r) => {
  const a = [...e];
  switch (r) {
    case "newest":
      return a.sort((n, i) => i.timestamp.getTime() - n.timestamp.getTime());
    case "oldest":
      return a.sort((n, i) => n.timestamp.getTime() - i.timestamp.getTime());
    case "unread-first":
      return a.sort((n, i) => n.isRead === i.isRead ? i.timestamp.getTime() - n.timestamp.getTime() : n.isRead ? 1 : -1);
    case "read-first":
      return a.sort((n, i) => n.isRead === i.isRead ? i.timestamp.getTime() - n.timestamp.getTime() : n.isRead ? -1 : 1);
    default:
      return a;
  }
}, $e = (e, r, a, n = "newest") => {
  let i = e;
  return i = Te(i, r), a && (i = Se(i, a)), i = Oe(i, n), i;
}, Pe = ({
  selectedNotifications: e,
  onMarkAllAsRead: r,
  onMarkAllAsUnread: a,
  onArchiveAll: n,
  onDeleteAll: i,
  onClearSelection: l,
  className: u = ""
}) => {
  const [h, c] = k(!1), [m, f] = k(null), g = e.length, x = async (y, b) => {
    if (g !== 0) {
      c(!0), f(null);
      try {
        const w = await y(e);
        f(w), w.success && l();
      } catch (w) {
        f({
          success: !1,
          processedCount: 0,
          failedCount: g,
          errors: [{ notificationId: "", error: w }]
        });
      } finally {
        c(!1);
      }
    }
  };
  return g === 0 ? null : /* @__PURE__ */ o("div", { className: `border-t border-border bg-widget-primary-light p-2 ${u}`, children: [
    /* @__PURE__ */ o("div", { className: "flex items-center justify-between", children: [
      /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
        /* @__PURE__ */ o("span", { className: "text-sm font-medium text-widget-primary", children: [
          g,
          " notification",
          g !== 1 ? "s" : "",
          " selected"
        ] }),
        m && !m.success && /* @__PURE__ */ o("span", { className: "text-xs text-[var(--widget-error)]", children: [
          m.failedCount,
          " failed"
        ] })
      ] }),
      /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
        /* @__PURE__ */ o(
          "button",
          {
            type: "button",
            onClick: () => x(r),
            disabled: h,
            className: "inline-flex items-center px-2 py-1 text-xs font-medium text-blue-700 bg-white border border-blue-300 rounded hover:bg-blue-50 focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",
            "data-testid": "bulk-mark-read",
            children: [
              /* @__PURE__ */ t(V, { className: "mr-1 w-4 h-4" }),
              "Mark Read"
            ]
          }
        ),
        /* @__PURE__ */ o(
          "button",
          {
            type: "button",
            onClick: () => x(a),
            disabled: h,
            className: "inline-flex items-center px-2 py-1 text-xs font-medium text-blue-700 bg-white border border-blue-300 rounded hover:bg-blue-50 focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",
            "data-testid": "bulk-mark-unread",
            children: [
              /* @__PURE__ */ t(ie, { className: "mr-1 w-4 h-4" }),
              "Mark Unread"
            ]
          }
        ),
        /* @__PURE__ */ o(
          "button",
          {
            type: "button",
            onClick: () => x(n),
            disabled: h,
            className: "inline-flex items-center px-2 py-1 text-xs font-medium text-text-secondary bg-white border border-border rounded hover:bg-widget-hover focus:outline-none focus:ring-2 focus:ring-text-secondary disabled:opacity-50 disabled:cursor-not-allowed transition-colors",
            "data-testid": "bulk-archive",
            children: [
              /* @__PURE__ */ t(ae, { className: "mr-1 w-4 h-4" }),
              "Archive"
            ]
          }
        ),
        /* @__PURE__ */ o(
          "button",
          {
            type: "button",
            onClick: () => {
              window.confirm(
                `Are you sure you want to delete ${g} notification${g !== 1 ? "s" : ""}? This action cannot be undone.`
              ) && x(i);
            },
            disabled: h,
            className: "inline-flex items-center px-2 py-1 text-xs font-medium text-[var(--widget-error)] bg-white border border-[var(--widget-error)]/30 rounded hover:bg-[var(--widget-error)]/10 focus:outline-none focus:ring-2 focus:ring-[var(--widget-error)] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",
            "data-testid": "bulk-delete",
            children: [
              /* @__PURE__ */ t(be, { className: "mr-1 w-4 h-4" }),
              "Delete"
            ]
          }
        ),
        /* @__PURE__ */ t(
          "button",
          {
            type: "button",
            onClick: l,
            disabled: h,
            className: "inline-flex items-center px-1 py-1 text-xs font-medium text-text-secondary hover:text-text-primary focus:outline-none focus:ring-2 focus:ring-text-secondary disabled:opacity-50 disabled:cursor-not-allowed transition-colors",
            "data-testid": "clear-selection",
            "aria-label": "Clear selection",
            children: /* @__PURE__ */ t(ne, { className: "w-5 h-5" })
          }
        )
      ] })
    ] }),
    h && /* @__PURE__ */ o("div", { className: "mt-2 flex items-center gap-2", children: [
      /* @__PURE__ */ t("div", { className: "animate-spin rounded-full h-4 w-4 border-b-2 border-[var(--widget-primary)]" }),
      /* @__PURE__ */ t("span", { className: "text-xs text-[var(--widget-primary)]", children: "Processing..." })
    ] }),
    m && /* @__PURE__ */ t("div", { className: "mt-2", children: m.success ? /* @__PURE__ */ o("div", { className: "text-xs text-[var(--widget-success)]", children: [
      "Successfully processed ",
      m.processedCount,
      " notification",
      m.processedCount !== 1 ? "s" : ""
    ] }) : /* @__PURE__ */ o("div", { className: "text-xs text-[var(--widget-error)]", children: [
      m.processedCount > 0 && /* @__PURE__ */ o("span", { children: [
        "Processed ",
        m.processedCount,
        ", "
      ] }),
      "Failed to process ",
      m.failedCount,
      " notification",
      m.failedCount !== 1 ? "s" : ""
    ] }) })
  ] });
}, Y = ({
  title: e = "No Items",
  description: r = "There are no items to display",
  icon: a
}) => /* @__PURE__ */ o("div", { className: "flex flex-col items-center justify-center py-8 px-4", children: [
  a && /* @__PURE__ */ t("div", { className: "mb-4 text-gray-300", children: a }),
  /* @__PURE__ */ t("h3", { className: "text-lg font-medium text-[var(--widget-text)] mb-2", children: e }),
  /* @__PURE__ */ t("p", { className: "text-sm text-text-gray-300 text-center", children: r })
] }), B = ({
  content: e,
  children: r,
  position: a = "top",
  delay: n = 200
}) => {
  const [i, l] = k(!1), [u, h] = k({ x: 0, y: 0 }), c = j(null), m = j(null), f = () => {
    c.current && clearTimeout(c.current), c.current = setTimeout(() => {
      if (m.current) {
        const b = m.current.getBoundingClientRect();
        let w = 0, s = 0;
        switch (a) {
          case "top":
            w = b.left + b.width / 2, s = b.top - 15;
            break;
          case "bottom":
            w = b.left + b.width / 2, s = b.bottom + 15;
            break;
          case "left":
            w = b.left - 15, s = b.top + b.height / 2;
            break;
          case "right":
            w = b.right + 15, s = b.top + b.height / 2;
            break;
        }
        h({ x: w, y: s }), l(!0);
      }
    }, n);
  }, g = () => {
    c.current && clearTimeout(c.current), l(!1);
  };
  I(() => () => {
    c.current && clearTimeout(c.current);
  }, []);
  const x = () => {
    switch (a) {
      case "top":
        return { marginTop: "-8px" };
      case "bottom":
        return { marginTop: "8px" };
      case "left":
        return { marginLeft: "-8px" };
      case "right":
        return { marginLeft: "8px" };
      default:
        return {};
    }
  };
  return /* @__PURE__ */ o(H, { children: [
    /* @__PURE__ */ t(
      "div",
      {
        ref: m,
        onMouseEnter: f,
        onMouseLeave: g,
        className: "inline-flex",
        children: r
      }
    ),
    i && /* @__PURE__ */ t(
      "div",
      {
        className: `
                                fixed z-50 px-2 py-1 text-xs font-medium text-[var(--widget-text-secondary)] rounded-md pointer-events-none
                                bg-[var(--widget-bg-secondary)] shadow-lg
                                ${{
          top: "-translate-x-1/2 -translate-y-full",
          bottom: "-translate-x-1/2",
          left: "-translate-x-full -translate-y-1/2",
          right: "-translate-y-1/2"
        }[a]}
                                animate-in fade-in-0 zoom-in-95 duration-200
                            `,
        style: {
          left: `${u.x}px`,
          top: `${u.y}px`,
          ...x()
        },
        children: e
      }
    )
  ] });
}, Be = (e) => {
  if (Number.isNaN(e.getTime())) return "Long ago";
  const n = (/* @__PURE__ */ new Date()).getTime() - e.getTime(), i = Math.floor(n / 6e4), l = Math.floor(n / 36e5), u = Math.floor(n / 864e5);
  return i < 1 ? "Just now" : i < 60 ? `${i}m ago` : l < 24 ? `${l}h ago` : u < 7 ? `${u}d ago` : e.toLocaleDateString();
}, A = ({ type: e, className: r }) => {
  const a = r || "w-4 h-4";
  switch (e) {
    case "mark_read":
      return /* @__PURE__ */ t(V, { className: a });
    case "snooze":
      return /* @__PURE__ */ t(Ne, { className: a });
    case "archive":
      return /* @__PURE__ */ t(ae, { className: a });
    default:
      return null;
  }
}, Ae = ({
  notification: e,
  onActionClick: r,
  onSelectionChange: a,
  isSelected: n = !1
}) => {
  const [i, l] = k(!1), u = Number.isNaN(e.timestamp.getTime()), h = u ? void 0 : e.timestamp.toISOString(), c = Be(e.timestamp), m = (g) => {
    r && r(e.id, g), l(!1);
  }, f = () => {
    a && a(!n);
  };
  return /* @__PURE__ */ o(
    "div",
    {
      className: `
        mx-widget-item relative group flex items-start gap-3 px-4 py-3 border-b border-border-light
        transition-all duration-200
        min-w-[20rem]
        ${n ? "bg-widget-primary-light" : e.isRead ? "bg-widget-background hover:bg-widget-hover" : "bg-blue-50/50 hover:bg-blue-50/70"}
      `,
      onMouseEnter: () => l(!0),
      onMouseLeave: () => l(!1),
      "data-testid": "notification-item",
      "data-notification-id": e.id,
      "data-mx-widget": "item",
      children: [
        a && /* @__PURE__ */ t("div", { className: "flex-shrink-0 pt-0.5", children: /* @__PURE__ */ t(
          "input",
          {
            type: "checkbox",
            checked: n,
            onChange: f,
            className: "w-4 h-4 text-[var(--widget-primary)] border-[var(--widget-border)] rounded cursor-pointer focus:ring-2 focus:ring-[var(--widget-primary)] focus:ring-offset-0",
            "aria-label": `Select notification: ${e.subject}`
          }
        ) }),
        /* @__PURE__ */ t("div", { className: "flex-shrink-0", children: e.avatar ? /* @__PURE__ */ t(
          "img",
          {
            src: e.avatar,
            alt: "",
            className: "w-10 h-10 rounded-full object-cover border border-border",
            "aria-hidden": "true",
            loading: "lazy"
          }
        ) : /* @__PURE__ */ t("div", { className: "w-10 h-10 rounded-full bg-gradient-to-br from-widget-primary to-widget-primary-hover flex items-center justify-center shadow-sm", children: /* @__PURE__ */ t("span", { className: "text-[var(--widget-text)] font-semibold text-base", children: e.subject.charAt(0).toUpperCase() }) }) }),
        /* @__PURE__ */ o("div", { className: "flex-1 min-w-0", children: [
          /* @__PURE__ */ o("div", { className: "flex items-start justify-between gap-2 mb-0.5", children: [
            /* @__PURE__ */ t(
              "h3",
              {
                className: `text-sm leading-5 text-[var(--widget-text)] ${e.isRead ? "font-medium" : "font-semibold"}`,
                children: e.subject
              }
            ),
            !e.isRead && /* @__PURE__ */ t("div", { className: "flex-shrink-0 mt-1.5 ml-1", children: /* @__PURE__ */ t(
              "div",
              {
                className: "w-2 h-2 rounded-full bg-unread-indicator shadow-sm",
                "aria-label": "Unread",
                role: "img"
              }
            ) })
          ] }),
          /* @__PURE__ */ t("p", { className: "text-sm text-[var(--widget-text-secondary)] line-clamp-2 leading-relaxed mb-2", children: e.body }),
          e.actions && e.actions.length > 0 && /* @__PURE__ */ t("div", { className: "flex items-center gap-2 mb-2", children: e.actions.map((g, x) => /* @__PURE__ */ t(
            "button",
            {
              onClick: (y) => {
                y.stopPropagation(), m(g);
              },
              className: `
                  px-3 py-1.5 rounded-md text-sm font-medium transition-colors
                  ${x === 0 ? "bg-[var(--widget-primary)] text-[var(--widget-text)] hover:bg-[var(--widget-primary-hover)] shadow-sm" : "bg-transparent text-[var(--widget-text-secondary)] hover:bg-[var(--widget-bg-hover)] border border-[var(--widget-border)]"}
                `,
              "data-mx-widget": "action",
              children: g.label
            },
            x
          )) }),
          /* @__PURE__ */ o("div", { className: "flex items-center justify-between min-h-[20px]", children: [
            /* @__PURE__ */ t("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ t("time", { className: "text-xs text-[var(--widget-text-tertiary)]", dateTime: h, children: c }) }),
            /* @__PURE__ */ o(
              "div",
              {
                className: `flex items-center gap-1 transition-opacity duration-200 ${i ? "opacity-100" : "opacity-0"}`,
                onClick: (g) => g.stopPropagation(),
                children: [
                  /* @__PURE__ */ t(B, { content: "Mark as read", position: "top", children: /* @__PURE__ */ t(
                    "button",
                    {
                      className: "inline-flex items-center justify-center w-7 h-7 rounded-md text-[var(--widget-text-secondary)] hover:text-[var(--widget-text)] hover:bg-[var(--widget-bg-hover)] transition-colors",
                      onClick: () => m({
                        type: "mark_read",
                        label: "Mark as read",
                        handler: async () => {
                        }
                      }),
                      "aria-label": "Mark as read",
                      children: /* @__PURE__ */ t(A, { type: "mark_read" })
                    }
                  ) }),
                  /* @__PURE__ */ t(B, { content: "Snooze", position: "top", children: /* @__PURE__ */ t(
                    "button",
                    {
                      className: "inline-flex items-center justify-center w-7 h-7 rounded-md text-[var(--widget-text-secondary)] hover:text-[var(--widget-text)] hover:bg-[var(--widget-bg-hover)] transition-colors",
                      onClick: () => m({ type: "custom", label: "Snooze", handler: async () => {
                      } }),
                      "aria-label": "Snooze",
                      children: /* @__PURE__ */ t(A, { type: "snooze" })
                    }
                  ) }),
                  /* @__PURE__ */ t(B, { content: "Archive", position: "top", children: /* @__PURE__ */ t(
                    "button",
                    {
                      className: "inline-flex items-center justify-center w-7 h-7 rounded-md text-[var(--widget-text-secondary)] hover:text-[var(--widget-text)] hover:bg-[var(--widget-bg-hover)] transition-colors",
                      onClick: () => m({ type: "archive", label: "Archive", handler: async () => {
                      } }),
                      "aria-label": "Archive",
                      children: /* @__PURE__ */ t(A, { type: "archive" })
                    }
                  ) })
                ]
              }
            )
          ] })
        ] }),
        /* @__PURE__ */ o("div", { className: "sr-only", children: [
          "Notification from",
          " ",
          u ? "Unknown time" : e.timestamp.toLocaleString(),
          ".",
          e.isRead ? "Read" : "Unread",
          ".",
          e.isArchived ? "Archived" : "Active",
          "."
        ] })
      ]
    }
  );
}, Q = ({ count: e = 3 }) => /* @__PURE__ */ t(H, { children: Array.from({ length: e }).map((r, a) => /* @__PURE__ */ o(
  "div",
  {
    className: "flex items-start gap-3 px-4 py-3 border-b border-border-light animate-pulse",
    children: [
      /* @__PURE__ */ t("div", { className: "flex-shrink-0", children: /* @__PURE__ */ t("div", { className: "w-10 h-10 rounded-full bg-widget-hover" }) }),
      /* @__PURE__ */ o("div", { className: "flex-1 space-y-2", children: [
        /* @__PURE__ */ t("div", { className: "h-4 w-3/4 rounded bg-widget-hover" }),
        /* @__PURE__ */ o("div", { className: "space-y-1", children: [
          /* @__PURE__ */ t("div", { className: "h-3 w-full rounded bg-widget-hover" }),
          /* @__PURE__ */ t("div", { className: "h-3 w-5/6 rounded bg-widget-hover" })
        ] }),
        /* @__PURE__ */ t("div", { className: "h-3 w-16 rounded bg-widget-hover" })
      ] }),
      /* @__PURE__ */ t("div", { className: "flex-shrink-0", children: /* @__PURE__ */ t("div", { className: "w-2 h-2 rounded-full bg-widget-hover" }) })
    ]
  },
  a
)) }), Re = ({
  notifications: e,
  isLoading: r = !1,
  error: a,
  onNotificationAction: n,
  selectedNotifications: i = [],
  onSelectionChange: l,
  onSelectAll: u,
  onLoadMore: h,
  hasMore: c = !1,
  className: m = ""
}) => {
  const f = j(null), g = j(null), [x, y] = k(!1);
  I(() => {
    if (!(!h || !c || x))
      return f.current = new IntersectionObserver(
        (s) => {
          s[0].isIntersecting && c && !x && (y(!0), h(), setTimeout(() => y(!1), 500));
        },
        {
          root: null,
          rootMargin: "100px",
          threshold: 0.1
        }
      ), g.current && f.current.observe(g.current), () => {
        f.current && f.current.disconnect();
      };
  }, [h, c, x]);
  const b = z(
    async (s, d) => {
      try {
        d.handler && await d.handler(s), n && d.type && n(s, d);
      } catch {
      }
    },
    [n]
  ), w = z(
    (s, d) => {
      l && l(s, d);
    },
    [l]
  );
  return r && e.length === 0 ? /* @__PURE__ */ t("div", { className: `flex flex-col h-full bg-widget-background min-w-[20rem] ${m}`, children: /* @__PURE__ */ t(Q, { count: 5 }) }) : a ? /* @__PURE__ */ t("div", { className: `flex flex-col h-full bg-widget-background min-w-[20rem] ${m}`, children: /* @__PURE__ */ t("div", { className: "flex items-center justify-center flex-1 py-12", children: /* @__PURE__ */ t(
    Y,
    {
      title: "Error Loading Notifications",
      description: "Failed to load notifications. Please try again.",
      icon: /* @__PURE__ */ t(
        "svg",
        {
          className: "w-12 h-12 text-[var(--widget-error)]",
          fill: "none",
          stroke: "currentColor",
          viewBox: "0 0 24 24",
          children: /* @__PURE__ */ t(
            "path",
            {
              strokeLinecap: "round",
              strokeLinejoin: "round",
              strokeWidth: 2,
              d: "M12 8v4m0 4v.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
            }
          )
        }
      )
    }
  ) }) }) : e.length === 0 ? /* @__PURE__ */ t("div", { className: `flex flex-col h-full bg-widget-background min-w-[20rem] ${m}`, children: /* @__PURE__ */ t("div", { className: "flex items-center justify-center flex-1 py-12", children: /* @__PURE__ */ t(
    Y,
    {
      title: "No Notifications",
      description: "You're all caught up! No notifications to display.",
      icon: /* @__PURE__ */ t(
        "svg",
        {
          className: "w-12 h-12 text-[var(--widget-text-tertiary)]",
          fill: "none",
          stroke: "currentColor",
          viewBox: "0 0 24 24",
          children: /* @__PURE__ */ t(
            "path",
            {
              strokeLinecap: "round",
              strokeLinejoin: "round",
              strokeWidth: 2,
              d: "M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"
            }
          )
        }
      )
    }
  ) }) }) : /* @__PURE__ */ o("div", { className: `flex flex-col h-full min-w-[20rem] ${m}`, children: [
    u && n && /* @__PURE__ */ t(
      Pe,
      {
        selectedNotifications: i,
        onMarkAllAsRead: async (s) => {
          try {
            for (const d of s)
              n(d, {
                type: "mark_read",
                label: "Mark as read",
                handler: async () => {
                }
              });
            return {
              success: !0,
              processedCount: s.length,
              failedCount: 0,
              errors: []
            };
          } catch (d) {
            return {
              success: !1,
              processedCount: 0,
              failedCount: s.length,
              errors: [{ notificationId: "", error: d }]
            };
          }
        },
        onMarkAllAsUnread: async (s) => {
          try {
            for (const d of s)
              n(d, {
                type: "mark_unread",
                label: "Mark as unread",
                handler: async () => {
                }
              });
            return {
              success: !0,
              processedCount: s.length,
              failedCount: 0,
              errors: []
            };
          } catch (d) {
            return {
              success: !1,
              processedCount: 0,
              failedCount: s.length,
              errors: [{ notificationId: "", error: d }]
            };
          }
        },
        onArchiveAll: async (s) => {
          try {
            for (const d of s)
              n(d, {
                type: "archive",
                label: "Archive",
                handler: async () => {
                }
              });
            return {
              success: !0,
              processedCount: s.length,
              failedCount: 0,
              errors: []
            };
          } catch (d) {
            return {
              success: !1,
              processedCount: 0,
              failedCount: s.length,
              errors: [{ notificationId: "", error: d }]
            };
          }
        },
        onDeleteAll: async (s) => {
          try {
            for (const d of s)
              n(d, {
                type: "delete",
                label: "Delete",
                handler: async () => {
                }
              });
            return {
              success: !0,
              processedCount: s.length,
              failedCount: 0,
              errors: []
            };
          } catch (d) {
            return {
              success: !1,
              processedCount: 0,
              failedCount: s.length,
              errors: [{ notificationId: "", error: d }]
            };
          }
        },
        onClearSelection: () => u(!1)
      }
    ),
    /* @__PURE__ */ t("div", { className: "flex-1", children: /* @__PURE__ */ o("div", { children: [
      e.map((s) => /* @__PURE__ */ t(
        Ae,
        {
          notification: s,
          onActionClick: b,
          isSelected: i.includes(s.id),
          onSelectionChange: l ? (d) => w(s.id, d) : void 0
        },
        s.id
      )),
      c && /* @__PURE__ */ t("div", { ref: g, className: "py-2", children: x && /* @__PURE__ */ t(Q, { count: 3 }) })
    ] }) })
  ] });
}, R = ({
  id: e,
  label: r,
  checked: a,
  onChange: n,
  disabled: i = !1,
  icon: l
}) => /* @__PURE__ */ o("div", { className: "flex items-center justify-between py-2.5", children: [
  r && /* @__PURE__ */ o(
    "label",
    {
      htmlFor: e,
      className: "flex items-center gap-2 text-sm font-medium text-text-primary cursor-pointer",
      children: [
        l && /* @__PURE__ */ t("span", { className: "text-widget-primary", children: l }),
        /* @__PURE__ */ t("span", { children: r })
      ]
    }
  ),
  /* @__PURE__ */ t(
    "button",
    {
      type: "button",
      id: e,
      role: "switch",
      "aria-checked": a,
      disabled: i,
      className: `relative inline-flex h-5 w-9 flex-shrink-0 rounded-full border-2 border-transparent 
                            transition-colors duration-200 ease-in-out
                            focus:outline-none focus:ring-2 focus:ring-widget-primary focus:ring-offset-2
                            ${a ? "bg-widget-primary" : "bg-gray-300 dark:bg-gray-600"}
                            ${i ? "opacity-50 cursor-not-allowed" : "cursor-pointer"}
                            `,
      onClick: () => !i && n(!a),
      children: /* @__PURE__ */ t(
        "span",
        {
          className: `pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow-md ring-0 
                                transition duration-200 ease-in-out
                                ${a ? "translate-x-4" : "translate-x-0"}
                            `
        }
      )
    }
  )
] }), Ie = {
  sm: "w-4 h-4",
  md: "w-8 h-8",
  lg: "w-12 h-12"
}, X = ({
  size: e = "md",
  label: r = "Loading..."
}) => /* @__PURE__ */ o("div", { className: "flex flex-col items-center justify-center gap-2", children: [
  /* @__PURE__ */ t(
    "div",
    {
      className: `${Ie[e]} animate-spin rounded-full border-2 border-gray-300 dark:border-gray-600 border-t-blue-500 dark:border-t-blue-400`,
      role: "status",
      "aria-label": r
    }
  ),
  r && /* @__PURE__ */ t("p", { className: "text-sm text-gray-600 dark:text-gray-400", children: r })
] }), Ve = ({
  preferences: e,
  onPreferenceChange: r,
  isLoading: a,
  specificPreferences: n,
  onLoadMoreSpecific: i,
  hasMoreSpecific: l,
  isListLoading: u,
  onMorePreferencesClick: h
}) => {
  const [c, m] = k({
    global: !0,
    schedule: !1
  }), [f, g] = k({}), x = (s) => {
    m((d) => ({ ...d, [s]: !d[s] }));
  }, y = (s, d) => {
    r(`channels.${s}`, d);
  }, b = (s) => {
    const { scrollTop: d, scrollHeight: M, clientHeight: E } = s.currentTarget;
    M - d - E < 50 && l && i && !u && i();
  }, w = (s) => {
    switch (s) {
      case "email":
        return /* @__PURE__ */ t(ye, { className: "w-4 h-4" });
      case "push":
        return /* @__PURE__ */ t(G, { className: "w-4 h-4" });
      case "sms":
        return /* @__PURE__ */ t(Ee, { className: "w-4 h-4" });
      case "inApp":
        return /* @__PURE__ */ t(ke, { className: "w-4 h-4" });
      default:
        return null;
    }
  };
  return n || e.subscriptions, /* @__PURE__ */ o(
    "div",
    {
      className: "h-full overflow-y-auto widget-scrollbar min-w-[20rem] p-2 bg-[var(--widget-background)]",
      "data-testid": "preferences-view",
      onScroll: b,
      children: [
        a && /* @__PURE__ */ t("div", { className: "absolute inset-0 bg-[var(--widget-bg)]/75 backdrop-blur-sm flex items-center justify-center z-10 transition-all duration-200", children: /* @__PURE__ */ t(X, { size: "lg" }) }),
        /* @__PURE__ */ o("div", { className: "space-y-2", children: [
          /* @__PURE__ */ o("div", { className: "border border-[var(--widget-border)] rounded-lg overflow-hidden", children: [
            /* @__PURE__ */ o(
              "button",
              {
                type: "button",
                onClick: () => x("global"),
                className: "w-full flex items-center justify-between px-2 py-1.5 bg-[var(--widget-bg-secondary)] hover:bg-[var(--widget-bg-hover)] transition-colors",
                children: [
                  /* @__PURE__ */ o("div", { className: "flex items-center gap-2  min-w-[20rem]", children: [
                    /* @__PURE__ */ t(G, { className: "w-5 h-5 text-widget-primary" }),
                    /* @__PURE__ */ t("span", { className: "font-semibold text-sm text-text-primary", children: "Global Preferences" })
                  ] }),
                  c.global ? /* @__PURE__ */ t(ze, { className: "w-5 h-5 text-text-secondary" }) : /* @__PURE__ */ t(je, { className: "w-5 h-5 text-text-secondary" })
                ]
              }
            ),
            c.global && /* @__PURE__ */ o("div", { className: " min-w-[20rem] px-2 pb-1.5 divide-y divide-border-light bg-[var(--widget-background)]", children: [
              /* @__PURE__ */ t(
                R,
                {
                  id: "channel-email",
                  label: "Email",
                  icon: w("email"),
                  checked: e.channels.email,
                  onChange: (s) => y("email", s),
                  disabled: a
                }
              ),
              /* @__PURE__ */ t(
                R,
                {
                  id: "channel-inapp",
                  label: "In-App",
                  icon: w("inApp"),
                  checked: e.channels.inApp,
                  onChange: (s) => y("inApp", s),
                  disabled: a
                }
              ),
              /* @__PURE__ */ t(
                R,
                {
                  id: "channel-push",
                  label: "Push",
                  icon: w("push"),
                  checked: e.channels.push,
                  onChange: (s) => y("push", s),
                  disabled: a
                }
              )
            ] })
          ] }),
          !1,
          !1,
          u && /* @__PURE__ */ t("div", { className: "flex justify-center p-2", children: /* @__PURE__ */ t(X, { size: "md" }) }),
          h && /* @__PURE__ */ t("div", { className: "pt-2 pb-1 flex justify-center", children: /* @__PURE__ */ t(
            "button",
            {
              onClick: () => {
                h();
              },
              className: "text-sm font-medium text-[var(--widget-primary)] hover:text-[var(--widget-primary-hover)] hover:underline focus:outline-none",
              children: "More Settings"
            }
          ) })
        ] })
      ]
    }
  );
}, De = ({
  notifications: e,
  activeTab: r,
  onTabChange: a,
  className: n = ""
}) => {
  const i = Z(() => {
    const l = e.length, u = e.filter((f) => !f.isRead).length, h = /* @__PURE__ */ new Map();
    e.forEach((f) => {
      f.tags.forEach((g) => {
        h.set(g, (h.get(g) || 0) + 1);
      });
    });
    const c = [
      {
        id: "all",
        label: "All",
        count: l,
        icon: /* @__PURE__ */ t(He, { className: "w-4 h-4" })
      },
      {
        id: "unread",
        label: "Unread",
        count: u,
        icon: /* @__PURE__ */ t(ie, { className: "w-4 h-4" })
      }
    ], m = Array.from(h.entries()).sort(([, f], [, g]) => g - f).slice(0, 5).map(([f, g]) => ({
      id: `tag:${f}`,
      label: f,
      count: g,
      icon: /* @__PURE__ */ t(Ce, { className: "w-4 h-4" })
    }));
    return [...c, ...m];
  }, [e]);
  return /* @__PURE__ */ t(
    "div",
    {
      className: `
        mx-widget-tabs flex items-center gap-1 overflow-x-auto widget-scrollbar border-b border-[var(--widget-border)] px-2 py-1.5 bg-[var(--widget-background)]
        ${n}
      `,
      role: "tablist",
      "data-mx-widget": "tabs",
      children: i.map((l) => {
        const u = r === l.id;
        return /* @__PURE__ */ o(
          "button",
          {
            onClick: () => a(l.id),
            className: `
              flex items-center gap-2 px-3 py-1.5 rounded-full text-sm font-medium transition-all whitespace-nowrap outline-none focus:ring-2 focus:ring-offset-1
              ${u ? "shadow-sm bg-[var(--widget-primary)] text-[var(--widget-text)]" : "tab-inactive text-[var(--widget-text-secondary)]"}
            `,
            role: "tab",
            "aria-selected": u,
            "data-testid": `tab-${l.id}`,
            children: [
              l.icon && /* @__PURE__ */ t(
                "span",
                {
                  className: u ? "text-[var(--widget-text)]" : "text-[var(--widget-text-tertiary)]",
                  children: l.icon
                }
              ),
              /* @__PURE__ */ t("span", { children: l.label }),
              l.count !== void 0 && l.count > 0 && /* @__PURE__ */ o(
                "span",
                {
                  className: `ml-1 text-[10px] font-semibold ${u ? "text-[var(--widget-text)]" : "text-[var(--widget-text-tertiary)]"}`,
                  children: [
                    "(",
                    l.count > 99 ? "99+" : l.count,
                    ")"
                  ]
                }
              )
            ]
          },
          l.id
        );
      })
    }
  );
}, Je = ({
  isOpen: e,
  onClose: r,
  position: a,
  currentView: n,
  onViewChange: i,
  notifications: l,
  onNotificationAction: u,
  preferences: h,
  onPreferenceChange: c,
  isPreferencesLoading: m = !1,
  size: f = "medium",
  onMorePreferencesClick: g,
  specificPreferences: x,
  onLoadMoreSpecific: y,
  hasMoreSpecific: b,
  isListLoading: w
}) => {
  const s = j(null), d = j(null), [M, E] = k("all"), [S, D] = k(""), se = z(
    async (p) => {
      try {
        for (const N of p)
          await u(N, {
            type: "mark_read",
            label: "Mark as read",
            handler: async () => {
            }
          });
        return { success: !0, processedCount: p.length, failedCount: 0, errors: [] };
      } catch (N) {
        return {
          success: !1,
          processedCount: 0,
          failedCount: p.length,
          errors: [{ notificationId: "", error: N }]
        };
      }
    },
    [u]
  ), le = Z(() => $e(l, M, S), [l, M, S]), O = z(
    (p) => {
      s.current && !s.current.contains(p.target) && r();
    },
    [r]
  ), $ = z(
    (p) => {
      p.key === "Escape" && r();
    },
    [r]
  ), P = z(
    (p) => {
      if (!(!e || !s.current) && p.key === "Tab") {
        const N = s.current.querySelectorAll(
          'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
        );
        if (N.length === 0) return;
        const F = N[0], U = N[N.length - 1];
        p.shiftKey ? document.activeElement === F && (U.focus(), p.preventDefault()) : document.activeElement === U && (F.focus(), p.preventDefault());
      }
    },
    [e]
  );
  if (I(() => (e ? (d.current = document.activeElement, document.addEventListener("mousedown", O), document.addEventListener("keydown", $), document.addEventListener("keydown", P), setTimeout(() => {
    s.current?.querySelector(
      'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
    )?.focus();
  }, 0)) : (d.current && d.current.focus(), E("all"), D("")), () => {
    document.removeEventListener("mousedown", O), document.removeEventListener("keydown", $), document.removeEventListener("keydown", P);
  }), [e, O, $, P]), !e) return null;
  const oe = {
    left: "left-0 origin-top-left",
    right: "right-0 origin-top-right"
  }, _ = l.filter((p) => !p.isRead).length;
  return /* @__PURE__ */ o(H, { children: [
    /* @__PURE__ */ t(
      "div",
      {
        className: "fixed inset-0 bg-black/20 backdrop-blur-sm z-40 md:hidden transition-opacity duration-200",
        "aria-hidden": "true",
        onClick: r
      }
    ),
    /* @__PURE__ */ o(
      "div",
      {
        ref: s,
        className: `
          mx-widget-popover min-w-[20rem] absolute top-full mt-2 ${oe[a]}
          w-[var(--widget-popover-width, 20rem)] max-h-[var(--widget-popover-max-height,580px)]
          border border-[var(--widget-border)] rounded-2xl overflow-hidden
          shadow-[var(--widget-shadow-xl)] bg-[var(--widget-background)]
          z-50 flex flex-col
          animate-in fade-in-0 zoom-in-95 duration-200
          max-sm:fixed max-sm:inset-x-4 max-sm:top-16 max-sm:bottom-4
          max-sm:w-auto max-sm:max-w-none max-sm:max-h-[calc(100vh-120px)]
        `,
        role: "dialog",
        "aria-modal": "true",
        "aria-label": "Notifications",
        "data-testid": "inbox-popover",
        "data-mx-widget": "popover",
        style: { minWidth: "20rem" },
        children: [
          /* @__PURE__ */ o("div", { className: "flex-shrink-0 flex items-center justify-between px-4 py-3 border-b border-[var(--widget-border)] bg-[var(--widget-background)]", children: [
            /* @__PURE__ */ t("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ t("h2", { className: "text-base font-semibold text-[var(--widget-text)]", children: n === "notifications" ? "Notifications" : "Preferences" }) }),
            /* @__PURE__ */ o("div", { className: "flex items-center gap-1", children: [
              n === "notifications" && /* @__PURE__ */ t(
                "button",
                {
                  type: "button",
                  className: "inline-flex items-center justify-center w-6 h-6 rounded-lg text-[var(--widget-text-secondary)] hover:text-[var(--widget-text)] hover:bg-[var(--widget-bg-hover)] transition-colors",
                  onClick: () => i("preferences"),
                  "aria-label": "Open preferences",
                  "data-testid": "preferences-button",
                  children: /* @__PURE__ */ t(re, { className: "w-4 h-4" })
                }
              ),
              n === "preferences" && /* @__PURE__ */ t(
                "button",
                {
                  type: "button",
                  className: "inline-flex items-center justify-center w-6 h-6 rounded-lg text-[var(--widget-text-secondary)] hover:text-[var(--widget-text)] hover:bg-[var(--widget-bg-hover)] transition-colors",
                  onClick: () => i("notifications"),
                  "aria-label": "Back to notifications",
                  "data-testid": "back-button",
                  children: /* @__PURE__ */ t(Me, { className: "w-5 h-5" })
                }
              ),
              /* @__PURE__ */ t(
                "button",
                {
                  type: "button",
                  className: "inline-flex items-center justify-center w-6 h-6 rounded-lg text-[var(--widget-text-secondary)] hover:text-[var(--widget-text)] hover:bg-[var(--widget-bg-hover)] transition-colors",
                  onClick: r,
                  "aria-label": "Close notifications",
                  "data-testid": "close-button",
                  children: /* @__PURE__ */ t(ne, { className: "w-5 h-5" })
                }
              )
            ] })
          ] }),
          n === "notifications" ? /* @__PURE__ */ o(H, { children: [
            /* @__PURE__ */ t("div", { className: "flex-shrink-0 px-4 py-2.5 border-b border-[var(--widget-border)] bg-[var(--widget-background)]", children: /* @__PURE__ */ o("div", { className: "relative", children: [
              /* @__PURE__ */ t("div", { className: "absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none", children: /* @__PURE__ */ t(xe, { className: "w-5 h-5 text-[var(--widget-text-tertiary)]" }) }),
              /* @__PURE__ */ t(
                "input",
                {
                  type: "text",
                  className: `
                    w-full pl-10 pr-3 py-1 
                    bg-[var(--widget-bg-secondary)] 
                    border border-[var(--widget-border)] 
                    rounded-lg 
                    text-sm text-[var(--widget-text)] 
                    placeholder:text-[var(--widget-text-tertiary)]
                    focus:outline-none focus:ring-2 focus:ring-[var(--widget-primary)] focus:border-transparent
                    transition-colors
                  `,
                  placeholder: "Search notifications...",
                  value: S,
                  onChange: (p) => D(p.target.value),
                  "aria-label": "Search notifications"
                }
              )
            ] }) }),
            /* @__PURE__ */ t(
              De,
              {
                notifications: l,
                activeTab: M,
                onTabChange: (p) => E(p),
                size: f
              }
            ),
            /* @__PURE__ */ t("div", { className: "flex-1 overflow-y-auto widget-scrollbar bg-[var(--widget-background)] max-h-[calc(var(--widget-popover-max-height)-200px)]", children: /* @__PURE__ */ t(q, { fallback: /* @__PURE__ */ t(Le, {}), children: /* @__PURE__ */ t(
              Re,
              {
                notifications: le,
                onNotificationAction: u
              }
            ) }) }),
            _ > 0 && /* @__PURE__ */ t("div", { className: "flex-shrink-0 px-4 py-2.5 border-t border-[var(--widget-border)] bg-[var(--widget-bg-hover)]", children: /* @__PURE__ */ t(
              "button",
              {
                type: "button",
                className: "w-full px-4 py-2 text-sm font-medium text-[var(--widget-primary)] hover:text-[var(--widget-primary-hover)] hover:bg-[var(--widget-primary-light)] rounded-lg transition-colors",
                onClick: () => {
                  const p = l.filter((N) => !N.isRead).map((N) => N.id);
                  se(p);
                },
                "aria-label": `Mark all ${_} notifications as read`,
                children: "Mark all as read"
              }
            ) })
          ] }) : /* @__PURE__ */ t("div", { className: "flex-1 overflow-y-auto widget-scrollbar", children: /* @__PURE__ */ t(q, { fallback: /* @__PURE__ */ t(J, {}), children: h && c ? /* @__PURE__ */ t(
            Ve,
            {
              preferences: h,
              onPreferenceChange: c,
              isLoading: m,
              onBack: () => i("notifications"),
              onMorePreferencesClick: g,
              specificPreferences: x,
              onLoadMoreSpecific: y,
              hasMoreSpecific: b,
              isListLoading: w
            }
          ) : /* @__PURE__ */ t(J, {}) }) })
        ]
      }
    )
  ] });
};
export {
  Ue as B,
  q as C,
  Je as I,
  Ge as L,
  We as M,
  Ae as N,
  Ve as P,
  qe as S,
  Ke as a
};
//# sourceMappingURL=components-DUT08KJF.js.map
