import React from 'react';
import { connect } from 'react-redux';
import { compose } from 'redux';
import { createStructuredSelector } from 'reselect';
import { withReducer } from '../../app/core/with-reducer';
import { fp as _ } from '../../common/utils/fp';
import { CarouselWelcome } from '../components/carousel-welcome';
import reducer, { ACTION } from '../reducer';
import { makeChangelogSelector, makeLoadingSelector } from '../selectors';
import { withErrorBoundary } from '../../common/hoc/with-error-boundary';
import { TState, TStepsEntity, TWelcomeRootState } from '../types';
import { MODULE_NAME } from '../constants';

type TStructured = {
  loading: TState['loading'];
  entity: TStepsEntity;
};

type TConnected = {
  complete: () => void;
} & TStructured;

type TPropsExternal = {};

const mapStateToProps = createStructuredSelector<
  TWelcomeRootState,
  TStructured
>({
  loading: makeLoadingSelector(),
  entity: makeChangelogSelector(),
  //†prop
});
const mapDispatchToProps = {
  getData: ACTION.getChangelog,
  complete: ACTION.completeChangelog,
  //†action
};

const Connected: React.FC<TConnected> = props => {
  return <CarouselWelcome {...props} variant="changelog" />;
};

export default compose(
  _.hoistStatics(CarouselWelcome),
  withReducer(MODULE_NAME, reducer),
  withErrorBoundary(MODULE_NAME),
  connect(
    mapStateToProps,
    mapDispatchToProps
  )
)(Connected) as React.FC<TPropsExternal>;
