component StatsBar {
  props {
    items: unknown[] = []
    columns: number = 4
    compact: boolean = true
    dividers: boolean = true
    icons: boolean = true
    size: string = "default"
    color: string = "primary"
    variant: string = "raised"
    maxWidth: string = "xl"
    class: string = ""
  }

  view {
    <section
      {...attrs}
      data-ui-component="StatsBar"
      data-columns='{columns}'
      data-compact='{compact ? "true" : "false"}'
      data-dividers='{dividers ? "true" : "false"}'
      data-icons='{icons ? "true" : "false"}'
      data-size='{size}'
      data-color='{color}'
      data-variant='{variant}'
      data-max-width='{maxWidth}'
      class='wrn-stats-bar {class}'
      aria-label="Key statistics"
    >
      <div class="wrn-stats-bar__inner">
        <div class="wrn-stats-bar__surface">
          {#each items as item, itemIndex}
            <article
              class="wrn-stats-bar__item"
              data-color='{item.color || color}'
              data-index='{itemIndex}'
            >
              <div class="wrn-stats-bar__content">
                {#if item.label}
                  <p class="wrn-stats-bar__label">{item.label}</p>
                {/if}

                <div class="wrn-stats-bar__value-row">
                  <strong class="wrn-stats-bar__value">{item.value}</strong>

                  {#if item.suffix}
                    <span class="wrn-stats-bar__suffix">{item.suffix}</span>
                  {/if}
                </div>

                {#if item.description}
                  <p class="wrn-stats-bar__description">{item.description}</p>
                {/if}

                {#if item.trend || item.trendLabel}
                  <div
                    class="wrn-stats-bar__trend"
                    data-direction='{item.trendDirection || "neutral"}'
                  >
                    {#if item.trendDirection === "up"}
                      <span
                        class="icon-[lucide--trending-up] wrn-stats-bar__trend-icon"
                        aria-hidden="true"
                      ></span>
                    {:else if item.trendDirection === "down"}
                      <span
                        class="icon-[lucide--trending-down] wrn-stats-bar__trend-icon"
                        aria-hidden="true"
                      ></span>
                    {:else}
                      <span
                        class="icon-[lucide--minus] wrn-stats-bar__trend-icon"
                        aria-hidden="true"
                      ></span>
                    {/if}

                    {#if item.trend}
                      <span class="wrn-stats-bar__trend-value">{item.trend}</span>
                    {/if}

                    {#if item.trendLabel}
                      <span class="wrn-stats-bar__trend-label">{item.trendLabel}</span>
                    {/if}
                  </div>
                {/if}
              </div>

              {#if icons && item.icon}
                <div class="wrn-stats-bar__icon" aria-hidden="true">
                  <span class='{item.icon}'></span>
                </div>
              {/if}
            </article>
          {/each}
        </div>
      </div>
    </section>
  }

  style {
    .wrn-stats-bar {
      --stats-accent: var(--wrn-color-primary);
      --stats-contrast: var(--wrn-color-primary-contrast);
      --stats-soft: color-mix(in srgb, var(--stats-accent) 12%, transparent);
      --stats-border: color-mix(in srgb, var(--stats-accent) 22%, var(--wrn-color-border));

      position: relative;
      width: 100%;
      color: var(--wrn-color-text);
    }

    .wrn-stats-bar[data-color="secondary"] {
      --stats-accent: var(--wrn-color-secondary);
      --stats-contrast: var(--wrn-color-secondary-contrast);
    }

    .wrn-stats-bar[data-color="info"] {
      --stats-accent: var(--wrn-color-info);
      --stats-contrast: var(--wrn-color-info-contrast);
    }

    .wrn-stats-bar[data-color="success"] {
      --stats-accent: var(--wrn-color-success);
      --stats-contrast: var(--wrn-color-success-contrast);
    }

    .wrn-stats-bar[data-color="warning"] {
      --stats-accent: var(--wrn-color-warning);
      --stats-contrast: var(--wrn-color-warning-contrast);
    }

    .wrn-stats-bar[data-color="danger"] {
      --stats-accent: var(--wrn-color-danger);
      --stats-contrast: var(--wrn-color-danger-contrast);
    }

    .wrn-stats-bar__inner {
      width: min(calc(100% - 2rem), 80rem);
      margin-inline: auto;
    }

    .wrn-stats-bar[data-max-width="compact"] .wrn-stats-bar__inner {
      width: min(calc(100% - 2rem), 64rem);
    }

    .wrn-stats-bar[data-max-width="lg"] .wrn-stats-bar__inner {
      width: min(calc(100% - 2rem), 72rem);
    }

    .wrn-stats-bar[data-max-width="wide"] .wrn-stats-bar__inner,
    .wrn-stats-bar[data-max-width="2xl"] .wrn-stats-bar__inner {
      width: min(calc(100% - 2rem), 90rem);
    }

    .wrn-stats-bar[data-max-width="full"] .wrn-stats-bar__inner {
      width: 100%;
      max-width: none;
    }

    .wrn-stats-bar__surface {
      display: grid;
      grid-template-columns: minmax(0, 1fr);
      overflow: hidden;
      background:
        linear-gradient(
          135deg,
          color-mix(in srgb, var(--stats-accent) 7%, transparent),
          transparent 42%
        ),
        var(--wrn-color-surface-raised);
      border: 1px solid var(--stats-border);
      border-radius: 1.25rem;
      box-shadow:
        0 1px 0 color-mix(in srgb, white 5%, transparent) inset,
        0 18px 48px color-mix(in srgb, black 16%, transparent);
    }

    .wrn-stats-bar[data-variant="default"] .wrn-stats-bar__surface {
      background: var(--wrn-color-surface);
      box-shadow: none;
    }

    .wrn-stats-bar[data-variant="soft"] .wrn-stats-bar__surface {
      background:
        linear-gradient(135deg, var(--stats-soft), transparent 58%),
        var(--wrn-color-surface-raised);
      box-shadow: none;
    }

    .wrn-stats-bar[data-variant="outline"] .wrn-stats-bar__surface {
      background: transparent;
      box-shadow: none;
    }

    .wrn-stats-bar[data-variant="minimal"] .wrn-stats-bar__surface {
      background: transparent;
      border-color: transparent;
      border-radius: 0;
      box-shadow: none;
    }

    .wrn-stats-bar[data-variant="solid"] .wrn-stats-bar__surface {
      color: var(--stats-contrast);
      background:
        linear-gradient(135deg, color-mix(in srgb, white 8%, transparent), transparent 52%),
        var(--stats-accent);
      border-color: color-mix(in srgb, white 24%, transparent);
      box-shadow: 0 20px 56px color-mix(in srgb, var(--stats-accent) 28%, transparent);
    }

    .wrn-stats-bar__item {
      --item-accent: var(--stats-accent);

      position: relative;
      display: grid;
      grid-template-columns: minmax(0, 1fr) auto;
      align-items: start;
      gap: 1rem;
      min-width: 0;
      padding: 1.5rem;
      transition:
        background-color 180ms ease,
        transform 180ms ease;
    }

    .wrn-stats-bar[data-compact="true"] .wrn-stats-bar__item {
      padding: 1.15rem 1.25rem;
    }

    .wrn-stats-bar[data-size="sm"] .wrn-stats-bar__item {
      padding: 1rem 1.1rem;
    }

    .wrn-stats-bar[data-size="lg"] .wrn-stats-bar__item {
      padding: 1.8rem;
    }

    .wrn-stats-bar__item[data-color="secondary"] {
      --item-accent: var(--wrn-color-secondary);
    }

    .wrn-stats-bar__item[data-color="info"] {
      --item-accent: var(--wrn-color-info);
    }

    .wrn-stats-bar__item[data-color="success"] {
      --item-accent: var(--wrn-color-success);
    }

    .wrn-stats-bar__item[data-color="warning"] {
      --item-accent: var(--wrn-color-warning);
    }

    .wrn-stats-bar__item[data-color="danger"] {
      --item-accent: var(--wrn-color-danger);
    }

    .wrn-stats-bar__item:hover {
      background: color-mix(in srgb, var(--item-accent) 6%, transparent);
    }

    .wrn-stats-bar[data-variant="solid"] .wrn-stats-bar__item:hover {
      background: color-mix(in srgb, white 8%, transparent);
    }

    .wrn-stats-bar__content {
      min-width: 0;
    }

    .wrn-stats-bar__label {
      margin: 0;
      color: var(--wrn-color-text-muted);
      font-size: 0.78rem;
      font-weight: 600;
      line-height: 1.4;
      letter-spacing: 0.01em;
    }

    .wrn-stats-bar__value-row {
      display: flex;
      align-items: baseline;
      gap: 0.25rem;
      margin-top: 0.45rem;
    }

    .wrn-stats-bar__value {
      margin: 0;
      color: var(--wrn-color-text);
      font-size: clamp(1.75rem, 2.4vw, 2.35rem);
      font-weight: 650;
      line-height: 1;
      letter-spacing: -0.035em;
    }

    .wrn-stats-bar[data-compact="true"] .wrn-stats-bar__value {
      font-size: clamp(1.45rem, 2vw, 1.9rem);
    }

    .wrn-stats-bar__suffix {
      color: var(--item-accent);
      font-size: 0.95rem;
      font-weight: 700;
    }

    .wrn-stats-bar__description {
      max-width: 30rem;
      margin: 0.7rem 0 0;
      color: var(--wrn-color-text-muted);
      font-size: 0.78rem;
      line-height: 1.55;
    }

    .wrn-stats-bar[data-compact="true"] .wrn-stats-bar__description {
      margin-top: 0.55rem;
      font-size: 0.73rem;
    }

    .wrn-stats-bar__icon {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 2.65rem;
      height: 2.65rem;
      color: var(--item-accent);
      background: color-mix(in srgb, var(--item-accent) 11%, transparent);
      border-radius: 0.85rem;
    }

    .wrn-stats-bar__icon > span {
      width: 1.2rem;
      height: 1.2rem;
    }

    .wrn-stats-bar[data-compact="true"] .wrn-stats-bar__icon {
      width: 2.35rem;
      height: 2.35rem;
      border-radius: 0.75rem;
    }

    .wrn-stats-bar__trend {
      display: inline-flex;
      align-items: center;
      gap: 0.3rem;
      width: fit-content;
      margin-top: 0.7rem;
      padding: 0.25rem 0.5rem;
      color: var(--wrn-color-text-muted);
      font-size: 0.7rem;
      line-height: 1;
      background: color-mix(in srgb, var(--wrn-color-text) 5%, transparent);
      border-radius: 999px;
    }

    .wrn-stats-bar__trend[data-direction="up"] {
      color: var(--wrn-color-success);
    }

    .wrn-stats-bar__trend[data-direction="down"] {
      color: var(--wrn-color-danger);
    }

    .wrn-stats-bar__trend-icon {
      width: 0.8rem;
      height: 0.8rem;
    }

    .wrn-stats-bar__trend-value {
      font-weight: 700;
    }

    .wrn-stats-bar__trend-label {
      opacity: 0.8;
    }

    .wrn-stats-bar[data-variant="solid"] .wrn-stats-bar__label,
    .wrn-stats-bar[data-variant="solid"] .wrn-stats-bar__description,
    .wrn-stats-bar[data-variant="solid"] .wrn-stats-bar__value,
    .wrn-stats-bar[data-variant="solid"] .wrn-stats-bar__suffix {
      color: var(--stats-contrast);
    }

    .wrn-stats-bar[data-variant="solid"] .wrn-stats-bar__label,
    .wrn-stats-bar[data-variant="solid"] .wrn-stats-bar__description {
      opacity: 0.78;
    }

    .wrn-stats-bar[data-variant="solid"] .wrn-stats-bar__icon {
      color: var(--stats-contrast);
      background: color-mix(in srgb, white 13%, transparent);
    }

    .wrn-stats-bar[data-dividers="true"] .wrn-stats-bar__item + .wrn-stats-bar__item {
      border-top: 1px solid var(--wrn-color-border);
    }

    .wrn-stats-bar[data-variant="solid"][data-dividers="true"]
      .wrn-stats-bar__item + .wrn-stats-bar__item {
      border-color: color-mix(in srgb, white 18%, transparent);
    }

    @media (min-width: 640px) {
      .wrn-stats-bar__surface {
        grid-template-columns: repeat(2, minmax(0, 1fr));
      }

      .wrn-stats-bar[data-columns="1"] .wrn-stats-bar__surface {
        grid-template-columns: minmax(0, 1fr);
      }

      .wrn-stats-bar[data-dividers="true"] .wrn-stats-bar__item {
        border-top: 0;
      }

      .wrn-stats-bar[data-dividers="true"] .wrn-stats-bar__item:nth-child(even) {
        border-left: 1px solid var(--wrn-color-border);
      }

      .wrn-stats-bar[data-dividers="true"] .wrn-stats-bar__item:nth-child(n + 3) {
        border-top: 1px solid var(--wrn-color-border);
      }

      .wrn-stats-bar[data-variant="solid"][data-dividers="true"]
        .wrn-stats-bar__item:nth-child(even),
      .wrn-stats-bar[data-variant="solid"][data-dividers="true"]
        .wrn-stats-bar__item:nth-child(n + 3) {
        border-color: color-mix(in srgb, white 18%, transparent);
      }
    }

    @media (min-width: 1024px) {
      .wrn-stats-bar[data-columns="1"] .wrn-stats-bar__surface {
        grid-template-columns: minmax(0, 1fr);
      }

      .wrn-stats-bar[data-columns="2"] .wrn-stats-bar__surface {
        grid-template-columns: repeat(2, minmax(0, 1fr));
      }

      .wrn-stats-bar[data-columns="3"] .wrn-stats-bar__surface {
        grid-template-columns: repeat(3, minmax(0, 1fr));
      }

      .wrn-stats-bar[data-columns="4"] .wrn-stats-bar__surface {
        grid-template-columns: repeat(4, minmax(0, 1fr));
      }

      .wrn-stats-bar[data-columns="5"] .wrn-stats-bar__surface {
        grid-template-columns: repeat(5, minmax(0, 1fr));
      }

      .wrn-stats-bar[data-columns="6"] .wrn-stats-bar__surface {
        grid-template-columns: repeat(6, minmax(0, 1fr));
      }

      .wrn-stats-bar[data-dividers="true"] .wrn-stats-bar__item,
      .wrn-stats-bar[data-dividers="true"] .wrn-stats-bar__item:nth-child(even),
      .wrn-stats-bar[data-dividers="true"] .wrn-stats-bar__item:nth-child(n + 3) {
        border-top: 0;
        border-left: 1px solid var(--wrn-color-border);
      }

      .wrn-stats-bar[data-dividers="true"] .wrn-stats-bar__item:first-child {
        border-left: 0;
      }

      .wrn-stats-bar[data-variant="solid"][data-dividers="true"] .wrn-stats-bar__item {
        border-color: color-mix(in srgb, white 18%, transparent);
      }
    }

    @media (max-width: 639px) {
      .wrn-stats-bar[data-max-width="full"] .wrn-stats-bar__surface {
        border-inline: 0;
        border-radius: 0;
      }
    }

    @media (prefers-reduced-motion: reduce) {
      .wrn-stats-bar__item {
        transition: none;
      }
    }
  }
}
