'use client';

import React from 'react';
import { usePathname, useRouter } from 'next/navigation';
import { CalendarClock, ClipboardList } from 'lucide-react';
import { useTranslation } from 'react-i18next';

const TABS = [
  { href: '/installation-requests', icon: CalendarClock, labelKey: 'nav.requests' },
  { href: '/history', icon: ClipboardList, labelKey: 'nav.history' },
] as const;

/** Navigation principale entre les deux pages de premier niveau. */
export function BottomTabBar() {
  const { t } = useTranslation();
  const router = useRouter();
  const pathname = usePathname();

  return (
    <nav className="flex-shrink-0 bg-white border-t border-border z-20" aria-label={t('nav.label')}>
      <div className="flex max-w-lg mx-auto">
        {TABS.map(({ href, icon: Icon, labelKey }) => {
          const active = pathname === href || pathname.startsWith(`${href}/`);
          return (
            <button
              key={href}
              type="button"
              aria-current={active ? 'page' : undefined}
              onClick={() => {
                if (pathname !== href) router.push(href);
              }}
              className={`flex-1 flex flex-col items-center gap-0.5 py-2 text-[11px] font-semibold transition-colors ${
                active ? 'text-primary' : 'text-muted-foreground hover:text-foreground'
              }`}
            >
              <span
                className={`flex items-center justify-center w-12 h-7 rounded-full transition-colors ${
                  active ? 'bg-primary/10' : ''
                }`}
              >
                <Icon className="w-5 h-5" />
              </span>
              {t(labelKey)}
            </button>
          );
        })}
      </div>
    </nav>
  );
}
