import { createSlice, type PayloadAction } from '@reduxjs/toolkit';

interface SignupState {
  email: string;
  phoneNumber: string;
  step: 'form' | 'otp' | 'complete';
}

const initialState: SignupState = {
  email: '',
  phoneNumber: '',
  step: 'form',
};

const signupSlice = createSlice({
  name: 'signup',
  initialState,
  reducers: {
    setSignupData(state, action: PayloadAction<{ email: string; phoneNumber: string }>) {
      state.email = action.payload.email;
      state.phoneNumber = action.payload.phoneNumber;
    },
    setSignupStep(state, action: PayloadAction<SignupState['step']>) {
      state.step = action.payload;
    },
    resetSignup() {
      return initialState;
    },
  },
});

export const { setSignupData, setSignupStep, resetSignup } = signupSlice.actions;
export const signupReducer = signupSlice.reducer;
