// API هر دو کلید phone و phone_number را می‌فرستد و یکی ممکن است null باشد؛ // UI و JSON-LD باید از یک منبع بخوانند تا صفحه و structured data یکی بگویند. export function getClinicPhone(clinic) { return (clinic?.phone_number || clinic?.phone || "").toString().trim(); } // مقدار DB ممکن است فاصله یا خط تیره داشته باشد و لینک tel: را خراب کند. export function telHref(phone) { const digits = (phone || "").replace(/[^\d+]/g, ""); return digits ? `tel:${digits}` : null; } export function toE164Ir(phone) { const d = (phone || "").replace(/\D/g, ""); if (!d) return null; if (d.startsWith("98")) return `+${d}`; if (d.startsWith("0")) return `+98${d.slice(1)}`; return `+98${d}`; } export function getClinicCity(clinic) { return clinic?.city?.[0]?.name?.trim() || null; } export function getClinicState(clinic) { return clinic?.state?.[0]?.name?.trim() || null; } // نشانی آزادِ بعضی رکوردها خودش نام شهر یا استان را دارد؛ در آن حالت تکرار نشود. export function getClinicAddress(clinic) { const street = clinic?.location?.trim() || ""; const city = getClinicCity(clinic); const state = getClinicState(clinic); const parts = []; if (state && !street.includes(state)) parts.push(state); if (city && !street.includes(city)) parts.push(city); if (street) parts.push(street); return parts.length ? parts.join("، ") : null; } export function hasClinicContact(clinic) { return Boolean( clinic?.["24_7"] || clinic?.field_working_days?.trim() || getClinicPhone(clinic) || getClinicAddress(clinic) || (clinic?.map?.latitude && clinic?.map?.longitude) ); }