// ECO-PANNEAU.FR - _react/riverains/_riverains.jsx const { useState, useEffect, useRef } = React; window.pano_RiverainView = ({ panneau, showToast, interactions = [], settings = {}, refreshData, isPreview = false, initialTab = 'home' }) => { const [activeTab, setActiveTab] = useState(initialTab); const [mountTime] = useState(Math.floor(Date.now() / 1000)); const scrollRef = useRef(null); // 1. - Gestion isolée des modales Zéro-Dette (SPA) const urlModal = window.pano_useUrlModal ? window.pano_useUrlModal() : {}; const [localModal, setLocalModal] = useState({ modal: null, targetId: null }); const [localDialog, setLocalDialog] = useState({ dialog: null, dialogId: null }); const activeModal = isPreview ? localModal.modal : urlModal.activeModal; const targetId = isPreview ? localModal.targetId : urlModal.targetId; const activeDialog = isPreview ? localDialog.dialog : urlModal.activeDialog; const dialogId = isPreview ? localDialog.dialogId : urlModal.dialogId; const openModal = (modal, target = null) => { if (isPreview) { setLocalModal({ modal, targetId: target }); } else if (urlModal.openModal) { urlModal.openModal(modal, target, false); } }; const openDialog = (dialog, target = null) => { if (isPreview) { setLocalDialog({ dialog, dialogId: target }); } else if (urlModal.openDialog) { urlModal.openDialog(dialog, target, false); } }; const closeCurrentLayer = () => { if (isPreview) { if (localDialog.dialog) setLocalDialog({ dialog: null, dialogId: null }); else if (localModal.modal) setLocalModal({ modal: null, targetId: null }); } else if (urlModal.closeCurrentLayer) { urlModal.closeCurrentLayer(); } }; // 2. - Récupération des icônes et composants const { AlertTriangleIcon, InfoIcon, UsersIcon, MessageSquareIcon, EyeIcon, MailIcon } = window.pano_getIcons(); const { RiverainAccueilTab, RiverainEquipeTab, RiverainContactTab, RiverainNewsletterTab, Button, ConfirmModal, NotificationBadge, LogoSVG, TextLogo, RiverainPdfModal, RiverainImageModal, RiverainArretesModal, RiverainDemoWarningModal } = window.pano_getComponents(); // 3. - Effets et télémétrie useEffect(() => { setActiveTab(initialTab); }, [initialTab]); useEffect(() => { if (isPreview && scrollRef.current) { scrollRef.current.scrollTo({ top: 0, behavior: 'smooth' }); } else if (!isPreview) { window.scrollTo({ top: 0, behavior: 'smooth' }); } }, [activeTab, isPreview]); useEffect(() => { if (!isPreview && panneau && panneau.id && panneau.id !== 'CONTACT_PUBLIC' && panneau.id !== 'demo-panneau' && panneau.status === 'Actif') { const trackKey = 'pano_view_' + panneau.id; if (!sessionStorage.getItem(trackKey)) { sessionStorage.setItem(trackKey, '1'); fetch((window.pano_CONFIG?.apiBaseUrl || '?api=') + 'panneaux/view&silent=1', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id: panneau.id }) }).catch(() => {}); } } }, [panneau, isPreview]); // 4. - Écrans d'erreur responsives if (!isPreview) { if (!panneau || panneau.status === 'Supprimé') { return (
{AlertTriangleIcon && }

Panneau introuvable

Ce panneau n'existe pas ou a été supprimé par son propriétaire.

