"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useCallback, useRef, useState } from "react";
import { OAuthAppListPanel } from "../oauth-app/OAuthAppListPanel";
import { CreateOAuthAppForm } from "../oauth-app/CreateOAuthAppForm";
import { OAuthAppDetailPanel } from "../oauth-app/OAuthAppDetailPanel";
import { useResourceAvailable, ApiResourceKind } from "../deployment-mode";
import { CloudFeatureNotice } from "../internal/CloudFeatureNotice";
import { useActiveOrgSlug } from "../organization/OrgProvider";
/** Settings section for organization OAuth app credentials. */
export function OAuthAppsSection() {
    const org = useActiveOrgSlug();
    const oauthAppsAvailable = useResourceAvailable(ApiResourceKind.oauth_app);
    const [flow, setFlow] = useState({ phase: "idle" });
    const listRefetchRef = useRef(null);
    const handleRefetchRef = useCallback((refetch) => {
        listRefetchRef.current = refetch;
    }, []);
    const handleCreated = useCallback(() => {
        listRefetchRef.current?.();
        setFlow({ phase: "idle" });
    }, []);
    const handleUpdated = useCallback(() => {
        listRefetchRef.current?.();
        setFlow({ phase: "idle" });
    }, []);
    const handleDeleted = useCallback(() => {
        listRefetchRef.current?.();
        setFlow({ phase: "idle" });
    }, []);
    return (_jsxs("section", { "aria-labelledby": "oauth-apps-heading", children: [_jsxs("div", { className: "mb-3 flex items-center justify-between", children: [_jsx("h2", { id: "oauth-apps-heading", className: "text-foreground text-sm font-semibold", children: "OAuth Apps" }), oauthAppsAvailable && org && flow.phase === "idle" && (_jsx("button", { type: "button", onClick: () => setFlow({ phase: "creating" }), className: "text-primary hover:text-foreground text-xs font-medium transition-colors", children: "+ New OAuth app" }))] }), _jsx("p", { className: "text-muted-foreground mb-4 text-xs", children: "OAuth app credentials configured for your organization. Create new apps here or bring your own from an MCP server's detail page." }), !oauthAppsAvailable ? (_jsx(CloudFeatureNotice, { children: "OAuth apps are not available in local mode. Bring-your-own-app OAuth requires the cloud platform." })) : flow.phase === "creating" ? (_jsx("div", { className: "border-border bg-card rounded-lg border p-4", children: _jsx(CreateOAuthAppForm, { org: org, onCreated: handleCreated, onCancel: () => setFlow({ phase: "idle" }) }) })) : flow.phase === "editing" ? (_jsx("div", { className: "border-border bg-card rounded-lg border p-4", children: _jsx(OAuthAppDetailPanel, { oauthApp: flow.oauthApp, onUpdated: handleUpdated, onDeleted: handleDeleted, onBack: () => setFlow({ phase: "idle" }) }) })) : (_jsx(OAuthAppListPanel, { org: org, onEdit: (app) => setFlow({ phase: "editing", oauthApp: app }), onRefetchRef: handleRefetchRef }))] }));
}
//# sourceMappingURL=OAuthAppsSection.js.map