import React from 'react'; import { Edit } from 'lucide-react'; import type { ModuleItem } from '../../types'; import { Pagination } from '../common/Pagination'; interface ModulesTabProps { modules: ModuleItem[]; searchQuery: string; statusFilter: string; categoryFilter: string; currentPage: number; perPage: number; onSearchChange: (query: string) => void; onStatusFilterChange: (status: string) => void; onCategoryFilterChange: (cat: string) => void; onPageChange: (page: number) => void; onPerPageChange: (perPage: number) => void; onToggleStatus: (mod: ModuleItem) => void; onEditModule: (mod: ModuleItem) => void; } export const ModulesTab: React.FC = ({ modules, searchQuery, statusFilter, categoryFilter, currentPage, perPage, onSearchChange, onStatusFilterChange, onCategoryFilterChange, onPageChange, onPerPageChange, onToggleStatus, onEditModule, }) => { const filtered = modules.filter((m) => { const matchesSearch = !searchQuery || (m.name || '').toLowerCase().includes(searchQuery.toLowerCase()) || (m.slug || '').toLowerCase().includes(searchQuery.toLowerCase()) || (m.code || '').toLowerCase().includes(searchQuery.toLowerCase()) || (m.description || '').toLowerCase().includes(searchQuery.toLowerCase()); const matchesStatus = statusFilter === 'all' || (statusFilter === 'active' && m.is_active) || (statusFilter === 'inactive' && !m.is_active); const matchesCategory = categoryFilter === 'all' || (m.category || '').toLowerCase() === categoryFilter.toLowerCase(); return matchesSearch && matchesStatus && matchesCategory; }); const totalFiltered = filtered.length; const totalPages = Math.max(1, Math.ceil(totalFiltered / perPage)); const safePage = Math.min(currentPage, totalPages); const startIndex = (safePage - 1) * perPage; const paginatedModules = filtered.slice(startIndex, startIndex + perPage); const categories = [ { key: 'all', label: 'All Categories' }, { key: 'point', label: 'Points' }, { key: 'Patterns', label: 'Patterns' }, { key: 'Nutrition', label: 'Nutrition' }, { key: 'Therapeutics', label: 'Therapeutics' }, ]; return (
{/* Search & Status Bar */}
{/* Search Box */}
{ onSearchChange(e.target.value); onPageChange(1); }} className="w-full bg-white border border-slate-200 rounded-xl pl-9 pr-4 py-2 text-xs text-slate-800 font-semibold focus:outline-none focus:border-indigo-500 placeholder:text-slate-400 shadow-sm" /> 🔍
{/* Status Filter Segmented Control (Fixed Alignment) */}
Status: {[ { key: 'all', label: `All (${modules.length})` }, { key: 'active', label: `Active (${modules.filter((m) => m.is_active).length})` }, { key: 'inactive', label: `Inactive (${modules.filter((m) => !m.is_active).length})` }, ].map((f) => ( ))}
{/* Category Filter Pills */}
Category: {categories.map((cat) => { const count = cat.key === 'all' ? modules.length : modules.filter((m) => (m.category || '').toLowerCase() === cat.key.toLowerCase()).length; const isSelected = categoryFilter.toLowerCase() === cat.key.toLowerCase(); return ( ); })}
{/* Modules Table */} {filtered.length === 0 ? (

No modules match the selected filters.

Try changing your search keywords or filter pills.

) : (
{paginatedModules.map((mod) => ( {/* Column 1: Module & Details */} {/* Column 2: Code / Slug */} {/* Column 3: Category */} {/* Column 4: Linked Plans */} {/* Column 5: Status */} {/* Column 6: Actions */} ))}
Module Name & Details Identifier / Code Category Linked Plans Catalog Status Actions
{(mod.name || 'M')[0].toUpperCase()}

{mod.name}

{mod.description || 'No description provided.'}

{mod.code && ( {mod.code} )} {mod.slug}
{mod.category || 'General'} {mod.linked_plans_count || 0} {mod.linked_plans_count === 1 ? 'Plan' : 'Plans'}
{mod.is_active ? '● Active' : '○ Inactive'}
{/* Unified Pagination */}
)}
); };