/* eslint-disable camelcase */
import React from 'react';
import PropTypes from 'prop-types';
import { FaArrowRight } from '@react-icons/all-files/fa/FaArrowRight';
import { imagePrettyUrl } from '~helpers/getters';
import LazyImage from '~hooks/lazy-image';
import BonusBox from '~molecules/bonus-box/template-four';
import OperatorCta from '~atoms/button/operator-cta';
import Rating from '~molecules/star-rating/one-star';
import Tnc from '~molecules/tnc';
import PrettyLink from '~atoms/pretty-link';
import styles from './bonus.module.scss';

export default function Bonus({
  operator,
  pageTemplate,
  module = {
    name: 'bonus',
  },
  tncEnable = true,
  tncFixed = false,
}) {
  const { standardised_logo_url, logo_url, bonus, name } = operator || {};
  const logo = standardised_logo_url || logo_url;

  const showTncFixed = tncEnable && tncFixed;

  return (
    <div
      className={`${styles.operatorBanner || ''} ${tncEnable ? styles.tncEnable : ''} ${
        showTncFixed ? styles.showTncFixed || '' : ''
      }`}
    >
      <div className={styles.container}>
        <div>
          <PrettyLink
            operator={operator}
            pageTemplate={pageTemplate}
            module={module.name}
            tracker={module?.tracking_link_name || 'main'}
            clickedElement="oneliner"
            className={`${styles.logo || ''} operator-banner-gtm logo-cta`}
          >
            <LazyImage alt={operator?.name} src={imagePrettyUrl(logo)} height={120} width={100} />
            <div className={styles.details}>
              {name && <span>{name}</span>}
              {bonus?.rating && <Rating rating={bonus?.rating} showDecimal />}
            </div>
          </PrettyLink>
          <div className={styles.bonus || ''}>
            <BonusBox item={operator} module="bonus" tracker={module?.type || 'main'} />
            {tncEnable && !tncFixed && <Tnc hasCollapse={false} operator={operator} />}
          </div>
        </div>

        <OperatorCta
          operator={operator}
          pageTemplate={pageTemplate}
          tracker={module?.tracking_link_name || 'main'}
          module={module.name}
          icon={<FaArrowRight fontSize={20} title="Right-pointing Arrow Icon" />}
        />
        {showTncFixed && <Tnc hasCollapse={false} operator={operator} />}
      </div>
    </div>
  );
}

Bonus.propTypes = {
  operator: PropTypes.shape({
    standardised_logo_url: PropTypes.string,
    logo: PropTypes.string,
    logo_url: PropTypes.string,
    bonus: PropTypes.shape({
      rating: PropTypes.string,
    }),
    name: PropTypes.string,
    rating: PropTypes.string,
    url: PropTypes.string,
    extra_fields: PropTypes.shape({
      terms_and_conditions_text_enabled: PropTypes.string,
    }),
    status: PropTypes.string,
  }),
  tncFixed: PropTypes.bool,
  tncEnable: PropTypes.bool,
  pageTemplate: PropTypes.string,
  module: PropTypes.shape({
    tracking_link_name: PropTypes.string,
    type: PropTypes.string,
    name: PropTypes.string,
  }),
};
