import { useMemoizedFn as e } from "ahooks";
import i from "@arcblock/ux/lib/Toast";
import { client as n } from "../../libs/client.js";
import { formatAxiosError as m } from "../../UserCenter/libs/utils.js";
function d(a) {
  const c = e(async ({ search: t, page: r = 1, pageSize: o = 20 }) => {
    try {
      return await n.user.getOrgs({ search: t, page: r, pageSize: o });
    } catch (s) {
      return console.error(s), {
        orgs: [],
        paging: {
          page: r,
          pageSize: o,
          total: 0
        }
      };
    }
  }), u = e(async ({ name: t, description: r }) => {
    try {
      return (await n.user.createOrg({ name: t, description: r })).data;
    } catch (o) {
      return console.error(o), i.error(m(o)), null;
    }
  }), g = e(async (t) => {
    try {
      return await n.user.getOrg(t);
    } catch (r) {
      return a.logout(), console.error(r), null;
    }
  }), l = e(async (t) => {
    try {
      const r = await n.user.getRole(t);
      return r.orgId ? await g(r.orgId) : null;
    } catch (r) {
      return console.error(r), null;
    }
  });
  return {
    getOrgs: c,
    createOrg: u,
    getCurrentOrg: l
  };
}
export {
  d as default
};
