/* eslint-disable import/no-extraneous-dependencies */
import React from 'react';
import PropTypes from 'prop-types';
import { BiLike } from '@react-icons/all-files/bi/BiLike';
import loadable from '@loadable/component';
import { BiDislike } from '@react-icons/all-files/bi/BiDislike';
import ReviewLink from 'gatsby-core-theme/src/components/atoms/review-link';
import Rating from '../../../ratings';
import OperatorDetails from '../../../../molecules/operator-details';
import styles from './template-four.module.scss';

const TemplateFour = ({
  item,
  useOneStarRating = true,
  page,
  showRibbon = false,
  showAuthor = true,
  showRatingLabel = false,
  showRatingDecimal = false,
  authorTemplateTwo = true,
  verifyIcon = '../../../images/verify.svg',
  showBonusForAll = false,
  BonusTemplate = loadable(() =>
    import(`gatsby-core-theme/src/components/molecules/bonus-box/template-three`)
  ),
}) => {
  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}
        showReviewLink={false}
        costumeStyle={styles.operatorDetails}
        imageWidth={88}
        imageHeight={88}
        ribbons={ribbons}
        showRibbon={showRibbon}
        icon={verifyIcon}
        template={page?.template}
        showAuthor={showAuthor}
        authorTemplateTwo={authorTemplateTwo}
        useOneStarRating={useOneStarRating}
        showRatingLabel={showRatingLabel}
        showRatingDecimal={showRatingDecimal}
        module="cards"
      />
      <div className={styles?.cardContent || ''}>
        <Rating item={relation} type="operatorCards" />
        {showBonusForAll ? (
          <BonusTemplate
            module="cards"
            welcomeBonus={false}
            item={relation}
            ctaBtn
            tracker="main"
          />
        ) : (
          !isInactive && (
            <BonusTemplate welcomeBonus={false} item={relation} ctaBtn tracker="main" />
          )
        )}
        <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>
  );
};

TemplateFour.propTypes = {
  item: PropTypes.shape({
    relation: PropTypes.shape({
      rating: PropTypes.string,
      name: PropTypes.string,
      path: PropTypes.string,
      status: PropTypes.string,
      standardised_logo_url_object: 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,
    type: PropTypes.string,
  }),
  authorTemplateTwo: PropTypes.bool,
  showAuthor: PropTypes.bool,

  verifyIcon: PropTypes.string,
  showRibbon: PropTypes.bool,
  useOneStarRating: PropTypes.bool,
  showRatingLabel: PropTypes.bool,
  showRatingDecimal: PropTypes.bool,
  showBonusForAll: PropTypes.bool,
  BonusTemplate: PropTypes.string,
};

export default TemplateFour;
