import { connect } from 'react-redux';

import { withRouter } from 'react-router';
import app from 'store/app';
import { StoreState } from 'store/rootReducer';
import generic from 'store/generic';
import genericApollo from 'store/genericApollo';
import GenericValue, { GenericValueProps } from './GenericValue';

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

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,
  dialogShow: app.actions.dialog.show.action,
};

const Wrapped = connect<GenericValueProps>(mapStateToProps, mapDispatchToProps)(GenericValue);

export default withRouter(Wrapped);
