'use client';

import { useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { resolveHashAlias } from '@/lib/routes';

/**
 * Hash deep-link bridge (§C.3.4). The VYNDR 2.0 prototype was a single HTML
 * file routed by hash (#scan, #terminal, …). We keep Next file-based routing,
 * so when a hash-style link lands here we translate it to the real route once
 * on mount. No-op for ordinary in-page anchors (only known aliases redirect).
 */
export default function HashRedirect() {
  const router = useRouter();
  useEffect(() => {
    if (typeof window === 'undefined') return;
    const target = resolveHashAlias(window.location.hash);
    if (target && window.location.pathname !== target) {
      router.replace(target);
    }
  }, [router]);
  return null;
}
