import React, { useState } from 'react'; import { View, Text, TextInput, TouchableOpacity, StyleSheet, Alert, ActivityIndicator, KeyboardAvoidingView, Platform, ScrollView, SafeAreaView, } from 'react-native'; import { useRouter, Link } from 'expo-router'; import { User, Mail, Lock, Phone, ArrowLeft, CheckCircle } from 'lucide-react-native'; import { Colors } from '../Fluxup/src/constants/theme'; // import { supabase } from '../lib/supabase'; export default function RegisterScreen() { const router = useRouter(); const [username, setUsername] = useState(''); const [email, setEmail] = useState(''); const [phone, setPhone] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [loading, setLoading] = useState(false); async function handleRegister() { // 1. Validação simples antes de enviar if (password !== confirmPassword) { Alert.alert('Erro', 'As palavras-passe não coincidem.'); return; } if (username.length < 3) { Alert.alert('Erro', 'O nome de utilizador deve ter pelo menos 3 caracteres.'); return; } setLoading(true); // Simulação de registo setTimeout(() => { setLoading(false); Alert.alert('Sucesso', 'Conta criada com sucesso! A entrar...'); // em vez de voltar ao login, encaminhamos directamente para a tela inicial router.replace('/inicio' as any); }, 1500); /* LÓGICA REAL DO SUPABASE (Para depois): // 1. Criar utilizador na Auth const { data: authData, error: authError } = await supabase.auth.signUp({ email: email, password: password, }); if (authError) { Alert.alert('Erro', authError.message); setLoading(false); return; } // 2. Guardar dados extra na tabela 'profiles' if (authData.user) { const { error: profileError } = await supabase .from('profiles') .insert([{ id: authData.user.id, username: username, phone_number: phone, full_name: username, // Podes mudar isto depois updated_at: new Date(), }]); if (profileError) { Alert.alert('Aviso', 'Conta criada, mas houve um erro ao salvar o perfil.'); } else { Alert.alert('Sucesso', 'Verifica o teu email para confirmar a conta!'); router.replace('/inicio'); } } setLoading(false); */ } return ( {/* Botão Voltar */} router.back()} style={styles.backButton}> Fluxup Registar nova conta {/* Nome de Utilizador */} {/* Email */} {/* Telemóvel */} {/* Password */} {/* Confirmar Password */} 0 && password !== confirmPassword ? { borderColor: '#EF4444' } : {} ]}> {/* Ícone de verificação verde se as senhas baterem */} {password.length > 0 && password === confirmPassword && ( )} {loading ? ( ) : ( Registar )} Já tens conta? Entrar ); } const primary = Colors.light.tint; const styles = StyleSheet.create({ safe: { flex: 1, backgroundColor: Colors.light.background, }, container: { flex: 1, backgroundColor: Colors.light.background, }, scrollContent: { flexGrow: 1, padding: 24, justifyContent: 'center', }, backButton: { marginTop: 20, marginBottom: 20, }, header: { marginBottom: 30, alignItems: 'center', }, title: { fontSize: 32, fontWeight: 'bold', color: primary, marginBottom: 8, }, subtitle: { fontSize: 16, color: Colors.light.icon, }, form: { width: '100%', }, inputContainer: { flexDirection: 'row', alignItems: 'center', backgroundColor: '#fff', borderRadius: 12, paddingHorizontal: 16, height: 56, marginBottom: 16, borderWidth: 1, borderColor: '#E5E7EB', }, inputIcon: { marginRight: 12, }, input: { flex: 1, height: '100%', color: Colors.light.text, fontSize: 16, }, button: { backgroundColor: primary, height: 56, borderRadius: 12, justifyContent: 'center', alignItems: 'center', marginTop: 10, shadowColor: primary, shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.3, shadowRadius: 8, elevation: 4, }, buttonText: { color: '#fff', fontSize: 18, fontWeight: 'bold', }, footer: { flexDirection: 'row', justifyContent: 'center', marginTop: 24, marginBottom: 20, }, footerText: { color: Colors.light.icon, fontSize: 16, }, linkText: { color: primary, fontWeight: 'bold', fontSize: 16, }, });