"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.usePDSAgent = usePDSAgent;
exports.usePossiblyUnauthedPDSAgent = usePossiblyUnauthedPDSAgent;
exports.useUnauthenticatedBlueskyAppViewAgent = useUnauthenticatedBlueskyAppViewAgent;
const react_1 = require("react");
const streamplace_1 = require("streamplace");
const streamplace_store_1 = require("./streamplace-store");
function usePDSAgent() {
    const oauthSession = (0, streamplace_store_1.useStreamplaceStore)((state) => state.oauthSession);
    // oauthsession is
    // - undefined when loading
    // - null when logged out, and
    // - SessionManager when logged in
    return (0, react_1.useMemo)(() => {
        if (!oauthSession) {
            if (oauthSession === undefined)
                return null;
            // TODO: change once we allow unauthed requests + profile indexing
            // it's bluesky's AppView b/c otherwise we'd have goosewithpipe.jpg
            // showing up everywhere
            return new streamplace_1.StreamplaceAgent("https://public.api.bsky.app"); // nodeUrl);
        }
        return new streamplace_1.StreamplaceAgent(oauthSession);
    }, [oauthSession]);
}
// can be unauthed, but will always use the current node URL
function usePossiblyUnauthedPDSAgent() {
    const nodeUrl = (0, streamplace_store_1.useUrl)();
    const oauthSession = (0, streamplace_store_1.useStreamplaceStore)((state) => state.oauthSession);
    // oauthsession is
    // - undefined when loading
    // - null when logged out, and
    // - SessionManager when logged in
    return (0, react_1.useMemo)(() => {
        if (!oauthSession) {
            return new streamplace_1.StreamplaceAgent(nodeUrl);
        }
        return new streamplace_1.StreamplaceAgent(oauthSession);
    }, [oauthSession]);
}
// always returns an unauthenticated agent pointed at the public bluesky API
// probably should not be used in most places, but in case we have a bug it may be useful
function useUnauthenticatedBlueskyAppViewAgent() {
    return (0, react_1.useMemo)(() => {
        return new streamplace_1.StreamplaceAgent("https://public.api.bsky.app");
    }, []);
}
//# sourceMappingURL=xrpc.js.map