/* eslint-disable import/no-extraneous-dependencies */
import React, { lazy, Suspense } from 'react';
import PropTypes from 'prop-types';
import { BiLike } from '@react-icons/all-files/bi/BiLike';
import { BiDislike } from '@react-icons/all-files/bi/BiDislike';
import { FaArrowRight } from '@react-icons/all-files/fa/FaArrowRight';
import ReviewLink from 'gatsby-core-theme/src/components/atoms/review-link';
import BonusTemplateDefault from 'gatsby-core-theme/src/components/molecules/bonus-box/template-three';
import OperatorCta from 'gatsby-core-theme/src/components/atoms/button/operator-cta';
import OperatorDetails from '../../../../molecules/operator-details';
import VariableComponent from '../variables';
import { TrackingKeys } from '~constants/tracking-api'
import styles from './template-three.module.scss';

const VerifyIcon = lazy(() => import('~images/icons/verify'));

const TemplateThree = ({
  showRibbon = false,
  item,
  useOneStarRating = true,
  page,
  showAuthor = true,
  verifyIcon = <Suspense fallback={<></>}><VerifyIcon /></Suspense>,
  showRatingLabel = false,
  showRatingDecimal = false,
  authorTemplateTwo = true,
  hasVariableComponent = false,
  showBonusForAll = false,
  showOperatorCta = true,
  operatorLogoWidth = 88,
  operatorLogoHeight = 88,
  BonusTemplate = BonusTemplateDefault,
  modulePosition,
  itemPosition,
}) => {
  const { ribbons } = item?.relation;
  const { relation, path } = item;
  const { name, status } = relation;
  const reviewPath = path || relation.path;
  const isInactive = status === 'inactive';

  return (
    <div
      className={`${styles?.operatorCard || ''} ${ribbons?.length > 0 ? styles?.withRibbon || '' : ''
        }`}
    >
      <OperatorDetails
        item={item?.relation}
        showReviewLink={false}
        costumeStyle={styles.operatorDetails}
        imageWidth={operatorLogoWidth}
        imageHeight={operatorLogoHeight}
        ribbons={ribbons}
        showRibbon={showRibbon}
        icon={verifyIcon}
        template={page?.template}
        showAuthor={showAuthor}
        authorTemplateTwo={authorTemplateTwo}
        useOneStarRating={useOneStarRating}
        showRatingLabel={showRatingLabel}
        showRatingDecimal={showRatingDecimal}
        moduleName={TrackingKeys?.CARDS}
        modulePosition={modulePosition}
        itemPosition={itemPosition}
      />
      <div className={styles?.cardContent || ''}>
        <div className={styles?.cardContentContainer || ''}>
          {showBonusForAll ? (
            <BonusTemplate
              moduleName={TrackingKeys?.CARDS}
              pageTemplate={page?.template}
              item={relation}
              tracker="main"
              modulePosition={modulePosition}
              itemPosition={itemPosition}
            />
          ) : (
            !isInactive && (
              <BonusTemplate
                moduleName={TrackingKeys?.CARDS}
                pageTemplate={page?.template}
                item={relation}
                tracker="main"
                modulePosition={modulePosition}
                itemPosition={itemPosition}
              />
            )
          )}
          <div className={styles?.cardFooter || ''}>
            {relation?.status !== 'not_recommended' && showOperatorCta && (
              <OperatorCta
                tracker="main"
                buttonSize="m"
                moduleName={TrackingKeys?.CARDS}
                operator={relation}
                translationsObj={{
                  active: { translationKey: 'play_now', defaultValue: 'Play Now' },
                  not_recommended: {
                    translationKey: 'not_recommended',
                    defaultValue: 'Not Recommended',
                  },
                  coming_soon: { translationKey: 'coming_soon', defaultValue: 'Soon Available' },
                  inactive: {
                    translationKey: 'inactive',
                    defaultValue: 'Not Accepting New Players',
                  },
                  blacklisted: { translationKey: 'blacklisted', defaultValue: 'Blacklisted' },
                }}
                gtmClass="operator-card-gtm btn-cta"
                pageTemplate={page?.template}
                icon={<FaArrowRight title="Right-pointing Arrow Icon" />}
              />
            )}
            {hasVariableComponent && <VariableComponent item={item} page={page} featured={false} />}
          </div>
        </div>
        <div className={styles?.feedback || ''}>
          {(item?.true_votes !== null || item?.false_votes !== null) && (
            <div className={styles?.feedbackCounter || ''}>
              <div className={styles?.likes || ''}>
                <BiLike color="#3E3C47" title="Like Icon" />
                {item?.true_votes}
              </div>
              <div className={styles?.dislikes || ''}>
                <BiDislike color="#3E3C47" title="Dislike Icon" />
                {item?.false_votes}
              </div>
            </div>
          )}
          <ReviewLink
            className={`${styles?.reviewLink || ''} operator-card-gtm`}
            template={page?.template}
            operatorName={name}
            reviewPath={reviewPath}
          />
        </div>
      </div>
    </div>
  );
};

TemplateThree.propTypes = {
  item: PropTypes.shape({
    relation: PropTypes.shape({
      rating: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
      name: PropTypes.string,
      path: PropTypes.string,
      status: PropTypes.string,
      logo: PropTypes.shape({
        filename: PropTypes.string,
      }),
    }),
    path: PropTypes.string,
    author: PropTypes.shape({
      name: PropTypes.string,
      image: PropTypes.string,
    }),
    true_votes: PropTypes.number,
    false_votes: PropTypes.number,
  }).isRequired,
  page: PropTypes.shape({
    template: PropTypes.string,
  }),
  authorTemplateTwo: PropTypes.bool,
  showAuthor: PropTypes.bool,
  verifyIcon: PropTypes.element,
  showRibbon: PropTypes.bool,
  hasVariableComponent: PropTypes.bool,
  useOneStarRating: PropTypes.bool,
  showRatingLabel: PropTypes.bool,
  showRatingDecimal: PropTypes.bool,
  showBonusForAll: PropTypes.bool,
  BonusTemplate: PropTypes.string,
  showOperatorCta: PropTypes.bool,
  operatorLogoWidth: PropTypes.number,
  operatorLogoHeight: PropTypes.number,
  modulePosition: PropTypes.number,
  itemPosition: PropTypes.number,
};

export default TemplateThree;
