import React from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { fetchCMS } from 'lib/redux/actions/cms-actions';


interface CMSI {
	status?,
	cms?,
	Component: React.ReactNode,
	fetchCMS?,
	endpoint: string,
	uniqueName?: string,
	id: string
}


const
	CMSComponent = ({ Component, cms, status, uniqueName, endpoint, fetchCMS, id }: CMSI) => {
		React.useEffect(() => {
			fetchCMS(endpoint, { uniqueName, id });
		}, []);

		// return <Component cms={cms} />;
	},
	mapStateToProps = state => state,
	mapDispatchToProps = dispatch => bindActionCreators({
		fetchCMS
	}, dispatch),
	CMS = connect(mapStateToProps, mapDispatchToProps)(CMSComponent);


export default CMS;


// interface OI {
// 	endpoint: string
// }
// 
// function cmsWrapper(Component, options: OI) {
// 
// 
// 	return <Component cms={cms} />
// }