import { useState as p, useEffect as F } from "react";
import { useMemoizedFn as n } from "ahooks";
import c from "@arcblock/ux/lib/Toast";
import { client as l } from "../libs/client.js";
import { formatAxiosError as u } from "../UserCenter/libs/utils.js";
function E({
  userDid: o,
  t: a,
  isMySelf: e
}) {
  const [i, f] = p(!1), t = n(async () => {
    try {
      if (e) {
        f(!0);
        return;
      }
      const r = await l.user.isFollowingUser({ userDid: o });
      f(r);
    } catch (r) {
      console.error(r);
    }
  }), m = n(async (r = o) => {
    if (!(e && r === o))
      try {
        await l.user.followUser({ userDid: r }), c.success(a("profile.follow_success")), t();
      } catch (s) {
        console.error(s), c.error(u(s));
      }
  }), w = n(async (r = o) => {
    if (!(e && r === o))
      try {
        await l.user.unfollowUser({ userDid: r }), c.success(a("profile.unfollow_success")), t();
      } catch (s) {
        console.error(s), c.error(u(s));
      }
  });
  return F(() => {
    o && !e && t();
  }, [t, o, e]), {
    followed: i,
    followUser: m,
    unfollowUser: w
  };
}
export {
  E as default
};
