import React from 'react'; import PropTypes from 'prop-types'; import {Copy, Check} from 'lucide-react'; import Tooltip from '@ui/Tooltip'; function FormatCard({ format, onEdit, onClone, sortBy, isSelectionMode, isSelected, willBeSelected, onSelect }) { const {content} = format; const totalTests = content.tests?.length || 0; const passedTests = content.tests?.filter(t => t.passes)?.length || 0; const passRate = Math.round((passedTests / totalTests) * 100) || 0; const getConditionStyle = condition => { if (condition.negate) { return 'bg-red-100 border-red-200 text-red-700 dark:bg-red-900/30 dark:border-red-700 dark:text-red-300'; } if (condition.required) { return 'bg-green-100 border-green-200 text-green-700 dark:bg-green-900/30 dark:border-green-700 dark:text-green-300'; } return 'bg-blue-100 border-blue-200 text-blue-700 dark:bg-blue-900/30 dark:border-blue-700 dark:text-blue-300'; }; const getDisplayConditions = conditions => { if (!conditions?.length) return []; // Sort conditions: required first, then non-required const sortedConditions = [...conditions].sort((a, b) => { if (a.required && !b.required) return -1; if (!a.required && b.required) return 1; return 0; }); if (sortedConditions.length <= 5) return sortedConditions; // Take first 6 conditions and add a count of remaining ones const displayConditions = sortedConditions.slice(0, 6); const remainingCount = sortedConditions.length - 6; // Add a virtual condition for the count displayConditions.push({ name: `+${remainingCount} more...`, isCounter: true }); return displayConditions; }; const handleClick = e => { if (isSelectionMode) { onSelect(e); } else { onEdit(); } }; const handleCloneClick = e => { e.stopPropagation(); onClone(format); }; const handleMouseDown = e => { // Prevent text selection when shift-clicking if (e.shiftKey) { e.preventDefault(); } }; return (
{/* Header Section */}

{content.name}

{sortBy === 'dateModified' && format.modified_date && (

Modified:{' '} {new Date( format.modified_date ).toLocaleString()}

)}
{isSelectionMode ? (
{isSelected && ( )} {willBeSelected && !isSelected && (
)}
) : ( )}
{/* Description */} {content.description && (

{content.description}

)} {/* Conditions and Test Results */}
{getDisplayConditions(content.conditions)?.map( (condition, index) => ( {condition.name} ) )}
{totalTests > 0 && (
= 80 ? 'text-yellow-600 dark:text-yellow-400' : 'text-red-600 dark:text-red-400' }`}> {passRate}% Pass Rate ({passedTests}/{totalTests})
)}
{/* Tags */} {content.tags?.length > 0 && (
{content.tags.map(tag => ( {tag} ))}
)}
); } FormatCard.propTypes = { format: PropTypes.shape({ file_name: PropTypes.string.isRequired, modified_date: PropTypes.string.isRequired, content: PropTypes.shape({ name: PropTypes.string.isRequired, description: PropTypes.string, conditions: PropTypes.arrayOf( PropTypes.shape({ name: PropTypes.string.isRequired, type: PropTypes.string.isRequired, pattern: PropTypes.string, required: PropTypes.bool, negate: PropTypes.bool }) ), tags: PropTypes.arrayOf(PropTypes.string), tests: PropTypes.arrayOf( PropTypes.shape({ id: PropTypes.number.isRequired, input: PropTypes.string.isRequired, expected: PropTypes.bool.isRequired, passes: PropTypes.bool.isRequired }) ) }).isRequired }).isRequired, onEdit: PropTypes.func.isRequired, onClone: PropTypes.func.isRequired, sortBy: PropTypes.string.isRequired, isSelectionMode: PropTypes.bool.isRequired, isSelected: PropTypes.bool.isRequired, willBeSelected: PropTypes.bool, onSelect: PropTypes.func.isRequired }; export default FormatCard;