<script>
  import { resolve } from '$app/paths';
  import { imageBaseUrl } from '$lib/config/imageCdn.js';
  import { t } from '$lib/translations';

  /** @type {readonly { titleKey: string; altKey: string; image: string; route: '/embroidery-viewer' | '/entrepreneurship-alagoas' | '/implant-file' }[]} */
  const works = [
    {
      titleKey: 'featured.workEmbroidery',
      image: 'embroidery-viewer-square-thumb.webp',
      altKey: 'featured.altEmbroidery',
      route: '/embroidery-viewer',
    },
    {
      titleKey: 'featured.workAlagoas',
      image: 'empreendedorismo-square-thumb.webp',
      altKey: 'featured.altAlagoas',
      route: '/entrepreneurship-alagoas',
    },
    {
      titleKey: 'featured.workImplant',
      image: 'implant-file-thumb.webp',
      altKey: 'featured.altImplant',
      route: '/implant-file',
    },
  ];
</script>

<section id="featured-works" class="featured">
  <header class="featured__header">
    <h1 class="featured__title">{$t('featured.sectionTitle')}</h1>
  </header>

  <ul class="featured__grid">
    {#each works as work (work.route)}
      <li class="featured__item">
        <a href={resolve(work.route)}>
          <img
            class="featured__image"
            src={`${imageBaseUrl}/t/f_webp/leomurca/${work.image}`}
            alt={$t(work.altKey)}
          />
          <p class="featured__label">{$t(work.titleKey)}</p>
        </a>
      </li>
    {/each}
  </ul>
</section>

<style>
  /* =========================
     Layout / Section
  ========================== */
  .featured {
    padding: 80px;
    margin: 0;
    background-color: var(--color-light-background);
  }

  /* =========================
     Header
  ========================== */
  .featured__header {
    text-align: center;
  }

  .featured__title {
    font-size: clamp(3.5rem, 4vw, 3.5rem);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
    margin: 0 0 1rem;
    color: var(--color-font-dark);
  }

  /* =========================
     Grid
  ========================== */
  .featured__grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin: 50px 0 0;
    padding: 0;
    list-style: none;
  }

  /* =========================
     Card Item
  ========================== */
  .featured__item {
    overflow: hidden;
    border-radius: 16px;
    cursor: pointer;
    transition:
      transform 0.25s ease,
      box-shadow 0.25s ease;
    will-change: transform;
  }

  .featured__item:hover {
    transform: scale(1.04);
  }

  /* =========================
     Image
  ========================== */
  .featured__image {
    width: 100%;
    display: block;
    object-fit: cover;
    border-radius: 16px;
  }

  /* =========================
     Label / Title
  ========================== */
  .featured__label {
    margin: 15px 0 12px 10px;
    font-size: 1.2rem;
    font-weight: 500;
    color: var(--color-font-dark);
  }

  /* =========================
     Responsive - Large
  ========================== */
  @media (max-width: 1350px) {
    .featured__title {
      font-size: clamp(3.3rem, 4vw, 3.3rem);
    }
  }

  @media (max-width: 1280px) {
    .featured__title {
      font-size: clamp(3rem, 4vw, 3rem);
    }

    .featured__label {
      font-size: 1.1rem;
    }
  }

  /* =========================
     Responsive - Tablet
  ========================== */
  @media (max-width: 900px) {
    .featured__grid {
      grid-template-columns: 1fr;
    }
  }

  /* =========================
     Responsive - Mobile
  ========================== */
  @media (max-width: 810px) {
    .featured {
      padding: 50px 10px;
    }
  }

  @media (max-width: 768px) {
    .featured__title {
      font-size: clamp(2rem, 4vw, 2rem);
    }

    .featured__label {
      margin-top: 0;
    }
  }
</style>
