import { ref } from 'vue' import api from '../axios.js' export function useWaitlist() { const loading = ref(false) const success = ref(false) const error = ref(null) async function submit(name, email, source = null) { loading.value = true error.value = null try { await api.post('/waitlist', { name, email, source, referrer: document.referrer || null, }) success.value = true } catch (e) { const fieldErrors = e.response?.data?.errors error.value = fieldErrors ? Object.values(fieldErrors)[0][0] : (e.response?.data?.message || 'Something went wrong — please try again.') } finally { loading.value = false } } return { loading, success, error, submit } }