'use client';

import Link from 'next/link';
import { usePathname } from 'next/navigation';
import styles from './layout.module.css';

interface Props {
  userEmail: string;
}

export function HeaderRight({ userEmail }: Props) {
  // `usePathname()` returns `string` in the App Router; normalize any trailing
  // slash in case `next.config.ts` ever flips `trailingSlash: true`.
  const pathname = usePathname().replace(/\/$/, '') || '/';
  const isAdminSubPage = pathname !== '/admin' && pathname.startsWith('/admin/');

  return (
    <div className={styles.headerRight}>
      <span className={styles.userEmail}>{userEmail}</span>
      {isAdminSubPage && (
        <Link href="/admin" className={styles.backLink}>
          Back to Admin
        </Link>
      )}
      <Link href="/dashboard" className={styles.backLink}>
        Back to Dashboard
      </Link>
    </div>
  );
}
