'use client';

import React from 'react';
import { Tag } from 'antd';
import type { ProjectStatus } from '../../lib/projects';

export const STATUS_META: Record<ProjectStatus, { label: string; color: string; tone: 'blue' | 'emerald' | 'amber' | 'slate' | 'rose' }> = {
  Planned: { label: 'Planned', color: 'blue', tone: 'blue' },
  Active: { label: 'Active', color: 'green', tone: 'emerald' },
  'On hold': { label: 'On Hold', color: 'orange', tone: 'amber' },
  Completed: { label: 'Completed', color: 'purple', tone: 'slate' },
  Cancelled: { label: 'Cancelled', color: 'default', tone: 'slate' },
};

export function ProjectStatusBadge({ status }: { status: ProjectStatus }) {
  const meta = STATUS_META[status] || { label: status, color: 'default' };
  return (
    <Tag color={meta.color} className="m-0 rounded-full font-medium px-2.5 py-0.5 text-[12px] border-0">
      {meta.label}
    </Tag>
  );
}

/** Formats an hour count as "1 hr" or "15.5 hrs". */
export function formatHours(hours: number | string | null | undefined): string {
  const n = Number(hours) || 0;
  return `${n.toLocaleString('en-IN', { maximumFractionDigits: 2 })} ${n === 1 ? 'hr' : 'hrs'}`;
}
