import { AlertCircle, Clock } from "lucide-react";

import { Badge } from "@/components/ui/badge";
import { dueLabel, dueState } from "@/lib/appwrite/due-date";
import type { Job } from "@/lib/appwrite/schema";

export function DueBadge({
  job,
  className,
}: {
  job: Pick<Job, "dueDate" | "status">;
  className?: string;
}) {
  const state = dueState(job);
  if (state.kind === "none" || state.kind === "future") return null;
  const variant: "destructive" | "secondary" = state.kind === "overdue" ? "destructive" : "secondary";
  return (
    <Badge variant={variant} className={`gap-1 ${className ?? ""}`}>
      {state.kind === "overdue" ? (
        <AlertCircle className="size-3" />
      ) : (
        <Clock className="size-3" />
      )}
      {dueLabel(state)}
    </Badge>
  );
}
