import { useEffect, useRef } from "react";
import {
Animated,
Dimensions,
Easing,
Modal,
Pressable,
Text,
View,
} from "react-native";
import { SafeAreaView } from "react-native-safe-area-context";
import { useAuthStore } from "@/stores/auth-store";
const SCREEN_WIDTH = Dimensions.get("window").width;
const DRAWER_WIDTH = Math.min(320, Math.round(SCREEN_WIDTH * 0.82));
const ANIM_MS = 220;
interface DrawerProps {
open: boolean;
onClose: () => void;
onNavigateAccount: () => void;
onNavigateSettings: () => void;
}
export function Drawer({
open,
onClose,
onNavigateAccount,
onNavigateSettings,
}: DrawerProps) {
const translateX = useRef(new Animated.Value(-DRAWER_WIDTH)).current;
const backdropOpacity = useRef(new Animated.Value(0)).current;
useEffect(() => {
Animated.parallel([
Animated.timing(translateX, {
toValue: open ? 0 : -DRAWER_WIDTH,
duration: ANIM_MS,
easing: Easing.out(Easing.cubic),
useNativeDriver: true,
}),
Animated.timing(backdropOpacity, {
toValue: open ? 0.4 : 0,
duration: ANIM_MS,
easing: Easing.out(Easing.cubic),
useNativeDriver: true,
}),
]).start();
}, [open, translateX, backdropOpacity]);
const user = useAuthStore((s) => s.user);
const signOut = useAuthStore((s) => s.signOut);
const isSigningOut = useAuthStore((s) => s.isSigningOut);
const initials = user?.email_prefix.slice(0, 2).toUpperCase() ?? "??";
return (
{initials}
{user?.email_prefix ?? ""}
{user?.email ?? ""}
{
onClose();
onNavigateAccount();
}}
/>
{
onClose();
onNavigateSettings();
}}
/>
{
void signOut();
}}
tone="destructive"
/>
);
}
function DrawerRow({
label,
onPress,
disabled,
tone = "default",
}: {
label: string;
onPress: () => void;
disabled?: boolean;
tone?: "default" | "destructive";
}) {
return (
{label}
);
}