import { connect } from 'react-redux';
import { StoreState } from 'store/rootReducer';
import app from 'store/app';
import { isValid, isSubmitting, getFormValues } from 'redux-form';
import generic from 'store/generic';
import genericApollo from 'store/genericApollo';
import ResourceItem, { StateProps, DispatchProps, OwnProps } from './ResourceItem';

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

const mapDispatchToProps = {
  // load
  load: generic.actions.detail.request.action,
  loadApollo: genericApollo.actions.detail.request.action,
  // update
  update: generic.actions.update.request.action,
  updateApollo: genericApollo.actions.update.request.action,
  // delete
  deleteItem: generic.actions.delete.request.action,
  deleteApollo: genericApollo.actions.delete.request.action,
  // other
  dialogShow: app.actions.dialog.show.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,
)(ResourceItem);

export default Wrapped;
