/* eslint-disable import/prefer-default-export */
import { Element } from 'react';
import PropTypes from 'prop-types';

export const breakpointSmall = 380;
export const breakpointMedium = 600;
export const breakpointLarge = 960;
export const breakpointXLarge = 1088;

export const urls = {
  economist: 'https://www.economist.com',
  weeklyEdition: 'https://www.economist.com/weeklyedition',
  search: 'https://www.economist.com/search',
  theWorldInBrief: 'https://www.economist.com/the-world-in-brief',
  subscribe: 'https://subscription.economist.com/DE/EngCore/Ecom/Masthead',
  subscribeFooter: 'https://subscribenow.economist.com',
  myEconomist: 'https://my.economist.com',
  cookiePolicy:
    'https://www.economistgroup.com/results_and_governance/governance/Cookies_information.html',
};

/**
 * URLs can be overwritten as props in some components.
 * The object should only accept valid keys, as defined in urls
 */
export const urlsPropShape = PropTypes.shape(
  Object.keys(urls).reduce(
    (shape, key) => ({
      ...shape,
      [key]: PropTypes.string,
    }),
    {},
  ),
);

export const accountData = {
  'account-logged-in': [
    {
      name: 'My Economist',
      url: '/my-economist',
    },
    {
      name: 'Saved stories',
      url: '/saved-stories',
    },
    {
      name: 'Admin account',
      url: '',
    },
    {
      name: 'My subscription',
      url: '',
    },
    {
      name: 'Personal information',
      url: '',
    },
    {
      name: 'Billing',
      url: '',
    },
    {
      name: 'Newsletters & preferences',
      url: '',
    },
    {
      name: 'Gift subscriptions',
      url: '',
    },
    {
      name: 'Help',
      url: '',
    },
    {
      name: 'Log out',
      url: '',
    },
  ],
  'account-logged-in-main': [
    {
      name: 'Saved stories',
      url: '/saved-stories',
    },
    {
      name: 'Admin account',
      url: '',
    },
    {
      name: 'Account',
      url: '/my-economist',
    },
    {
      name: 'Log out',
      url: '',
    },
  ],
  'account-logged-out': [
    {
      name: 'Log in',
      url: '',
    },
  ],
  'subscriber-exlusives': [
    {
      name: 'Podcasts',
      url: '/audio/podcasts',
    },
    {
      name: 'Newsletters',
      url: '/newsletters',
    },
    {
      name: 'Video',
      url: '/video',
    },
    {
      name: 'Insider',
      url: '/insider',
    },
    {
      name: 'The Economist app',
      url: '/get-the-app',
    },
  ],
};

export const clientAdminData = {
  name: 'My group subscription',
  url: '',
};

