import type { ContentStatus, EntityStatus } from "@/lib/cms/types";
import { cn } from "@/lib/utils";

const CONTENT_STATUS = {
  PUBLISHED: {
    label: "Published",
    className: "bg-success-soft text-success",
    dot: "bg-success",
  },
  SCHEDULED: {
    label: "Scheduled",
    className: "bg-info-soft text-info",
    dot: "bg-info",
  },
  DRAFT: {
    label: "Draft",
    className: "bg-muted text-muted-foreground",
    dot: "bg-muted-foreground/60",
  },
} satisfies Record<
  ContentStatus,
  { label: string; className: string; dot: string }
>;

const ENTITY_STATUS = {
  ACTIVE: {
    label: "Active",
    className: "bg-success-soft text-success",
    dot: "bg-success",
  },
  INACTIVE: {
    label: "Inactive",
    className: "bg-muted text-muted-foreground",
    dot: "bg-muted-foreground/60",
  },
} satisfies Record<
  EntityStatus,
  { label: string; className: string; dot: string }
>;

export const contentStatusLabel = (status: ContentStatus) =>
  CONTENT_STATUS[status].label;

function Pill({
  label,
  className,
  dot,
  size = "default",
}: {
  label: string;
  className: string;
  dot: string;
  size?: "default" | "sm";
}) {
  return (
    <span
      className={cn(
        "inline-flex w-fit shrink-0 items-center gap-1.5 rounded-full font-medium whitespace-nowrap",
        size === "sm" ? "h-5 px-2 text-[0.6875rem]" : "h-6 px-2.5 text-xs",
        className,
      )}
    >
      <span className={cn("size-1.5 rounded-full", dot)} aria-hidden="true" />
      {label}
    </span>
  );
}

export function ContentStatusBadge({
  status,
  size,
  className,
}: {
  status: ContentStatus;
  size?: "default" | "sm";
  className?: string;
}) {
  const config = CONTENT_STATUS[status];
  return (
    <Pill {...config} size={size} className={cn(config.className, className)} />
  );
}

export function EntityStatusBadge({
  status,
  size,
}: {
  status: EntityStatus;
  size?: "default" | "sm";
}) {
  return <Pill {...ENTITY_STATUS[status]} size={size} />;
}
