'use client'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import type { AgentCredentials } from '@/features/agent-registration/credentials'; import CopyControl from './CopyControl'; const EXPIRATION_OPTIONS = [ { id: '24hours', seconds: 86_400 }, { id: '7days', seconds: 604_800 }, { id: '1month', seconds: 2_592_000 }, { id: '1year', seconds: 31_536_000 }, { id: 'custom', seconds: -1 }, { id: 'neverExpire', seconds: null }, ] as const; const MAX_CUSTOM_DAYS = 365; type ExpirationId = (typeof EXPIRATION_OPTIONS)[number]['id']; interface CredentialsStepProps { readonly credentials: AgentCredentials; readonly token?: string; readonly issuingToken: boolean; readonly tokenError: string | null; readonly onIssueToken: (ttlSeconds: number | null) => void; readonly onContinue: () => void; } function CredentialRow({ label, value }: { readonly label: string; readonly value: string }) { return (
{label}
{value}
); } export default function CredentialsStep({ credentials, token, issuingToken, tokenError, onIssueToken, onContinue, }: CredentialsStepProps) { const { t } = useTranslation(); const [expiration, setExpiration] = useState('neverExpire'); const [customDays, setCustomDays] = useState(''); const [validationError, setValidationError] = useState(null); const issueToken = () => { const option = EXPIRATION_OPTIONS.find(({ id }) => id === expiration); if (!option) { setValidationError(t('agentRegistration.invalidExpiration')); return; } if (option.seconds === -1) { const days = Number.parseInt(customDays, 10); if (!Number.isSafeInteger(days) || days < 1 || days > MAX_CUSTOM_DAYS) { setValidationError(t('agentRegistration.enterValidDays')); return; } setValidationError(null); onIssueToken(days * 86_400); return; } setValidationError(null); onIssueToken(option.seconds); }; return (

{t('agentRegistration.privateKeySaveNow')}

{credentials.privateKey}

{t('agentRegistration.privateKeyWarning')}

{t('agentRegistration.apiToken')}

{token ? (
{t('agentRegistration.tokenIssued')}
{token}
) : (
{expiration === 'custom' && (
setCustomDays(event.target.value)} className="w-full px-3 py-2 bg-transparent border border-border font-mono text-[12px] text-ink focus:outline-none focus:border-ink" disabled={issuingToken} />
)}
)} {(validationError || tokenError) && (

{validationError ?? tokenError}

)}
); }