---
import { Image } from 'astro:assets'
import type { GlobImage } from '../../types/generic'
import { plsLoadImage } from '../../utils/tools'

export interface Props {
  name: string
  origin: string
  imageFile: string
  link: string
}

const { link, imageFile, origin, name } = Astro.props
const imagePath = `/src/assets/favourites/${imageFile}`
const images = import.meta.glob<GlobImage>(
  '/src/assets/favourites/*.{png,webp}'
)
const loadedImage = plsLoadImage(images, imagePath)
---

<a
  href={link}
  target="_blank"
  rel="noopener noreferrer"
  aria-label=`${name} - new window`
>
  <div class="heading">{name}</div>
  <Image src={loadedImage} alt={name} loading={'eager'} width={128} height={128} quality={100}/>
  <h2 class="subtext">
    {origin}
  </h2>
</a>

<style>
  .heading {
    display: flex;
    height: fit-content;
    min-height: 2.5rem;
    line-height: 1.75rem;
    font-size: 24px;
    color: var(--c-primary-text);
    max-width: 200px;
    padding-bottom: 0.3rem;
    font-weight: 500;
    margin: 0px;
    justify-content: center;
    align-items: center;
  }

  a {
    transition: border-color var(--a-time-default) var(--a-animation-1);
    border-radius: 1rem;
    display: flex;
    flex-wrap: wrap;
    flex-direction: column;
    background-color: var(--c-primary-background);
    padding: 0em 0.25em;
    width: max(40%, 128px);
    height: auto;
    justify-content: center;
    align-items: center;
    text-align: center;
    text-decoration: none;
    border: 2px var(--c-primary-background) solid;

    &:hover {
      border: 2px var(--c-accent-1) solid;
    }

    img {
      width: min(90%, 100px);
      margin: 0px 0.5rem;
      height: auto;
      border-radius: 1rem;
    }
  }

  @media (min-width: 512px) {
    a {
      padding: 10px 10px;
      width: auto;
      height: auto;
      img {
        width: 128px;
      }
    }
  }

  .subtext {
    color: var(--c-primary-text);
    font-size: 16px;
    font-weight: 400;
    margin: 0.5rem;
    line-height: 20px;
  }
</style>