interface UserProfile { home_airports: string[] default_adults: number default_children: number default_infants: number locale: string show_origin_time: boolean } export function useUserPreferences() { const user = useSupabaseUser() const profile = useState('user-profile', () => null) const loading = useState('user-profile-loading', () => false) let fetchPromise: Promise | null = null async function fetchProfile() { if (!user.value) return if (fetchPromise) return fetchPromise loading.value = true fetchPromise = (async () => { try { const data = await $fetch('/api/profile') profile.value = data } catch { profile.value = null } finally { loading.value = false fetchPromise = null } })() return fetchPromise } async function updateProfile(updates: Partial) { if (!user.value) return try { const data = await $fetch('/api/profile', { method: 'PATCH', body: updates }) profile.value = data } catch { // silent } } const homeAirports = computed(() => profile.value?.home_airports ?? []) const defaultPassengers = computed(() => ({ adult: profile.value?.default_adults ?? 1, child: profile.value?.default_children ?? 0, infant: profile.value?.default_infants ?? 0 })) watch(user, (u) => { if (u) fetchProfile() else profile.value = null }, { immediate: true }) return { profile, loading, homeAirports, defaultPassengers, fetchProfile, updateProfile } }