import { Map, fromJS, List } from "immutable";

export function showState(
  state = Map(
    fromJS({
      loading: true,
    })
  ),
  action
) {
  // 框架在初始化state的值时，action默认带一个type小于1的随机值(即：action={type: 0.12354556435634})，这里判断小于1时返回默认值
  if (action.type && action.type < 1) return state;
  state = state.sf(["loading"], action);
  return state;
}
//日期
export function SelectData(state = List(), action) {
  if (action.type && action.type < 1) return state;
  state = List(fromJS(action));
  return state;
}
var defalutCard = [
  { cardName: "home-init", cardWidth: "49%", display: "block" },
  { cardName: "home-account", cardWidth: "49%", display: "block" },
  { cardName: "home-voucher", cardWidth: "49%", display: "block" },
  { cardName: "home-invoice", cardWidth: "49%", display: "block" },
  { cardName: "home-condition", cardWidth: "49%", display: "block" },
  { cardName: "home-receive", cardWidth: "49%", display: "block" },
];
export function cardShow(state = List(defalutCard), action) {
  let index;
  let arr = [];
  if (action.type && action.type < 1) return state;
  switch (action.type) {
    case "big":
      state = state.toJS();
      state = state.map((item, index) => {
        if (item.cardName === action.data.cardName) {
          item.display = "block";
          item.cardWidth = "100%";
        } else {
          item.display = "none";
        }
        arr.push(item);
      });
      state = List(fromJS(arr));
      return state;
    case "small":
      state = state.toJS();
      state = state.map((item, index) => {
        if (item.cardWidth === "100%") {
          item.cardWidth = "49%";
        }
        item.display = "block";
        arr.push(item);
      });
      state = List(fromJS(arr));
      return state;
    default:
      state = List(fromJS(action.data));
      return state;
  }
}
