import types from "../actions/types";

const initialState = {
    isPlaying: false,
    duration: 0,
    currentTime: 0,
    volume: 1,
    isRepeated: false,
    isShuffled: false,
    track: "",
    playlist: {},
};

const playerReducer = (state = initialState, action) => {
    switch (action.type) {
        case types.TOGGLE_PLAY:
            return { ...state, isPlaying: action.payload };

        case types.PLAY:
            return { ...state, isPlaying: true };

        case types.PAUSE:
            return { ...state, isPlaying: false };

        case types.SET_DURATION:
            return { ...state, duration: action.payload };

        case types.SET_CURRENT_TIME:
            return { ...state, currentTime: action.payload };

        case types.SET_VOLUME:
            return { ...state, volume: action.payload };

        case types.TOGGLE_REPEAT:
            return { ...state, isRepeated: action.payload };

        default:
            return state;
    }
};

export default playerReducer;
