import { jsxs as w, jsx as s } from "react/jsx-runtime";
import { useMemo as l } from "react";
import { styled as z, Button as C, Box as F } from "@mui/material";
import { useMemoizedFn as u } from "ahooks";
import { joinURL as N } from "ufo";
import h from "lodash/noop";
import { Icon as U } from "@iconify/react";
import v from "@mui/icons-material/Notifications";
import L from "@mui/icons-material/NotificationsOff";
import P from "../use-follow.js";
import { useLocaleContext as g } from "../../Locale/context.js";
import { translate as y } from "../../Locale/util.js";
import { isSupportFollow as j } from "../../Util/index.js";
const _ = {
  zh: {
    chat: "聊天",
    follow: "关注",
    unfollow: "取消关注",
    follow_success: "关注成功",
    unfollow_success: "取消关注成功"
  },
  en: {
    chat: "Chat",
    follow: "Follow",
    unfollow: "Unfollow",
    follow_success: "Follow success",
    unfollow_success: "Unfollow success"
  }
}, B = () => {
  const { componentMountPoints: o = [] } = window.blocklet || {};
  return o.find((n) => n.name === "did-comments")?.mountPoint;
};
function I({
  user: o,
  showSocialActions: t,
  session: n
}) {
  const { locale: e } = g() || { locale: "en" }, i = u((d, m = {}) => y(_, d, e, "en", m)), r = l(() => !!n?.user?.did, [n?.user?.did]), c = l(() => B(), []), a = u(() => {
    if (!r) {
      n?.login(h, {
        openMode: "redirect",
        redirect: window.location.href
      });
      return;
    }
    window.open(N(c, `/chat/dm/${o?.did}`), "_blank");
  });
  return l(() => (typeof t == "boolean" ? !!t : t?.chat) && !!c, [t, c]) ? /* @__PURE__ */ w(
    x,
    {
      className: "user-card__social-actions-chat",
      variant: "outlined",
      color: "primary",
      size: "small",
      onClick: a,
      children: [
        /* @__PURE__ */ s(U, { icon: "tabler:message-dots", style: { marginRight: 4 } }),
        i("chat")
      ]
    }
  ) : null;
}
function $({
  user: o,
  showSocialActions: t,
  session: n,
  onFollowClick: e
}) {
  const { locale: i } = g() || { locale: "en" }, r = u((p, M = {}) => y(_, p, i, "en", M)), c = l(() => !!n?.user?.did, [n?.user?.did]), a = l(() => typeof t == "boolean" ? !!t : t?.follow, [t]), { followed: f, followUser: d, unfollowUser: m } = P({
    user: o,
    t: r,
    isMySelf: !1,
    visible: !!a
  }), b = u((p) => {
    if (!c) {
      n?.login(h, {
        openMode: "redirect",
        redirect: window.location.href
      });
      return;
    }
    f ? m(o.did) : d(o.did), e && typeof e == "function" && e(o, p);
  });
  return a ? /* @__PURE__ */ w(
    x,
    {
      className: "user-card__social-actions-follow",
      variant: "outlined",
      color: "primary",
      size: "small",
      onClick: b,
      children: [
        f ? /* @__PURE__ */ s(L, { sx: { fontSize: 14, mr: 0.5 } }) : /* @__PURE__ */ s(v, { sx: { fontSize: 14, mr: 0.5 } }),
        r(f ? "unfollow" : "follow")
      ]
    }
  ) : null;
}
function S({ showSocialActions: o, session: t, user: n, onFollowClick: e = void 0 }) {
  const i = l(() => t?.user?.did === n?.did, [t?.user?.did, n?.did]), r = l(() => j(), []);
  return i || !r || !o ? null : /* @__PURE__ */ w(F, { className: "user-card__social-actions", sx: { display: "flex", gap: 1 }, children: [
    /* @__PURE__ */ s(I, { session: t, user: n, showSocialActions: o }),
    /* @__PURE__ */ s($, { onFollowClick: e, session: t, user: n, showSocialActions: o })
  ] });
}
const x = z(C)`
  color: ${({ theme: o }) => o.palette.text.primary};
  font-weight: 500;
  border-color: ${({ theme: o }) => o.palette.grey[300]};
  line-height: 1.5;
`;
export {
  x as ButtonWrapper,
  S as default
};
