import { jsxs as _jsxs, Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
import { blockExplorerUrl } from "../Components/Links";
import { useActions, useAppState } from "../overmind";
import { useCachedPool, useCachedPowerups } from "./useCached";
export const usePowerup = (user) => {
    const actions = useActions();
    const state = useAppState();
    const poolInfo = useCachedPool({ owner: user?.username });
    const isMember = state.newcoin.pools[poolInfo.code];
    const currentUserPowerups = useCachedPowerups();
    const rating = currentUserPowerups?.out?.value?.find((u) => u.id === user?.id);
    const isPowering = !!rating;
    const timeSince = rating?.rating?.created ? Date.now() - new Date(rating?.rating?.created).getDate() : -1;
    const powerup = async (amount) => {
        // !isPowering &&
        user &&
            (await actions.api.user.powerup({
                user,
                amount: amount || 1,
                messageWrapper: (msg, rating) => rating?.TxID_mintFile ? (_jsxs("a", { href: blockExplorerUrl.newscan(rating.TxID_mintFile), target: "_blank", rel: "noreferrer", children: [msg, ". Click to see a Newcoin receipt."] })) : (_jsx(_Fragment, { children: msg })),
            }));
    };
    const isPoweringProcessing = state.indicators.specific["api.user.powerup"] && !(isPowering && timeSince > 60000);
    return {
        powerup,
        isPoweringProcessing,
        isMember,
    };
};
//# sourceMappingURL=usePowerup.js.map