// Shared primitives & icons for Michelle's landing page.

const Eyebrow = ({ children, light, className = "" }) => (
  <div className={`tag-num uppercase flex items-center gap-3 ${light ? 'text-gold' : 'text-gold2'} ${className}`}>
    <span className="inline-block w-6 h-px bg-current opacity-60"></span>
    <span>{children}</span>
  </div>
);

const SectionLabel = ({ num, label, light = false }) => (
  <div className={`tag-num uppercase flex items-center gap-4 ${light ? 'text-gold3' : 'text-ink'}`}>
    <span className="opacity-60">§ {num}</span>
    <span className={`inline-block w-10 h-px ${light ? 'bg-gold' : 'bg-ink/30'}`}></span>
    <span>{label}</span>
  </div>
);

const PrimaryCTA = ({ children, href = "#contato", className = "", size = "md" }) => {
  const sizes = {
    sm: "px-5 py-2.5 text-sm",
    md: "px-7 py-4 text-[15px]",
    lg: "px-10 py-6 text-lg md:text-xl",
    xl: "px-12 py-7 text-xl md:text-2xl",
  };
  return (
    <a href={href} className={`group inline-flex items-center gap-3 rounded-[10px] bg-ink text-white font-medium tracking-wide hover:bg-ink3 transition-colors duration-200 ${sizes[size]} ${className}`}>
      <span>{children}</span>
      <span className="inline-block transition-transform duration-200 group-hover:translate-x-1">→</span>
    </a>
  );
};

const GhostCTA = ({ children, href = "#contato", className = "" }) => (
  <a href={href} className={`inline-flex items-center gap-2 rounded-[10px] border border-ink/30 text-ink px-7 py-4 text-[15px] font-medium hover:border-ink hover:bg-ink hover:text-white transition-all duration-200 ${className}`}>
    {children}
  </a>
);

// Icons (minimal, line-based)
const Icon = ({ name, className = "w-6 h-6" }) => {
  const stroke = "currentColor";
  const sw = 1.4;
  const icons = {
    target: (
      <svg viewBox="0 0 24 24" fill="none" className={className}>
        <circle cx="12" cy="12" r="9" stroke={stroke} strokeWidth={sw}/>
        <circle cx="12" cy="12" r="5" stroke={stroke} strokeWidth={sw}/>
        <circle cx="12" cy="12" r="1.5" fill={stroke}/>
      </svg>
    ),
    filter: (
      <svg viewBox="0 0 24 24" fill="none" className={className}>
        <path d="M3 5h18l-7 8v6l-4 2v-8L3 5z" stroke={stroke} strokeWidth={sw} strokeLinejoin="round"/>
      </svg>
    ),
    broadcast: (
      <svg viewBox="0 0 24 24" fill="none" className={className}>
        <circle cx="12" cy="12" r="2" stroke={stroke} strokeWidth={sw}/>
        <path d="M7 7a7 7 0 000 10M17 7a7 7 0 010 10M4 4a11 11 0 000 16M20 4a11 11 0 010 16" stroke={stroke} strokeWidth={sw} strokeLinecap="round"/>
      </svg>
    ),
    map: (
      <svg viewBox="0 0 24 24" fill="none" className={className}>
        <path d="M9 4L3 6v14l6-2 6 2 6-2V4l-6 2-6-2z" stroke={stroke} strokeWidth={sw} strokeLinejoin="round"/>
        <path d="M9 4v14M15 6v14" stroke={stroke} strokeWidth={sw}/>
      </svg>
    ),
    network: (
      <svg viewBox="0 0 24 24" fill="none" className={className}>
        <circle cx="5" cy="12" r="2" stroke={stroke} strokeWidth={sw}/>
        <circle cx="19" cy="6" r="2" stroke={stroke} strokeWidth={sw}/>
        <circle cx="19" cy="18" r="2" stroke={stroke} strokeWidth={sw}/>
        <circle cx="12" cy="12" r="2" stroke={stroke} strokeWidth={sw}/>
        <path d="M7 12h3M14 12L17 7M14 12l3 5" stroke={stroke} strokeWidth={sw}/>
      </svg>
    ),
    cloud: (
      <svg viewBox="0 0 24 24" fill="none" className={className}>
        <path d="M7 18a4 4 0 010-8 6 6 0 0111.5 1.5A3.5 3.5 0 0118 18H7z" stroke={stroke} strokeWidth={sw} strokeLinejoin="round"/>
        <path d="M11 13l1.5 1.5L15 12" stroke={stroke} strokeWidth={sw} strokeLinecap="round" strokeLinejoin="round"/>
      </svg>
    ),
    method: (
      <svg viewBox="0 0 24 24" fill="none" className={className}>
        <rect x="3" y="4" width="18" height="16" rx="1.5" stroke={stroke} strokeWidth={sw}/>
        <path d="M7 9h10M7 13h7M7 17h4" stroke={stroke} strokeWidth={sw} strokeLinecap="round"/>
      </svg>
    ),
    precision: (
      <svg viewBox="0 0 24 24" fill="none" className={className}>
        <path d="M12 3l2 5 5 1-4 3.5 1 5L12 14.5 8 17.5l1-5L5 9l5-1 2-5z" stroke={stroke} strokeWidth={sw} strokeLinejoin="round"/>
      </svg>
    ),
    result: (
      <svg viewBox="0 0 24 24" fill="none" className={className}>
        <path d="M3 18l5-6 4 4 8-10" stroke={stroke} strokeWidth={sw} strokeLinecap="round" strokeLinejoin="round"/>
        <path d="M14 6h6v6" stroke={stroke} strokeWidth={sw} strokeLinecap="round" strokeLinejoin="round"/>
      </svg>
    ),
    check: (
      <svg viewBox="0 0 24 24" fill="none" className={className}>
        <circle cx="12" cy="12" r="9" stroke={stroke} strokeWidth={sw}/>
        <path d="M8 12.5l2.5 2.5L16 9.5" stroke={stroke} strokeWidth={sw} strokeLinecap="round" strokeLinejoin="round"/>
      </svg>
    ),
    x: (
      <svg viewBox="0 0 24 24" fill="none" className={className}>
        <circle cx="12" cy="12" r="9" stroke={stroke} strokeWidth={sw}/>
        <path d="M9 9l6 6M15 9l-6 6" stroke={stroke} strokeWidth={sw} strokeLinecap="round"/>
      </svg>
    ),
    whatsapp: (
      <span
        className={`inline-block bg-current ${className}`}
        style={{
          WebkitMask: 'url(whatsapp-glyph-black.svg) center / contain no-repeat',
          mask: 'url(whatsapp-glyph-black.svg) center / contain no-repeat',
        }}
        aria-hidden="true"
      />
    ),
    linkedin: (
      <svg viewBox="0 0 24 24" fill="none" className={className}>
        <rect x="3" y="3" width="18" height="18" rx="2" stroke={stroke} strokeWidth={sw}/>
        <path d="M7 10v7M7 7v.5M11 17v-4a2 2 0 014 0v4M11 10v7" stroke={stroke} strokeWidth={sw} strokeLinecap="round"/>
      </svg>
    ),
    arrow: (
      <svg viewBox="0 0 24 24" fill="none" className={className}>
        <path d="M5 12h14M13 6l6 6-6 6" stroke={stroke} strokeWidth={sw} strokeLinecap="round" strokeLinejoin="round"/>
      </svg>
    ),
    quote: (
      <svg viewBox="0 0 24 24" fill="currentColor" className={className}>
        <path d="M7 7h4v4H8c0 2 1 3 3 3v3c-4 0-6-2-6-6V7zm9 0h4v4h-3c0 2 1 3 3 3v3c-4 0-6-2-6-6V7z"/>
      </svg>
    ),
    plus: (
      <svg viewBox="0 0 24 24" fill="none" className={className}>
        <path d="M12 5v14M5 12h14" stroke={stroke} strokeWidth={sw} strokeLinecap="round"/>
      </svg>
    ),
    sparkle: (
      <svg viewBox="0 0 24 24" fill="none" className={className}>
        <path d="M12 3v6M12 15v6M3 12h6M15 12h6M6 6l3 3M15 15l3 3M18 6l-3 3M9 15l-3 3" stroke={stroke} strokeWidth={sw} strokeLinecap="round"/>
      </svg>
    ),
  };
  return icons[name] || null;
};

