import React from 'react';
import PropTypes from 'prop-types';
import { createNamespace } from '../../../../../tools/namingTools';
import { useResponsive } from '../../../../../tools/widths/useResponsive';
import { RIGHT } from '../../../../../constants/alignment';
import { hasSocialNetworks, hasLogo, hasNavigationBar } from '../../../../../tools/footerHelpers';
import { footerDataPropTypes, footerSettingsPropTypes } from '../../../../../constants/components/prop-types/footer';
import FooterLogo from '../../common/footer-logo/FooterLogo';
import FooterNavigation from '../../common/footer-navigation/FooterNavigation';
import FooterSocials from '../../common/footer-socials/FooterSocials';
import FooterCopyright from '../../common/footer-copyright/FooterCopyright';

import './styles/FooterClassic.scss';

const n = createNamespace('FooterClassic');

const FooterClassic = ({
    data: {
        logo,
        locale,
        marketplaceName,
        i18n
    },
    settings
}) => {
    const { xxLargeUp } = useResponsive();

    const {
        socials,
        copyright,
        navigation,
        displayLanguageSwitcher,
        displayNavSeparator,
        displayLogo,
        displaySocialMedia,
        displayDefaultSocialIcons
    } = settings;

    const showNavigation = hasNavigationBar(navigation, locale);
    const showSocials = displaySocialMedia && hasSocialNetworks(socials);
    const showLogo = displayLogo && hasLogo(logo);

    const renderSocialBlock = () => {
        const props = {
            ...socials,
            ...{
                i18n,
                showTitle: false,
                showCustomIcon: !displayDefaultSocialIcons,
                iconAlign: xxLargeUp ? RIGHT.value : null
            }
        };

        return (
            <div {...n('socials').props}>
                <FooterSocials {...props} />
            </div>
        );
    };

    const renderNavigationBlock = () => {
        const props = {
            i18n,
            locale,
            navigation,
            withSeparator: displayNavSeparator,
            withLanguageSwitcher: displayLanguageSwitcher
        };

        return (
            <div {...n('nav').props}>
                <FooterNavigation {...props} />
            </div>
        );
    };

    const renderLogoBlock = () => (
        <div {...n('logo').props}>
            <FooterLogo src={logo} url="/" alt={marketplaceName} />
        </div>
    );

    const renderCopyrightBlock = () => (
        <div {...n('copyright').props}>
            <FooterCopyright text={copyright} />
        </div>
    );

    return (
        <div {...n('wrapper').withTestId().props}>
            {(showLogo || showNavigation || showSocials) && (
                <div {...n('section', 'top').props}>
                    <div {...n('row').props}>
                        {showLogo && (
                            <div {...n('col', 'logo').props}>
                                {showLogo && renderLogoBlock()}
                            </div>
                        )}
                        {showNavigation && (
                            <div {...n('col', 'nav').props}>
                                {showNavigation && renderNavigationBlock()}
                            </div>
                        )}
                        {showSocials && (
                            <div {...n('col', ['socials', socials.items.length > 4 && 'large']).props}>
                                {showSocials && renderSocialBlock()}
                            </div>
                        )}
                    </div>
                    {copyright && renderCopyrightBlock()}
                </div>

            )}
        </div>
    );
};

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

FooterClassic.defaultProps = {
    data: {},
    settings: {}
};

export default FooterClassic;
