Added calendar, profits and booking for owner
This commit is contained in:
@ -228,14 +228,14 @@ export default function ClientLayout({ children }) {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<motion.button
|
{/* <motion.button
|
||||||
whileHover={{ scale: 1.1, rotate: 360 }}
|
whileHover={{ scale: 1.1, rotate: 360 }}
|
||||||
whileTap={{ scale: 0.9 }}
|
whileTap={{ scale: 0.9 }}
|
||||||
onClick={() => changeLanguage(currentLanguage === 'en' ? 'ar' : 'en')}
|
onClick={() => changeLanguage(currentLanguage === 'en' ? 'ar' : 'en')}
|
||||||
className="flex items-center justify-center w-10 h-10 bg-gray-100 hover:bg-gray-200 rounded-full transition-all duration-200 ml-4"
|
className="flex items-center justify-center w-10 h-10 bg-gray-100 hover:bg-gray-200 rounded-full transition-all duration-200 ml-4"
|
||||||
>
|
>
|
||||||
<Globe className="w-5 h-5 text-gray-700" />
|
<Globe className="w-5 h-5 text-gray-700" />
|
||||||
</motion.button>
|
</motion.button> */}
|
||||||
|
|
||||||
{user && (
|
{user && (
|
||||||
<div className="relative" ref={menuRef}>
|
<div className="relative" ref={menuRef}>
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
// app/admin/page.js (محدث)
|
|
||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
|
|||||||
762
app/owner/bookings/page.js
Normal file
762
app/owner/bookings/page.js
Normal file
@ -0,0 +1,762 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState, useEffect } from 'react';
|
||||||
|
import { motion, AnimatePresence } from 'framer-motion';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import Link from 'next/link';
|
||||||
|
import {
|
||||||
|
Calendar,
|
||||||
|
Home,
|
||||||
|
User,
|
||||||
|
Mail,
|
||||||
|
Phone,
|
||||||
|
DollarSign,
|
||||||
|
CheckCircle,
|
||||||
|
XCircle,
|
||||||
|
Clock,
|
||||||
|
MapPin,
|
||||||
|
Bed,
|
||||||
|
Bath,
|
||||||
|
Square,
|
||||||
|
CalendarDays,
|
||||||
|
ChevronLeft,
|
||||||
|
ChevronRight,
|
||||||
|
Eye,
|
||||||
|
MessageCircle,
|
||||||
|
ArrowLeft,
|
||||||
|
Loader2,
|
||||||
|
Filter,
|
||||||
|
Search,
|
||||||
|
Download,
|
||||||
|
TrendingUp,
|
||||||
|
Users,
|
||||||
|
Building
|
||||||
|
} from 'lucide-react';
|
||||||
|
import toast, { Toaster } from 'react-hot-toast';
|
||||||
|
import Image from 'next/image';
|
||||||
|
|
||||||
|
const OwnerBookingCalendar = ({ property, onDateSelect, selectedDates }) => {
|
||||||
|
const [currentMonth, setCurrentMonth] = useState(new Date());
|
||||||
|
const [hoverDate, setHoverDate] = useState(null);
|
||||||
|
|
||||||
|
const daysInMonth = new Date(
|
||||||
|
currentMonth.getFullYear(),
|
||||||
|
currentMonth.getMonth() + 1,
|
||||||
|
0
|
||||||
|
).getDate();
|
||||||
|
|
||||||
|
const firstDayOfMonth = new Date(
|
||||||
|
currentMonth.getFullYear(),
|
||||||
|
currentMonth.getMonth(),
|
||||||
|
1
|
||||||
|
).getDay();
|
||||||
|
|
||||||
|
const monthNames = [
|
||||||
|
'يناير', 'فبراير', 'مارس', 'إبريل', 'مايو', 'يونيو',
|
||||||
|
'يوليو', 'أغسطس', 'سبتمبر', 'أكتوبر', 'نوفمبر', 'ديسمبر'
|
||||||
|
];
|
||||||
|
|
||||||
|
const isDateBooked = (date) => {
|
||||||
|
if (!property?.bookings) return false;
|
||||||
|
const dateStr = date.toISOString().split('T')[0];
|
||||||
|
return property.bookings.some(booking => {
|
||||||
|
const start = new Date(booking.startDate);
|
||||||
|
const end = new Date(booking.endDate);
|
||||||
|
const current = new Date(date);
|
||||||
|
return current >= start && current <= end;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const isDateSelected = (date) => {
|
||||||
|
if (!selectedDates) return false;
|
||||||
|
const dateStr = date.toISOString().split('T')[0];
|
||||||
|
return dateStr === selectedDates.start || dateStr === selectedDates.end;
|
||||||
|
};
|
||||||
|
|
||||||
|
const isInRange = (date) => {
|
||||||
|
if (!selectedDates?.start || !selectedDates?.end) return false;
|
||||||
|
const dateStr = date.toISOString().split('T')[0];
|
||||||
|
return dateStr > selectedDates.start && dateStr < selectedDates.end;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDateClick = (date) => {
|
||||||
|
if (isDateBooked(date)) return;
|
||||||
|
onDateSelect?.(date);
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderDays = () => {
|
||||||
|
const days = [];
|
||||||
|
const totalDays = daysInMonth + firstDayOfMonth;
|
||||||
|
|
||||||
|
for (let i = 0; i < totalDays; i++) {
|
||||||
|
if (i < firstDayOfMonth) {
|
||||||
|
days.push(<div key={`empty-${i}`} className="p-2" />);
|
||||||
|
} else {
|
||||||
|
const dayNumber = i - firstDayOfMonth + 1;
|
||||||
|
const date = new Date(
|
||||||
|
currentMonth.getFullYear(),
|
||||||
|
currentMonth.getMonth(),
|
||||||
|
dayNumber
|
||||||
|
);
|
||||||
|
|
||||||
|
const isBooked = isDateBooked(date);
|
||||||
|
const isSelected = isDateSelected(date);
|
||||||
|
const inRange = isInRange(date);
|
||||||
|
const isToday = date.toDateString() === new Date().toDateString();
|
||||||
|
|
||||||
|
days.push(
|
||||||
|
<button
|
||||||
|
key={dayNumber}
|
||||||
|
onClick={() => handleDateClick(date)}
|
||||||
|
disabled={isBooked}
|
||||||
|
onMouseEnter={() => setHoverDate(dayNumber)}
|
||||||
|
onMouseLeave={() => setHoverDate(null)}
|
||||||
|
className={`
|
||||||
|
p-2 rounded-lg text-center text-sm transition-all relative
|
||||||
|
${isBooked ? 'bg-red-100 text-red-500 cursor-not-allowed line-through' : ''}
|
||||||
|
${isSelected ? 'bg-amber-500 text-white shadow-md' : ''}
|
||||||
|
${inRange ? 'bg-amber-100' : ''}
|
||||||
|
${!isBooked && !isSelected ? 'hover:bg-amber-50 hover:text-amber-600 cursor-pointer' : ''}
|
||||||
|
${isToday && !isSelected && !isBooked ? 'border-2 border-amber-500' : ''}
|
||||||
|
`}
|
||||||
|
>
|
||||||
|
{dayNumber}
|
||||||
|
{isBooked && (
|
||||||
|
<span className="absolute -top-1 -right-1 w-2 h-2 bg-red-500 rounded-full" />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return days;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 p-6">
|
||||||
|
{/* رأس التقويم */}
|
||||||
|
<div className="flex items-center justify-between mb-6">
|
||||||
|
<button
|
||||||
|
onClick={() => setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() - 1, 1))}
|
||||||
|
className="p-2 hover:bg-gray-100 rounded-xl transition-colors"
|
||||||
|
>
|
||||||
|
<ChevronRight className="w-5 h-5 text-gray-600" />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<h3 className="text-lg font-bold text-gray-900 flex items-center gap-2">
|
||||||
|
<CalendarDays className="w-5 h-5 text-amber-500" />
|
||||||
|
{monthNames[currentMonth.getMonth()]} {currentMonth.getFullYear()}
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={() => setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() + 1, 1))}
|
||||||
|
className="p-2 hover:bg-gray-100 rounded-xl transition-colors"
|
||||||
|
>
|
||||||
|
<ChevronLeft className="w-5 h-5 text-gray-600" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* أيام الأسبوع */}
|
||||||
|
<div className="grid grid-cols-7 gap-1 mb-3 text-center text-sm font-medium text-gray-500">
|
||||||
|
<div>أحد</div>
|
||||||
|
<div>إثنين</div>
|
||||||
|
<div>ثلاثاء</div>
|
||||||
|
<div>أربعاء</div>
|
||||||
|
<div>خميس</div>
|
||||||
|
<div>جمعة</div>
|
||||||
|
<div>سبت</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-7 gap-1">
|
||||||
|
{renderDays()}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-wrap gap-4 mt-6 pt-4 border-t border-gray-200 text-xs">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="w-3 h-3 bg-red-100 rounded" />
|
||||||
|
<span className="text-gray-600">محجوز</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="w-3 h-3 bg-amber-500 rounded" />
|
||||||
|
<span className="text-gray-600">محدد</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="w-3 h-3 bg-amber-100 rounded" />
|
||||||
|
<span className="text-gray-600">ضمن الفترة</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="w-3 h-3 border-2 border-amber-500 rounded" />
|
||||||
|
<span className="text-gray-600">اليوم</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const BookingCard = ({ booking, onViewDetails, onContact }) => {
|
||||||
|
const formatCurrency = (amount) => {
|
||||||
|
return amount?.toLocaleString() + ' ل.س';
|
||||||
|
};
|
||||||
|
|
||||||
|
const getStatusBadge = (status) => {
|
||||||
|
const statusConfig = {
|
||||||
|
pending: { label: 'قيد الانتظار', color: 'bg-yellow-100 text-yellow-800', icon: Clock },
|
||||||
|
confirmed: { label: 'مؤكد', color: 'bg-green-100 text-green-800', icon: CheckCircle },
|
||||||
|
cancelled: { label: 'ملغي', color: 'bg-red-100 text-red-800', icon: XCircle },
|
||||||
|
completed: { label: 'منتهي', color: 'bg-gray-100 text-gray-800', icon: CheckCircle }
|
||||||
|
};
|
||||||
|
|
||||||
|
const config = statusConfig[status] || statusConfig.pending;
|
||||||
|
const Icon = config.icon;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span className={`inline-flex items-center gap-1 px-2 py-1 rounded-lg text-xs font-medium ${config.color}`}>
|
||||||
|
<Icon className="w-3 h-3" />
|
||||||
|
{config.label}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, y: 20 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
className="bg-white rounded-2xl shadow-sm hover:shadow-md transition-all border border-gray-200 overflow-hidden"
|
||||||
|
>
|
||||||
|
<div className="p-5">
|
||||||
|
<div className="flex justify-between items-start mb-4">
|
||||||
|
<div>
|
||||||
|
<div className="flex items-center gap-2 mb-2">
|
||||||
|
<h3 className="font-bold text-gray-900">{booking.propertyTitle}</h3>
|
||||||
|
{getStatusBadge(booking.status)}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-1 text-gray-500 text-sm">
|
||||||
|
<MapPin className="w-4 h-4" />
|
||||||
|
{booking.location}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="text-left">
|
||||||
|
<div className="text-lg font-bold text-amber-600">{formatCurrency(booking.totalAmount)}</div>
|
||||||
|
<div className="text-xs text-gray-500">إجمالي المبلغ</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="bg-gray-50 rounded-xl p-3 mb-4">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<div className="w-10 h-10 bg-amber-100 rounded-full flex items-center justify-center">
|
||||||
|
<User className="w-5 h-5 text-amber-600" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="font-medium text-gray-900">{booking.tenantName}</p>
|
||||||
|
<div className="flex items-center gap-2 text-xs text-gray-500">
|
||||||
|
<Phone className="w-3 h-3" />
|
||||||
|
{booking.tenantPhone}
|
||||||
|
<Mail className="w-3 h-3 mr-1" />
|
||||||
|
{booking.tenantEmail}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-3 gap-3 mb-4 text-center">
|
||||||
|
<div className="bg-gray-50 p-2 rounded-lg">
|
||||||
|
<Calendar className="w-4 h-4 text-amber-500 mx-auto mb-1" />
|
||||||
|
<div className="text-xs text-gray-500">من</div>
|
||||||
|
<div className="text-sm font-medium">{booking.startDate}</div>
|
||||||
|
</div>
|
||||||
|
<div className="bg-gray-50 p-2 rounded-lg">
|
||||||
|
<Calendar className="w-4 h-4 text-amber-500 mx-auto mb-1" />
|
||||||
|
<div className="text-xs text-gray-500">إلى</div>
|
||||||
|
<div className="text-sm font-medium">{booking.endDate}</div>
|
||||||
|
</div>
|
||||||
|
<div className="bg-gray-50 p-2 rounded-lg">
|
||||||
|
<Clock className="w-4 h-4 text-amber-500 mx-auto mb-1" />
|
||||||
|
<div className="text-xs text-gray-500">المدة</div>
|
||||||
|
<div className="text-sm font-medium">{booking.days} يوم</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex gap-3 pt-3 border-t border-gray-100">
|
||||||
|
<button
|
||||||
|
onClick={() => onViewDetails(booking)}
|
||||||
|
className="flex-1 bg-gray-100 text-gray-700 py-2 rounded-xl text-sm font-medium hover:bg-gray-200 transition-colors flex items-center justify-center gap-2"
|
||||||
|
>
|
||||||
|
<Eye className="w-4 h-4" />
|
||||||
|
التفاصيل
|
||||||
|
</button>
|
||||||
|
{/* <button
|
||||||
|
onClick={() => onContact(booking)}
|
||||||
|
className="flex-1 bg-amber-500 text-white py-2 rounded-xl text-sm font-medium hover:bg-amber-600 transition-colors flex items-center justify-center gap-2"
|
||||||
|
>
|
||||||
|
<MessageCircle className="w-4 h-4" />
|
||||||
|
تواصل
|
||||||
|
</button> */}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</motion.div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const BookingDetailsModal = ({ booking, isOpen, onClose }) => {
|
||||||
|
if (!isOpen || !booking) return null;
|
||||||
|
|
||||||
|
const formatCurrency = (amount) => {
|
||||||
|
return amount?.toLocaleString() + ' ل.س';
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0 }}
|
||||||
|
animate={{ opacity: 1 }}
|
||||||
|
exit={{ opacity: 0 }}
|
||||||
|
className="fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center p-4 z-50"
|
||||||
|
onClick={onClose}
|
||||||
|
>
|
||||||
|
<motion.div
|
||||||
|
initial={{ scale: 0.9, y: 20 }}
|
||||||
|
animate={{ scale: 1, y: 0 }}
|
||||||
|
exit={{ scale: 0.9, y: 20 }}
|
||||||
|
className="bg-white rounded-2xl w-full max-w-2xl max-h-[90vh] overflow-y-auto shadow-2xl"
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
>
|
||||||
|
<div className="sticky top-0 bg-gradient-to-r from-amber-500 to-amber-600 p-6 text-white">
|
||||||
|
<div className="flex justify-between items-center">
|
||||||
|
<h2 className="text-xl font-bold">تفاصيل الحجز</h2>
|
||||||
|
<button onClick={onClose} className="p-1 hover:bg-white/20 rounded-full">
|
||||||
|
<XCircle className="w-6 h-6" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p className="text-amber-100 text-sm mt-1">رقم الحجز: #{booking.id}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="p-6 space-y-6">
|
||||||
|
<div className="bg-gray-50 p-4 rounded-xl">
|
||||||
|
<h3 className="font-bold text-gray-900 mb-3">معلومات العقار</h3>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p><span className="text-gray-500">العقار:</span> {booking.propertyTitle}</p>
|
||||||
|
<p><span className="text-gray-500">الموقع:</span> {booking.location}</p>
|
||||||
|
{booking.propertyDetails && (
|
||||||
|
<div className="flex gap-3 mt-2">
|
||||||
|
<span className="text-sm bg-white px-2 py-1 rounded-lg">{booking.propertyDetails.bedrooms} غرف</span>
|
||||||
|
<span className="text-sm bg-white px-2 py-1 rounded-lg">{booking.propertyDetails.bathrooms} حمامات</span>
|
||||||
|
<span className="text-sm bg-white px-2 py-1 rounded-lg">{booking.propertyDetails.area} م²</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="bg-gray-50 p-4 rounded-xl">
|
||||||
|
<h3 className="font-bold text-gray-900 mb-3">معلومات المستأجر</h3>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p><span className="text-gray-500">الاسم:</span> {booking.tenantName}</p>
|
||||||
|
<p><span className="text-gray-500">البريد الإلكتروني:</span> {booking.tenantEmail}</p>
|
||||||
|
<p><span className="text-gray-500">رقم الهاتف:</span> {booking.tenantPhone}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="bg-gray-50 p-4 rounded-xl">
|
||||||
|
<h3 className="font-bold text-gray-900 mb-3">تفاصيل الحجز</h3>
|
||||||
|
<div className="grid grid-cols-2 gap-4">
|
||||||
|
<div>
|
||||||
|
<p className="text-gray-500">تاريخ البداية</p>
|
||||||
|
<p className="font-medium">{booking.startDate}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-gray-500">تاريخ النهاية</p>
|
||||||
|
<p className="font-medium">{booking.endDate}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-gray-500">عدد الأيام</p>
|
||||||
|
<p className="font-medium">{booking.days} يوم</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-gray-500">حالة الحجز</p>
|
||||||
|
<p className="font-medium">{booking.status === 'pending' ? 'قيد الانتظار' :
|
||||||
|
booking.status === 'confirmed' ? 'مؤكد' :
|
||||||
|
booking.status === 'cancelled' ? 'ملغي' : 'منتهي'}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="bg-amber-50 p-4 rounded-xl">
|
||||||
|
<h3 className="font-bold text-amber-700 mb-3">المعلومات المالية</h3>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div className="flex justify-between">
|
||||||
|
<span className="text-gray-600">السعر اليومي</span>
|
||||||
|
<span className="font-medium">{formatCurrency(booking.dailyPrice)}</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-between">
|
||||||
|
<span className="text-gray-600">المدة ({booking.days} أيام)</span>
|
||||||
|
<span className="font-medium">{formatCurrency(booking.dailyPrice * booking.days)}</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-between">
|
||||||
|
<span className="text-gray-600">سلفة الضمان</span>
|
||||||
|
<span className="font-medium">{formatCurrency(booking.securityDeposit || 0)}</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-between pt-2 border-t border-amber-200 font-bold">
|
||||||
|
<span className="text-gray-900">الإجمالي</span>
|
||||||
|
<span className="text-amber-600 text-lg">{formatCurrency(booking.totalAmount)}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{booking.notes && (
|
||||||
|
<div className="bg-gray-50 p-4 rounded-xl">
|
||||||
|
<h3 className="font-bold text-gray-900 mb-2">ملاحظات</h3>
|
||||||
|
<p className="text-gray-600">{booking.notes}</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</motion.div>
|
||||||
|
</motion.div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function OwnerBookingsPage() {
|
||||||
|
const router = useRouter();
|
||||||
|
const [user, setUser] = useState(null);
|
||||||
|
const [bookings, setBookings] = useState([]);
|
||||||
|
const [filteredBookings, setFilteredBookings] = useState([]);
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
const [selectedBooking, setSelectedBooking] = useState(null);
|
||||||
|
const [filterStatus, setFilterStatus] = useState('all');
|
||||||
|
const [searchTerm, setSearchTerm] = useState('');
|
||||||
|
const [dateRange, setDateRange] = useState({ start: '', end: '' });
|
||||||
|
const [showCalendar, setShowCalendar] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const storedUser = localStorage.getItem('user');
|
||||||
|
if (storedUser) {
|
||||||
|
const userData = JSON.parse(storedUser);
|
||||||
|
if (userData.role !== 'owner') {
|
||||||
|
router.push('/');
|
||||||
|
} else {
|
||||||
|
setUser(userData);
|
||||||
|
loadBookings();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
router.push('/auth/choose-role');
|
||||||
|
}
|
||||||
|
}, [router]);
|
||||||
|
|
||||||
|
const loadBookings = () => {
|
||||||
|
const storedBookings = localStorage.getItem('ownerBookings');
|
||||||
|
if (storedBookings) {
|
||||||
|
setBookings(JSON.parse(storedBookings));
|
||||||
|
setFilteredBookings(JSON.parse(storedBookings));
|
||||||
|
} else {
|
||||||
|
const mockBookings = [
|
||||||
|
{
|
||||||
|
id: 'BK001',
|
||||||
|
propertyId: 1,
|
||||||
|
propertyTitle: 'فيلا فاخرة في المزة',
|
||||||
|
location: 'دمشق، المزة',
|
||||||
|
propertyDetails: { bedrooms: 5, bathrooms: 4, area: 450 },
|
||||||
|
tenantName: 'أحمد محمد',
|
||||||
|
tenantEmail: 'ahmed@example.com',
|
||||||
|
tenantPhone: '0933111222',
|
||||||
|
startDate: '2024-03-10',
|
||||||
|
endDate: '2024-03-15',
|
||||||
|
days: 5,
|
||||||
|
dailyPrice: 500000,
|
||||||
|
totalAmount: 2500000,
|
||||||
|
securityDeposit: 500000,
|
||||||
|
status: 'confirmed',
|
||||||
|
createdAt: '2024-02-25',
|
||||||
|
notes: 'طلب الحجز من خلال الموقع'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'BK002',
|
||||||
|
propertyId: 2,
|
||||||
|
propertyTitle: 'شقة حديثة في الشهباء',
|
||||||
|
location: 'حلب، الشهباء',
|
||||||
|
propertyDetails: { bedrooms: 3, bathrooms: 2, area: 180 },
|
||||||
|
tenantName: 'سارة أحمد',
|
||||||
|
tenantEmail: 'sara@example.com',
|
||||||
|
tenantPhone: '0945123789',
|
||||||
|
startDate: '2024-03-05',
|
||||||
|
endDate: '2024-03-08',
|
||||||
|
days: 3,
|
||||||
|
dailyPrice: 250000,
|
||||||
|
totalAmount: 750000,
|
||||||
|
securityDeposit: 250000,
|
||||||
|
status: 'pending',
|
||||||
|
createdAt: '2024-02-24',
|
||||||
|
notes: 'تحتاج إلى تأكيد'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'BK003',
|
||||||
|
propertyId: 3,
|
||||||
|
propertyTitle: 'بيت عائلي في بابا عمرو',
|
||||||
|
location: 'حمص، بابا عمرو',
|
||||||
|
propertyDetails: { bedrooms: 4, bathrooms: 3, area: 300 },
|
||||||
|
tenantName: 'محمد الحلبي',
|
||||||
|
tenantEmail: 'mohammed@example.com',
|
||||||
|
tenantPhone: '0956123456',
|
||||||
|
startDate: '2024-02-20',
|
||||||
|
endDate: '2024-03-20',
|
||||||
|
days: 30,
|
||||||
|
dailyPrice: 350000,
|
||||||
|
totalAmount: 10500000,
|
||||||
|
securityDeposit: 500000,
|
||||||
|
status: 'completed',
|
||||||
|
createdAt: '2024-02-15',
|
||||||
|
notes: 'تم إنهاء الإيجار بنجاح'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
setBookings(mockBookings);
|
||||||
|
setFilteredBookings(mockBookings);
|
||||||
|
localStorage.setItem('ownerBookings', JSON.stringify(mockBookings));
|
||||||
|
}
|
||||||
|
setIsLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let filtered = [...bookings];
|
||||||
|
|
||||||
|
if (filterStatus !== 'all') {
|
||||||
|
filtered = filtered.filter(b => b.status === filterStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (searchTerm) {
|
||||||
|
filtered = filtered.filter(b =>
|
||||||
|
b.propertyTitle.includes(searchTerm) ||
|
||||||
|
b.tenantName.includes(searchTerm) ||
|
||||||
|
b.id.includes(searchTerm)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dateRange.start) {
|
||||||
|
filtered = filtered.filter(b => b.startDate >= dateRange.start);
|
||||||
|
}
|
||||||
|
if (dateRange.end) {
|
||||||
|
filtered = filtered.filter(b => b.endDate <= dateRange.end);
|
||||||
|
}
|
||||||
|
|
||||||
|
setFilteredBookings(filtered);
|
||||||
|
}, [filterStatus, searchTerm, dateRange, bookings]);
|
||||||
|
|
||||||
|
const handleViewDetails = (booking) => {
|
||||||
|
setSelectedBooking(booking);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleContact = (booking) => {
|
||||||
|
toast.success(`جاري فتح محادثة مع ${booking.tenantName}`, {
|
||||||
|
icon: '💬',
|
||||||
|
style: { background: '#dcfce7', color: '#166534' }
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleStatusChange = (bookingId, newStatus) => {
|
||||||
|
const updatedBookings = bookings.map(b =>
|
||||||
|
b.id === bookingId ? { ...b, status: newStatus } : b
|
||||||
|
);
|
||||||
|
setBookings(updatedBookings);
|
||||||
|
setFilteredBookings(updatedBookings);
|
||||||
|
localStorage.setItem('ownerBookings', JSON.stringify(updatedBookings));
|
||||||
|
toast.success(`تم تحديث حالة الحجز بنجاح`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const statusCounts = {
|
||||||
|
all: bookings.length,
|
||||||
|
pending: bookings.filter(b => b.status === 'pending').length,
|
||||||
|
confirmed: bookings.filter(b => b.status === 'confirmed').length,
|
||||||
|
completed: bookings.filter(b => b.status === 'completed').length,
|
||||||
|
cancelled: bookings.filter(b => b.status === 'cancelled').length
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen bg-gray-50 flex items-center justify-center">
|
||||||
|
<div className="text-center">
|
||||||
|
<Loader2 className="w-12 h-12 text-amber-500 animate-spin mx-auto mb-4" />
|
||||||
|
<p className="text-gray-600">جاري تحميل الحجوزات...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen bg-gray-50 py-8">
|
||||||
|
<Toaster position="top-center" reverseOrder={false} />
|
||||||
|
|
||||||
|
<BookingDetailsModal
|
||||||
|
booking={selectedBooking}
|
||||||
|
isOpen={!!selectedBooking}
|
||||||
|
onClose={() => setSelectedBooking(null)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="container mx-auto px-4">
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, y: -20 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
className="flex flex-col md:flex-row justify-between items-start md:items-center mb-8 gap-4"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<h1 className="text-3xl font-bold text-gray-900 mb-2">حجوزاتي</h1>
|
||||||
|
<p className="text-gray-600">مرحباً {user?.name}، لديك {bookings.length} حجز</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex gap-3">
|
||||||
|
<button
|
||||||
|
onClick={() => setShowCalendar(!showCalendar)}
|
||||||
|
className="px-4 py-2 bg-white border border-gray-300 rounded-xl text-gray-700 hover:bg-gray-50 transition-colors flex items-center gap-2"
|
||||||
|
>
|
||||||
|
<Calendar className="w-5 h-5" />
|
||||||
|
{showCalendar ? 'إخفاء التقويم' : 'عرض التقويم'}
|
||||||
|
</button>
|
||||||
|
{/* <button className="px-4 py-2 bg-green-600 text-white rounded-xl hover:bg-green-700 transition-colors flex items-center gap-2">
|
||||||
|
<Download className="w-5 h-5" />
|
||||||
|
تصدير التقرير
|
||||||
|
</button> */}
|
||||||
|
</div>
|
||||||
|
</motion.div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 md:grid-cols-5 gap-4 mb-8">
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, y: 20 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
transition={{ delay: 0.1 }}
|
||||||
|
className="bg-white rounded-xl shadow-sm p-4 text-center border border-gray-200 cursor-pointer hover:shadow-md transition-all"
|
||||||
|
onClick={() => setFilterStatus('all')}
|
||||||
|
>
|
||||||
|
<div className="text-2xl font-bold text-gray-900">{statusCounts.all}</div>
|
||||||
|
<div className="text-sm text-gray-600">جميع الحجوزات</div>
|
||||||
|
</motion.div>
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, y: 20 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
transition={{ delay: 0.2 }}
|
||||||
|
className={`bg-white rounded-xl shadow-sm p-4 text-center border cursor-pointer hover:shadow-md transition-all ${
|
||||||
|
filterStatus === 'pending' ? 'border-yellow-500 bg-yellow-50' : 'border-gray-200'
|
||||||
|
}`}
|
||||||
|
onClick={() => setFilterStatus('pending')}
|
||||||
|
>
|
||||||
|
<div className="text-2xl font-bold text-yellow-600">{statusCounts.pending}</div>
|
||||||
|
<div className="text-sm text-gray-600">قيد الانتظار</div>
|
||||||
|
</motion.div>
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, y: 20 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
transition={{ delay: 0.3 }}
|
||||||
|
className={`bg-white rounded-xl shadow-sm p-4 text-center border cursor-pointer hover:shadow-md transition-all ${
|
||||||
|
filterStatus === 'confirmed' ? 'border-green-500 bg-green-50' : 'border-gray-200'
|
||||||
|
}`}
|
||||||
|
onClick={() => setFilterStatus('confirmed')}
|
||||||
|
>
|
||||||
|
<div className="text-2xl font-bold text-green-600">{statusCounts.confirmed}</div>
|
||||||
|
<div className="text-sm text-gray-600">مؤكدة</div>
|
||||||
|
</motion.div>
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, y: 20 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
transition={{ delay: 0.4 }}
|
||||||
|
className={`bg-white rounded-xl shadow-sm p-4 text-center border cursor-pointer hover:shadow-md transition-all ${
|
||||||
|
filterStatus === 'completed' ? 'border-gray-500 bg-gray-50' : 'border-gray-200'
|
||||||
|
}`}
|
||||||
|
onClick={() => setFilterStatus('completed')}
|
||||||
|
>
|
||||||
|
<div className="text-2xl font-bold text-gray-600">{statusCounts.completed}</div>
|
||||||
|
<div className="text-sm text-gray-600">منتهية</div>
|
||||||
|
</motion.div>
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, y: 20 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
transition={{ delay: 0.5 }}
|
||||||
|
className={`bg-white rounded-xl shadow-sm p-4 text-center border cursor-pointer hover:shadow-md transition-all ${
|
||||||
|
filterStatus === 'cancelled' ? 'border-red-500 bg-red-50' : 'border-gray-200'
|
||||||
|
}`}
|
||||||
|
onClick={() => setFilterStatus('cancelled')}
|
||||||
|
>
|
||||||
|
<div className="text-2xl font-bold text-red-600">{statusCounts.cancelled}</div>
|
||||||
|
<div className="text-sm text-gray-600">ملغية</div>
|
||||||
|
</motion.div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-col md:flex-row gap-4 mb-6">
|
||||||
|
<div className="flex-1 relative">
|
||||||
|
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 w-5 h-5 text-gray-400" />
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="ابحث باسم العقار أو المستأجر.."
|
||||||
|
value={searchTerm}
|
||||||
|
onChange={(e) => setSearchTerm(e.target.value)}
|
||||||
|
className="w-full pl-10 pr-4 py-3 border border-gray-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-3">
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
value={dateRange.start}
|
||||||
|
onChange={(e) => setDateRange({...dateRange, start: e.target.value})}
|
||||||
|
className="px-4 py-3 border border-gray-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500"
|
||||||
|
placeholder="من تاريخ"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
value={dateRange.end}
|
||||||
|
onChange={(e) => setDateRange({...dateRange, end: e.target.value})}
|
||||||
|
className="px-4 py-3 border border-gray-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500"
|
||||||
|
placeholder="إلى تاريخ"
|
||||||
|
/>
|
||||||
|
{(dateRange.start || dateRange.end) && (
|
||||||
|
<button
|
||||||
|
onClick={() => setDateRange({ start: '', end: '' })}
|
||||||
|
className="px-4 py-3 bg-gray-100 text-gray-700 rounded-xl hover:bg-gray-200 transition-colors"
|
||||||
|
>
|
||||||
|
مسح
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{showCalendar && (
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, y: -20 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
className="mb-6"
|
||||||
|
>
|
||||||
|
<OwnerBookingCalendar
|
||||||
|
property={{ bookings }}
|
||||||
|
onDateSelect={(date) => console.log('Date selected:', date)}
|
||||||
|
/>
|
||||||
|
</motion.div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{filteredBookings.length === 0 ? (
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, y: 20 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
className="bg-white rounded-2xl p-12 text-center border-2 border-dashed border-gray-300"
|
||||||
|
>
|
||||||
|
<div className="w-24 h-24 bg-amber-100 rounded-full flex items-center justify-center mx-auto mb-4">
|
||||||
|
<Calendar className="w-12 h-12 text-amber-600" />
|
||||||
|
</div>
|
||||||
|
<h3 className="text-xl font-bold text-gray-900 mb-2">لا توجد حجوزات</h3>
|
||||||
|
<p className="text-gray-600 mb-4">
|
||||||
|
{filterStatus !== 'all' ? 'لا توجد حجوزات في هذه الفئة' : 'لم يتم استلام أي حجوزات بعد'}
|
||||||
|
</p>
|
||||||
|
{filterStatus !== 'all' && (
|
||||||
|
<button
|
||||||
|
onClick={() => setFilterStatus('all')}
|
||||||
|
className="inline-flex items-center gap-2 bg-amber-500 text-white px-6 py-3 rounded-xl font-medium hover:bg-amber-600"
|
||||||
|
>
|
||||||
|
عرض جميع الحجوزات
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</motion.div>
|
||||||
|
) : (
|
||||||
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||||
|
{filteredBookings.map((booking) => (
|
||||||
|
<BookingCard
|
||||||
|
key={booking.id}
|
||||||
|
booking={booking}
|
||||||
|
onViewDetails={handleViewDetails}
|
||||||
|
onContact={handleContact}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
736
app/owner/calendar/page.js
Normal file
736
app/owner/calendar/page.js
Normal file
@ -0,0 +1,736 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState, useEffect } from 'react';
|
||||||
|
import { motion, AnimatePresence } from 'framer-motion';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import Link from 'next/link';
|
||||||
|
import {
|
||||||
|
Calendar,
|
||||||
|
ChevronLeft,
|
||||||
|
ChevronRight,
|
||||||
|
Home,
|
||||||
|
Building,
|
||||||
|
MapPin,
|
||||||
|
Bed,
|
||||||
|
Bath,
|
||||||
|
Square,
|
||||||
|
DollarSign,
|
||||||
|
Eye,
|
||||||
|
ArrowLeft,
|
||||||
|
Loader2,
|
||||||
|
Filter,
|
||||||
|
Download,
|
||||||
|
Printer,
|
||||||
|
ChevronDown,
|
||||||
|
X,
|
||||||
|
CheckCircle,
|
||||||
|
XCircle,
|
||||||
|
Clock,
|
||||||
|
Users,
|
||||||
|
TrendingUp,
|
||||||
|
CalendarDays,
|
||||||
|
LayoutGrid,
|
||||||
|
List,
|
||||||
|
AlertCircle,
|
||||||
|
XCircle as XCircleIcon,
|
||||||
|
Calendar as CalendarIcon
|
||||||
|
} from 'lucide-react';
|
||||||
|
import toast, { Toaster } from 'react-hot-toast';
|
||||||
|
|
||||||
|
const MonthlyCalendar = ({ properties, selectedPropertyId, onDateClick, onPropertySelect }) => {
|
||||||
|
const [currentMonth, setCurrentMonth] = useState(new Date());
|
||||||
|
const [selectedDate, setSelectedDate] = useState(null);
|
||||||
|
const [viewType, setViewType] = useState('grid');
|
||||||
|
|
||||||
|
const monthNames = [
|
||||||
|
'يناير', 'فبراير', 'مارس', 'إبريل', 'مايو', 'يونيو',
|
||||||
|
'يوليو', 'أغسطس', 'سبتمبر', 'أكتوبر', 'نوفمبر', 'ديسمبر'
|
||||||
|
];
|
||||||
|
|
||||||
|
const daysInMonth = new Date(
|
||||||
|
currentMonth.getFullYear(),
|
||||||
|
currentMonth.getMonth() + 1,
|
||||||
|
0
|
||||||
|
).getDate();
|
||||||
|
|
||||||
|
const firstDayOfMonth = new Date(
|
||||||
|
currentMonth.getFullYear(),
|
||||||
|
currentMonth.getMonth(),
|
||||||
|
1
|
||||||
|
).getDay();
|
||||||
|
|
||||||
|
const isDateBookedForProperty = (date, property) => {
|
||||||
|
if (!property?.bookings) return false;
|
||||||
|
const dateStr = date.toISOString().split('T')[0];
|
||||||
|
return property.bookings.some(booking => {
|
||||||
|
const start = new Date(booking.startDate);
|
||||||
|
const end = new Date(booking.endDate);
|
||||||
|
const current = new Date(date);
|
||||||
|
return current >= start && current <= end;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const getDayStatus = (date) => {
|
||||||
|
if (selectedPropertyId === 'all') {
|
||||||
|
const totalProperties = properties.length;
|
||||||
|
const bookedCount = properties.filter(p => isDateBookedForProperty(date, p)).length;
|
||||||
|
|
||||||
|
if (bookedCount === 0) return { status: 'all_available', label: 'جميع العقارات متاحة', color: 'bg-green-100 text-green-800' };
|
||||||
|
if (bookedCount === totalProperties) return { status: 'all_booked', label: 'جميع العقارات محجوزة', color: 'bg-red-100 text-red-800' };
|
||||||
|
return { status: 'partial', label: `${bookedCount}/${totalProperties} محجوز`, color: 'bg-yellow-100 text-yellow-800' };
|
||||||
|
} else {
|
||||||
|
const property = properties.find(p => p.id === selectedPropertyId);
|
||||||
|
if (!property) return { status: 'no_property', label: 'غير متاح', color: 'bg-gray-100 text-gray-500' };
|
||||||
|
|
||||||
|
const isBooked = isDateBookedForProperty(date, property);
|
||||||
|
return {
|
||||||
|
status: isBooked ? 'booked' : 'available',
|
||||||
|
label: isBooked ? 'محجوز' : 'متاح',
|
||||||
|
color: isBooked ? 'bg-red-100 text-red-800' : 'bg-green-100 text-green-800'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDateClick = (date) => {
|
||||||
|
setSelectedDate(date);
|
||||||
|
onDateClick?.(date);
|
||||||
|
};
|
||||||
|
|
||||||
|
const changeMonth = (direction) => {
|
||||||
|
setCurrentMonth(new Date(currentMonth.getFullYear(), currentMonth.getMonth() + direction, 1));
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderDays = () => {
|
||||||
|
const days = [];
|
||||||
|
const totalDays = daysInMonth + firstDayOfMonth;
|
||||||
|
|
||||||
|
for (let i = 0; i < totalDays; i++) {
|
||||||
|
if (i < firstDayOfMonth) {
|
||||||
|
days.push(<div key={`empty-${i}`} className="p-2 md:p-3" />);
|
||||||
|
} else {
|
||||||
|
const dayNumber = i - firstDayOfMonth + 1;
|
||||||
|
const date = new Date(
|
||||||
|
currentMonth.getFullYear(),
|
||||||
|
currentMonth.getMonth(),
|
||||||
|
dayNumber
|
||||||
|
);
|
||||||
|
|
||||||
|
const isToday = date.toDateString() === new Date().toDateString();
|
||||||
|
const status = getDayStatus(date);
|
||||||
|
const isSelected = selectedDate?.toDateString() === date.toDateString();
|
||||||
|
|
||||||
|
days.push(
|
||||||
|
<button
|
||||||
|
key={dayNumber}
|
||||||
|
onClick={() => handleDateClick(date)}
|
||||||
|
className={`
|
||||||
|
p-2 md:p-3 rounded-xl text-center transition-all relative group
|
||||||
|
${status.color}
|
||||||
|
${isToday ? 'ring-2 ring-amber-500 ring-offset-2' : ''}
|
||||||
|
${isSelected ? 'ring-2 ring-blue-500 ring-offset-2' : ''}
|
||||||
|
hover:scale-105 hover:shadow-md
|
||||||
|
`}
|
||||||
|
>
|
||||||
|
<div className="text-sm md:text-base font-medium">{dayNumber}</div>
|
||||||
|
<div className="text-xs mt-1 hidden md:block">{status.label}</div>
|
||||||
|
{status.status === 'partial' && (
|
||||||
|
<div className="absolute -top-1 -right-1 w-2 h-2 bg-yellow-500 rounded-full animate-pulse" />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return days;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 overflow-hidden">
|
||||||
|
<div className="p-4 md:p-6 border-b border-gray-200">
|
||||||
|
<div className="flex flex-col md:flex-row justify-between items-center gap-4">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<button
|
||||||
|
onClick={() => changeMonth(-1)}
|
||||||
|
className="p-2 hover:bg-gray-100 rounded-xl transition-colors"
|
||||||
|
>
|
||||||
|
<ChevronRight className="w-5 h-5" />
|
||||||
|
</button>
|
||||||
|
<h2 className="text-xl md:text-2xl font-bold text-gray-900">
|
||||||
|
{monthNames[currentMonth.getMonth()]} {currentMonth.getFullYear()}
|
||||||
|
</h2>
|
||||||
|
<button
|
||||||
|
onClick={() => changeMonth(1)}
|
||||||
|
className="p-2 hover:bg-gray-100 rounded-xl transition-colors"
|
||||||
|
>
|
||||||
|
<ChevronLeft className="w-5 h-5" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<button
|
||||||
|
onClick={() => setCurrentMonth(new Date())}
|
||||||
|
className="px-4 py-2 bg-amber-500 text-white rounded-xl text-sm hover:bg-amber-600 transition-colors"
|
||||||
|
>
|
||||||
|
اليوم
|
||||||
|
</button>
|
||||||
|
<div className="flex border border-gray-200 rounded-xl overflow-hidden">
|
||||||
|
<button
|
||||||
|
onClick={() => setViewType('grid')}
|
||||||
|
className={`p-2 transition-colors ${viewType === 'grid' ? 'bg-amber-500 text-white' : 'bg-white text-gray-600 hover:bg-gray-100'}`}
|
||||||
|
>
|
||||||
|
<LayoutGrid className="w-4 h-4" />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => setViewType('list')}
|
||||||
|
className={`p-2 transition-colors ${viewType === 'list' ? 'bg-amber-500 text-white' : 'bg-white text-gray-600 hover:bg-gray-100'}`}
|
||||||
|
>
|
||||||
|
<List className="w-4 h-4" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-7 gap-1 p-4 bg-gray-50 border-b border-gray-200">
|
||||||
|
{['أحد', 'إثنين', 'ثلاثاء', 'أربعاء', 'خميس', 'جمعة', 'سبت'].map((day, index) => (
|
||||||
|
<div key={index} className="text-center text-sm font-medium text-gray-600 py-2">
|
||||||
|
{day}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="p-4">
|
||||||
|
<div className="grid grid-cols-7 gap-1 md:gap-2">
|
||||||
|
{renderDays()}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="p-4 border-t border-gray-200 bg-gray-50">
|
||||||
|
<div className="flex flex-wrap gap-4 justify-center text-xs">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="w-3 h-3 bg-green-100 rounded" />
|
||||||
|
<span className="text-gray-600">متاح</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="w-3 h-3 bg-red-100 rounded" />
|
||||||
|
<span className="text-gray-600">محجوز</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="w-3 h-3 bg-yellow-100 rounded" />
|
||||||
|
<span className="text-gray-600">محجوز جزئياً</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="w-3 h-3 ring-2 ring-amber-500 rounded" />
|
||||||
|
<span className="text-gray-600">اليوم</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="w-3 h-3 ring-2 ring-blue-500 rounded" />
|
||||||
|
<span className="text-gray-600">محدد</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const PropertyCalendarList = ({ properties, selectedDate, onPropertyClick }) => {
|
||||||
|
const formatCurrency = (amount) => {
|
||||||
|
return amount?.toLocaleString() + ' ل.س';
|
||||||
|
};
|
||||||
|
|
||||||
|
const isDateBooked = (property, date) => {
|
||||||
|
if (!property?.bookings || !date) return false;
|
||||||
|
const dateStr = date.toISOString().split('T')[0];
|
||||||
|
return property.bookings.some(booking => {
|
||||||
|
const start = new Date(booking.startDate);
|
||||||
|
const end = new Date(booking.endDate);
|
||||||
|
const current = new Date(date);
|
||||||
|
return current >= start && current <= end;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const getBookingForDate = (property, date) => {
|
||||||
|
if (!property?.bookings || !date) return null;
|
||||||
|
const dateStr = date.toISOString().split('T')[0];
|
||||||
|
return property.bookings.find(booking => {
|
||||||
|
const start = new Date(booking.startDate);
|
||||||
|
const end = new Date(booking.endDate);
|
||||||
|
const current = new Date(date);
|
||||||
|
return current >= start && current <= end;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!selectedDate) {
|
||||||
|
return (
|
||||||
|
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 p-12 text-center">
|
||||||
|
<CalendarDays className="w-16 h-16 text-gray-300 mx-auto mb-4" />
|
||||||
|
<h3 className="text-lg font-bold text-gray-700 mb-2">اختر تاريخاً</h3>
|
||||||
|
<p className="text-gray-500">اضغط على أي يوم في التقويم لعرض حالة العقارات في ذلك التاريخ</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const formattedDate = selectedDate.toLocaleDateString('ar-SA', {
|
||||||
|
weekday: 'long',
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'long',
|
||||||
|
day: 'numeric'
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 overflow-hidden">
|
||||||
|
<div className="p-4 md:p-6 border-b border-gray-200 bg-gradient-to-r from-amber-50 to-amber-100">
|
||||||
|
<h3 className="text-lg font-bold text-gray-900 flex items-center gap-2">
|
||||||
|
<CalendarDays className="w-5 h-5 text-amber-500" />
|
||||||
|
حالة العقارات في تاريخ: {formattedDate}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="divide-y divide-gray-200">
|
||||||
|
{properties.map((property) => {
|
||||||
|
const isBooked = isDateBooked(property, selectedDate);
|
||||||
|
const booking = getBookingForDate(property, selectedDate);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<motion.div
|
||||||
|
key={property.id}
|
||||||
|
initial={{ opacity: 0, x: -20 }}
|
||||||
|
animate={{ opacity: 1, x: 0 }}
|
||||||
|
className={`p-4 md:p-6 hover:bg-gray-50 transition-colors cursor-pointer ${isBooked ? 'bg-red-50/30' : 'bg-green-50/30'}`}
|
||||||
|
onClick={() => onPropertyClick(property)}
|
||||||
|
>
|
||||||
|
<div className="flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
|
||||||
|
<div className="flex-1">
|
||||||
|
<div className="flex items-center gap-2 mb-2">
|
||||||
|
<h4 className="font-bold text-gray-900 text-lg">{property.title}</h4>
|
||||||
|
<span className={`px-2 py-1 rounded-lg text-xs font-medium ${
|
||||||
|
isBooked ? 'bg-red-100 text-red-800' : 'bg-green-100 text-green-800'
|
||||||
|
}`}>
|
||||||
|
{isBooked ? 'محجوز' : 'متاح'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-1 text-gray-500 text-sm mb-2">
|
||||||
|
<MapPin className="w-4 h-4" />
|
||||||
|
{property.location}
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-wrap gap-3 text-sm text-gray-600">
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<Bed className="w-4 h-4" />
|
||||||
|
<span>{property.bedrooms} غرف</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<Bath className="w-4 h-4" />
|
||||||
|
<span>{property.bathrooms} حمامات</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<Square className="w-4 h-4" />
|
||||||
|
<span>{property.area} م²</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="text-right">
|
||||||
|
<div className="text-lg font-bold text-amber-600">{formatCurrency(property.price)}</div>
|
||||||
|
<div className="text-xs text-gray-500">/يوم</div>
|
||||||
|
{isBooked && booking && (
|
||||||
|
<div className="mt-2 text-xs text-gray-500">
|
||||||
|
<div>مستأجر: {booking.tenantName || 'غير معروف'}</div>
|
||||||
|
<div>من: {booking.startDate} إلى {booking.endDate}</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</motion.div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const PropertyDetailsModal = ({ property, isOpen, onClose }) => {
|
||||||
|
if (!isOpen || !property) return null;
|
||||||
|
|
||||||
|
const formatCurrency = (amount) => {
|
||||||
|
return amount?.toLocaleString() + ' ل.س';
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0 }}
|
||||||
|
animate={{ opacity: 1 }}
|
||||||
|
exit={{ opacity: 0 }}
|
||||||
|
className="fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center p-4 z-50"
|
||||||
|
onClick={onClose}
|
||||||
|
>
|
||||||
|
<motion.div
|
||||||
|
initial={{ scale: 0.9, y: 20 }}
|
||||||
|
animate={{ scale: 1, y: 0 }}
|
||||||
|
exit={{ scale: 0.9, y: 20 }}
|
||||||
|
className="bg-white rounded-2xl w-full max-w-2xl max-h-[90vh] overflow-y-auto shadow-2xl"
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
>
|
||||||
|
<div className="sticky top-0 bg-gradient-to-r from-amber-500 to-amber-600 p-6 text-white">
|
||||||
|
<div className="flex justify-between items-center">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-xl font-bold">{property.title}</h2>
|
||||||
|
<p className="text-amber-100 text-sm mt-1">{property.location}</p>
|
||||||
|
</div>
|
||||||
|
<button onClick={onClose} className="p-1 hover:bg-white/20 rounded-full">
|
||||||
|
<XCircleIcon className="w-6 h-6" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="p-6 space-y-6">
|
||||||
|
{property.images && property.images.length > 0 && (
|
||||||
|
<div>
|
||||||
|
<h3 className="font-bold text-gray-900 mb-3">صور العقار</h3>
|
||||||
|
<div className="grid grid-cols-2 gap-3">
|
||||||
|
{property.images.slice(0, 4).map((image, index) => (
|
||||||
|
<div key={index} className="relative h-32 rounded-lg overflow-hidden bg-gray-100">
|
||||||
|
<img src={image} alt={`${property.title} ${index + 1}`} className="w-full h-full object-cover" />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||||
|
<div className="bg-gray-50 p-3 rounded-xl text-center">
|
||||||
|
<Bed className="w-5 h-5 text-amber-500 mx-auto mb-1" />
|
||||||
|
<div className="text-sm font-bold">{property.bedrooms}</div>
|
||||||
|
<div className="text-xs text-gray-500">غرف نوم</div>
|
||||||
|
</div>
|
||||||
|
<div className="bg-gray-50 p-3 rounded-xl text-center">
|
||||||
|
<Bath className="w-5 h-5 text-amber-500 mx-auto mb-1" />
|
||||||
|
<div className="text-sm font-bold">{property.bathrooms}</div>
|
||||||
|
<div className="text-xs text-gray-500">حمامات</div>
|
||||||
|
</div>
|
||||||
|
<div className="bg-gray-50 p-3 rounded-xl text-center">
|
||||||
|
<Square className="w-5 h-5 text-amber-500 mx-auto mb-1" />
|
||||||
|
<div className="text-sm font-bold">{property.area}</div>
|
||||||
|
<div className="text-xs text-gray-500">م²</div>
|
||||||
|
</div>
|
||||||
|
<div className="bg-gray-50 p-3 rounded-xl text-center">
|
||||||
|
<DollarSign className="w-5 h-5 text-amber-500 mx-auto mb-1" />
|
||||||
|
<div className="text-sm font-bold">{formatCurrency(property.price)}</div>
|
||||||
|
<div className="text-xs text-gray-500">/يوم</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{property.features && property.features.length > 0 && (
|
||||||
|
<div>
|
||||||
|
<h3 className="font-bold text-gray-900 mb-3">المميزات</h3>
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
{property.features.map((feature, index) => (
|
||||||
|
<span key={index} className="px-2 py-1 bg-gray-100 text-gray-700 rounded-lg text-xs">
|
||||||
|
{feature}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{property.bookings && property.bookings.length > 0 && (
|
||||||
|
<div>
|
||||||
|
<h3 className="font-bold text-gray-900 mb-3 flex items-center gap-2">
|
||||||
|
<Clock className="w-4 h-4 text-amber-500" />
|
||||||
|
الحجوزات القادمة
|
||||||
|
</h3>
|
||||||
|
<div className="space-y-2">
|
||||||
|
{property.bookings.slice(0, 3).map((booking, index) => (
|
||||||
|
<div key={index} className="bg-gray-50 p-3 rounded-lg flex justify-between items-center">
|
||||||
|
<div>
|
||||||
|
<p className="font-medium text-gray-900">{booking.startDate} - {booking.endDate}</p>
|
||||||
|
<p className="text-xs text-gray-500">مستأجر: {booking.tenantName || 'غير معروف'}</p>
|
||||||
|
</div>
|
||||||
|
<span className="text-sm font-bold text-amber-600">{formatCurrency(booking.totalAmount)}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="p-6 pt-0 flex gap-3">
|
||||||
|
<Link
|
||||||
|
href={`/owner/properties/edit?id=${property.id}`}
|
||||||
|
className="flex-1 bg-amber-500 text-white py-3 rounded-xl text-center font-medium hover:bg-amber-600 transition-colors"
|
||||||
|
>
|
||||||
|
تعديل العقار
|
||||||
|
</Link>
|
||||||
|
<button
|
||||||
|
onClick={() => window.location.href = `/owner/bookings?property=${property.id}`}
|
||||||
|
className="flex-1 bg-gray-100 text-gray-700 py-3 rounded-xl text-center font-medium hover:bg-gray-200 transition-colors"
|
||||||
|
>
|
||||||
|
عرض الحجوزات
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</motion.div>
|
||||||
|
</motion.div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function OwnerCalendarPage() {
|
||||||
|
const router = useRouter();
|
||||||
|
const [user, setUser] = useState(null);
|
||||||
|
const [properties, setProperties] = useState([]);
|
||||||
|
const [filteredProperties, setFilteredProperties] = useState([]);
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
const [selectedPropertyId, setSelectedPropertyId] = useState('all');
|
||||||
|
const [selectedDate, setSelectedDate] = useState(null);
|
||||||
|
const [selectedProperty, setSelectedProperty] = useState(null);
|
||||||
|
const [showFilters, setShowFilters] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const storedUser = localStorage.getItem('user');
|
||||||
|
if (storedUser) {
|
||||||
|
const userData = JSON.parse(storedUser);
|
||||||
|
if (userData.role !== 'owner') {
|
||||||
|
router.push('/');
|
||||||
|
} else {
|
||||||
|
setUser(userData);
|
||||||
|
loadProperties();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
router.push('/auth/choose-role');
|
||||||
|
}
|
||||||
|
}, [router]);
|
||||||
|
|
||||||
|
const loadProperties = () => {
|
||||||
|
const storedProperties = localStorage.getItem('ownerProperties');
|
||||||
|
if (storedProperties) {
|
||||||
|
const props = JSON.parse(storedProperties);
|
||||||
|
setProperties(props);
|
||||||
|
setFilteredProperties(props);
|
||||||
|
} else {
|
||||||
|
const mockProperties = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
title: 'فيلا فاخرة في المزة',
|
||||||
|
location: 'دمشق، المزة',
|
||||||
|
bedrooms: 5,
|
||||||
|
bathrooms: 4,
|
||||||
|
area: 450,
|
||||||
|
price: 500000,
|
||||||
|
features: ['مسبح', 'حديقة خاصة', 'موقف سيارات', 'أمن 24/7'],
|
||||||
|
images: ['/villa1.jpg'],
|
||||||
|
status: 'available',
|
||||||
|
bookings: [
|
||||||
|
{ startDate: '2024-03-10', endDate: '2024-03-15', totalAmount: 2500000, tenantName: 'أحمد محمد' },
|
||||||
|
{ startDate: '2024-03-20', endDate: '2024-03-25', totalAmount: 2500000, tenantName: 'سارة أحمد' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
title: 'شقة حديثة في الشهباء',
|
||||||
|
location: 'حلب، الشهباء',
|
||||||
|
bedrooms: 3,
|
||||||
|
bathrooms: 2,
|
||||||
|
area: 180,
|
||||||
|
price: 250000,
|
||||||
|
features: ['مطبخ مجهز', 'بلكونة', 'موقف سيارات', 'مصعد'],
|
||||||
|
images: ['/apartment1.jpg'],
|
||||||
|
status: 'available',
|
||||||
|
bookings: [
|
||||||
|
{ startDate: '2024-03-05', endDate: '2024-03-08', totalAmount: 750000, tenantName: 'محمد علي' }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
title: 'بيت عائلي في بابا عمرو',
|
||||||
|
location: 'حمص، بابا عمرو',
|
||||||
|
bedrooms: 4,
|
||||||
|
bathrooms: 3,
|
||||||
|
area: 300,
|
||||||
|
price: 350000,
|
||||||
|
features: ['حديقة كبيرة', 'موقف سيارات', 'مدفأة', 'كراج'],
|
||||||
|
images: ['/house1.jpg'],
|
||||||
|
status: 'booked',
|
||||||
|
bookings: []
|
||||||
|
}
|
||||||
|
];
|
||||||
|
setProperties(mockProperties);
|
||||||
|
setFilteredProperties(mockProperties);
|
||||||
|
localStorage.setItem('ownerProperties', JSON.stringify(mockProperties));
|
||||||
|
}
|
||||||
|
setIsLoading(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const calendarStats = {
|
||||||
|
totalProperties: properties.length,
|
||||||
|
availableToday: properties.filter(p => {
|
||||||
|
const today = new Date();
|
||||||
|
const isBooked = p.bookings?.some(b => {
|
||||||
|
const start = new Date(b.startDate);
|
||||||
|
const end = new Date(b.endDate);
|
||||||
|
return today >= start && today <= end;
|
||||||
|
});
|
||||||
|
return !isBooked;
|
||||||
|
}).length,
|
||||||
|
bookedToday: properties.filter(p => {
|
||||||
|
const today = new Date();
|
||||||
|
return p.bookings?.some(b => {
|
||||||
|
const start = new Date(b.startDate);
|
||||||
|
const end = new Date(b.endDate);
|
||||||
|
return today >= start && today <= end;
|
||||||
|
});
|
||||||
|
}).length,
|
||||||
|
upcomingBookings: properties.reduce((sum, p) => sum + (p.bookings?.length || 0), 0)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen bg-gray-50 flex items-center justify-center">
|
||||||
|
<div className="text-center">
|
||||||
|
<Loader2 className="w-12 h-12 text-amber-500 animate-spin mx-auto mb-4" />
|
||||||
|
<p className="text-gray-600">جاري تحميل التقويم...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen bg-gray-50 py-8">
|
||||||
|
<Toaster position="top-center" reverseOrder={false} />
|
||||||
|
|
||||||
|
<PropertyDetailsModal
|
||||||
|
property={selectedProperty}
|
||||||
|
isOpen={!!selectedProperty}
|
||||||
|
onClose={() => setSelectedProperty(null)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="container mx-auto px-4">
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, y: -20 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
className="flex flex-col md:flex-row justify-between items-start md:items-center mb-8 gap-4"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<h1 className="text-3xl font-bold text-gray-900 mb-2">تقويم العقارات</h1>
|
||||||
|
<p className="text-gray-600">مرحباً {user?.name}، تتبع حالة عقاراتك عبر التقويم</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex gap-3">
|
||||||
|
<button
|
||||||
|
onClick={() => setShowFilters(!showFilters)}
|
||||||
|
className="px-4 py-2 bg-white border border-gray-300 rounded-xl text-gray-700 hover:bg-gray-50 transition-colors flex items-center gap-2"
|
||||||
|
>
|
||||||
|
<Filter className="w-5 h-5" />
|
||||||
|
فلترة العقارات
|
||||||
|
<ChevronDown className={`w-4 h-4 transition-transform ${showFilters ? 'rotate-180' : ''}`} />
|
||||||
|
</button>
|
||||||
|
{/* <button className="px-4 py-2 bg-green-600 text-white rounded-xl hover:bg-green-700 transition-colors flex items-center gap-2">
|
||||||
|
<Printer className="w-5 h-5" />
|
||||||
|
طباعة التقويم
|
||||||
|
</button> */}
|
||||||
|
</div>
|
||||||
|
</motion.div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 mb-8">
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, y: 20 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
transition={{ delay: 0.1 }}
|
||||||
|
className="bg-white rounded-xl shadow-sm p-4 text-center border border-gray-200"
|
||||||
|
>
|
||||||
|
<Building className="w-6 h-6 text-amber-500 mx-auto mb-2" />
|
||||||
|
<div className="text-2xl font-bold text-gray-900">{calendarStats.totalProperties}</div>
|
||||||
|
<div className="text-sm text-gray-600">إجمالي العقارات</div>
|
||||||
|
</motion.div>
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, y: 20 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
transition={{ delay: 0.2 }}
|
||||||
|
className="bg-white rounded-xl shadow-sm p-4 text-center border border-gray-200"
|
||||||
|
>
|
||||||
|
<CheckCircle className="w-6 h-6 text-green-500 mx-auto mb-2" />
|
||||||
|
<div className="text-2xl font-bold text-green-600">{calendarStats.availableToday}</div>
|
||||||
|
<div className="text-sm text-gray-600">متاح اليوم</div>
|
||||||
|
</motion.div>
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, y: 20 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
transition={{ delay: 0.3 }}
|
||||||
|
className="bg-white rounded-xl shadow-sm p-4 text-center border border-gray-200"
|
||||||
|
>
|
||||||
|
<XCircle className="w-6 h-6 text-red-500 mx-auto mb-2" />
|
||||||
|
<div className="text-2xl font-bold text-red-600">{calendarStats.bookedToday}</div>
|
||||||
|
<div className="text-sm text-gray-600">محجوز اليوم</div>
|
||||||
|
</motion.div>
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, y: 20 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
transition={{ delay: 0.4 }}
|
||||||
|
className="bg-white rounded-xl shadow-sm p-4 text-center border border-gray-200"
|
||||||
|
>
|
||||||
|
<CalendarDays className="w-6 h-6 text-blue-500 mx-auto mb-2" />
|
||||||
|
<div className="text-2xl font-bold text-blue-600">{calendarStats.upcomingBookings}</div>
|
||||||
|
<div className="text-sm text-gray-600">حجوزات قادمة</div>
|
||||||
|
</motion.div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<AnimatePresence>
|
||||||
|
{showFilters && (
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, height: 0 }}
|
||||||
|
animate={{ opacity: 1, height: 'auto' }}
|
||||||
|
exit={{ opacity: 0, height: 0 }}
|
||||||
|
className="mb-6 overflow-hidden"
|
||||||
|
>
|
||||||
|
<div className="bg-white rounded-2xl shadow-sm border border-gray-200 p-4">
|
||||||
|
<div className="flex flex-wrap gap-3 items-center">
|
||||||
|
<label className="text-sm font-medium text-gray-700">اختر عقاراً:</label>
|
||||||
|
<select
|
||||||
|
value={selectedPropertyId}
|
||||||
|
onChange={(e) => setSelectedPropertyId(e.target.value)}
|
||||||
|
className="px-4 py-2 border border-gray-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500"
|
||||||
|
>
|
||||||
|
<option value="all">جميع العقارات</option>
|
||||||
|
{properties.map((property) => (
|
||||||
|
<option key={property.id} value={property.id}>{property.title}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<button
|
||||||
|
onClick={() => setSelectedPropertyId('all')}
|
||||||
|
className="px-3 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition-colors"
|
||||||
|
>
|
||||||
|
إعادة تعيين
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</motion.div>
|
||||||
|
)}
|
||||||
|
</AnimatePresence>
|
||||||
|
|
||||||
|
<div className="mb-8">
|
||||||
|
<MonthlyCalendar
|
||||||
|
properties={filteredProperties}
|
||||||
|
selectedPropertyId={selectedPropertyId}
|
||||||
|
onDateClick={setSelectedDate}
|
||||||
|
onPropertySelect={setSelectedProperty}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<PropertyCalendarList
|
||||||
|
properties={filteredProperties}
|
||||||
|
selectedDate={selectedDate}
|
||||||
|
onPropertyClick={setSelectedProperty}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{selectedDate && (
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0 }}
|
||||||
|
animate={{ opacity: 1 }}
|
||||||
|
className="mt-6 text-center text-sm text-gray-500"
|
||||||
|
>
|
||||||
|
<AlertCircle className="w-4 h-4 inline ml-1" />
|
||||||
|
اضغط على أي عقار لعرض التفاصيل الكاملة
|
||||||
|
</motion.div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
466
app/owner/profits/page.js
Normal file
466
app/owner/profits/page.js
Normal file
@ -0,0 +1,466 @@
|
|||||||
|
'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';
|
||||||
|
|
||||||
|
const StatCard = ({ title, value, change, icon: Icon, color, trend }) => {
|
||||||
|
return (
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, y: 20 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
className="bg-white rounded-2xl shadow-sm border border-gray-200 p-6 hover:shadow-md transition-all"
|
||||||
|
>
|
||||||
|
<div className="flex justify-between items-start mb-4">
|
||||||
|
<div className={`w-12 h-12 ${color} rounded-xl flex items-center justify-center`}>
|
||||||
|
<Icon className="w-6 h-6 text-white" />
|
||||||
|
</div>
|
||||||
|
<div className={`flex items-center gap-1 text-sm ${trend === 'up' ? 'text-green-600' : 'text-red-600'}`}>
|
||||||
|
{trend === 'up' ? <TrendingUp className="w-4 h-4" /> : <TrendingDown className="w-4 h-4" />}
|
||||||
|
<span>{Math.abs(change)}%</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<h3 className="text-sm text-gray-600 mb-1">{title}</h3>
|
||||||
|
<div className="text-2xl font-bold text-gray-900">{value}</div>
|
||||||
|
</motion.div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const PropertyProfitCard = ({ property, onViewDetails }) => {
|
||||||
|
const formatCurrency = (amount) => {
|
||||||
|
return amount?.toLocaleString() + ' ل.س';
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, y: 20 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
className="bg-white rounded-2xl shadow-sm border border-gray-200 overflow-hidden hover:shadow-md transition-all"
|
||||||
|
>
|
||||||
|
<div className="p-5">
|
||||||
|
<div className="flex justify-between items-start mb-4">
|
||||||
|
<div>
|
||||||
|
<h3 className="font-bold text-gray-900 mb-1">{property.title}</h3>
|
||||||
|
<p className="text-sm text-gray-500">{property.location}</p>
|
||||||
|
</div>
|
||||||
|
<span className={`px-2 py-1 rounded-lg text-xs font-medium ${
|
||||||
|
property.status === 'active' ? 'bg-green-100 text-green-800' : 'bg-gray-100 text-gray-600'
|
||||||
|
}`}>
|
||||||
|
{property.status === 'active' ? 'نشط' : 'غير نشط'}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4 mb-4">
|
||||||
|
<div className="bg-gray-50 p-3 rounded-xl text-center">
|
||||||
|
<DollarSign className="w-5 h-5 text-amber-500 mx-auto mb-1" />
|
||||||
|
<div className="text-xs text-gray-500">إجمالي الأرباح</div>
|
||||||
|
<div className="text-lg font-bold text-amber-600">{formatCurrency(property.totalProfit)}</div>
|
||||||
|
</div>
|
||||||
|
<div className="bg-gray-50 p-3 rounded-xl text-center">
|
||||||
|
<Calendar className="w-5 h-5 text-blue-500 mx-auto mb-1" />
|
||||||
|
<div className="text-xs text-gray-500">عدد الحجوزات</div>
|
||||||
|
<div className="text-lg font-bold text-blue-600">{property.totalBookings}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2 mb-4">
|
||||||
|
<div className="flex justify-between text-sm">
|
||||||
|
<span className="text-gray-500">هذا الشهر</span>
|
||||||
|
<span className="font-medium text-gray-900">{formatCurrency(property.monthlyProfit)}</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-between text-sm">
|
||||||
|
<span className="text-gray-500">الأسبوع الماضي</span>
|
||||||
|
<span className="font-medium text-gray-900">{formatCurrency(property.weeklyProfit)}</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex justify-between text-sm">
|
||||||
|
<span className="text-gray-500">متوسط السعر اليومي</span>
|
||||||
|
<span className="font-medium text-gray-900">{formatCurrency(property.avgDailyPrice)}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={() => onViewDetails(property)}
|
||||||
|
className="w-full bg-gray-100 text-gray-700 py-2 rounded-xl text-sm font-medium hover:bg-gray-200 transition-colors flex items-center justify-center gap-2"
|
||||||
|
>
|
||||||
|
<Eye className="w-4 h-4" />
|
||||||
|
عرض التفاصيل
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</motion.div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
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 (
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0 }}
|
||||||
|
animate={{ opacity: 1 }}
|
||||||
|
exit={{ opacity: 0 }}
|
||||||
|
className="fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center p-4 z-50"
|
||||||
|
onClick={onClose}
|
||||||
|
>
|
||||||
|
<motion.div
|
||||||
|
initial={{ scale: 0.9, y: 20 }}
|
||||||
|
animate={{ scale: 1, y: 0 }}
|
||||||
|
exit={{ scale: 0.9, y: 20 }}
|
||||||
|
className="bg-white rounded-2xl w-full max-w-3xl max-h-[90vh] overflow-y-auto shadow-2xl"
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
>
|
||||||
|
<div className="sticky top-0 bg-gradient-to-r from-amber-500 to-amber-600 p-6 text-white">
|
||||||
|
<div className="flex justify-between items-center">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-xl font-bold">{property.title}</h2>
|
||||||
|
<p className="text-amber-100 text-sm mt-1">{property.location}</p>
|
||||||
|
</div>
|
||||||
|
<button onClick={onClose} className="p-1 hover:bg-white/20 rounded-full">
|
||||||
|
<XCircle className="w-6 h-6" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="p-6 space-y-6">
|
||||||
|
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||||
|
<div className="bg-amber-50 p-4 rounded-xl text-center">
|
||||||
|
<div className="text-2xl font-bold text-amber-600">{formatCurrency(property.totalProfit)}</div>
|
||||||
|
<div className="text-xs text-gray-600 mt-1">إجمالي الأرباح</div>
|
||||||
|
</div>
|
||||||
|
<div className="bg-blue-50 p-4 rounded-xl text-center">
|
||||||
|
<div className="text-2xl font-bold text-blue-600">{property.totalBookings}</div>
|
||||||
|
<div className="text-xs text-gray-600 mt-1">عدد الحجوزات</div>
|
||||||
|
</div>
|
||||||
|
<div className="bg-green-50 p-4 rounded-xl text-center">
|
||||||
|
<div className="text-2xl font-bold text-green-600">{property.occupancyRate}%</div>
|
||||||
|
<div className="text-xs text-gray-600 mt-1">نسبة الإشغال</div>
|
||||||
|
</div>
|
||||||
|
<div className="bg-purple-50 p-4 rounded-xl text-center">
|
||||||
|
<div className="text-2xl font-bold text-purple-600">{formatCurrency(property.avgDailyPrice)}</div>
|
||||||
|
<div className="text-xs text-gray-600 mt-1">متوسط السعر اليومي</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="bg-gray-50 p-4 rounded-xl">
|
||||||
|
<h3 className="font-bold text-gray-900 mb-4">الأرباح الشهرية</h3>
|
||||||
|
<div className="space-y-3">
|
||||||
|
{monthlyData.map((data, index) => (
|
||||||
|
<div key={index}>
|
||||||
|
<div className="flex justify-between text-sm mb-1">
|
||||||
|
<span className="text-gray-600">{data.month}</span>
|
||||||
|
<span className="font-medium text-gray-900">{formatCurrency(data.profit)}</span>
|
||||||
|
</div>
|
||||||
|
<div className="w-full bg-gray-200 rounded-full h-2">
|
||||||
|
<motion.div
|
||||||
|
initial={{ width: 0 }}
|
||||||
|
animate={{ width: `${(data.profit / maxProfit) * 100}%` }}
|
||||||
|
transition={{ duration: 0.8, delay: index * 0.1 }}
|
||||||
|
className="bg-amber-500 h-2 rounded-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="bg-gray-50 p-4 rounded-xl">
|
||||||
|
<h3 className="font-bold text-gray-900 mb-4">آخر الحجوزات</h3>
|
||||||
|
<div className="space-y-3">
|
||||||
|
{property.recentBookings?.map((booking, index) => (
|
||||||
|
<div key={index} className="bg-white p-3 rounded-lg flex justify-between items-center">
|
||||||
|
<div>
|
||||||
|
<p className="font-medium text-gray-900">{booking.tenantName}</p>
|
||||||
|
<p className="text-xs text-gray-500">{booking.startDate} - {booking.endDate}</p>
|
||||||
|
</div>
|
||||||
|
<div className="text-right">
|
||||||
|
<p className="font-bold text-amber-600">{formatCurrency(booking.amount)}</p>
|
||||||
|
<p className="text-xs text-gray-500">{booking.status === 'completed' ? 'مكتمل' : 'قيد التنفيذ'}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</motion.div>
|
||||||
|
</motion.div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
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'); // month, year, all
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const storedUser = localStorage.getItem('user');
|
||||||
|
if (storedUser) {
|
||||||
|
const userData = JSON.parse(storedUser);
|
||||||
|
if (userData.role !== 'owner') {
|
||||||
|
router.push('/');
|
||||||
|
} else {
|
||||||
|
setUser(userData);
|
||||||
|
loadProfitsData();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
router.push('/auth/choose-role');
|
||||||
|
}
|
||||||
|
}, [router]);
|
||||||
|
|
||||||
|
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 (
|
||||||
|
<div className="min-h-screen bg-gray-50 flex items-center justify-center">
|
||||||
|
<div className="text-center">
|
||||||
|
<Loader2 className="w-12 h-12 text-amber-500 animate-spin mx-auto mb-4" />
|
||||||
|
<p className="text-gray-600">جاري تحميل بيانات الأرباح...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="min-h-screen bg-gray-50 py-8">
|
||||||
|
<Toaster position="top-center" reverseOrder={false} />
|
||||||
|
|
||||||
|
<ProfitDetailsModal
|
||||||
|
property={selectedProperty}
|
||||||
|
isOpen={!!selectedProperty}
|
||||||
|
onClose={() => setSelectedProperty(null)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="container mx-auto px-4">
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0, y: -20 }}
|
||||||
|
animate={{ opacity: 1, y: 0 }}
|
||||||
|
className="flex flex-col md:flex-row justify-between items-start md:items-center mb-8 gap-4"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<h1 className="text-3xl font-bold text-gray-900 mb-2">الأرباح والإحصائيات</h1>
|
||||||
|
<p className="text-gray-600">مرحباً {user?.name}، إليك ملخص أرباحك</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex gap-3">
|
||||||
|
<select
|
||||||
|
value={selectedPeriod}
|
||||||
|
onChange={(e) => setSelectedPeriod(e.target.value)}
|
||||||
|
className="px-4 py-2 border border-gray-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500"
|
||||||
|
>
|
||||||
|
<option value="month">آخر 30 يوم</option>
|
||||||
|
<option value="year">آخر 12 شهر</option>
|
||||||
|
<option value="all">جميع الفترات</option>
|
||||||
|
</select>
|
||||||
|
{/* <button className="px-4 py-2 bg-green-600 text-white rounded-xl hover:bg-green-700 transition-colors flex items-center gap-2">
|
||||||
|
<Download className="w-5 h-5" />
|
||||||
|
تصدير التقرير
|
||||||
|
</button> */}
|
||||||
|
</div>
|
||||||
|
</motion.div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
|
||||||
|
<StatCard
|
||||||
|
title="إجمالي الأرباح"
|
||||||
|
value={formatCurrency(totalStats.totalProfit)}
|
||||||
|
change={12.5}
|
||||||
|
icon={Wallet}
|
||||||
|
color="bg-amber-500"
|
||||||
|
trend="up"
|
||||||
|
/>
|
||||||
|
<StatCard
|
||||||
|
title="عدد الحجوزات"
|
||||||
|
value={totalStats.totalBookings}
|
||||||
|
change={8.2}
|
||||||
|
icon={Calendar}
|
||||||
|
color="bg-blue-500"
|
||||||
|
trend="up"
|
||||||
|
/>
|
||||||
|
<StatCard
|
||||||
|
title="متوسط نسبة الإشغال"
|
||||||
|
value={`${totalStats.avgOccupancy}%`}
|
||||||
|
change={5.3}
|
||||||
|
icon={PieChart}
|
||||||
|
color="bg-green-500"
|
||||||
|
trend="up"
|
||||||
|
/>
|
||||||
|
<StatCard
|
||||||
|
title="العقارات النشطة"
|
||||||
|
value={totalStats.activeProperties}
|
||||||
|
change={0}
|
||||||
|
icon={Building}
|
||||||
|
color="bg-purple-500"
|
||||||
|
trend="up"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mb-6">
|
||||||
|
<div className="flex justify-between items-center mb-4">
|
||||||
|
<h2 className="text-xl font-bold text-gray-900">أرباح العقارات</h2>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<button
|
||||||
|
onClick={() => setFilteredProperties(properties)}
|
||||||
|
className="px-3 py-1.5 bg-gray-100 rounded-lg text-sm hover:bg-gray-200 transition-colors"
|
||||||
|
>
|
||||||
|
عرض الكل
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{filteredProperties.length === 0 ? (
|
||||||
|
<div className="bg-white rounded-2xl p-12 text-center border-2 border-dashed border-gray-300">
|
||||||
|
<div className="w-24 h-24 bg-amber-100 rounded-full flex items-center justify-center mx-auto mb-4">
|
||||||
|
<DollarSign className="w-12 h-12 text-amber-600" />
|
||||||
|
</div>
|
||||||
|
<h3 className="text-xl font-bold text-gray-900 mb-2">لا توجد بيانات</h3>
|
||||||
|
<p className="text-gray-600">لا توجد أرباح مسجلة حتى الآن</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-6">
|
||||||
|
{filteredProperties.map((property) => (
|
||||||
|
<PropertyProfitCard
|
||||||
|
key={property.id}
|
||||||
|
property={property}
|
||||||
|
onViewDetails={setSelectedProperty}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<motion.div
|
||||||
|
initial={{ opacity: 0 }}
|
||||||
|
animate={{ opacity: 1 }}
|
||||||
|
transition={{ delay: 0.6 }}
|
||||||
|
className="bg-gradient-to-r from-amber-500 to-amber-600 rounded-2xl p-6 text-white mt-8"
|
||||||
|
>
|
||||||
|
<div className="flex items-center justify-between flex-wrap gap-4">
|
||||||
|
<div>
|
||||||
|
<h3 className="text-lg font-bold mb-1">احصل على المزيد من الأرباح</h3>
|
||||||
|
<p className="text-amber-100 text-sm">أضف عقارات جديدة وحسّن أسعارك لزيادة الإشغال</p>
|
||||||
|
</div>
|
||||||
|
<Link
|
||||||
|
href="/owner/properties/add"
|
||||||
|
className="px-6 py-2 bg-white text-amber-600 rounded-xl font-medium hover:bg-amber-50 transition-colors"
|
||||||
|
>
|
||||||
|
إضافة عقار جديد
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</motion.div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -379,13 +379,13 @@ export default function HomePage() {
|
|||||||
<p className="text-gray-200 mb-4">
|
<p className="text-gray-200 mb-4">
|
||||||
يمكنك إدارة عقاراتك من خلال لوحة التحكم الخاصة بك
|
يمكنك إدارة عقاراتك من خلال لوحة التحكم الخاصة بك
|
||||||
</p>
|
</p>
|
||||||
{/* <Link
|
<Link
|
||||||
href="/owner/properties"
|
href="/owner/properties"
|
||||||
className="inline-flex items-center gap-2 bg-amber-500 text-white px-6 py-3 rounded-xl font-medium hover:bg-amber-600 transition-colors"
|
className="inline-flex items-center gap-2 bg-amber-500 text-white px-6 py-3 rounded-xl font-medium hover:bg-amber-600 transition-colors"
|
||||||
>
|
>
|
||||||
<Building className="w-5 h-5" />
|
<Building className="w-5 h-5" />
|
||||||
إدارة عقاراتي
|
إدارة عقاراتي
|
||||||
</Link> */}
|
</Link>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user