{LogoSVG && } {TextLogo && }
); } if (panneau.status === 'Brouillon') { return (
{AlertTriangleIcon && }

En attente de publication

Ce panneau n'a pas encore été publié.

{LogoSVG && } {TextLogo && }
); } if (panneau.status === 'Hors ligne' || panneau.status === 'Désactivé' || panneau.status === 'Suspendu') { return (
{AlertTriangleIcon && }

Panneau inactif

Ce panneau a été désactivé par son propriétaire sur la plateforme .

{LogoSVG && } {TextLogo && }
); } } else if (!panneau) { return
Chargement de l'aperçu...
; } // 5. - Variables de configuration const isPublicContact = panneau.id === 'CONTACT_PUBLIC'; const isDemo = panneau.id === 'demo-panneau'; const isSimulated = isPreview || isDemo; const themeColor = panneau.themeColor || '#059669'; const hasNoAds = panneau.hasNoAds; const displayOpts = panneau.displayOptions || {}; const hideLegal = displayOpts.hideLegal === true; const hasIntervenants = panneau.intervenants && panneau.intervenants.length > 0; const hasLots = panneau.lots && panneau.lots.length > 0; const hideTeamTab = !hasIntervenants && !hasLots; const showNewsletterTab = settings?.opt_newsletter !== 'disabled' && !isPublicContact; const showMessagingTab = settings?.opt_messaging !== 'disabled'; const panelInteractions = (interactions || []).filter(i => i.panneauId === panneau.id); const unreadCount = isSimulated ? 0 : panelInteractions.filter(m => !m.resolved && (m.authorType === 'Admin' || m.authorType === 'Client')).length; // L'image de fond (Header) reste en taille originale const displayImageUrl = (isPublicContact && settings?.contact_header_image) ? `${window.pano_CONFIG.apiBaseUrl}file/download&type=image&id=${settings.contact_header_image}` : (panneau.imageId ? `${window.pano_CONFIG.apiBaseUrl}file/download&type=image&id=${panneau.imageId}` : panneau.imageUrl); // CORRECTION OOM : Le logo du MOA passe en miniature (&preview=1) const displayMoaLogoUrl = panneau.maitreOuvrageLogoId ? `${window.pano_CONFIG.apiBaseUrl}file/download&type=image&id=${panneau.maitreOuvrageLogoId}&preview=1` : panneau.maitreOuvrageLogoUrl; const showPanelBanner = !isPublicContact && !isSimulated && settings?.panel_banner_active === '1' && settings?.panel_banner_msg; const handleExternalLink = (e, url) => { if (isSimulated) { if (e) { e.preventDefault(); e.stopPropagation(); } openDialog('demo_warning', 'link'); return true; } return false; }; useEffect(() => { if (activeTab === 'team' && hideTeamTab) setActiveTab('home'); if (activeTab === 'newsletter' && !showNewsletterTab) setActiveTab('home'); if (activeTab === 'contact' && !showMessagingTab) setActiveTab('home'); }, [activeTab, hideTeamTab, showNewsletterTab, showMessagingTab]); const rootClasses = isPreview ? "flex flex-col bg-slate-50 relative text-slate-800 font-sans selection:bg-emerald-200 h-full w-full" : "flex flex-col bg-slate-50 relative text-slate-800 font-sans selection:bg-emerald-200 min-h-screen w-full"; const contentClasses = isPreview ? "flex-1 flex flex-col overflow-y-auto custom-scrollbar relative w-full" : "flex-1 flex flex-col relative w-full max-w-4xl mx-auto sm:px-6 md:px-8"; const navPosition = isPreview ? 'absolute' : 'fixed'; const basePb = isPublicContact ? 40 : (!hasNoAds ? 100 : 60); // 6. - Rendu UI return (
{showPanelBanner && (
]*>?/gm, '') }} className="admin-html break-words leading-relaxed" />
)}
{displayImageUrl && ( <> Panneau
)} {!displayImageUrl &&
} {displayImageUrl && !isPublicContact && Button && EyeIcon && (
{activeTab === 'home' && RiverainAccueilTab && ( )} {activeTab === 'team' && !hideTeamTab && RiverainEquipeTab && ( )} {activeTab === 'newsletter' && showNewsletterTab && RiverainNewsletterTab && ( )} {activeTab === 'contact' && showMessagingTab && RiverainContactTab && ( )}
{(!isPublicContact) && (
setActiveTab('home')} className={`cursor-pointer flex flex-col items-center justify-center h-full space-y-1 transition-colors ${activeTab === 'home' ? 'text-slate-900' : 'text-slate-400 hover:text-slate-600'} ${isPreview ? 'w-full' : 'w-full sm:w-32'}`}> {InfoIcon && } Le panneau
{!hideTeamTab && (
setActiveTab('team')} className={`cursor-pointer flex flex-col items-center justify-center h-full space-y-1 transition-colors ${activeTab === 'team' ? 'text-slate-900' : 'text-slate-400 hover:text-slate-600'} ${isPreview ? 'w-full' : 'w-full sm:w-32'}`}> {UsersIcon && } L'équipe
)} {showNewsletterTab && (
setActiveTab('newsletter')} className={`cursor-pointer flex flex-col items-center justify-center h-full space-y-1 transition-colors ${activeTab === 'newsletter' ? 'text-slate-900' : 'text-slate-400 hover:text-slate-600'} ${isPreview ? 'w-full' : 'w-full sm:w-32'}`}> {MailIcon && } Info riverains
)} {showMessagingTab && (
setActiveTab('contact')} className={`cursor-pointer flex flex-col items-center justify-center h-full space-y-1 relative transition-colors ${activeTab === 'contact' ? 'text-slate-900' : 'text-slate-400 hover:text-slate-600'} ${isPreview ? 'w-full' : 'w-full sm:w-32'}`}>
{MessageSquareIcon && } {NotificationBadge && }
Contact
)}
)} {(!hasNoAds || isPublicContact) && LogoSVG && TextLogo && ( { if (isSimulated) { e.preventDefault(); e.stopPropagation(); openDialog('demo_warning', 'link'); } }} className={`w-full bg-slate-900 text-white flex items-center justify-center gap-1.5 opacity-95 hover:opacity-100 transition-colors shrink-0 ${isSimulated ? 'cursor-pointer' : ''}`} title="Créer mon panneau de chantier" style={{ height: 'calc(40px + env(safe-area-inset-bottom))', paddingBottom: 'env(safe-area-inset-bottom)' }} > )}
{/* Ouverture isolée des modales Zéro-Dette */} {activeModal === 'pdf' && targetId && RiverainPdfModal && ( openModal('arretes')} isPreview={isPreview} /> )} {activeModal === 'image' && displayImageUrl && RiverainImageModal && ( )} {activeModal === 'arretes' && RiverainArretesModal && ( openModal('pdf', id)} isPreview={isPreview} /> )} {activeDialog === 'demo_warning' && dialogId && RiverainDemoWarningModal && ( )}
); }; /* EOF ========== [_react/riverains/_riverains.jsx] */