2026-03-30 13:44:52 +00:00
|
|
|
import PropertyDetail from './PropertyDetail';
|
2026-02-15 01:53:37 +03:00
|
|
|
|
2026-03-30 13:44:52 +00:00
|
|
|
// Server-side API fetch for metadata (runs at request time on server)
|
|
|
|
|
async function fetchPropertyForMeta(id) {
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(`http://45.93.137.91/api/RentProperties/GetRentProperties`, {
|
|
|
|
|
next: { revalidate: 60 },
|
|
|
|
|
});
|
|
|
|
|
if (!res.ok) return null;
|
|
|
|
|
const text = await res.text();
|
|
|
|
|
const json = JSON.parse(text);
|
|
|
|
|
const items = Array.isArray(json?.data) ? json.data : Array.isArray(json) ? json : [];
|
|
|
|
|
return items.find(p => p.id == id) || items[0] || null;
|
|
|
|
|
} catch {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-26 22:20:33 +00:00
|
|
|
|
2026-03-30 13:44:52 +00:00
|
|
|
function mapProperty(item) {
|
|
|
|
|
const info = item.propertyInformation || item.PropertyInformation || {};
|
|
|
|
|
let details = {};
|
|
|
|
|
try { details = JSON.parse(info.detailsJSON || info.DetailsJSON || '{}'); } catch {}
|
|
|
|
|
|
|
|
|
|
const price = item.monthlyRent || item.MonthlyRent || item.dailyRent || item.DailyRent || 0;
|
|
|
|
|
const priceUnit = item.monthlyRent || item.MonthlyRent ? 'monthly' : 'daily';
|
|
|
|
|
const buildingType = info.buildingType ?? info.BuildingType ?? 0;
|
|
|
|
|
const type = { 0: 'apartment', 1: 'villa', 2: 'house' }[buildingType] || 'apartment';
|
|
|
|
|
const typeLabel = { 0: 'شقة', 1: 'فيلا', 2: 'بيت' }[buildingType] || 'عقار';
|
|
|
|
|
const address = info.address || info.Address || '';
|
|
|
|
|
const bedrooms = info.numberOfBedRooms || info.NumberOfBedRooms || 0;
|
|
|
|
|
const bathrooms = info.numberOfBathRooms || info.NumberOfBathRooms || 0;
|
|
|
|
|
const area = info.space || info.Space || 0;
|
|
|
|
|
const desc = info.description || info.Description || '';
|
|
|
|
|
const images = info.images || info.Images || [];
|
|
|
|
|
const firstImage = Array.isArray(images) && images[0] ? images[0] : '';
|
2026-03-30 01:01:42 +00:00
|
|
|
|
2026-03-26 22:20:33 +00:00
|
|
|
return {
|
2026-03-30 13:44:52 +00:00
|
|
|
title: `${typeLabel} في ${address}`,
|
|
|
|
|
description: desc || `${typeLabel} في ${address} · ${bedrooms} غرف نوم · ${bathrooms} حمامات · ${area} م²`,
|
|
|
|
|
price,
|
|
|
|
|
priceUnit,
|
|
|
|
|
typeLabel,
|
|
|
|
|
address,
|
|
|
|
|
bedrooms,
|
|
|
|
|
bathrooms,
|
|
|
|
|
area,
|
|
|
|
|
image: firstImage,
|
2026-03-26 22:20:33 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 13:44:52 +00:00
|
|
|
export async function generateMetadata({ params }) {
|
|
|
|
|
const { id } = await params;
|
|
|
|
|
const raw = await fetchPropertyForMeta(id);
|
2026-03-30 13:36:12 +00:00
|
|
|
|
2026-03-30 13:44:52 +00:00
|
|
|
if (!raw) {
|
|
|
|
|
return {
|
|
|
|
|
title: 'SweetHome - عقار',
|
|
|
|
|
description: 'اكتشف أفضل العقارات للإيجار',
|
2026-03-30 13:36:12 +00:00
|
|
|
};
|
2026-02-15 01:53:37 +03:00
|
|
|
}
|
|
|
|
|
|
2026-03-30 13:44:52 +00:00
|
|
|
const p = mapProperty(raw);
|
|
|
|
|
const priceStr = `${p.price.toLocaleString()} ل.س / ${p.priceUnit === 'daily' ? 'يوم' : 'شهر'}`;
|
2026-03-30 14:07:52 +00:00
|
|
|
const propertyImage = p.image
|
2026-03-30 13:44:52 +00:00
|
|
|
? (p.image.startsWith('http') ? p.image : `http://45.93.137.91${p.image}`)
|
|
|
|
|
: '';
|
2026-03-30 14:07:52 +00:00
|
|
|
const logoUrl = `http://45.93.137.91/logo.png`;
|
|
|
|
|
|
|
|
|
|
// Use property image if available, otherwise logo
|
|
|
|
|
const ogImages = propertyImage
|
|
|
|
|
? [{ url: propertyImage, width: 1200, height: 630 }, { url: logoUrl, width: 512, height: 512 }]
|
|
|
|
|
: [{ url: logoUrl, width: 512, height: 512 }];
|
2026-03-26 22:20:33 +00:00
|
|
|
|
2026-03-30 13:44:52 +00:00
|
|
|
return {
|
|
|
|
|
title: `${p.title} - ${priceStr}`,
|
|
|
|
|
description: p.description,
|
|
|
|
|
openGraph: {
|
|
|
|
|
title: `${p.title} - ${priceStr}`,
|
|
|
|
|
description: p.description,
|
2026-03-30 14:07:52 +00:00
|
|
|
images: ogImages,
|
|
|
|
|
url: `http://45.93.137.91/property/${id}`,
|
2026-03-30 13:44:52 +00:00
|
|
|
type: 'website',
|
|
|
|
|
siteName: 'SweetHome',
|
|
|
|
|
},
|
|
|
|
|
twitter: {
|
|
|
|
|
card: 'summary_large_image',
|
|
|
|
|
title: `${p.title} - ${priceStr}`,
|
|
|
|
|
description: p.description,
|
2026-03-30 14:07:52 +00:00
|
|
|
images: ogImages.map(i => i.url),
|
2026-03-30 13:44:52 +00:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
2026-03-29 21:34:25 +00:00
|
|
|
|
2026-03-30 13:44:52 +00:00
|
|
|
export default function PropertyPage({ params }) {
|
|
|
|
|
return <PropertyDetail params={params} />;
|
2026-03-26 22:20:33 +00:00
|
|
|
}
|