import React from 'react';
import { Badge } from "@/components/ui/badge";

export function StatusBadge({ 
    status, 
    reason = '', 
    size = 'default',
    showReason = true,
    className = ""
}) {
    const getStatusConfig = (status) => {
        const lowerStatus = status?.toLowerCase();
        
        switch (lowerStatus) {
            case 'raised':
                return {
                    variant: 'success',
                    label: 'Raised',
                    className: 'bg-green-100 text-green-800 border-green-200'
                };
            case 'rejected':
                return {
                    variant: 'destructive',
                    label: 'Rejected',
                    className: 'bg-yellow-100 text-yellow-800 border-yellow-200'
                };
            case 'new':
                return {
                    variant: 'secondary',
                    label: 'New',
                    className: 'bg-blue-100 text-blue-800 border-blue-200'
                };
            case 'active':
                return {
                    variant: 'success',
                    label: 'Active',
                    className: 'bg-green-100 text-green-800 border-green-200'
                };
            case 'inactive':
                return {
                    variant: 'secondary',
                    label: 'Inactive',
                    className: 'bg-gray-100 text-gray-800 border-gray-200'
                };
            default:
                return {
                    variant: 'secondary',
                    label: status || 'Unknown',
                    className: 'bg-gray-100 text-gray-800 border-gray-200'
                };
        }
    };

    const getSizeClasses = (size) => {
        switch (size) {
            case 'small':
                return 'text-xs px-2 py-1';
            case 'large':
                return 'text-base px-3 py-2';
            default:
                return 'text-sm px-2.5 py-1.5';
        }
    };

    const statusConfig = getStatusConfig(status);
    const sizeClasses = getSizeClasses(size);

    if (status === 'rejected' && showReason && reason) {
        return (
            <div className={`flex flex-col items-start ${className}`}>
                <Badge 
                    variant={statusConfig.variant} 
                    className={`${statusConfig.className} ${sizeClasses} font-sans`}
                >
                    {statusConfig.label}
                </Badge>
                <p className="text-xs text-gray-500 mt-1 font-sans">
                    Reason: {reason}
                </p>
            </div>
        );
    }

    return (
        <Badge 
            variant={statusConfig.variant} 
            className={`${statusConfig.className} ${sizeClasses} font-sans ${className}`}
        >
            {statusConfig.label}
        </Badge>
    );
}

// Predefined status configurations for common use cases
export const statusConfigs = {
    violations: {
        new: { label: 'New', variant: 'secondary', className: 'bg-blue-100 text-blue-800 border-blue-200' },
        raised: { label: 'Raised', variant: 'success', className: 'bg-green-100 text-green-800 border-green-200' },
        rejected: { label: 'Rejected', variant: 'destructive', className: 'bg-yellow-100 text-yellow-800 border-yellow-200' }
    },
    constables: {
        active: { label: 'Active', variant: 'success', className: 'bg-green-100 text-green-800 border-green-200' },
        inactive: { label: 'Inactive', variant: 'secondary', className: 'bg-gray-100 text-gray-800 border-gray-200' }
    }
};

// Helper function to get status badge for violations
export const getViolationStatusBadge = (status, reason = '', size = 'default') => (
    <StatusBadge status={status} reason={reason} size={size} />
);

// Helper function to get status badge for constables
export const getConstableStatusBadge = (status, size = 'default') => (
    <StatusBadge status={status} size={size} showReason={false} />
);