// We temporarily store navigation list data here, eventually
// this should be provided by the content platform.
export const getNavigationListData = (baseUrl = urls.economist) => ({
  account: [
    {
      name: 'Manage my account',
      url: 'https://my.economist.com',
    },
    {
      name: 'Log out',
      url: '',
    },
  ],
  opinion: [
    {
      name: 'Leaders',
      url: `${baseUrl}/leaders`,
    },
    {
      name: 'Letters to the editor',
      url: `${baseUrl}/letters`,
    },
    {
      name: 'By Invitation',
      url: `${baseUrl}/by-invitation`,
    },
  ],
  'current-topics': [
    {
      name: 'War in the Middle East',
      url: `${baseUrl}/topics/war-in-the-middle-east`,
    },
    {
      name: 'War in Ukraine',
      url: `${baseUrl}/topics/ukraine-at-war`,
    },
    {
      name: 'The World Ahead 2026',
      url: `${baseUrl}/topics/the-world-ahead-2026`,
    },
    {
      name: 'Climate change',
      url: `${baseUrl}/topics/climate-change`,
    },
    { name: 'Geopolitics', url: `${baseUrl}/topics/geopolitics` },
    {
      name: 'The world economy',
      url: `${baseUrl}/topics/economy`,
    },
    {
      name: 'Artificial intelligence',
      url: `${baseUrl}/topics/artificial-intelligence`,
    },
  ],
  world: [
    {
      name: 'The world this week',
      url: `${baseUrl}/the-world-this-week`,
    },
    {
      name: 'China',
      url: `${baseUrl}/topics/china`,
    },
    {
      name: 'United States',
      url: `${baseUrl}/topics/united-states`,
    },
    {
      name: 'Europe',
      url: `${baseUrl}/europe`,
    },
    {
      name: 'Britain',
      url: `${baseUrl}/topics/britain`,
    },
    {
      name: 'Middle East & Africa',
      url: `${baseUrl}/middle-east-and-africa`,
    },
    {
      name: 'Asia',
      url: `${baseUrl}/asia`,
    },
    {
      name: 'The Americas',
      url: `${baseUrl}/the-americas`,
    },
    {
      name: 'International',
      url: `${baseUrl}/international`,
    },
    {
      name: 'A-Z of international relations',
      url: `${baseUrl}/international-relations-a-to-z`,
    },
    {
      name: 'A-Z of military terms',
      url: `${baseUrl}/military-terms-a-to-z`,
    },
    {
      name: 'A-Z of US politics',
      url: `${baseUrl}/interactive/us-politics-glossary-election-terms`,
    },
    {
      name: 'US presidential tracker',
      url: `${baseUrl}/interactive/trump-approval-tracker`,
    },
  ],
  'in-depth': [
    {
      name: 'Science & technology',
      url: `${baseUrl}/science-and-technology`,
    },
    {
      name: 'Briefing',
      url: `${baseUrl}/briefing`,
    },
    {
      name: 'Graphic detail',
      url: `${baseUrl}/graphic-detail`,
    },
    {
      name: 'The Economist explains',
      url: `${baseUrl}/the-economist-explains`,
    },
    {
      name: 'Special reports',
      url: `${baseUrl}/special-reports`,
    },
    {
      name: 'Technology Quarterly',
      url: `${baseUrl}/technology-quarterly`,
    },
    {
      name: 'Essay',
      url: `${baseUrl}/essay`,
    },
    {
      name: 'Schools brief',
      url: `${baseUrl}/schools-brief`,
    },
  ],
  'business-and-economics': [
    {
      name: 'Finance & economics',
      url: `${baseUrl}/finance-and-economics`,
    },
    {
      name: 'Business',
      url: `${baseUrl}/business`,
    },
    {
      name: 'Big Mac index',
      url: `${baseUrl}/big-mac-index`,
    },
    {
      name: 'A-Z of economics',
      url: `${baseUrl}/economics-a-to-z`,
    },
    {
      name: 'Economic & financial indicators',
      url: `${baseUrl}/economic-and-financial-indicators`,
    },
  ],
  'culture-and-society': [
    {
      name: '1843 magazine',
      url: `${baseUrl}/1843`,
    },
    {
      name: 'Culture',
      url: `${baseUrl}/culture`,
    },
    {
      name: 'Obituary',
      url: `${baseUrl}/obituary`,
    },
    {
      name: 'The Economist reads',
      url: `${baseUrl}/the-economist-reads`,
    },
    {
      name: 'Christmas Specials',
      url: `${baseUrl}/christmas-specials`,
    },
  ],
  more: [
    {
      name: 'Podcasts',
      url: `${baseUrl}/audio/podcasts`,
    },
    {
      name: 'Newsletters',
      url: `${baseUrl}/newsletters`,
    },
    {
      name: 'Video',
      url: `${baseUrl}/video`,
    },
    {
      name: 'The Economist app',
      url: `${baseUrl}/get-the-app`,
    },
    {
      name: 'SecureDrop',
      url: `${baseUrl}/securedrop/`,
    },
    {
      name: 'Insider',
      url: `${baseUrl}/insider`,
    },
    {
      name: 'Economist Education courses',
      url: 'https://education.economist.com/',
    },
    {
      name: 'Economist Enterprise',
      url: `${baseUrl}/enterprise/`,
    },
  ],
});

export const REGIONS = {
  GERMANY: 'DE',
  US: 'US',
};

