---
import Layout from "../layouts/Layout.astro";
---

<Layout wide>
  <Fragment slot="head">
    <title th:text="|${title} - ${site.title}|"></title>
  </Fragment>

  <section class="wi-equipments">
    <div class="wi-container">
      <div class="wi-equipments__header">
        <h1 class="wi-equipments__title" th:text="${title}">装备</h1>
        <span class="wi-page-accent"></span>
      </div>

      <div class="wi-equipments__groups">
        <th:block th:each="group : ${equipmentFinder.groupBy()}">
          <div class="wi-equipments__group">
            <h2 class="wi-equipments__group-title" th:text="${group.spec?.displayName}"></h2>
            <div class="wi-equipments__grid">
              <article
                class="wi-equipments__card"
                th:each="equip : ${group.equipments}"
              >
                <a
                  class="wi-equipments__card-link"
                  th:if="${!#strings.isEmpty(equip.spec?.url)}"
                  th:href="${equip.spec?.url}"
                  target="_blank"
                  rel="noopener noreferrer"
                  tabindex="-1"
                  aria-hidden="true"
                ></a>
                <div class="wi-equipments__cover" th:if="${!#strings.isEmpty(equip.spec?.cover)}">
                  <img
                    th:src="${equip.spec?.cover}"
                    th:alt="${equip.spec?.displayName}"
                    class="wi-equipments__cover-img"
                    loading="lazy"
                    decoding="async"
                  />
                </div>
                <div
                  class="wi-equipments__cover wi-equipments__cover--placeholder"
                  th:if="${#strings.isEmpty(equip.spec?.cover)}"
                >
                  <span th:text="${#strings.substring(equip.spec?.displayName ?: '', 0, 1)}"></span>
                </div>
                <div class="wi-equipments__body">
                  <h3
                    class="wi-equipments__name"
                    th:text="${equip.spec?.displayName}"
                  ></h3>
                  <p
                    class="wi-equipments__spec"
                    th:if="${!#strings.isEmpty(equip.spec?.specification)}"
                    th:text="${equip.spec?.specification}"
                  ></p>
                  <p
                    class="wi-equipments__desc"
                    th:if="${!#strings.isEmpty(equip.spec?.description)}"
                    th:text="${equip.spec?.description}"
                  ></p>
                </div>
              </article>
            </div>
          </div>
        </th:block>
      </div>
    </div>
  </section>
</Layout>

<style>
  .wi-equipments {
    padding-block: 1rem;
  }

  .wi-equipments__header {
    text-align: center;
    margin-bottom: var(--space-3xl);
  }

  .wi-equipments__title {
    font-size: var(--text-4xl);
    margin-bottom: var(--space-sm);
  }

  .wi-page-accent {
    display: block;
    width: 48px;
    height: 3px;
    margin: var(--space-sm) auto 0;
    border-radius: 9999px;
    background: var(--accent);
  }

  .wi-equipments__groups {
    display: flex;
    flex-direction: column;
    gap: var(--space-3xl);
  }

  .wi-equipments__group-title {
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--ink);
    padding-bottom: var(--space-sm);
    border-bottom: 2px solid var(--accent);
    display: inline-block;
    margin-bottom: var(--space-lg);
  }

  .wi-equipments__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: var(--space-lg);
  }

  .wi-equipments__card {
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--bg-raised);
    border: 1px solid var(--rule);
    border-radius: 16px;
    overflow: hidden;
    transition:
      transform var(--duration-normal) var(--ease-out-expo),
      box-shadow var(--duration-normal) var(--ease-out-expo),
      border-color var(--duration-normal) var(--ease-out-expo);
  }

  .wi-equipments__card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent);
  }

  .wi-equipments__card-link {
    position: absolute;
    inset: 0;
    z-index: 1;
  }

  .wi-equipments__cover {
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    background: var(--bg);
  }

  .wi-equipments__cover-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--duration-normal) var(--ease-out-expo);
  }

  .wi-equipments__card:hover .wi-equipments__cover-img {
    transform: scale(1.05);
  }

  .wi-equipments__cover--placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-bg);
    color: var(--accent);
    font-size: var(--text-4xl);
    font-weight: 700;
  }

  .wi-equipments__body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: var(--space-md) var(--space-lg) var(--space-lg);
    min-width: 0;
  }

  .wi-equipments__name {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .wi-equipments__spec {
    font-size: var(--text-sm);
    color: var(--accent);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .wi-equipments__desc {
    font-size: var(--text-xs);
    color: var(--ink-3);
    line-height: var(--leading-relaxed);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  @media (max-width: 640px) {
    .wi-equipments__grid {
      grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }

    .wi-equipments__body {
      padding: var(--space-sm) var(--space-md) var(--space-md);
    }
  }
</style>
