import { reducers as listReducers } from './list';
import { reducers as searchReducers } from './search';

export { actions as listActions } from './list';
export { actions as searchActions } from './search';

export interface InteractionItem {
  id: number;
  name: string;
  pages: { id: number; name: string }[];
  published: 0 | 1; //0 未发布 1已发布
  uniqueTag: string;
  updatedAt: Date;
  createdAt: Date;
}

export interface InteractionListState {
  loading: boolean;
  createLoading: boolean;
  list: InteractionItem[];
  search: string;
  sortType: 'byCreatedAt' | 'byUpdatedAt';
}

const reducers = [listReducers, searchReducers];

const initialState = {
  loading: false,
  createLoading: false,
  list: [],
  search: '',
  sortType: 'byUpdatedAt'
};

export default function reducer(state = initialState, action) {
  let newState;
  switch (action.type) {
    default:
      newState = state;
      break;
  }
  return reducers.reduce((s, r) => r(s, action), newState);
}
