import { connect } from 'react-redux';
import { StoreState } from 'store/rootReducer';

import generic from 'store/generic';
import genericApollo from 'store/genericApollo';
import Listing, { ListingProps } from './Listing';

const mapStateToProps = (state: StoreState): Record<string, any> => ({
  list: state.generic.list,
  detail: state.generic.detail,
  lg: state.content.lg,
});

const mapDispatchToProps = {
  load: generic.actions.list.request.action,
  loadApollo: genericApollo.actions.list.request.action,
  loadMore: generic.actions.listMore.request.action,
  loadMoreApollo: genericApollo.actions.listMore.request.action,

  search: generic.actions.list.request.action,

  resetHistory: generic.actions.history.reset.action,
  pushHistory: generic.actions.history.push.action,
  exportList: generic.actions.export.request.action,
  resetDetail: generic.actions.detail.reset.action,
};

const Wrapped = connect<ListingProps>(mapStateToProps, mapDispatchToProps)(Listing);

export default Wrapped;
