'use client';
import { useEffect, useState } from 'react';
import { Copy, ExternalLink, KeyRound, Loader2, RefreshCw, Trash2 } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import { OAuthClient } from '@/lib/api';
import { OAuthEndpoints, buildAuthorizeUrl } from '@/lib/oauth-url';
function CopyRow({ label, value, onCopy }: { label: string; value: string; onCopy: (value: string, label: string) => void }) {
return (
{label}
{value}
);
}
export function OAuthClientDetailDialog({
client,
endpoints,
open,
onOpenChange,
onCopy,
onRotateSecret,
onToggleActive,
onDelete,
onSaveRedirectUris
}: {
client: OAuthClient | null;
endpoints: OAuthEndpoints;
open: boolean;
onOpenChange: (open: boolean) => void;
onCopy: (value: string, label: string) => void;
onRotateSecret: (clientId: string) => void;
onToggleActive: (client: OAuthClient) => void;
onDelete: (client: OAuthClient) => void;
onSaveRedirectUris: (client: OAuthClient, redirectUris: string[]) => Promise;
}) {
const [redirectUrisDraft, setRedirectUrisDraft] = useState('');
const [savingRedirectUris, setSavingRedirectUris] = useState(false);
useEffect(() => {
if (!client) return;
setRedirectUrisDraft(client.redirectUris.join('\n'));
}, [client]);
if (!client) return null;
const primaryRedirect = client.redirectUris[0] ?? 'https://app.example.com/oauth/callback';
const scope = client.scopes.join(' ');
const sampleAuthorizeUrl = buildAuthorizeUrl(endpoints.issuer, {
clientId: client.clientId,
redirectUri: primaryRedirect,
scope
});
return (
);
}