import { create } from "zustand";

interface OnboardingState {
  currentStep: number;
  path: "create" | "join" | null;
  residenceId: number | null;
  isComplete: boolean;
  nextStep: () => void;
  prevStep: () => void;
  setPath: (path: "create" | "join") => void;
  setResidenceId: (id: number) => void;
  complete: () => void;
  reset: () => void;
}

export const useOnboardingStore = create<OnboardingState>()((set) => ({
  currentStep: 0,
  path: null,
  residenceId: null,
  isComplete: false,
  nextStep: () => set((s) => ({ currentStep: s.currentStep + 1 })),
  prevStep: () => set((s) => ({ currentStep: Math.max(0, s.currentStep - 1) })),
  setPath: (path) => set({ path, currentStep: 2 }),
  setResidenceId: (id) => set({ residenceId: id }),
  complete: () => set({ isComplete: true }),
  reset: () =>
    set({ currentStep: 0, path: null, residenceId: null, isComplete: false }),
}));
