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

import Manage, { StateProps, DispatchProps, OwnProps } from './Manage';

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

const mapDispatchToProps = {
  dialogShow: app.actions.dialog.show.action,
  load: generic.actions.detail.request.action,

  resetList: generic.actions.list.reset.action,
  add: generic.actions.add.request.action,
  addApollo: genericApollo.actions.add.request.action,
  updateApollo: genericApollo.actions.update.request.action,

  loadApollo: genericApollo.actions.detail.request.action,

  update: generic.actions.update.request.action,
  reset: generic.actions.detail.reset.action,
  genericAction: generic.actions.genericAction.request.action,
  pushHistory: generic.actions.history.push.action,
};

const Wrapped = connect<StateProps, DispatchProps, OwnProps>(
  mapStateToProps,
  mapDispatchToProps,
)(Manage);

export default Wrapped;
