/**
 * Status Badge Components
 *
 * Reusable badge components for displaying project and autonomy status.
 */

'use client';

import { CircleDot } from 'lucide-react';
import { Badge } from '@/components/ui/badge';
import { cn } from '@/lib/utils';
import type { ProjectStatus, AutonomyLevel } from './types';

// ============================================================================
// Project Status Badge
// ============================================================================

const projectStatusConfig: Record<ProjectStatus, { label: string; className: string }> = {
  active: {
    label: 'Active',
    className: 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200',
  },
  paused: {
    label: 'Paused',
    className: 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200',
  },
  completed: {
    label: 'Completed',
    className: 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200',
  },
  archived: {
    label: 'Archived',
    className: 'bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400',
  },
};

interface ProjectStatusBadgeProps {
  status: ProjectStatus;
  className?: string;
}

export function ProjectStatusBadge({ status, className }: ProjectStatusBadgeProps) {
  /* istanbul ignore next -- defensive fallback for invalid status */
  const config = projectStatusConfig[status] || projectStatusConfig.active;

  return (
    <Badge variant="outline" className={cn(config.className, className)}>
      {config.label}
    </Badge>
  );
}

// ============================================================================
// Autonomy Level Badge
// ============================================================================

const autonomyLevelConfig: Record<AutonomyLevel, { label: string; description: string }> = {
  full_control: {
    label: 'Full Control',
    description: 'Approve every action',
  },
  milestone: {
    label: 'Milestone',
    description: 'Approve at sprint boundaries',
  },
  autonomous: {
    label: 'Autonomous',
    description: 'Only major decisions',
  },
};

interface AutonomyBadgeProps {
  level: AutonomyLevel;
  showDescription?: boolean;
  className?: string;
}

export function AutonomyBadge({ level, showDescription = false, className }: AutonomyBadgeProps) {
  /* istanbul ignore next -- defensive fallback for invalid level */
  const config = autonomyLevelConfig[level] || autonomyLevelConfig.milestone;

  return (
    <Badge variant="secondary" className={cn('gap-1', className)} title={config.description}>
      <CircleDot className="h-3 w-3" aria-hidden="true" />
      {config.label}
      {showDescription && <span className="text-muted-foreground"> - {config.description}</span>}
    </Badge>
  );
}
