// Dashboard home page function DashboardPage({ host, billingStatus, onOpenProperty, state, setState, onNavigate, showToast, reloadData, onNewProperty }) { const _renewalDate = React.useMemo(() => { const iso = billingStatus?.current_period_end; if (!iso) return null; return new Date(iso).toLocaleDateString("it-IT", { day: "numeric", month: "long" }); }, [billingStatus?.current_period_end]); const _planName = billingStatus?.plan_display_name || (host?.plan ? host.plan.charAt(0).toUpperCase() + host.plan.slice(1) : null); const _propLimit = billingStatus?.property_limit; const _propLimitLabel = _propLimit != null ? `fino a ${_propLimit} camere` : "camere illimitate"; const _dailyMsgLimit = billingStatus?.daily_msg_limit; const requests = state.recentRequests; const pendingCount = requests.filter(r => r.status === "pending").length; const stats = { properties: state.properties.length, activeSessions: state.properties.reduce((a, p) => a + p.sessions.filter(s => s.status === "active").length, 0), monthlyMessages: state.monthlyMessages ?? 0, }; const _greeting = () => { const h = new Date().getHours(); if (h >= 5 && h < 12) return "Buongiorno"; if (h >= 12 && h < 18) return "Buon pomeriggio"; return "Buonasera"; }; const _greetingSubtitle = () => { if (pendingCount === 1) return "1 ospite aspetta la tua risposta"; if (pendingCount > 1) return `${pendingCount} ospiti aspettano la tua risposta`; return "Tutto tranquillo, nessuna richiesta in sospeso"; }; const updateRequestStatus = async (session, newStatus) => { try { const propertyId = session._propertyId || session.propertyId; if (newStatus === "active") { await window.API.approveSession(propertyId, session.id); showToast("Accesso approvato · ospite notificato su WhatsApp"); } else if (newStatus === "rejected") { await window.API.rejectSession(propertyId, session.id); showToast("Accesso rifiutato"); } else if (newStatus === "expired") { await window.API.revokeSession(propertyId, session.id); showToast("Accesso revocato"); } await reloadData(); } catch (err) { showToast(err.message || "Errore", "error"); } }; const _subStatus = billingStatus?.subscription_status; const _showStatus = _subStatus && _subStatus !== "active"; return (
{/* Welcome header */}

{_greeting()}, {host?.full_name?.split(" ")[0] || "Host"}{" "} 👋

{_greetingSubtitle()}

{/* Tre card: Piano · Strutture · Messaggi scambiati */}
{/* Card piano */}
Il tuo abbonamento
Piano {_planName || "—"}
{_renewalDate ? `Rinnovo il ${_renewalDate}` : _propLimitLabel} {_showStatus && ( {_subStatus === "past_due" ? "In sospeso" : _subStatus} )}
{/* Card strutture */}
Strutture
{stats.properties}
{stats.activeSessions === 0 ? "Nessun ospite attivo" : `${stats.activeSessions} ${stats.activeSessions === 1 ? "ospite" : "ospiti"} in soggiorno`}
{/* Card messaggi scambiati */}
Messaggi scambiati
{stats.monthlyMessages}
{_dailyMsgLimit != null ? `Limite ${_dailyMsgLimit}/giorno` : "Questo mese"}
{/* Recent requests */}

Richieste recenti degli ospiti

Ultimi 7 giorni

{requests.length === 0 ? (
Nessuna richiesta ancora
) : (
{requests.map(r => ( ))}
Ospite Telefono Struttura Stato Data Azioni
{r.guest.split(" ").map(p => p[0]).slice(0, 2).join("")}
{r.guest}
{r.phone} {r.property} {r.requested} {r.status === "pending" && (
)} {r.status === "active" && ( )} {(r.status === "rejected" || r.status === "expired") && ( Chiusa )}
)}
{/* Properties overview */}

Le tue strutture

{state.properties.map(p => (
onOpenProperty(p.id)}>
{p.photo_url ? {p.name} : p.name}
{p.name}
{p.city}
))}
); } window.DashboardPage = DashboardPage;