import React, { Component } from 'react';
import { ContentManagementSystem } from '@brandingbrand/fsengage';
export function withCMSProvider(WrappedComponent) {
    return class CommerceProvider extends Component {
        constructor(props) {
            super(props);
            this.fetchData = () => {
                const { cmsProviderManagementConfig, cmsProviderGroup, cmsProviderSlot, cmsProviderIdentifier } = this.props;
                const CMS = new ContentManagementSystem(cmsProviderManagementConfig);
                CMS.contentForSlot(cmsProviderGroup, cmsProviderSlot, cmsProviderIdentifier)
                    .then(data => {
                    this.setState({
                        cmsData: data
                    });
                })
                    .catch(error => {
                    console.warn(`Error fetching content for slot ${cmsProviderGroup}, ` +
                        `${cmsProviderSlot}, ${cmsProviderIdentifier}`, error);
                });
            };
            this.state = {
                cmsData: null
            };
        }
        componentDidMount() {
            this.fetchData();
        }
        render() {
            return (<WrappedComponent {...this.props} {...this.state}/>);
        }
    };
}
//# sourceMappingURL=CMSProvider.js.map