import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { Spin } from "../../Components/Spin";
import { UserWidgetHeading } from "../../Components/UserWidget";
import { json } from "overmind";
import { useActions, useAppState } from "../../overmind";
import { useBadges } from "../../hooks/useBadges";
import { useCachedPool, useCachedUser } from "../../hooks/useCached";
import { useEffect, useState } from "react";
import { useParams } from "react-router";
import { useSetTitle } from "../../hooks/useSetTitle";
import Deferred from "../../Components/Deferred";
import TopFolders from "../../Components/TopFolders";
import UserDetail from "src/Components/UserDetail";
export const User = () => {
    const [activeKey, setActiveKey] = useState("Folders");
    let { username: paramsUsername } = useParams();
    const state = useAppState();
    const actions = useActions();
    let username = paramsUsername || state.api.auth.user?.username || "";
    useEffect(() => {
        actions.api.user.getMoods({ id: state.api.auth.user?.id || "" });
        setActiveKey("Folders");
    }, [username]);
    const user = useCachedUser({ username }, true);
    useSetTitle(user?.username);
    const { badges, isBadgesLoading, badgesError } = useBadges(user?.id || "");
    const moodList = json(user.moods || []).sort((m1, m2) => (m1.stakeToAccess || 0) - (m2.stakeToAccess || 0));
    const poolInfo = useCachedPool({ owner: user.username });
    const symbol = poolInfo.code;
    if (!user.id || !user.username)
        return (_jsx(Deferred, { deferTime: 200, visible: state.indicators.specific["api.user.read"], children: state.indicators.specific["api.user.read"] ? (_jsx(Spin, {})) : (_jsx(Deferred, { deferTime: 200, visible: false, children: _jsxs("div", { children: ["User not found. The user may exist in the newcoin network,", _jsx("br", {}), "check\u00A0", _jsx("a", { href: `https://explorer-dev.newcoin.org/account/${user.username}`, children: "the newcoin block explorer." })] }) })) }));
    switch (activeKey) {
        case "Folders":
            return (_jsxs(_Fragment, { children: [_jsx(UserWidgetHeading, { user: user, setActiveKey: setActiveKey, activeKey: activeKey, badges: badges, badgesError: badgesError, isBadgesLoading: isBadgesLoading }), _jsx(TopFolders, { userMoods: moodList, maxPostsToShow: 5, title: "", loadMoreMoodsHandler: () => actions.api.user.getMoods({ id: user.id || "" }), randomizeMoods: false })] }));
        case "UserDetail":
            return (_jsxs(_Fragment, { children: [_jsx(UserWidgetHeading, { user: user, setActiveKey: setActiveKey, activeKey: activeKey, badges: badges, badgesError: badgesError, isBadgesLoading: isBadgesLoading }), _jsx(UserDetail, { user: user, badges: badges })] }));
        default:
            return (_jsx(UserWidgetHeading, { user: user, setActiveKey: setActiveKey, activeKey: activeKey, badges: badges, badgesError: badgesError, isBadgesLoading: isBadgesLoading }));
    }
};
//# sourceMappingURL=User.js.map