'use client';

import { LpIcon } from '@/features/list-page/ui/LpIcon';
import { cn } from '@/lib/utils/cn';
import { STALE_STAGE_DAYS, stageDays, stagePillTitle } from '../stageRules';

/**
 * The board card's "In stage: 3d" pill (card.html, list-page.js stagePill): days since the record
 * entered its stage, amber after 30 days. Nothing when the time is unknown.
 */
export function StagePill({
  stageName,
  record,
}: {
  stageName: string;
  record: { stageEnteredAt?: string | null; timeInStageMs?: number | null };
}) {
  const days = stageDays(record);
  if (days === null) return null;
  return (
    <div className="lp-bcard__meta">
      <span
        className={cn('lp-stage-pill', days > STALE_STAGE_DAYS && 'is-stale')}
        title={stagePillTitle(stageName, days)}
      >
        <LpIcon name="clock" className="lp-i--xs" />
        In stage: {days}d
      </span>
    </div>
  );
}
