import { Typography } from '../../Typography'
import { Rate, RateTermDetails } from '../types'

import { Button } from '../../Button'
import { MaterialIcon } from '../../Icons/MaterialIcon'
import Modal from '../Modal'
import styles from '../rate-card.module.css'
import { variants } from '../variants'

interface CampaignRateCardProps {
  name: string
  value: string
  isSelected: boolean
  rateTitle: string
  paymentTerm: string
  bannerText: string
  rate: Rate
  memberRate?: Rate
  omnibusRate?: Rate
  comparisonRate?: Omit<Rate, 'label'>
  isHighlightedRate?: boolean
  approximateRate?: Rate
  handleChange: () => void
  handleTermsClick?: () => void
  rateTermDetails: RateTermDetails[]
}

export default function CampaignRateCard({
  name,
  value,
  isSelected,
  rateTitle,
  paymentTerm,
  rate,
  memberRate,
  approximateRate,
  comparisonRate,
  omnibusRate,
  bannerText,
  isHighlightedRate,
  handleChange,
  rateTermDetails,
}: CampaignRateCardProps) {
  const classNames = variants({
    variant: 'Campaign',
  })

  return (
    <label>
      <input
        className={styles.radio}
        type="radio"
        name={name}
        value={value}
        checked={isSelected}
        onChange={handleChange}
      />
      <div className={classNames}>
        <Typography variant="Tag/sm">
          <p className={styles.banner}>{bannerText}</p>
        </Typography>
        <div className={styles.container}>
          <header>
            <Typography variant="Tag/sm">
              <h3 className={styles.title}>
                <Modal
                  title={rateTitle}
                  subtitle={paymentTerm}
                  trigger={
                    <Button variant="Icon" size="Small">
                      <MaterialIcon
                        icon="info"
                        size={20}
                        color="Icon/Default"
                      />
                    </Button>
                  }
                >
                  {rateTermDetails.map((termGroup) => (
                    <div key={termGroup.title} className={styles.terms}>
                      <Typography variant={'Body/Paragraph/mdBold'}>
                        <p>{termGroup.title}</p>
                      </Typography>
                      {termGroup.terms.map((term) => (
                        <Typography key={term}>
                          <p className={styles.term}>
                            <MaterialIcon
                              icon="check"
                              color="Icon/Feedback/Success"
                              size={20}
                              className={styles.termsIcon}
                            />
                            {term}
                          </p>
                        </Typography>
                      ))}
                    </div>
                  ))}
                </Modal>
                {rateTitle}
                <span className={styles.textSecondary}>
                  {` / ${paymentTerm}`}
                </span>
              </h3>
            </Typography>
            <div className={styles.checkIcon}>
              <MaterialIcon icon="check" size={22} color="Icon/Inverted" />
            </div>
          </header>
          <div className={styles.content}>
            <div
              className={`${styles.rateRow} ${isHighlightedRate ? styles.highlightedRate : ''}`}
            >
              <Typography variant="Body/Supporting text (caption)/smBold">
                <p>{rate.label}</p>
              </Typography>
              <Typography variant="Title/Subtitle/md">
                <p>
                  {`${rate.price} `}
                  <Typography variant="Body/Supporting text (caption)/smBold">
                    <span>{rate.unit}</span>
                  </Typography>
                </p>
              </Typography>
            </div>
            {memberRate ? (
              <div className={`${styles.rateRow} ${styles.highlightedRate}`}>
                <Typography variant="Body/Supporting text (caption)/smBold">
                  <p>{memberRate.label}</p>
                </Typography>
                <Typography variant="Title/Subtitle/md">
                  <p>
                    {`${memberRate.price} `}
                    <Typography variant="Body/Supporting text (caption)/smBold">
                      <span>{memberRate.unit}</span>
                    </Typography>
                  </p>
                </Typography>
              </div>
            ) : null}
            {comparisonRate ? (
              <div className={`${styles.rateRow} ${styles.comparisonRate}`}>
                <Typography variant="Title/Subtitle/md">
                  <p>
                    <span className={styles.strikethrough}>{rate.price}</span>{' '}
                    <Typography variant="Body/Supporting text (caption)/smBold">
                      <span className={styles.strikethrough}>
                        {comparisonRate.unit}
                      </span>
                    </Typography>
                  </p>
                </Typography>
              </div>
            ) : null}
            {approximateRate ? (
              <div className={`${styles.rateRow} ${styles.approximateRate}`}>
                <Typography variant="Body/Supporting text (caption)/smRegular">
                  <p>{approximateRate.label}</p>
                </Typography>
                <Typography variant="Body/Supporting text (caption)/smRegular">
                  <p>
                    {approximateRate.price} {approximateRate.unit}
                  </p>
                </Typography>
              </div>
            ) : null}
          </div>
          {omnibusRate ? (
            <footer className={styles.footer}>
              <Typography variant="Tag/sm">
                <p>{omnibusRate.label}</p>
              </Typography>
              <Typography variant="Tag/sm">
                <p>
                  {omnibusRate.price} {omnibusRate.unit}
                </p>
              </Typography>
            </footer>
          ) : null}
        </div>
      </div>
    </label>
  )
}
