File size: 3,537 Bytes
373030b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { useEffect, useRef } from "react";
import useInViewAnimation from "./useInViewAnimation";
import Button from "./Button";
import DocCard from "./DocCards";
import Logo from "../Logo";
import "./sections.css";

/* Mouse-trail spawns mini document mockups, cloned from a hidden pool of
   DocCards (React renders the pool once; the trail clones plain DOM). */
const TRAIL_VARIANTS = [
  "invoice",
  "packing",
  "report",
  "declaration",
  "answer",
  "certificate",
];

const SPAWN_INTERVAL_MS = 80;
const TRAIL_LIFETIME_MS = 1000;

// Big white rounded container with a mouse-trail DocCard spawner, serif
// heading, and one dark logo-pill CTA. Trail is throttled to 80ms, cleaned
// up on unmount, and fully disabled under prefers-reduced-motion.
export default function PartnerSection({ onGetStarted }) {
  const [ref, inView] = useInViewAnimation();
  const boxRef = useRef(null);
  const poolRef = useRef(null);

  useEffect(() => {
    const box = boxRef.current;
    const pool = poolRef.current;
    if (!box || !pool) return undefined;
    const reduced = window.matchMedia("(prefers-reduced-motion: reduce)");

    let lastSpawn = 0;
    let cardIndex = 0;
    const live = new Set();
    const timers = new Set();

    const onMove = (e) => {
      if (reduced.matches) return;
      const protos = pool.children;
      if (!protos.length) return;
      const now = performance.now();
      if (now - lastSpawn < SPAWN_INTERVAL_MS) return;
      lastSpawn = now;

      const rect = box.getBoundingClientRect();
      // Clone a prototype DocCard (static markup, no handlers — safe to clone).
      const card = protos[cardIndex % protos.length].cloneNode(true);
      cardIndex += 1;
      card.classList.add("st-trail-card");
      card.style.left = `${e.clientX - rect.left}px`;
      card.style.top = `${e.clientY - rect.top}px`;
      card.style.setProperty("--st-rot", `${(Math.random() * 20 - 10).toFixed(1)}deg`);
      box.appendChild(card);
      live.add(card);

      const t = window.setTimeout(() => {
        card.remove();
        live.delete(card);
        timers.delete(t);
      }, TRAIL_LIFETIME_MS);
      timers.add(t);
    };

    box.addEventListener("mousemove", onMove);
    return () => {
      box.removeEventListener("mousemove", onMove);
      timers.forEach((t) => window.clearTimeout(t));
      live.forEach((card) => card.remove());
    };
  }, []);

  return (
    <section id="about" className="st-partner" aria-label="Partner with Tamga">
      <div className="st-partner-box" ref={boxRef}>
        {/* Hidden prototypes the mouse-trail clones from (never displayed). */}
        <div ref={poolRef} className="st-trail-pool" aria-hidden="true">
          {TRAIL_VARIANTS.map((v) => (
            <DocCard key={v} variant={v} />
          ))}
        </div>
        <div ref={ref}>
          <h2
            className={`st-partner-h st-serif ${inView ? "st-fade-up" : "st-hidden"}`}
            style={{ animationDelay: "0.1s" }}
          >
            Partner with Tamga
          </h2>
          <div
            className={`st-partner-cta ${inView ? "st-fade-up" : "st-hidden"}`}
            style={{ animationDelay: "0.2s" }}
          >
            <Button variant="primary" onClick={onGetStarted} ariaLabel="Start free pilot">
              <span className="st-partner-avatar" aria-hidden="true">
                <Logo size={22} />
              </span>
              Start free pilot
            </Button>
          </div>
        </div>
      </div>
    </section>
  );
}