import { useState, useEffect } from 'react'
import { Button } from "/components/ui/button"
import { Input } from "/components/ui/input"
import { Label } from "/components/ui/label"
import { Card, CardContent, CardFooter, CardHeader, CardTitle } from "/components/ui/card"
import { Home, Settings, Bell, Phone as PhoneIcon, User, Mail, Trash2, Edit2, CreditCard, Plus } from "lucide-react"
// Main App Component
export default function PhonebookApp() {
const [isLoggedIn, setIsLoggedIn] = useState(false)
const [username, setUsername] = useState('')
const handleLogin = (user: string) => {
setUsername(user)
setIsLoggedIn(true)
}
const handleLogout = () => {
setIsLoggedIn(false)
setUsername('')
}
if (!isLoggedIn) {
return
}
return
}
// Login Page Component
function LoginPage({ onLogin }: { onLogin: (username: string) => void }) {
const [formData, setFormData] = useState({
username: '',
password: ''
})
const [errors, setErrors] = useState({
username: '',
password: ''
})
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault()
if (!formData.username) {
setErrors({ ...errors, username: 'Username is required' })
return
}
if (!formData.password) {
setErrors({ ...errors, password: 'Password is required' })
return
}
onLogin(formData.username)
}
return (
)
}
// Dashboard Component
function Dashboard({ username, onLogout }: { username: string; onLogout: () => void }) {
const [activeTab, setActiveTab] = useState('phonebook')
const [credits, setCredits] = useState(10)
const [contacts, setContacts] = useState([])
const [searchTerm, setSearchTerm] = useState('')
useEffect(() => {
// Sample contacts
setContacts([
{
id: '1',
name: 'John Doe',
phone: '+1 (555) 123-4567',
email: 'john@example.com'
},
{
id: '2',
name: 'Jane Smith',
phone: '+1 (555) 987-6543',
email: 'jane@example.com'
}
])
}, [])
const handleCall = (phone: string) => {
if (credits <= 0) {
alert('Not enough credits!')
setActiveTab('topup')
return
}
setCredits(credits - 1)
alert(`Calling ${phone}...`)
}
const handleTopUp = (amount: number) => {
setCredits(credits + amount)
alert(`Added ${amount} credits!`)
}
return (
{/* Sidebar */}
Phonebook
Welcome, {username}
{/* Main Content */}
{activeTab === 'phonebook' && (
setSearchTerm(e.target.value)}
/>
{contacts.filter(c =>
c.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
c.phone.includes(searchTerm)
).map(contact => (
{contact.name}
{contact.phone}
))}
)}
{activeTab === 'topup' && (
Top Up Credits
{[5, 10, 20].map(amount => (
{amount} Credits
${amount}
))}
)}
)
}
interface Contact {
id: string
name: string
phone: string
email: string
}