import { PostState, PostStateLabels } from "@nice/common";

export function PostBadge({
	type,
	value,
	className = "",
}: {
	type: "priority" | "category" | "state" | "tag";
	value: string;
	className?: string;
}) {
	return (
		value && (
			<span
				className={`
                inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium
                ${getBadgeStyle(type, value)}
                
                ${className}
            `}>
				{type === "state"
					? PostStateLabels?.[value]
					: value?.toUpperCase()}
			</span>
		)
	);
}

const BADGE_STYLES = {
	priority: {
		high: "bg-white text-red-800",
		medium: "bg-white text-yellow-800",
		low: "bg-white text-green-800",
	},
	category: {
		complaint: "bg-white text-orange-800",
		suggestion: "bg-white text-blue-800",
		request: "bg-white text-purple-800",
		feedback: "bg-white text-teal-800",
	},
	state: {
		[PostState.PENDING]: "bg-white text-yellow-800",
		[PostState.PROCESSING]: "bg-white text-blue-800",
		[PostState.RESOLVED]: "bg-white text-green-800",
	},
	tag: {
		_: "bg-white text-primary-800",
	},
} as const;

const getBadgeStyle = (
	type: keyof typeof BADGE_STYLES,
	value: string
): string => {
	if (type === "tag") {
		return "bg-white text-primary";
	}
	return (
		BADGE_STYLES[type][value as keyof (typeof BADGE_STYLES)[typeof type]] ||
		"bg-white text-gray-800"
	);
};
