import { ChevronRight } from 'lucide-react';

import { Link } from '@inertiajs/react';

import type { SiteSummary } from '@/types';

interface SetupProgressPillProps {
  site: SiteSummary;
}

function getCompletedCount(site: SiteSummary): number {
  return [site.has_gsc, site.has_analysis, site.has_reviewed_recommendation].filter(Boolean).length;
}

function getNextStepHref(site: SiteSummary): string {
  if (!site.has_gsc) return route('onboarding.index', site.id);
  if (!site.has_analysis) return route('analyze.index', site.id);
  return route('recommendations.index', site.id) + '?from=wizard';
}

/**
 * SetupProgressPill — compact progress anchor rendered in the Dashboard PageHeader
 * after the setup checklist has been dismissed but activation is not yet complete.
 *
 * ACT-006: Prevents dismissed-early users from losing all progress context.
 * Auto-removes once the user is fully activated (gate is in Dashboard.tsx).
 */
export default function SetupProgressPill({ site }: SetupProgressPillProps) {
  const completedCount = getCompletedCount(site);
  const totalSteps = 3;
  const nextHref = getNextStepHref(site);

  return (
    <Link
      href={nextHref}
      className="inline-flex items-center gap-1 rounded-full border border-primary/30 bg-primary/5 px-3 py-1.5 text-xs font-medium text-primary hover:bg-primary/10 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
      aria-label={`Setup ${completedCount} of ${totalSteps} steps complete — continue setup`}
    >
      Setup {completedCount}/{totalSteps}
      <ChevronRight className="h-3 w-3" aria-hidden="true" />
    </Link>
  );
}
