import React, { useState, useEffect } from 'react'; import { Organization, Project, Player } from '../types'; import { Icons } from '../components/IconSet'; import { dbService } from '../services/DatabaseService'; interface CityProfileProps { city: Organization; onBack: () => void; backLabel?: string; onSelectPlayer: (id: string) => void; onSelectProject: (id: string) => void; } const CityProfile: React.FC = ({ city, onBack, backLabel = 'Zurück', onSelectPlayer, onSelectProject }) => { const [activeTab, setActiveTab] = useState<'overview' | 'residents' | 'ventures'>('overview'); const [residents, setResidents] = useState([]); const [ventures, setVentures] = useState([]); const [cityStats, setCityStats] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { const loadCityData = () => { // Load residents (players in this city) const allPlayers = dbService.getPlayers(); const cityResidents = allPlayers.filter(p => p.stats.organizationId === city.id); setResidents(cityResidents); // Load ventures (projects in this city) const allProjects = dbService.getProjects(); const cityVentures = allProjects.filter(p => p.associatedOrgId === city.id); setVentures(cityVentures); // Calculate dynamic city statistics const stats = { citizens: cityResidents.length, businesses: cityVentures.length, activeBusinesses: cityVentures.filter(p => p.status === 'active').length, recruitingBusinesses: cityVentures.filter(p => p.hiring).length, // Merge with existing static stats ...city.cityStats }; setCityStats(stats); setLoading(false); }; // Initial load loadCityData(); // Subscribe to updates const unsub = dbService.subscribe(loadCityData); return unsub; }, [city.id]); return (
{/* Hero Header */}
{city.name}
{city.establishedYear && (
GEGR. {city.establishedYear}
)}

{city.name}

{city.memberCount} Mitglieder
{city.status}
{city.mayor && (
Aktueller Anführer
{city.mayor}
)}
{/* Navigation Tabs */}
{/* Content Area */}
{activeTab === 'overview' && (

Über {city.name}

{city.description}

{city.gallery && city.gallery.length > 0 && (

Bildarchiv

{city.gallery.map((url, idx) => (
{`Gallery
))}
)}
{city.cityStats && (

Stadt-Statistiken

{/* Tax Rate */}
Steuersatz
{city.cityStats.taxRate}%
Pro Transaktion
{/* Defense */}
Verteidigungswert
{city.cityStats.defenseRating}/10
{/* Gov Type */}
Regierungsform
{city.cityStats.government}
{/* Biome */}
Biom {city.cityStats.biome}
Spezialität {city.cityStats.specialty}
)}
)} {activeTab === 'residents' && (
{residents.map(player => (
onSelectPlayer(player.uuid)} className="bg-surface border border-border p-4 rounded-xl flex items-center gap-4 hover:border-accentInfo/50 transition-colors cursor-pointer group hover:shadow-card hover:bg-surfaceHighlight/30" >
{player.username.charAt(0)}
{player.username}
{player.stats.role}
))} {residents.length === 0 &&
Keine Bewohner öffentlich registriert.
}
)} {activeTab === 'ventures' && (
{ventures.map(project => (
onSelectProject(project.id)} className="bg-surface border border-border rounded-xl p-5 hover:border-accentInfo/50 transition-all cursor-pointer group hover:shadow-card hover:bg-surfaceHighlight/30" >
{project.category} {project.hiring && ( STELLEN )}

{project.title}

{project.description}

Geführt von {project.owner}
{project.progress}% Fortschr.
))} {ventures.length === 0 &&
Keine aktiven Unternehmen in dieser Organisation.
}
)}
); }; export default CityProfile;