import { useMemo } from "react"; import { View } from "react-native"; import { Text } from "react-native-paper"; import { PriorityStatus } from "@/constants/priorityStatusEnum"; import { SizeEnum } from "@/constants/sizeEnum"; type PriorityData = { bars: number; color: string; }; const PRIORITY_CONFIG: Record = { [PriorityStatus.HIGH_PRIORITY]: { bars: 3, color: "bg-highRisk" }, [PriorityStatus.MODERATE_PRIORITY]: { bars: 2, color: "bg-mediumRisk" }, [PriorityStatus.LOW_PRIORITY]: { bars: 1, color: "bg-lowRisk" }, }; const SIZE_CONFIG = { [SizeEnum.Small]: { width: "w-1", heights: ["h-2", "h-3", "h-4"], }, [SizeEnum.Moderate]: { width: "w-1.5", heights: ["h-3", "h-4", "h-5"], }, [SizeEnum.Regular]: { width: "w-1.5", heights: ["h-3", "h-4", "h-5"], }, [SizeEnum.Large]: { width: "w-2", heights: ["h-4", "h-6", "h-8"], }, }; interface PriorityIndicatorProps { priority: PriorityStatus | string; showLabel?: boolean; size?: SizeEnum; } export const PriorityIndicator = ({ priority, showLabel = false, size = SizeEnum.Moderate, }: PriorityIndicatorProps) => { const { filledBars, barColor, barSizes } = useMemo(() => { const priorityData = PRIORITY_CONFIG[priority] || { bars: 0, color: "bg-mediumGray", }; const sizeData = SIZE_CONFIG[size] || SIZE_CONFIG[SizeEnum.Moderate]; return { filledBars: priorityData.bars, barColor: priorityData.color, barSizes: { width: sizeData.width, heights: sizeData.heights, }, }; }, [priority, size]); return ( = 1 ? barColor : "bg-mediumGray" }`} /> = 2 ? barColor : "bg-mediumGray" }`} /> = 3 ? barColor : "bg-mediumGray" }`} /> {showLabel && ( {typeof priority === "string" ? priority.charAt(0).toUpperCase() + priority.slice(1).toLowerCase() : priority} )} ); };