import React from 'react' import { Link } from 'react-router-dom' import { useComponents } from '../../contexts/ComponentContext' import { useEntities } from '../../contexts/EntityContext' import { useSystemHealth } from '../../utils/hooks/useDeveloperKit' import { FaDatabase, FaBolt, FaServer, FaPuzzlePiece, FaCog, FaChartLine, FaCode, FaCheckCircle, FaArrowRight, FaExclamationCircle, FaWifi, FaWindowClose, } from 'react-icons/fa' import { ROUTES_ENUM } from '@/routes/route.constant' import { useLocalization } from '@/utils/hooks/useLocalization' const Dashboard: React.FC = () => { const { components } = useComponents() const { entities, migrations, generatedEndpoints } = useEntities() const { isOnline, lastCheck, recheckHealth } = useSystemHealth() const { translate } = useLocalization() const stats = [ { name: translate('::App.DeveloperKit.Dashboard.Stats.Entities'), value: entities.filter((e) => e.isActive).length, total: entities.length, icon: FaDatabase, color: 'text-blue-600', bgColor: 'bg-blue-100', href: ROUTES_ENUM.protected.saas.developerKit.entities, }, { name: translate('::App.DeveloperKit.Dashboard.Stats.Migrations'), value: migrations.filter((m) => m.status === 'pending').length, total: migrations.length, icon: FaBolt, color: 'text-yellow-600', bgColor: 'bg-yellow-100', href: ROUTES_ENUM.protected.saas.developerKit.migrations, }, { name: translate('::App.DeveloperKit.Dashboard.Stats.APIs'), value: generatedEndpoints.filter((e) => e.isActive).length, total: generatedEndpoints.length, icon: FaServer, color: 'text-emerald-600', bgColor: 'bg-emerald-100', href: ROUTES_ENUM.protected.saas.developerKit.endpoints, }, { name: translate('::App.DeveloperKit.Components'), value: components?.filter((c) => c.isActive).length, total: components?.length, icon: FaPuzzlePiece, color: 'text-purple-600', bgColor: 'bg-purple-100', href: ROUTES_ENUM.protected.saas.developerKit.components, }, ] const developmentFlow = [ { step: 1, title: translate('::App.DeveloperKit.Entity.CreateEntity'), description: translate('::App.DeveloperKit.Dashboard.Flow.CreateEntity.Desc'), icon: FaDatabase, color: 'bg-blue-600', href: ROUTES_ENUM.protected.saas.developerKit.entitiesNew, status: 'ready', }, { step: 2, title: translate('::App.DeveloperKit.Dashboard.Flow.GenerateMigration'), description: translate('::App.DeveloperKit.Dashboard.Flow.GenerateMigration.Desc'), icon: FaBolt, color: 'bg-yellow-600', href: ROUTES_ENUM.protected.saas.developerKit.migrations, status: entities.some((e) => e.migrationStatus === 'pending') ? 'action-needed' : 'ready', }, { step: 3, title: translate('::App.DeveloperKit.Dashboard.Flow.ApplyMigration'), description: translate('::App.DeveloperKit.Dashboard.Flow.ApplyMigration.Desc'), icon: FaCheckCircle, color: 'bg-green-600', href: ROUTES_ENUM.protected.saas.developerKit.migrations, status: migrations.some((m) => m.status === 'pending') ? 'action-needed' : 'ready', }, { step: 4, title: translate('::App.DeveloperKit.Dashboard.Flow.GenerateAPI'), description: translate('::App.DeveloperKit.Dashboard.Flow.GenerateAPI.Desc'), icon: FaServer, color: 'bg-emerald-600', href: ROUTES_ENUM.protected.saas.developerKit.endpoints, status: 'ready', }, { step: 5, title: translate('::App.DeveloperKit.Dashboard.Flow.BuildComponent'), description: translate('::App.DeveloperKit.Dashboard.Flow.BuildComponent.Desc'), icon: FaPuzzlePiece, color: 'bg-purple-600', href: ROUTES_ENUM.protected.saas.developerKit.componentsNew, status: 'ready', }, ] const recentEntities = entities.slice(0, 3) const recentMigrations = migrations.slice(0, 3) const recentEndpoints = [ ...generatedEndpoints.map((e) => ({ id: e.id, name: `${e.entityName} ${e.operationType}`, method: e.method, path: e.path, description: `Generated ${e.operationType} for ${e.entityName}`, isActive: e.isActive, lastModificationTime: e.lastModificationTime, creationTime: e.creationTime, })), ].slice(0, 3) const systemHealth = [ { name: translate('::App.DeveloperKit.Dashboard.SystemHealth.Frontend'), status: translate('::App.DeveloperKit.Dashboard.SystemHealth.Healthy'), icon: FaCode, }, { name: translate('::App.DeveloperKit.Dashboard.SystemHealth.Backend'), status: isOnline ? translate('::App.DeveloperKit.Dashboard.SystemHealth.Healthy') : translate('::App.DeveloperKit.Dashboard.SystemHealth.Offline'), icon: FaServer, }, { name: translate('::App.DeveloperKit.Dashboard.SystemHealth.Database'), status: isOnline ? translate('::App.DeveloperKit.Dashboard.SystemHealth.Healthy') : translate('::App.DeveloperKit.Dashboard.SystemHealth.Unknown'), icon: FaDatabase, }, { name: translate('::App.DeveloperKit.Dashboard.SystemHealth.Migrations'), status: migrations.some((m) => m.status === 'failed') ? translate('::App.DeveloperKit.Dashboard.SystemHealth.Warning') : translate('::App.DeveloperKit.Dashboard.SystemHealth.Healthy'), icon: FaBolt, }, ] return (
{/* Header */}

{translate('::App.DeveloperKit.Dashboard.Title')}

{translate('::App.DeveloperKit.Dashboard.Description')}

{/* Stats Grid */}
{stats.map((stat) => { const Icon = stat.icon return (

{stat.name}

{stat.value} / {stat.total}

) })}
{/* Development Flow */}

{translate('::App.DeveloperKit.Dashboard.Flow.Title')}

{developmentFlow.map((flow, index) => { const Icon = flow.icon return (
{flow.step}

{flow.title}

{flow.description}

{flow.status === 'action-needed' && (
)}
{index < developmentFlow.length - 1 && (
)} ) })}
{/* System Health */}

{translate('::App.DeveloperKit.Dashboard.SystemHealth.Title')}

{systemHealth.map((system) => { const Icon = system.icon return (
{system.name}
{system.status === 'offline' ? 'Offline' : system.status}
) })}
{/* Recent Entities */}

{translate('::App.DeveloperKit.Dashboard.RecentEntities.Title')}

{translate('::App.DeveloperKit.Dashboard.ViewAll')}
{recentEntities.length > 0 ? ( recentEntities.map((entity) => (

{entity.displayName}

{entity.fields.length} fields • {entity.migrationStatus}

)) ) : (

{translate('::App.DeveloperKit.Dashboard.Empty.Entity')}

Create your first entity
)}
{/* Recent Migrations */}

{translate('::App.DeveloperKit.Dashboard.RecentMigrations.Title')}

{translate('::App.DeveloperKit.Dashboard.ViewAll')}
{recentMigrations.length > 0 ? ( recentMigrations.map((migration) => (

{migration.entityName}

{migration.status} • {new Date(migration.creationTime).toLocaleDateString()}

)) ) : (

{translate('::App.DeveloperKit.Dashboard.Empty.Migration')}

{translate('::App.DeveloperKit.Dashboard.Action.GenerateMigrations')}
)}
{/* Recent API Endpoints */}

{translate('::App.DeveloperKit.Dashboard.RecentEndpoints.Title')}

{translate('::App.DeveloperKit.Dashboard.ViewAll')}
{recentEndpoints.length > 0 ? ( recentEndpoints.map((endpoint) => (
{endpoint.method}

{endpoint.name}

{endpoint.path}

)) ) : (

{translate('::App.DeveloperKit.Dashboard.Empty.Endpoint')}

{translate('::App.DeveloperKit.Dashboard.Action.CreateEntity')}
)}
) } export default Dashboard