import Taro from "@tarojs/taro";
import { createSlice } from "@reduxjs/toolkit";

const navigationReducer = createSlice({
  name: "navigation", // store的名字
  initialState: {
    background: "#fff",
  },
  reducers: {
    setColor(state, { payload }) {
      state.background = payload;

      Taro.setNavigationBarColor({
        frontColor: "#ffffff",
        backgroundColor: state.background,
        animation: {
          duration: 600,
          timingFunc: "easeIn",
        },
      });
    },
    resetColor(state) {
      state.background = "#fff";
      Taro.setNavigationBarColor({
        frontColor: "#000000",
        backgroundColor: "#ffffff",
        animation: {
          duration: 600,
          timingFunc: "easeIn",
        },
      });
    },
  },
});

export const { setColor, resetColor } = navigationReducer.actions;
export default navigationReducer.reducer;
