import { useState } from 'react' import { Link } from 'react-router-dom' import { mockAlerts } from '../lib/mock-data.ts' import type { PriceAlert } from '../types/api.ts' export function Alerts() { const [alerts, setAlerts] = useState(mockAlerts) const [showCreate, setShowCreate] = useState(false) const triggered = alerts.filter((a) => a.triggered) const watching = alerts.filter((a) => !a.triggered) function handleDelete(id: string) { setAlerts((prev) => prev.filter((a) => a.id !== id)) } return (

Price Alerts

{/* Create alert form */} {showCreate && setShowCreate(false)} onCreated={(a) => { setAlerts((prev) => [a, ...prev]) setShowCreate(false) }} />} {/* Triggered alerts */} {triggered.length > 0 && (

Triggered ({triggered.length})

{triggered.map((alert) => ( ))}
)} {/* Watching alerts */}

Watching ({watching.length})

{watching.length === 0 ? (

No active alerts.{' '} Search products {' '} to set one up.

) : (
{watching.map((alert) => ( ))}
)}
) } function AlertCard({ alert, onDelete, }: { alert: PriceAlert onDelete: (id: string) => void }) { const priceDiff = alert.currentPrice - alert.targetPrice const isBelow = priceDiff <= 0 return (
{alert.productName}
Target: ${alert.targetPrice.toFixed(2)} · Now: ${alert.currentPrice.toFixed(2)}
{alert.triggered && (

Price dropped ${Math.abs(priceDiff).toFixed(2)} below target

)}
{/* Status indicator */}
{alert.triggered && ( )}
{/* Progress bar toward target */} {!alert.triggered && (
)}
) } function CreateAlertForm({ onClose, onCreated, }: { onClose: () => void onCreated: (alert: PriceAlert) => void }) { const [productName, setProductName] = useState('') const [targetPrice, setTargetPrice] = useState('') function handleSubmit(e: React.FormEvent) { e.preventDefault() if (!productName || !targetPrice) return onCreated({ id: `a-${Date.now()}`, productId: `prod-${Date.now()}`, productName, targetPrice: parseFloat(targetPrice), currentPrice: parseFloat(targetPrice) + 0.50, triggered: false, }) } return (
setProductName(e.target.value)} className="min-h-12 w-full rounded-xl border border-gray-200 px-4 text-base focus:border-brand-blue focus:outline-none focus:ring-1 focus:ring-brand-blue" /> setTargetPrice(e.target.value)} className="min-h-12 w-full rounded-xl border border-gray-200 px-4 text-base focus:border-brand-blue focus:outline-none focus:ring-1 focus:ring-brand-blue" />
) }