import { useState } from 'react'; import { Cloud, ExternalLink, Globe, Layers, Mail, Megaphone, Share2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils'; import { type DashboardService } from '@/types'; const ACTIVATION_REQUESTED_KEY = 'service_activation_requested'; function getRequestedServices(): string[] { try { return JSON.parse(localStorage.getItem(ACTIVATION_REQUESTED_KEY) ?? '[]'); } catch { return []; } } function markServiceRequested(identifier: string): void { const current = getRequestedServices(); if (!current.includes(identifier)) { localStorage.setItem(ACTIVATION_REQUESTED_KEY, JSON.stringify([...current, identifier])); } } const iconMap: Record = { envelope: Mail, share: Share2, cloud: Cloud, megaphone: Megaphone, 'globe-alt': Globe, }; const colorSchemes = [ { card: 'bg-secondary', titleBg: 'bg-accent', titleText: 'text-accent-foreground', linkText: 'text-foreground', iconText: 'text-foreground/10', }, { card: 'bg-primary', titleBg: 'bg-white', titleText: 'text-black', linkText: 'text-foreground', iconText: 'text-foreground/10', }, { card: 'bg-accent', titleBg: 'bg-primary', titleText: 'text-primary-foreground', linkText: 'text-accent-foreground', iconText: 'text-white/10', }, ]; interface Props { service: DashboardService; index: number; onRequest: (identifier: string) => void; } export function ServiceCard({ service, index, onRequest }: Props) { const [alreadyRequested, setAlreadyRequested] = useState(() => getRequestedServices().includes(service.identifier), ); const scheme = colorSchemes[index % colorSchemes.length]; const Icon = iconMap[service.icon ?? ''] ?? Layers; function handleRequest() { markServiceRequested(service.identifier); setAlreadyRequested(true); onRequest(service.identifier); } return (

{service.name}

{service.description && (

{service.description}

)}
{service.is_active ? ( Accéder au service ) : ( )}
); }