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 { menusPropTypes } from '../../constants/components/prop-types/menu';
import { CLASSIC_LAYOUT, NEWSLETTER_SOCIAL_LAYOUT, SITEMAP_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 FooterSiteMap from './atoms/layout/footer-sitemap/FooterSiteMap';
import FooterFeatureBar from './atoms/layout/footer-feature-bar/FooterFeatureBar';
import { MENUS } from '../../constants/menus';

const n = createNamespace('Footer');

const FOOTER_LAYOUT_COMPONENT = {
    [CLASSIC_LAYOUT]: FooterClassic,
    [NEWSLETTER_SOCIAL_LAYOUT]: FooterNewsletterSocial,
    [SITEMAP_LAYOUT]: FooterSiteMap,
    [FEATURE_BAR_LAYOUT]: FooterFeatureBar
};
export const FooterComponent = ({
    data,
    settings,
    menus
}) => {
    const { layout: footerLayout } = settings;
    if (!footerLayout) {
        return null;
    }
    const componentVariables = getComponentVariables(settings);
    const FooterLayoutComponent = FOOTER_LAYOUT_COMPONENT[footerLayout];
    return (
        <div {...n('wrapper').withVariables(componentVariables).withTestId().props}>
            <FooterLayoutComponent {...{ data, settings, menus }} />
        </div>
    );
};

FooterComponent.schema = () => ({
    name: 'Footer',
    form: footerSchemaForm,
    title: 'uieditor.sfbComponent.footer.title',
    iconName: 'footer',
    menus: [MENUS.FOOTER_MENU, MENUS.BOTTOM_BAR_MENU],
    marketplaceData: {
        locale: 'config.locale',
        logo: 'config.logo',
        marketplaceName: 'config.marketplaceName',
        pageId: 'config.pageId',
        links: 'common.links',
        support: 'config.channelSettings.support',
        termsAndConditionsUrl: 'config.channelSettings.termsUrl',
        privacyPolicyUrl: 'config.channelSettings.privacyPolicyUrl'
    }
});

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

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

export default withListener(FooterComponent);