export const getFooterData = ({
  baseUrl = urls.economist,
  amp = false,
} = {}) => ({
  customerLinks: [
    {
      name: 'Subscribe',
      url: `https://subscribenow.economist.com`,
    },
    {
      name: 'Economist Enterprise',
      url: `${baseUrl}/enterprise`,
    },
    {
      name: 'Reuse our content',
      url: `${baseUrl}/syndication`,
    },
    {
      name: 'Help and contact us',
      url: `https://myaccount.economist.com/s/help`,
    },
  ],
  economistGroupLinks: [
    { name: 'The Economist Group', url: 'https://www.economistgroup.com/' },
    { name: 'Economist Intelligence', url: 'https://www.eiu.com/n/' },
    {
      name: 'Economist Impact',
      url: 'https://impact.economist.com/',
    },
    {
      name: 'Economist Impact Events',
      url:
        'https://events.economist.com/?RefID=e.com-home&utm_source=e.com&utm_medium=website&utm_campaign=group-aff&utm_content=footer-link',
    },
    { name: 'Working here', url: 'https://www.economistgroup.com/careers' },
    {
      name: 'Economist Education Courses',
      url: 'https://education.economist.com',
    },
    { name: 'Executive Jobs', url: 'https://jobs.economist.com/' },
  ],
  minorLinks: [
    {
      id: 'footer-terms-of-use',
      name: 'Terms of Use',
      url: 'https://www.economistgroup.com/terms-of-use',
    },
    {
      id: 'footer-privacy',
      name: 'Privacy',
      url: 'https://www.economistgroup.com/privacy-policy',
    },
    {
      id: 'footer-cookie-policy',
      name: 'Cookie Policy',
      url: 'https://www.economistgroup.com/cookies-policy',
    },
    {
      id: 'footer-accessibility',
      name: 'Accessibility',
      url: 'https://www.economistgroup.com/accessibility-policy',
    },
    {
      id: 'footer-modern-slavery-statement',
      name: 'Modern Slavery Statement',
      url: 'https://www.economistgroup.com/esg/modern-slavery-act-statement',
    },
    {
      id: 'sitemap',
      name: 'Sitemap',
      url: 'https://www.economist.com/sitemap',
    },
    {
      id: 'footer-ccpa',
      name: 'Your Data Rights',
      url: 'https://www.economist.com/privacyportal',
    },
    {
      id: 'footer-cancel',
      name: 'Cancel subscription',
      url: 'https://subscribenow.economist.com/amend',
      allowedRegions: [REGIONS.GERMANY],
    },
  ].filter(item => typeof item.amp === 'undefined' || item.amp === amp),
  socialLinks: {
    FACEBOOK_LINK: 'https://www.facebook.com/theeconomist',
    INSTAGRAM_LINK: 'https://www.instagram.com/theeconomist',
    TWITTER_LINK: 'https://www.twitter.com/theeconomist',
    LINKEDIN_LINK: 'https://www.linkedin.com/company/the-economist',
    YOUTUBE_LINK: 'https://www.youtube.com/user/economistmagazine',
    RSS_LINK: 'https://www.economist.com/rss',
    THREADS_LINK: 'https://www.threads.net/@theeconomist',
    TIKTOK_LINK: 'https://www.tiktok.com/@theeconomist',
  },
  theEconomistLinks: [
    {
      name: 'About',
      url: 'https://www.economistgroup.com/about-us',
    },
    { name: 'Advertise', url: 'https://impact.economist.com/' },
    { name: 'Press centre', url: 'https://www.economistgroup.com/group-news' },
    { name: 'SecureDrop', url: 'https://www.economist.com/securedrop/' },
  ],
});

export const keyCodes = {
  TAB: 9,
  ESC: 27,
  SPACE: 32,
  ENTER: 13,
};

export const keyValues = {
  TAB: 'Tab',
  ESC: 'Escape',
};

export const reactElementPropType = PropTypes.oneOfType([
  PropTypes.object,
  PropTypes.shape({ current: PropTypes.instanceOf(Element) }),
]);
