/* eslint-disable import/no-extraneous-dependencies */
import React from 'react';
import loadable from '@loadable/component';
import { getExtraField } from 'gatsby-core-theme/src/helpers/getters';

export const footerContent = (props) => {
  let ModuleComponent = null;

  switch (props.footerTemplate) {
    case 'template_two':
      ModuleComponent = loadable(() =>
        import('../../../../components/molecules/footer/variants/template-two')
      );
      return <ModuleComponent {...props} />;
    case 'template_three':
      ModuleComponent = loadable(() =>
        import('../../../../components/molecules/footer/variants/template-three')
      );
      return <ModuleComponent {...props} />;
    default:
      ModuleComponent = loadable(() =>
        import('../../../../components/molecules/footer/variants/template-one')
      );
      return <ModuleComponent {...props} />;
  }
};

const Footer = (props) => {
  const helpText = `
  <p>
    Gambling can be addictive, please play responsibly.
    <br />
    If you are a problem gambler, please visit this
    <a
      href="https://www.begambleaware.org/"
      target="_blank"
      rel="nofollow"
      class="footer-gtm"
    >
      website
    </a>
    in order to get help.
  </p>`;
  const phoneNum = '- 89 241 5401';

  const footerLogos = getExtraField(props.section?.extra_fields, 'logos');

  const getFooterLogos = () => {
    let refactoredFooterLogos = { children: [] };

    if (footerLogos === null) {
      refactoredFooterLogos = {
        children: [...props.page?.responsibleGaming],
      };
    } else {
      refactoredFooterLogos = {
        ...footerLogos,
        children: [...props.page?.responsibleGaming, ...footerLogos.children],
      };
    }

    return refactoredFooterLogos;
  };

  props = {
    ...props,
    showLinks: props.template !== 'ppc',
    copyrightDisclaimer: getExtraField(props.section?.extra_fields, 'copyright_disclaimer'),
    footerLogos: props.page?.responsibleGaming?.length ? getFooterLogos() : footerLogos,
    hasDisclaimer: true,
    showCopyright: true,
    footerMenu: getExtraField(props.section?.extra_fields, 'links'),
    asSeenOn: getExtraField(props.section?.extra_fields, 'as_seen_on'),
    gamblingText: getExtraField(props.section?.extra_fields, 'gambling_text'),
    socialIcons: getExtraField(props.section?.extra_fields, 'social_icons'),
    logo: '../../../../../images/logo.svg',
    dmcaImage: '../../../../../images/dmca.png',
    dmcaWidth: 100,
    dmcaHeight: 30,
    securityIcon: '../../../../../images/security.svg',
    helpText,
    phoneNum,
  };

  return footerContent(props);
};

export default Footer;
