import { DEFAULT_TIMEZONE } from '@/lib/format-date';
import { type SharedData } from '@/types';
import { usePage } from '@inertiajs/react';

/**
 * Returns the current user's preferred timezone, falling back to Eastern
 * for guests or before the preference has been set.
 */
export function useUserTimezone(): string {
    const { auth } = usePage<SharedData>().props;

    return auth.user?.timezone ?? DEFAULT_TIMEZONE;
}
