// 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 (
);
}
if (panneau.status === 'Brouillon') {
return (
);
}
if (panneau.status === 'Hors ligne' || panneau.status === 'Désactivé' || panneau.status === 'Suspendu') {
return (
);
}
} 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 && (
<>
>
)}
{!displayImageUrl &&
}
{displayImageUrl && !isPublicContact && Button && EyeIcon && (
{activeTab === 'home' && RiverainAccueilTab && (
)}
{activeTab === 'team' && !hideTeamTab && RiverainEquipeTab && (
)}
{activeTab === 'newsletter' && showNewsletterTab && RiverainNewsletterTab && (
)}
{activeTab === 'contact' && showMessagingTab && RiverainContactTab && (
)}
{/* 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] */