import { defineStore } from 'pinia';
import axios from "axios";

export const useAuthStore = defineStore('auth', {
  state: () => ({
    user: null,
    token: null,
  }),

  actions: {
    async register(name, email, birth_date, phone, password) {
      try {
        const data = await axios.post(
            `${import.meta.env.VITE_API_URL}/users/`,
            {
                name, 
                email, 
                birth_date, 
                phone, 
                password
            },
            {
                headers: {
                  accept: "application/json",
                  "Content-Type": "application/json",
                },
            }
        
        );
      } catch (error) {
        console.error("Register failed:", error.message);
        throw new Error("Register failed. Check your data.");
      }
    },
  },
});
