import React from 'react';
import PropTypes from 'prop-types';
import withListener from '../withListener';
import { createNamespace } from '../../tools/namingTools';
import { getComponentVariables } from '../../tools/footerHelpers';
import { footerSchemaForm } from '../../constants/components/schemas/footer';
import { footerDataPropTypes, footerSettingsPropTypes } from '../../constants/components/prop-types/footer';
import { CLASSIC_LAYOUT, NEWSLETTER_SOCIAL_LAYOUT, BOTTOM_BAR_LAYOUT, FEATURE_BAR_LAYOUT } from '../../constants/components/footer';
import FooterClassic from './atoms/layout/footer-classic/FooterClassic';
import FooterNewsletterSocial from './atoms/layout/footer-newsletter-social/FooterNewsletterSocial';
import FooterBottomBar from './atoms/layout/footer-bottom-bar/FooterBottomBar';
import FooterFeatureBar from './atoms/layout/footer-feature-bar/FooterFeatureBar';

const n = createNamespace('Footer');

const FOOTER_LAYOUT_COMPONENT = {
    [CLASSIC_LAYOUT]: FooterClassic,
    [NEWSLETTER_SOCIAL_LAYOUT]: FooterNewsletterSocial,
    [BOTTOM_BAR_LAYOUT]: FooterBottomBar,
    [FEATURE_BAR_LAYOUT]: FooterFeatureBar
};

export const FooterComponent = ({
    data,
    settings
}) => {
    const componentVariables = getComponentVariables(settings);
    const FooterLayoutComponent = FOOTER_LAYOUT_COMPONENT[settings.layout];

    return (
        <div {...n('wrapper').withVariables(componentVariables).withTestId().props}>
            <FooterLayoutComponent {...{ data, settings }} />
        </div>
    );
};

FooterComponent.schema = () => ({
    name: 'Footer',
    form: footerSchemaForm,
    marketplaceData: {
        locale: 'config.locale',
        logo: 'config.logo',
        marketplaceName: 'config.marketplaceName'
    }
});

FooterComponent.propTypes = {
    data: PropTypes.shape(footerDataPropTypes),
    settings: PropTypes.shape(footerSettingsPropTypes)
};

FooterComponent.defaultProps = {
    data: {},
    settings: {
        layout: CLASSIC_LAYOUT,
        displayLogo: true
    }
};

export default withListener(FooterComponent);
