import { useCallback, useState } from 'react';
import { Image, Linking, Pressable, ScrollView, View } from 'react-native';
import { router, useFocusEffect } from 'expo-router';
import { SafeAreaView } from 'react-native-safe-area-context';
import Svg, { Path } from 'react-native-svg';
import { api, API_URL, Summary } from '../src/api';
import { useSession, useStore } from '../src/session';
import { BrandSymbol, Button, Card, T, unit } from '../src/ui';
import { font, useColors } from '../src/theme';
function ScanIcon({ color }: { color: string }) {
return (
);
}
/** Adresse de l'espace web du Dirigeant (conception de la carte). */
const ESPACE_URL = 'https://monespacepro.eu/espace';
const greeting = () => (new Date().getHours() >= 18 ? 'Bonsoir' : 'Bonjour');
const today = () => new Date().toLocaleDateString('fr-FR', { weekday: 'long', day: 'numeric', month: 'long' });
export default function Home() {
const { me } = useSession();
// Magasin inscrit en ligne : tant que la carte n'est pas conçue, pas de scan possible.
return me?.store.cardDesign ? : ;
}
/** En-tête commun : logo du magasin, date, accès au compte. */
function Header() {
const c = useColors();
const { me } = useSession();
const logo = me?.store.cardDesign?.logoUrl;
const first = me?.displayName.split(' ')[0] ?? '';
return (
{logo ? : }
{me?.store.name}
{today()}
router.push('/account')}>
{({ pressed }) => (
{first.charAt(0).toUpperCase()}
)}
);
}
/** Ligne d'action ou de réglage : pictogramme, titre, sous-titre, chevron. */
function Row({ icon, title, sub, onPress }: { icon: string; title: string; sub?: string; onPress: () => void }) {
const c = useColors();
return (
{({ pressed }) => (
{icon}
{title}
{!!sub && {sub}}
›
)}
);
}
const sectionTitle = (c: ReturnType) => ({ color: c.text3, textTransform: 'uppercase' as const, fontSize: 13, letterSpacing: 0.5 });
function NoCardYet() {
const c = useColors();
const { me, reload } = useSession();
const isManager = me?.role === 'MANAGER';
return (
🎨
{isManager ? 'Dernière étape' : 'Presque prêt'}
{isManager
? 'Concevez votre carte de fidélité (logo, couleurs, récompenses) sur votre espace web. Le scan des cartes s’active ensuite.'
: 'La carte de fidélité du magasin n’est pas encore prête. Revenez un peu plus tard.'}
{isManager &&
);
}
function Counter() {
const c = useColors();
const { me } = useSession();
const store = useStore();
const [summary, setSummary] = useState(null);
const [tab, setTab] = useState<'scan' | 'config'>('scan');
const load = useCallback(async () => {
try {
setSummary(await api.get('/api/staff/summary'));
} catch {
/* résumé indicatif : on garde l'ancien */
}
}, []);
useFocusEffect(
useCallback(() => {
load();
}, [load]),
);
const isManager = me?.role === 'MANAGER';
const u = unit(store.design.pointsMode);
return (
{isManager && (
{(
[
['scan', 'Scan'],
['config', 'Configuration'],
] as const
).map(([k, label]) => (
setTab(k)}
style={{ flex: 1, paddingVertical: 10, borderRadius: 10, alignItems: 'center', backgroundColor: tab === k ? c.primary : 'transparent' }}
>
{label}
))}
)}
{tab === 'config' && isManager ? (
) : (
<>
{greeting()} {me?.displayName.split(' ')[0]} 👋
{/* Action principale */}
router.push('/scan')}
style={({ pressed }) => ({
backgroundColor: pressed ? c.primaryPressed : c.primary,
borderRadius: 26,
paddingVertical: 40,
paddingHorizontal: 24,
alignItems: 'center',
gap: 14,
shadowColor: c.primary,
shadowOpacity: 0.35,
shadowRadius: 16,
shadowOffset: { width: 0, height: 8 },
elevation: 6,
})}
>
Scanner une carte
QR code du Wallet du client
{/* Chiffres du jour */}
{isManager ? "Aujourd'hui au magasin" : "Mes opérations aujourd'hui"}
{[
['🧾', summary?.operations ?? '—', 'opérations'],
['➕', summary?.pointsGiven ?? '—', `${u} donnés`],
['🎁', summary?.rewards ?? '—', 'récompenses'],
].map(([icon, n, l]) => (
{icon}
{n}
{l}
))}
{/* Autres actions */}
{isManager && router.push('/campaigns')} />}
{isManager && router.push('/stats')} />}
router.push('/history')} />
>
)}
);
}
/** Onglet Configuration (Dirigeant) : tout ce qui se règle. */
function ConfigTab() {
const c = useColors();
return (
Fidélisation
router.push('/loyalty')} />
Linking.openURL(ESPACE_URL)} />
Équipe et compte
router.push('/team')} />
router.push('/account')} />
);
}