component List {
  outputs {
    select(payload: { sourceEvent?: Event; [key: string]: string | number | boolean | null | object })
  }

  props {
    size: string = "default"
    color: string = "primary"
    title: string = "List"
    description: string = ""
    items: unknown[] = []
    variant: string = "default"
    class: string = ""
  }

  view {
    <section
      data-ui-component="List"
      aria-label='{title}'
      class='wire-list {class}'
    >
      {#if title || description}
        <header class="wire-list__header">
          {#if title}
            <h3 class="wire-list__title">{title}</h3>
          {/if}
          {#if description}
            <p class="wire-list__description">{description}</p>
          {/if}
        </header>
      {/if}

      <ul
        class="wire-list__items"
        data-variant='{variant}'
      >
        {#each items as item, index}
          <li
            class="wire-list__item"
            data-variant='{variant}'
            @click='if (!item.href) { output.select({ item: item, index: index }) }'
          >
            {#if item.href}
              <a
                href='{item.href}'
                class="wire-list__row"
                data-size='{size}'
                @click='output.select({ item: item, index: index })'
              >
                {#if item.icon}
                  <span class="wire-list__leading-icon"><span class='{item.icon}' aria-hidden="true"></span>
                  </span>
                {/if}
                {#if item.imageSrc}
                  <img src='{item.imageSrc}' alt='{item.imageAlt || ""}' class="wire-list__image" loading="lazy" />
                {/if}
                <div class="wire-list__body">
                  <div class="wire-list__heading">
                    <p class="wire-list__item-title">{item.title || item.label}</p>
                    {#if item.meta}
                      <span class="wire-list__meta">{item.meta}</span>
                    {/if}
                  </div>
                  {#if item.description}
                    <p class="wire-list__item-description">{item.description}</p>
                  {/if}
                  {#if item.badge}
                    <span class="wire-list__badge">{item.badge}</span>
                  {/if}
                </div>
                <span class="icon-[lucide--chevron-right] wire-list__chevron" aria-hidden="true"></span>
              </a>
            {:else}
              <div class="wire-list__row" data-size='{size}'>
                {#if item.icon}
                  <span class="wire-list__leading-icon"><span class='{item.icon}' aria-hidden="true"></span>
                  </span>
                {/if}
                <div class="wire-list__body">
                  <p class="wire-list__item-title">{item.title || item.label}</p>
                  {#if item.description}
                    <p class="wire-list__item-description">{item.description}</p>
                  {/if}
                </div>
              </div>
            {/if}
          </li>
        {:empty}
          <li class="wire-list__empty">
            No items available.
          </li>
        {/each}
      </ul>

      <slot></slot>
    </section>
  }

  style {
    .wire-list { width: 100%; }
    .wire-list__header { margin-bottom: 1rem; }
    .wire-list__title { color: var(--wire-color-text); font-size: 1.125rem; font-weight: 700; }
    .wire-list__description { margin-top: 0.25rem; color: var(--wire-color-text-muted); font-size: 0.875rem; line-height: 1.5rem; }
    .wire-list__items { overflow: hidden; }
    .wire-list__items:is([data-variant="default"], [data-variant="divided"]) > .wire-list__item + .wire-list__item { border-top: 1px solid var(--wire-color-border); }
    .wire-list__items[data-variant="card"] { border: 1px solid var(--wire-color-border); border-radius: calc(var(--wire-radius) * 1.5); background: var(--wire-color-surface-raised); }
    .wire-list__items[data-variant="separated"] { display: grid; gap: 0.75rem; }
    .wire-list__item { min-width: 0; }
    .wire-list__item[data-variant="separated"] { border: 1px solid var(--wire-color-border); border-radius: var(--wire-radius); background: var(--wire-color-surface-raised); }
    .wire-list__row { display: flex; min-width: 0; align-items: flex-start; gap: 0.75rem; padding: 0.75rem 1rem; outline: none; transition: background var(--wire-motion-base); }
    a.wire-list__row:hover { background: var(--wire-color-surface-soft); }
    .wire-list__row:focus-visible { box-shadow: inset 0 0 0 2px var(--wire-color-focus); }
    .wire-list__row[data-size="sm"] { padding: 0.625rem 0.75rem; }
    .wire-list__row[data-size="lg"] { padding: 1rem 1.25rem; }
    .wire-list__leading-icon { display: flex; width: 2.5rem; height: 2.5rem; flex: none; align-items: center; justify-content: center; border-radius: var(--wire-radius); color: var(--wire-color-primary); background: var(--wire-color-primary-soft); }
    .wire-list__leading-icon > span { width: 1.25rem; height: 1.25rem; }
    .wire-list__image { width: 3rem; height: 3rem; flex: none; border-radius: var(--wire-radius); object-fit: cover; }
    .wire-list__body { min-width: 0; flex: 1; }
    .wire-list__heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; }
    .wire-list__item-title { overflow: hidden; color: var(--wire-color-text); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
    .wire-list__meta { flex: none; color: var(--wire-color-text-muted); font-size: 0.75rem; }
    .wire-list__item-description { display: -webkit-box; margin-top: 0.25rem; overflow: hidden; color: var(--wire-color-text-muted); font-size: 0.875rem; line-height: 1.25rem; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
    .wire-list__badge { display: inline-flex; margin-top: 0.5rem; padding: 0.25rem 0.625rem; border-radius: 999px; color: var(--wire-color-primary); background: var(--wire-color-primary-soft); font-size: 0.75rem; font-weight: 600; }
    .wire-list__chevron { width: 1rem; height: 1rem; flex: none; margin-top: 0.25rem; color: var(--wire-color-text-muted); transition: color var(--wire-motion-base), transform var(--wire-motion-base); }
    .wire-list__row:hover .wire-list__chevron { color: var(--wire-color-primary); transform: translateX(0.125rem); }
    .wire-list__empty { padding: 1.5rem; border: 1px dashed var(--wire-color-border); border-radius: var(--wire-radius); color: var(--wire-color-text-muted); font-size: 0.875rem; text-align: center; }
  }
}
