import React from 'react';
import PropTypes from 'prop-types';
import FooterList from './footer-list';
import FooterCookieNotice from './footer-cookie-notice';
import {
  getFooterData,
  urlsPropShape,
  urls as defaultUrls,
} from '../../constants';
import 'reset-css/reset.css';
import '../color/color';
import '../grid/grid';
import '../media-queries/media-queries';
import '../typography/typography';
import css from './footer-secondary.css';

const FooterSecondary = ({ amp, subscribeUrl, region, overrideUrls }) => {
  const { customerLinks, minorLinks } = getFooterData({ amp });
  const currentYear = new Date().getFullYear();
  const urls = { ...defaultUrls, ...overrideUrls };

  // The "subscribe" link needs to be configurable by consumers. This is because
  // the URL is used to identify the source of a referral and the relevant team
  // create new URLs for new pages.
  const subscribeLink = customerLinks.find(link => link.name === 'Subscribe');
  /* subscribeUrl is deprecated. See prop documentation */
  subscribeLink.url = subscribeUrl || urls.subscribeFooter;

  return (
    <footer
      itemType='http://schema.org/WPFooter'
      className={css['ds-footer-secondary']}
      role='contentinfo'
    >
      <div className={`${css['ds-footer-secondary-cols-alpha']}`}>
        <div
          id='ds-footer-secondary-customer-links'
          className={css['ds-footer-secondary-cols-alpha__lead']}
        >
          <FooterList links={customerLinks} secondary major inverse />
        </div>
      </div>
      <FooterCookieNotice />
      <div className={css['ds-footer-secondary-cols-omega']}>
        <FooterList
          region={region}
          links={minorLinks}
          inverse
          secondary
          minor
        />
        <p
          id='ds-footer-secondary-copyright'
          className={css['ds-footer-secondary__copyright']}
        >
          Copyright &copy; The Economist Newspaper Limited {currentYear}. All
          rights reserved.
        </p>
      </div>
    </footer>
  );
};

FooterSecondary.defaultProps = {
  amp: false,
  overrideUrls: {},
  region: null,
  subscribeUrl: null,
};

FooterSecondary.propTypes = {
  amp: PropTypes.bool,
  /** any url that needs to be overriden in the default urls */
  overrideUrls: urlsPropShape,
  /**
   * deprecated: subscribeUrl should be passed in through the overrideUrls prop as overrideUrls.subscribe
   */
  subscribeUrl: PropTypes.string,
  region: PropTypes.string,
};

export default FooterSecondary;
