'use client';

import React, { useRef } from 'react';
import { useScroll, useTransform, m, LazyMotion, domAnimation } from 'framer-motion';
import { useLocale } from 'next-intl';

export function DeepDrillAnimation() {
  const containerRef = useRef<HTMLDivElement>(null);
  const locale = useLocale();
  
  const { scrollYProgress } = useScroll({
    target: containerRef,
    offset: ["start center", "end center"]
  });

  const drillDepth = useTransform(scrollYProgress, [0, 1], ["0%", "100%"]);
  
  return (
    <div ref={containerRef} className="relative w-full py-12 md:py-32 flex flex-col items-center">
      
      <div className="absolute inset-0 bg-[#050B14] -mx-[50vw] px-[50vw]" />
      
      <div className="relative z-10 w-full max-w-3xl mx-auto flex flex-col items-center text-center text-white">
        
        <h3 className="text-2xl md:text-3xl font-heading font-extrabold mb-8 tracking-tight">
          {locale === 'en' ? 'Precision in Depth' : 'Präzision in der Tiefe'}
        </h3>
        <p className="text-white/60 text-lg mb-16 max-w-xl">
          {locale === 'en' 
            ? 'Horizontal Directional Drilling (HDD) allows us to cross obstacles and rivers with extreme care.'
            : 'Horizontalspülbohrverfahren (HDD) erlaubt uns, Hindernisse und Flüsse extrem schonend zu unterqueren.'}
        </p>

        {/* The Drill Path */}
        <div className="relative w-2 h-96 bg-white/10 rounded-full mb-16">
          <m.div 
            className="absolute top-0 left-0 w-full bg-primary rounded-full"
            style={{ height: drillDepth, boxShadow: '0 0 20px rgba(130,237,32,0.6)' }}
          >
            {/* The Drill Head */}
            <div className="absolute -bottom-2 -left-2 w-6 h-6 bg-white rounded-full border-4 border-primary shadow-[0_0_15px_rgba(255,255,255,1)]" />
          </m.div>
        </div>

        {/* The Reveal Data */}
        <m.div 
          initial={{ opacity: 0, y: 20 }}
          whileInView={{ opacity: 1, y: 0 }}
          viewport={{ once: true, margin: "-50px" }}
          transition={{ duration: 0.8 }}
          className="flex flex-col items-center"
        >
          <div className="font-mono text-5xl md:text-8xl font-black text-white tracking-tighter mb-4" style={{ fontVariantNumeric: 'tabular-nums' }}>
            102.771<span className="text-primary text-2xl md:text-5xl ml-2">m</span>
          </div>
          <div className="text-sm font-bold uppercase tracking-widest text-primary">
            {locale === 'en' ? 'Drilled distance since 2023' : 'Gebohrte Strecke seit 2023'}
          </div>
        </m.div>

      </div>
    </div>
  );
}
