import React, { useState } from 'react'; import { Button } from '../../ui/button'; import { Input } from '../../ui/input'; import { X, Key, Copy, Check } from 'lucide-react'; import { useToast } from '../../../context/ToastContext'; interface CreateAPIKeyModalProps { onClose: () => void; onCreate: (keyData: { name: string, scopes: string[] }) => void; } const SCOPES = [ { id: 'user.read', label: 'Read User Data' }, { id: 'user.write', label: 'Update User Profile' }, { id: 'tracks.read', label: 'Read Tracks' }, { id: 'tracks.upload', label: 'Upload Tracks' }, { id: 'sales.read', label: 'Read Sales Data' }, ]; export const CreateAPIKeyModal: React.FC = ({ onClose, onCreate }) => { const { addToast } = useToast(); const [step, setStep] = useState(1); const [name, setName] = useState(''); const [selectedScopes, setSelectedScopes] = useState(['user.read']); const [generatedKey, setGeneratedKey] = useState(''); const toggleScope = (id: string) => { setSelectedScopes(prev => prev.includes(id) ? prev.filter(s => s !== id) : [...prev, id]); }; const handleGenerate = () => { if (!name) { addToast("Please name your key", "error"); return; } // Mock Key Generation const mockKey = `vz_${Math.random().toString(36).substr(2, 8)}_${Math.random().toString(36).substr(2, 16)}`; setGeneratedKey(mockKey); onCreate({ name, scopes: selectedScopes }); // Notify parent setStep(2); }; const copyKey = () => { navigator.clipboard.writeText(generatedKey); addToast("API Key copied to clipboard", "success"); }; return (

{step === 1 ? 'Create API Key' : 'API Key Generated'}

{step === 1 ? (
setName(e.target.value)} autoFocus />
{SCOPES.map(scope => ( ))}
) : (

Key Created Successfully

Please copy your API key now. For security reasons, you won't be able to see it again.

{generatedKey}
)}
{step === 1 ? ( <> ) : ( )}
); };