import { useEffect, useRef, useState } from "react"; import agricultureBio from "&/images/certifications/agriculture-biologique.png"; import agricultureBioWebp from "&/images/certifications/agriculture-biologique.webp"; import bienEtre from "&/images/certifications/bien-etre-animal.png"; import bienEtreWebp from "&/images/certifications/bien-etre-animal.webp"; import conformite from "&/images/certifications/conformite-certifiee.jpg"; import conformiteWebp from "&/images/certifications/conformite-certifiee.webp"; import labelRouge from "&/images/certifications/label-rouge.png"; import labelRougeWebp from "&/images/certifications/label-rouge.webp"; import origineGeo from "&/images/certifications/origine-geographique.png"; import origineGeoWebp from "&/images/certifications/origine-geographique.webp"; import impact from "&/images/certifications/planet-scrore.png"; import impactWebp from "&/images/certifications/planet-scrore.webp"; import { GetTranslation } from "@/lib/utils"; const CERTIFICATIONS = [ { webp: labelRougeWebp, fallback: labelRouge, label: "front.certifications.quality.text", alt: "front.certifications.quality.alt", title: "front.certifications.quality.title", }, { webp: origineGeoWebp, fallback: origineGeo, label: "front.certifications.origin.text", alt: "front.certifications.origin.alt", title: "front.certifications.origin.title", }, { webp: agricultureBioWebp, fallback: agricultureBio, label: "front.certifications.organic.text", alt: "front.certifications.organic.alt", title: "front.certifications.organic.title", }, { webp: conformiteWebp, fallback: conformite, label: "front.certifications.product_cerf.text", alt: "front.certifications.product_cerf.alt", title: "front.certifications.product_cerf.title", }, { webp: bienEtreWebp, fallback: bienEtre, label: "front.certifications.animalWelfare.text", alt: "front.certifications.animalWelfare.alt", title: "front.certifications.animalWelfare.title", }, { webp: impactWebp, fallback: impact, label: "front.certifications.environmentalImpact.text", alt: "front.certifications.environmentalImpact.text", title: "front.certifications.environmentalImpact.title", }, ]; export default function CertificationsSection() { const scrollerRef = useRef(null); const [thumb, setThumb] = useState({ width: 200, left: 0 }); useEffect(() => { const scroller = scrollerRef.current; if (!scroller) return; const updateThumb = () => { const { scrollLeft, scrollWidth, clientWidth } = scroller; const thumbWidth = (clientWidth / scrollWidth) * 100; const maxScroll = scrollWidth - clientWidth; const scrollRatio = maxScroll > 0 ? scrollLeft / maxScroll : 0; const thumbLeft = scrollRatio * (100 - thumbWidth); setThumb({ width: thumbWidth, left: thumbLeft }); }; updateThumb(); scroller.addEventListener("scroll", updateThumb, { passive: true }); window.addEventListener("resize", updateThumb); return () => { scroller.removeEventListener("scroll", updateThumb); window.removeEventListener("resize", updateThumb); }; }, []); return (

{GetTranslation("front.certifications.title")}

{GetTranslation("front.certifications.subtitle")}

{/* Mobile */}
{CERTIFICATIONS.map((cert) => (
{GetTranslation(cert.alt)}

{GetTranslation(cert.label)}

))}
{/* Custom progress Bar */}
{/* Desktop */}
{CERTIFICATIONS.map((cert) => (
{GetTranslation(cert.alt)}

{GetTranslation(cert.label)}

))}
); }