// Photo block
const PhotoPlaceholder = ({ label = "FOTO DA MICHELLE", className = "", shape = "circle" }) => {
  const rounded = shape === "circle" ? "rounded-full" : "rounded-[18px]";
  return (
    <div className={`relative ${rounded} border border-ink/15 flex items-center justify-center overflow-hidden ${className}`}>
      <img
        src="image.png"
        alt={label}
        className="absolute inset-0 w-full h-full object-cover object-center"
      />
      {/* corner ticks */}
      <span className="absolute top-3 left-3 w-3 h-px bg-ink/30"></span>
      <span className="absolute top-3 left-3 w-px h-3 bg-ink/30"></span>
      <span className="absolute top-3 right-3 w-3 h-px bg-ink/30"></span>
      <span className="absolute top-3 right-3 w-px h-3 bg-ink/30"></span>
      <span className="absolute bottom-3 left-3 w-3 h-px bg-ink/30"></span>
      <span className="absolute bottom-3 left-3 w-px h-3 bg-ink/30"></span>
      <span className="absolute bottom-3 right-3 w-3 h-px bg-ink/30"></span>
      <span className="absolute bottom-3 right-3 w-px h-3 bg-ink/30"></span>
    </div>
  );
};

// Reveal-on-scroll wrapper
const Reveal = ({ children, delay = 0, className = "" }) => {
  const ref = React.useRef(null);
  React.useEffect(() => {
    const el = ref.current;
    if (!el) return;
    let revealed = false;
    const reveal = () => {
      if (revealed) return;
      revealed = true;
      setTimeout(() => el.classList.add('in'), delay);
    };

    // If already in view at mount, reveal immediately (don't rely on IO's initial callback).
    const rect = el.getBoundingClientRect();
    const vh = window.innerHeight || document.documentElement.clientHeight;
    if (rect.top < vh * 0.95 && rect.bottom > 0) {
      reveal();
      return;
    }

    // Fallback timer in case the observer never fires in this environment.
    const fallback = setTimeout(reveal, 1800);

    let io;
    try {
      io = new IntersectionObserver((entries) => {
        entries.forEach(e => { if (e.isIntersecting) reveal(); });
      }, { threshold: 0, rootMargin: '0px 0px -8% 0px' });
      io.observe(el);
    } catch (err) {
      reveal();
    }
    return () => { clearTimeout(fallback); if (io) io.disconnect(); };
  }, [delay]);
  return <div ref={ref} className={`reveal ${className}`}>{children}</div>;
};

// Section wrapper with consistent vertical padding
const Section = ({ id, dark = false, children, className = "" }) => (
  <section
    id={id}
    className={`relative ${dark ? 'bg-ink text-canvas grain' : 'bg-canvas text-ink'} ${className}`}
  >
    <div className="max-w-[1240px] mx-auto px-6 md:px-10 py-20 md:py-32">
      {children}
    </div>
  </section>
);

Object.assign(window, {
  Eyebrow, SectionLabel, PrimaryCTA, GhostCTA, Icon,
  PhotoPlaceholder, Reveal, Section,
});
