import type { DrawerState } from '@/redux/drawer/drawer.types';
import type { DrawerName } from '@/types/drawerName';
import type { PayloadAction } from '@reduxjs/toolkit';

export const openDrawerReducer = (state: DrawerState, action: PayloadAction<DrawerName>): void => {
  state.isOpen = true;
  state.drawerName = action.payload;
};

export const closeDrawerReducer = (state: DrawerState): void => {
  state.isOpen = false;
};

export const setSearchDrawerStateReducer = (
  state: DrawerState,
  action: PayloadAction<DrawerState['searchDrawerState']>,
): void => {
  const { currentStep, selectedValue } = action.payload;

  state.searchDrawerState.currentStep = currentStep;
  state.searchDrawerState.selectedValue = selectedValue;
};

export const clearSearchDrawerStateReducer = (state: DrawerState): void => {
  state.searchDrawerState.currentStep = 0;
  state.searchDrawerState.selectedValue = {
    name: '',
    valueType: 'none',
  };
};