import { getCurrentUser } from "@/lib/auth" import { getJobsByPlumberId, getPlumberEarnings } from "@/lib/plumber-jobs" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { DollarSign, TrendingUp, Calendar, CheckCircle, Star } from "lucide-react" export default async function PlumberEarningsPage() { const user = await getCurrentUser() const jobs = user ? getJobsByPlumberId(user.id) : [] const earnings = user ? getPlumberEarnings(user.id) : null const completedJobs = jobs.filter((job) => job.status === "completed") const thisMonthJobs = completedJobs.filter((job) => { const jobDate = new Date(job.completedAt || job.createdAt) const now = new Date() return jobDate.getMonth() === now.getMonth() && jobDate.getFullYear() === now.getFullYear() }) return (

تقرير الأرباح

تتبع أرباحك ومهامك المكتملة

{/* Earnings Overview */} {earnings && (

الأرباح الإجمالية

{earnings.totalEarnings} جنيه

أرباح هذا الشهر

{earnings.monthlyEarnings} جنيه

المهام المكتملة

{earnings.completedJobs}

متوسط التقييم

{earnings.averageRating.toFixed(1)}

من {earnings.totalReviews} تقييم

)} {/* Recent Completed Jobs */} المهام المكتملة مؤخراً {completedJobs.length > 0 ? (
{completedJobs.map((job) => (

{job.serviceName}

العميل: {job.customerName}

{new Date(job.completedAt || job.createdAt).toLocaleDateString("ar-EG")}

{job.actualPrice || job.estimatedPrice} جنيه

{job.customerRating && (
{job.customerRating}
)}
))}
) : (

لا توجد مهام مكتملة بعد

)}
{/* Monthly Summary */} ملخص هذا الشهر

{thisMonthJobs.length}

مهام مكتملة

{thisMonthJobs.reduce((sum, job) => sum + (job.actualPrice || job.estimatedPrice), 0)} جنيه

أرباح الشهر

{thisMonthJobs.length > 0 ? ( thisMonthJobs.reduce((sum, job) => sum + (job.actualPrice || job.estimatedPrice), 0) / thisMonthJobs.length ).toFixed(0) : 0}{" "} جنيه

متوسط المهمة

) }