component Marquee {
  outputs {
    // Fired when the reader pauses the scroll, by hover, focus or the button.
    pause(payload: { sourceEvent?: Event; [key: string]: string | number | boolean | null | object })
    resume(payload: { sourceEvent?: Event; [key: string]: string | number | boolean | null | object })
  }

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

  state paused: boolean = false

  view {
    <section
      data-ui-component="Marquee"
      aria-label='{title}'
      class='wire-marquee {class}'
    >
      <div class="wire-marquee__layout">
        {#if title}
          <div class="wire-marquee__title">
            <span class="icon-[lucide--megaphone] wire-marquee__icon" aria-hidden="true"></span>
            <span>{title}</span>
          </div>
        {/if}

        <div
          class="wire-marquee__window"
          @mouseenter='paused = true; output.pause({})'
          @mouseleave='paused = false; output.resume({})'
          @focusin='paused = true'
          @focusout='paused = false'
        >
          <div
            class="wire-marquee__track"
            class:wire-marquee-paused='paused'
          >
            {#each items as item}
              <a
                href='{item.href || "#"}'
                class="wire-marquee__item"
              >
                <span
                  class="wire-marquee__dot"
                  data-color='{item.color || "primary"}'
                  aria-hidden="true"
                ></span>
                <span>{item.label || item.title}</span>
                {#if item.meta}
                  <span class="wire-marquee__meta">{item.meta}</span>
                {/if}
              </a>
            {:empty}
              <p class="wire-marquee__empty">{description || "No announcements available."}</p>
            {/each}

            {#if items.length > 0}
              {#each items as item}
                <a
                  href='{item.href || "#"}'
                  aria-hidden="true"
                  tabindex="-1"
                  class="wire-marquee__item"
                >
                  <span class="wire-marquee__dot" aria-hidden="true"></span>
                  <span>{item.label || item.title}</span>
                </a>
              {/each}
            {/if}
          </div>
        </div>

        <button
          type="button"
          aria-label='{paused ? "Resume announcements" : "Pause announcements"}'
          class="wire-marquee__toggle"
          @click='paused = !paused; paused ? output.pause({}) : output.resume({})'
        >
          <span class="icon-[lucide--pause] wire-marquee__icon" data-show='!paused' aria-hidden="true"></span>
          <span class="icon-[lucide--play] wire-marquee__icon" data-show='paused' aria-hidden="true"></span>
        </button>
      </div>

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

  style {
    .wire-marquee { overflow: hidden; border-block: 1px solid var(--wire-color-border); background: var(--wire-color-surface-raised); }
    .wire-marquee__layout { display: flex; align-items: stretch; }
    .wire-marquee__title { position: relative; z-index: 1; display: flex; flex: none; align-items: center; gap: 0.5rem; padding: 0.75rem 1rem; border-right: 1px solid var(--wire-color-border); color: var(--wire-color-on-primary); background: var(--wire-color-primary); font-size: 0.875rem; font-weight: 700; }
    .wire-marquee__window { position: relative; min-width: 0; flex: 1; overflow: hidden; }
    .wire-marquee__track {
      display: flex; width: max-content; min-width: 100%; align-items: center;
      animation: wire-marquee 32s linear infinite;
    }
    .wire-marquee-paused { animation-play-state: paused; }
    .wire-marquee__item { display: flex; flex: none; align-items: center; gap: 0.75rem; padding: 0.75rem 1.25rem; color: var(--wire-color-text); font-size: 0.875rem; font-weight: 500; transition: color var(--wire-motion-base), background var(--wire-motion-base); }
    .wire-marquee__item:hover { color: var(--wire-color-primary); background: var(--wire-color-primary-soft); }
    .wire-marquee__item:focus-visible, .wire-marquee__toggle:focus-visible { outline: 2px solid var(--wire-color-focus); outline-offset: -2px; }
    .wire-marquee__dot { width: 0.5rem; height: 0.5rem; flex: none; border-radius: 50%; background: var(--wire-color-primary); }
    .wire-marquee__dot[data-color="danger"] { background: var(--wire-color-danger); }
    .wire-marquee__dot[data-color="warning"] { background: var(--wire-color-warning); }
    .wire-marquee__dot[data-color="success"] { background: var(--wire-color-success); }
    .wire-marquee__meta { color: var(--wire-color-text-muted); font-size: 0.75rem; }
    .wire-marquee__empty { padding: 0.75rem 1.25rem; color: var(--wire-color-text-muted); font-size: 0.875rem; }
    .wire-marquee__toggle { display: flex; flex: none; align-items: center; justify-content: center; padding-inline: 1rem; border: 0; border-left: 1px solid var(--wire-color-border); color: var(--wire-color-text-muted); background: transparent; transition: color var(--wire-motion-base), background var(--wire-motion-base); }
    .wire-marquee__toggle:hover { color: var(--wire-color-text); background: var(--wire-color-surface-soft); }
    .wire-marquee__icon { width: 1rem; height: 1rem; }
    @media (min-width: 40rem) { .wire-marquee__title { padding-inline: 1.25rem; } }

    .wire-marquee-paused {
      animation-play-state: paused;
    }

    @keyframes wire-marquee {
      from { transform: translateX(0); }
      to { transform: translateX(-50%); }
    }

    @media (prefers-reduced-motion: reduce) {
      .wire-marquee__track {
        animation: none;
      }
    }
  }
}
