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