import clsx from 'clsx';
import Heading from '@theme/Heading';
import styles from './styles.module.css';

const ExternalLink = require('@site/static/homepage/icons/ExternalLink.svg').default;

type ModuleItem = {
  title: string;
  previewImage: string;
  documentationUrl: string;
  showcaseUrl: string;
};

const ModulesList: ModuleItem[] = [
  {
    title: 'Reactions Module',
    previewImage: 'https://placehold.co/504x260?text=Reactions+Module',
    documentationUrl: '/docs/overview/experiences/reactions',
    showcaseUrl: '/docs/overview/experiences/reactions#showcase',
  },
];

function Module({
  title,
  previewImage,
  documentationUrl,
  showcaseUrl,
}: ModuleItem) {
  return (
    <div className={clsx(styles.module)}>
      <a
        href={showcaseUrl}
        className={clsx(styles.moduleShowcasePreviewContainer)}
      >
        <img
          src={previewImage}
          className={clsx(styles.modulePreviewImage)}
          alt={`${title} module preview image`}
        />

        <div className={clsx(styles.moduleShowcasePreviewOverlay)}>
          <ExternalLink className={clsx(styles.moduleShowcasePreviewIcon)} />
        </div>
      </a>
      <div>
        <Heading as="h3" className={clsx(styles.moduleTitle)}>
          {title}
        </Heading>
        <div className={clsx(styles.moduleNavigation)}>
          <a href={documentationUrl} className={clsx(styles.moduleLink)}>
            Documentation
          </a>
          <span>•</span>
          <a href={showcaseUrl} className={clsx(styles.moduleLink)}>
            Showcase
          </a>
        </div>
      </div>
    </div>
  );
}

export default function HomepageModules(): JSX.Element {
  return (
    <section className={styles.modules}>
      <Heading as="h2" className={clsx('text--center', styles.heading)}>
        Modules catalog
      </Heading>
      <div className={clsx('container', styles.modulesContainer)}>
        {ModulesList.map((props, idx) => (
          <Module key={idx} {...props} />
        ))}
      </div>
    </section>
  );
}
