'use client'; import { useState, useEffect } from 'react'; import { motion } from 'framer-motion'; import { useRouter } from 'next/navigation'; import Link from 'next/link'; import { DollarSign, TrendingUp, TrendingDown, Calendar, Home, Building, Download, Filter, ChevronLeft, ChevronRight, ArrowLeft, Loader2, Eye, PieChart, BarChart, LineChart, Wallet, CreditCard, Clock, CheckCircle, XCircle } from 'lucide-react'; import toast, { Toaster } from 'react-hot-toast'; import AuthService from '../../services/AuthService'; const StatCard = ({ title, value, change, icon: Icon, color, trend }) => { return (
{trend === 'up' ? : } {Math.abs(change)}%

{title}

{value}
); }; const PropertyProfitCard = ({ property, onViewDetails }) => { const formatCurrency = (amount) => { return amount?.toLocaleString() + ' ل.س'; }; return (

{property.title}

{property.location}

{property.status === 'active' ? 'نشط' : 'غير نشط'}
إجمالي الأرباح
{formatCurrency(property.totalProfit)}
عدد الحجوزات
{property.totalBookings}
هذا الشهر {formatCurrency(property.monthlyProfit)}
الأسبوع الماضي {formatCurrency(property.weeklyProfit)}
متوسط السعر اليومي {formatCurrency(property.avgDailyPrice)}
); }; const ProfitDetailsModal = ({ property, isOpen, onClose }) => { if (!isOpen || !property) return null; const formatCurrency = (amount) => { return amount?.toLocaleString() + ' ل.س'; }; const monthlyData = [ { month: 'يناير', profit: 1250000 }, { month: 'فبراير', profit: 1500000 }, { month: 'مارس', profit: 1800000 }, { month: 'إبريل', profit: 2100000 }, { month: 'مايو', profit: 2500000 }, { month: 'يونيو', profit: 2300000 } ]; const maxProfit = Math.max(...monthlyData.map(d => d.profit)); return ( e.stopPropagation()} >

{property.title}

{property.location}

{formatCurrency(property.totalProfit)}
إجمالي الأرباح
{property.totalBookings}
عدد الحجوزات
{property.occupancyRate}%
نسبة الإشغال
{formatCurrency(property.avgDailyPrice)}
متوسط السعر اليومي

الأرباح الشهرية

{monthlyData.map((data, index) => (
{data.month} {formatCurrency(data.profit)}
))}

آخر الحجوزات

{property.recentBookings?.map((booking, index) => (

{booking.tenantName}

{booking.startDate} - {booking.endDate}

{formatCurrency(booking.amount)}

{booking.status === 'completed' ? 'مكتمل' : 'قيد التنفيذ'}

))}
); }; export default function OwnerProfitsPage() { const router = useRouter(); const [user, setUser] = useState(null); const [properties, setProperties] = useState([]); const [filteredProperties, setFilteredProperties] = useState([]); const [isLoading, setIsLoading] = useState(true); const [selectedProperty, setSelectedProperty] = useState(null); const [dateRange, setDateRange] = useState({ start: '', end: '' }); const [selectedPeriod, setSelectedPeriod] = useState('month'); useEffect(() => { const authUser = AuthService.getUser(); if (authUser && AuthService.isOwner()) { setUser({ name: authUser.name || authUser.email, email: authUser.email, role: 'owner', }); loadData(); } else { router.push('/auth/choose-role'); } }, [router]); // month, year, all const loadProfitsData = () => { const storedProfits = localStorage.getItem('ownerProfits'); if (storedProfits) { setProperties(JSON.parse(storedProfits)); setFilteredProperties(JSON.parse(storedProfits)); } else { const mockProperties = [ { id: 1, title: 'فيلا فاخرة في المزة', location: 'دمشق، المزة', status: 'active', totalProfit: 12500000, totalBookings: 24, monthlyProfit: 3200000, weeklyProfit: 850000, avgDailyPrice: 500000, occupancyRate: 78, recentBookings: [ { tenantName: 'أحمد محمد', startDate: '2024-03-10', endDate: '2024-03-15', amount: 2500000, status: 'completed' }, { tenantName: 'سارة أحمد', startDate: '2024-03-05', endDate: '2024-03-08', amount: 1500000, status: 'completed' } ] }, { id: 2, title: 'شقة حديثة في الشهباء', location: 'حلب، الشهباء', status: 'active', totalProfit: 5800000, totalBookings: 18, monthlyProfit: 1500000, weeklyProfit: 400000, avgDailyPrice: 250000, occupancyRate: 65, recentBookings: [ { tenantName: 'محمد علي', startDate: '2024-03-12', endDate: '2024-03-14', amount: 750000, status: 'completed' } ] }, { id: 3, title: 'بيت عائلي في بابا عمرو', location: 'حمص، بابا عمرو', status: 'active', totalProfit: 8400000, totalBookings: 12, monthlyProfit: 2100000, weeklyProfit: 525000, avgDailyPrice: 350000, occupancyRate: 45, recentBookings: [] } ]; setProperties(mockProperties); setFilteredProperties(mockProperties); localStorage.setItem('ownerProfits', JSON.stringify(mockProperties)); } setIsLoading(false); }; const totalStats = { totalProfit: properties.reduce((sum, p) => sum + p.totalProfit, 0), totalBookings: properties.reduce((sum, p) => sum + p.totalBookings, 0), avgOccupancy: Math.round(properties.reduce((sum, p) => sum + p.occupancyRate, 0) / properties.length), activeProperties: properties.filter(p => p.status === 'active').length }; const formatCurrency = (amount) => { if (amount >= 1000000) { return (amount / 1000000).toFixed(1) + ' مليون ل.س'; } return amount?.toLocaleString() + ' ل.س'; }; if (isLoading) { return (

جاري تحميل بيانات الأرباح...

); } return (
setSelectedProperty(null)} />

الأرباح والإحصائيات

مرحباً {user?.name}، إليك ملخص أرباحك

{/* */}

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

{filteredProperties.length === 0 ? (

لا توجد بيانات

لا توجد أرباح مسجلة حتى الآن

) : (
{filteredProperties.map((property) => ( ))}
)}

احصل على المزيد من الأرباح

أضف عقارات جديدة وحسّن أسعارك لزيادة الإشغال

إضافة عقار جديد
); }