import React, { useState } from 'react'; import { View, Text, TextInput, TouchableOpacity, StyleSheet, SafeAreaView, KeyboardAvoidingView, Platform, ScrollView, Alert, ActivityIndicator } from 'react-native'; import { Car, Music } from 'lucide-react-native'; import { colors } from '../../utils/colors'; import { supabase } from '../../services/supabase'; import { makeRedirectUri } from 'expo-auth-session'; import * as WebBrowser from 'expo-web-browser'; import * as QueryParams from 'expo-auth-session/build/QueryParams'; WebBrowser.maybeCompleteAuthSession(); // @ts-ignore export default function RegisterScreen({ navigation }) { const [name, setName] = useState(''); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [loading, setLoading] = useState(false); const handleRegister = async () => { if (!name || !email || !password || !confirmPassword) { Alert.alert('Erro', 'Por favor preenche todos os campos.'); return; } if (password !== confirmPassword) { Alert.alert('Erro', 'As passwords não coincidem.'); return; } setLoading(true); const { error } = await supabase.auth.signUp({ email, password, options: { data: { name: name, } } }); if (error) { Alert.alert('Erro no registo', error.message); } setLoading(false); }; const handleSpotifyAuth = async () => { try { const redirectUri = makeRedirectUri(); const { data, error } = await supabase.auth.signInWithOAuth({ provider: 'spotify', options: { redirectTo: redirectUri, }, }); if (error) throw error; if (data?.url) { const res = await WebBrowser.openAuthSessionAsync(data.url, redirectUri); if (res.type === 'success') { const { url } = res; const { params, errorCode } = QueryParams.getQueryParams(url); if (errorCode) throw new Error(errorCode); if (params.access_token && params.refresh_token) { await supabase.auth.setSession({ access_token: params.access_token, refresh_token: params.refresh_token, }); } } } } catch (err: any) { Alert.alert('Erro', err?.message || 'Ocorreu um erro no Spotify Auth.'); } }; return ( {/* Header Section */} Roadtrip DJ Cria a tua conta {/* Form Card */} {loading ? ( ) : ( Criar Conta )} {/* Note: Placeholder Spotify logo */} Registar com Spotify Já tens conta? navigation.navigate('Login')}> Entrar ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: colors.primary, }, keyboardView: { flex: 1, }, scrollContent: { flexGrow: 1, justifyContent: 'center', alignItems: 'center', paddingHorizontal: 20, paddingTop: 40, paddingBottom: 40, }, headerContainer: { alignItems: 'center', marginBottom: 30, }, iconWrapper: { position: 'relative', marginBottom: 20, width: 100, height: 100, alignItems: 'center', justifyContent: 'center', }, carIconContainer: { width: 80, height: 80, borderRadius: 40, backgroundColor: 'rgba(255, 255, 255, 0.2)', alignItems: 'center', justifyContent: 'center', }, musicIconContainer: { position: 'absolute', bottom: 5, right: 5, width: 32, height: 32, borderRadius: 16, backgroundColor: '#000000', alignItems: 'center', justifyContent: 'center', }, title: { fontSize: 32, fontWeight: '800', color: colors.white, marginBottom: 8, }, subtitle: { fontSize: 16, color: colors.white, fontWeight: '500', }, card: { backgroundColor: colors.white, width: '100%', borderRadius: 24, padding: 24, shadowColor: '#000', shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.1, shadowRadius: 12, elevation: 5, }, input: { backgroundColor: colors.inputBackground, borderRadius: 12, paddingHorizontal: 16, paddingVertical: 16, fontSize: 16, marginBottom: 16, color: colors.textMain, }, primaryButton: { backgroundColor: colors.primary, borderRadius: 12, paddingVertical: 16, alignItems: 'center', marginBottom: 16, }, primaryButtonText: { color: colors.white, fontSize: 16, fontWeight: 'bold', }, spotifyButton: { backgroundColor: colors.spotify, borderRadius: 12, paddingVertical: 16, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', marginBottom: 24, }, spotifyIcon: { marginRight: 8, }, spotifyButtonText: { color: colors.white, fontSize: 16, fontWeight: 'bold', }, footerContainer: { flexDirection: 'row', justifyContent: 'center', alignItems: 'center', }, footerText: { color: colors.textSecondary, fontSize: 14, }, footerLink: { color: colors.textMain, fontSize: 14, fontWeight: 'bold', }, });