import { useMemo } from 'react';
import * as THREE from 'three';

/**
 * Renders the visible hard edges of a geometry as a lightweight lineSegments.
 * Pure R3F (no drei Edges / Line2) to avoid the LineMaterial prop-handling crash.
 * Place as a child of a <mesh> so pointer events bubble to the parent.
 */
export default function EdgeLines({ geometry, color = '#3a4550', opacity = 0.75, threshold = 18 }) {
  const edges = useMemo(() => {
    if (!geometry) return null;
    try {
      return new THREE.EdgesGeometry(geometry, threshold);
    } catch {
      return null;
    }
  }, [geometry, threshold]);

  if (!edges) return null;

  return (
    <lineSegments geometry={edges} raycast={() => null}>
      <lineBasicMaterial color={color} transparent opacity={opacity} depthWrite={false} />
    </lineSegments>
  );
}