import { useState, useEffect } from 'react' import { Search, Coins, Sparkles, TrendingUp, User, Calendar, Hash } from 'lucide-react' import toast from 'react-hot-toast' const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:3001/api' export default function IssueStars() { const [userId, setUserId] = useState('') const [amount, setAmount] = useState('') const [reason, setReason] = useState('') const [loading, setLoading] = useState(false) const [userInfo, setUserInfo] = useState(null) const [recentTransactions, setRecentTransactions] = useState([]) useEffect(() => { loadRecentTransactions() }, []) const loadRecentTransactions = async () => { try { const response = await fetch(`${API_URL}/stars/recent?limit=10`) const data = await response.json() if (data.success) { setRecentTransactions(data.data) } } catch (error) { console.error('Failed to load recent transactions:', error) } } const searchUser = async () => { if (!userId) return try { const response = await fetch(`${API_URL}/stars/user/${userId}`) const data = await response.json() if (data.success) { setUserInfo(data.data) toast.success(`User found: ${data.data.user.firstName || 'User ' + userId}`) } else { toast.error(data.error || 'User not found') setUserInfo(null) } } catch (error) { toast.error('User not found') setUserInfo(null) } } const issueStars = async (e) => { e.preventDefault() if (!userId || !amount || amount <= 0) { toast.error('Please enter valid User ID and amount') return } setLoading(true) try { const response = await fetch(`${API_URL}/stars/issue`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ userId: parseInt(userId), amount: parseInt(amount), reason: reason || 'Admin issued stars' }) }) const data = await response.json() if (data.success) { toast.success(`✨ Successfully issued ${amount} stars!`) setAmount('') setReason('') loadRecentTransactions() searchUser() // Refresh user info } else { toast.error(data.error || 'Failed to issue stars') } } catch (error) { toast.error('Failed to issue stars') } finally { setLoading(false) } } return (
{/* Page Header */}

Issue Telegram Stars

Grant stars to users directly from admin panel

{/* Main Form */}
{/* User Search Card */}

Find User

setUserId(e.target.value)} onKeyPress={(e) => e.key === 'Enter' && searchUser()} placeholder="Enter User ID" className="input w-full pl-12" />
{/* User Info Display */} {userInfo && (

{userInfo.user.firstName} {userInfo.user.lastName || ''}

@{userInfo.user.userName || `user${userInfo.user.userId}`} · ID: {userInfo.user.userId}

Current Balance

{userInfo.balance}

)}
{/* Issue Stars Form */}
{/* Background decoration */}

Issue Stars

setAmount(e.target.value)} placeholder="Enter amount" min="1" required className="input w-full pl-12 text-lg font-medium" />
{/* Quick Amount Buttons */}
{[50, 100, 500, 1000, 5000].map((amt) => ( ))}