// import { createSlice, PayloadAction } from "@reduxjs/toolkit";

// interface BookingState {
//   city: string | null;
// }

// const initialState: BookingState = {
//   city: null,
// };

// const bookingSlice = createSlice({
//   name: "booking",
//   initialState,
//   reducers: {
//     setCity(state, action: PayloadAction<string>) {
//       state.city = action.payload;
//     },
//     clearCity(state) {
//       state.city = null;
//     },
//   },
// });

// export const { setCity, clearCity } = bookingSlice.actions;
// export default bookingSlice.reducer;


import { createSlice, PayloadAction } from "@reduxjs/toolkit";

export type VehicleType = "bike" | "car" | null;

interface BookingState {
  city: string | null;
  vehicle: VehicleType;
}

const initialState: BookingState = {
  city: null,
  vehicle: null,
};

const bookingSlice = createSlice({
  name: "booking",
  initialState,
  reducers: {
    // ✅ CITY
    setCity(state, action: PayloadAction<string>) {
      state.city = action.payload;
    },
    clearCity(state) {
      state.city = null;

      // 🔥 ALSO reset vehicle when city changes
      state.vehicle = null;
    },

    // ✅ VEHICLE
    setVehicle(state, action: PayloadAction<"bike" | "car">) {
      state.vehicle = action.payload;
    },
    clearVehicle(state) {
      state.vehicle = null;
    },
  },
});

export const { setCity, clearCity, setVehicle, clearVehicle } =
  bookingSlice.actions;

export default bookingSlice.reducer;