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

import app from 'store/app';
import generic from 'store/generic';
import genericApollo from 'store/genericApollo';

import Detail, { DetailProps } from './Detail';

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

const mapDispatchToProps = {
  dialogShow: app.actions.dialog.show.action,
  loadApollo: genericApollo.actions.detail.request.action,
  deleteApollo: genericApollo.actions.delete.request.action,

  update: generic.actions.update.request.action,
  add: generic.actions.add.request.action,
  reset: generic.actions.detail.reset.action,
  deleteItem: generic.actions.delete.request.action,
  pushHistory: generic.actions.history.push.action,
};

const Wrapped = connect<DetailProps>(mapStateToProps, mapDispatchToProps)(Detail);

export default Wrapped;
