'use client';

import { useT } from '@/lib/i18n/react';
import { cn } from '@/lib/cn';
import { Button } from '@/components/ui/primitives/Button';

interface RecentSearchesProps {
  title: string;
  searches: string[];
  onSelect: (query: string) => void;
  onClear?: () => void;
  className?: string;
}

export function RecentSearches({
  title,
  searches,
  onSelect,
  onClear,
  className,
}: RecentSearchesProps) {
  const t = useT('search');
  if (searches.length === 0) return null;

  return (
    <div className={cn('flex flex-col gap-2', className)}>
      <div className="flex items-center justify-between gap-3">
        <p className="text-text-secondary text-sm font-medium">{title}</p>
        {onClear ? (
          <Button type="button" variant="ghost" size="sm" onClick={onClear}>
            {t('clear_recent_searches')}
          </Button>
        ) : null}
      </div>
      <ul className="flex flex-wrap gap-2">
        {searches.map((q) => (
          <li key={q}>
            <Button
              type="button"
              variant="ghost"
              size="sm"
              onClick={() => onSelect(q)}
              className="rounded-full"
            >
              {q}
            </Button>
          </li>
        ))}
      </ul>
    </div>
  );
}
