import { ReactNode } from 'react';
import { ActivityIndicator, Pressable, ScrollView, StyleSheet, Text, TextProps, View, ViewStyle } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import Svg, { Circle, Path } from 'react-native-svg';
import { font, useColors } from './theme';
/**
* Écran standard. `noHeader` : écran sans barre de titre, le contenu reste sous
* la Dynamic Island / l'encoche (marge haute de sécurité).
*/
export function Screen({ children, scroll = false, style, noHeader = false }: { children: ReactNode; scroll?: boolean; style?: ViewStyle; noHeader?: boolean }) {
const c = useColors();
const inner = {children};
return (
{scroll ? {inner} : inner}
);
}
type Variant = 'h1' | 'h2' | 'body' | 'label' | 'muted' | 'big';
export function T({ v = 'body', style, ...props }: TextProps & { v?: Variant }) {
const c = useColors();
const s = {
h1: { fontFamily: font.bold, fontSize: 28, lineHeight: 34, color: c.text },
h2: { fontFamily: font.bold, fontSize: 20, lineHeight: 26, color: c.text },
body: { fontFamily: font.regular, fontSize: 17, lineHeight: 24, color: c.text },
label: { fontFamily: font.semibold, fontSize: 15, lineHeight: 20, color: c.text },
muted: { fontFamily: font.regular, fontSize: 15, lineHeight: 21, color: c.text3 },
big: { fontFamily: font.extrabold, fontSize: 56, lineHeight: 62, color: c.text },
}[v];
return ;
}
export function Button({
label,
onPress,
variant = 'primary',
disabled,
loading,
icon,
large,
}: {
label: string;
onPress: () => void;
variant?: 'primary' | 'secondary' | 'danger';
disabled?: boolean;
loading?: boolean;
icon?: ReactNode;
large?: boolean;
}) {
const c = useColors();
const bg = { primary: c.primary, secondary: c.surface, danger: c.err }[variant];
const fg = variant === 'secondary' ? c.text : c.onPrimary;
return (
[
styles.btn,
{
backgroundColor: variant === 'primary' && pressed ? c.primaryPressed : bg,
borderColor: variant === 'secondary' ? c.border : bg,
minHeight: large ? 72 : 56,
opacity: disabled ? 0.5 : pressed && variant !== 'primary' ? 0.8 : 1,
},
]}
>
{loading ? (
) : (
<>
{icon}
{label}
>
)}
);
}
export function Card({ children, style }: { children: ReactNode; style?: ViewStyle }) {
const c = useColors();
return (
{children}
);
}
export function Banner({ tone, children }: { tone: 'error' | 'warn' | 'ok'; children: ReactNode }) {
const c = useColors();
const [bg, fg] = { error: [c.errBg, c.err], warn: [c.warnBg, c.warn], ok: [c.okBg, c.ok] }[tone];
return (
{children}
);
}
/** Symbole officiel MonEspacePro. */
export function BrandSymbol({ size = 32, arch }: { size?: number; arch?: string }) {
const c = useColors();
return (
);
}
export const euros = (cents: number) => (cents / 100).toLocaleString('fr-FR', { style: 'currency', currency: 'EUR' });
export function unit(mode: 'AMOUNT' | 'STAMP', n = 2) {
if (mode === 'STAMP') return n > 1 ? 'tampons' : 'tampon';
return n > 1 ? 'points' : 'point';
}
const styles = StyleSheet.create({
btn: { borderRadius: 16, borderWidth: 1, paddingHorizontal: 20, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 10 },
});