"use client"; import { useState, useEffect } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { PlusCircle, Building, Home, DollarSign, MapPin, Bed, Bath, Square, Edit, Trash2, Eye, Calendar, TrendingUp, Users, FileText, Image as ImageIcon, CheckCircle, XCircle, AlertCircle, ChevronRight, ChevronLeft, Loader2, Clock, Wifi, Zap, Flame, Droplets, Cigarette, Dog, Music, Warehouse, Layers, Sofa, DoorOpen, Wind, Pencil, Save, X, Star, Ban, Check, } from "lucide-react"; import toast, { Toaster } from "react-hot-toast"; import AuthService from "../../services/AuthService"; import { getMyRentListings, getMySaleListings, editRentProperty, } from "../../utils/api"; const DeleteConfirmationModal = ({ isOpen, onClose, onConfirm, propertyTitle, }) => { if (!isOpen) return null; return ( e.stopPropagation()} >

تأكيد الحذف

هل أنت متأكد من حذف العقار:{" "} "{propertyTitle}"؟

هذا الإجراء لا يمكن التراجع عنه

); }; const serviceLabels = { Electricity: "كهرباء", Internet: "إنترنت", Heating: "تدفئة", Water: "ماء", Pool: "مسبح", PrivateGarden: "حديقة خاصة", Parking: "موقف سيارات", Security247: "حراسة 24 س", CentralHeating: "تدفئة مركزية", CentralAirConditioning: "تكييف مركزي", EquippedKitchen: "مطبخ مجهز", MaidsRoom: "غرفة خادمة", Elevator: "مصعد", Gym: "نادي رياضي", Sauna: "ساونا", Jacuzzi: "جاكوزي", Balcony: "بلكونة", Rooftop: "سطح", Furnished: "مفروش", AirConditioning: "تكييف", SatelliteTV: "تلفاز", Fireplace: "مدفأة", StudyRoom: "غرفة دراسة", Storage: "مستودع", Laundry: "غرفة غسيل", SmartHome: "منزل ذكي", }; const termLabels = { NoSmoking: "ممنوع التدخين", NoAnimals: "ممنوع الحيوانات الأليفة", NoParties: "ممنوع الحفلات", NoAlcohol: "ممنوع الكحول", SuitableForChildren: "مناسب للأطفال", SuitableForFamilies: "مناسب للعائلات", SuitableForStudents: "مناسب للطلاب", SuitableForElderly: "مناسب لكبار السن", OnlyFemales: "إناث فقط", OnlyMales: "ذكور فقط", }; const PropertyViewModal = ({ isOpen, onClose, property }) => { if (!isOpen || !property) return null; return ( e.stopPropagation()} >

{property.title}

تم الإضافة:{" "} {new Date(property.createdAt).toLocaleDateString("ar-SA")}

{property.images && property.images.length > 0 && (

صور العقار

{property.images.map((image, index) => (
{`${property.title}
))}
)}

معلومات أساسية

نوع العقار: {property.propertyTypeLabel || "عقار"}

{property.purpose === "rent" && (

حالة التأثيث: {property.furnished ? "مفروش" : "غير مفروش"}

)}

حالة العقار: {property.status === "available" ? "متاح" : "مؤجر"}

{property.description && (

الوصف: {property.description}

)}

التفاصيل

{property.bedrooms} غرف
{property.bathrooms} حمامات
{property.area} م²
{property.floor > 0 && (
{property.floor} طابق
)} {property.salons > 0 && (
{property.salons} صالونات
)} {property.balconies > 0 && (
{property.balconies} بلكونات
)} {property.bookedCount > 0 && (
{property.bookedCount} حجوزات
)}

الموقع

{property.address || "لم يتم تحديد العنوان"} {property.city && `، ${property.city}`} {property.district && `، ${property.district}`}

{property.services && (Array.isArray(property.services) ? property.services.length > 0 : Object.keys(property.services).length > 0) && (

الخدمات المتوفرة

{Array.isArray(property.services) ? property.services.map((svc, i) => ( {serviceLabels[svc] || svc} )) : Object.entries(property.services).map(([key, value]) => { if (!value) return null; const detail = typeof value === "object" && value.detail ? value.detail : typeof value === "string" ? value : null; return ( {serviceLabels[key] || key} {detail && ( · {detail} )} ); })}
)} {property.terms && Object.keys(property.terms).length > 0 && (

شروط الاستخدام

{Object.entries(property.terms).map(([key, value]) => { if (!value) return null; return (
{key.startsWith("No") || key.startsWith("Only") ? ( ) : ( )} {termLabels[key] || key}
); })}
)}

معلومات السعر

{property.purpose === "rent" ? (
{property.dailyPrice > 0 && (

السعر اليومي: {Number(property.dailyPrice).toLocaleString()} ل.س

)} {property.monthlyPrice > 0 && (

السعر الشهري: {Number(property.monthlyPrice).toLocaleString()} ل.س

)} {property.deposit > 0 && (

التأمين: {Number(property.deposit).toLocaleString()} ل.س

)}

نوع الإيجار:{" "} {property.rentType === "daily" ? "يومي" : property.rentType === "monthly" ? "شهري" : "يومي وشهري"}

{property.rating > 0 && (

التقييم: {Number(property.rating).toFixed(1)}{" "}

)}
) : (

سعر البيع: {Number(property.salePrice).toLocaleString()} ل.س

)}
); }; const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => { const [formData, setFormData] = useState({ ...property }); const [isSaving, setIsSaving] = useState(false); const [editingField, setEditingField] = useState(null); const [tempValues, setTempValues] = useState({}); const sections = [ { title: "معلومات أساسية", fields: [ { id: "title", label: "عنوان العقار", type: "text" }, { id: "description", label: "الوصف", type: "textarea" }, { id: "propertyType", label: "نوع العقار", type: "select", options: [ { value: "apartment", label: "شقة" }, { value: "villa", label: "فيلا" }, { value: "suite", label: "سويت" }, { value: "room", label: "غرفة ضمن شقة" }, ], }, { id: "furnished", label: "حالة العقار", type: "radio", options: [ { value: true, label: "مفروش" }, { value: false, label: "غير مفروش" }, ], }, ], }, { title: "التفاصيل", fields: [ { id: "bedrooms", label: "عدد الغرف", type: "number" }, { id: "bathrooms", label: "عدد الحمامات", type: "number" }, { id: "livingRooms", label: "عدد الصالونات", type: "number" }, { id: "area", label: "المساحة (م²)", type: "number" }, ], }, { title: "الموقع", fields: [ { id: "address", label: "العنوان الكامل", type: "text" }, { id: "city", label: "المدينة", type: "text" }, { id: "district", label: "الحي", type: "text" }, ], }, { title: "السعر", fields: formData?.purpose === "rent" ? [ { id: "dailyPrice", label: "السعر اليومي", type: "number" }, { id: "monthlyPrice", label: "السعر الشهري", type: "number" }, { id: "rentType", label: "نوع الإيجار", type: "select", options: [ { value: "daily", label: "يومي" }, { value: "monthly", label: "شهري" }, { value: "both", label: "يومي وشهري" }, ], }, ] : [{ id: "salePrice", label: "سعر البيع", type: "number" }], }, ]; const startEditing = (fieldId) => { setEditingField(fieldId); setTempValues({ ...tempValues, [fieldId]: formData[fieldId] }); }; const cancelEditing = () => { setEditingField(null); setTempValues({}); }; const saveField = (fieldId) => { setFormData({ ...formData, [fieldId]: tempValues[fieldId], }); setEditingField(null); setTempValues({}); const fieldLabel = sections .flatMap((s) => s.fields) .find((f) => f.id === fieldId)?.label; toast.success(`تم تحديث ${fieldLabel}`); }; const handleTempChange = (fieldId, value) => { setTempValues({ ...tempValues, [fieldId]: value }); }; const handleSave = () => { setIsSaving(true); setTimeout(() => { onSave(formData); setIsSaving(false); onClose(); toast.success("تم تحديث العقار بنجاح"); }, 1000); }; if (!isOpen || !property) return null; return ( e.stopPropagation()} >

تعديل العقار

قم بتحديث معلومات العقار

{formData.images && formData.images.length > 0 && (

صور العقار

{formData.images.map((image, index) => (
{`Property
))}
)} {sections.map((section, sectionIndex) => (

{section.title}

{section.fields.map((field) => (
{editingField !== field.id && ( )}
{editingField === field.id ? (
{field.type === "textarea" ? (