component Footer {
  outputs {
    select(payload: { value?: string | number | boolean | null; values?: Array<string | number | boolean | null | object>; sourceEvent?: Event; [key: string]: string | number | boolean | null | object } | string | number | boolean | null)
    action(payload: { sourceEvent?: Event; [key: string]: string | number | boolean | null | object })
  }

  props {

    size: string = "default"
    color: string = "primary"
    label: string = "Footer navigation"
    items: unknown[] = []
    columns: number = 3
    maxWidth: string = "compact"
    copyright: string = ""
    class: string = ""
  }

  view {
    <footer
      {...attrs}
      data-ui-component="Footer"
      data-size='{size}'
      data-color='{color}'
      class='wire-footer {maxWidth === "full" ? "wire-footer--width-full" : ""} {class}'
    >
      <div
        class="wire-footer__grid"
      >
        <div
          class="wire-footer__pre"
        >
          <slot
            name="pre-footer"
          >
          </slot>
        </div>

        {#if items.length > 0}
          <nav
            class='wire-footer__links wire-footer--columns-{columns}'
            aria-label='{label}'
          >
            {#each items as item, itemIndex}
              {#if item.type === "header"}
                <section
                  class="wire-footer__column"
                  aria-labelledby='footer-heading-{itemIndex}'
                >
                  {#if item.icon}
                    <span
                      class='{item.icon}'
                      aria-hidden="true"
                    >
                    </span>
                  {/if}

                  <h2
                    id='footer-heading-{itemIndex}'
                    class="wire-footer__heading"
                  >
                    {item.label || item.title}
                  </h2>

                  {#if item.description}
                    <p>
                      {item.description}
                    </p>
                  {/if}

                  {#if (item.items || item.links || []).length > 0}
                    <div
                      class="wire-footer__column-links"
                    >
                      {#each item.items || item.links || [] as child, childIndex}
                        <a
                          href='{child.href || "#"}'
                          target='{child.target || ""}'
                          rel='{child.external ? "noopener noreferrer" : (child.rel || "")}'
                          aria-current='{child.active ? "page" : ""}'
                          class="wire-footer__link"
                          @click='output.select({ item: child, parent: item, itemIndex: childIndex, sectionIndex: itemIndex }); child.action && output.action({ item: child, parent: item, itemIndex: childIndex, sectionIndex: itemIndex })'
                        >
                          {#if child.icon}
                            <span
                              class='{child.icon}'
                              aria-hidden="true"
                            >
                            </span>
                          {/if}

                          <span>
                            {child.label || child.title}
                          </span>

                          {#if child.badge}
                            <span
                              class="wire-badge wire-badge--default"
                            >
                              {child.badge}
                            </span>
                          {/if}

                          {#if child.external}
                            <span
                              class="icon-[lucide--arrow-up-right]"
                              aria-hidden="true"
                            >
                            </span>
                          {/if}
                        </a>
                      {/each}
                    </div>
                  {/if}
                </section>

              {:else if item.type === "link" || item.href}
                <section
                  class="wire-footer__column"
                >
                  <div
                    class="wire-footer__column-links"
                  >
                    <a
                      href='{item.href || "#"}'
                      target='{item.target || ""}'
                      rel='{item.external ? "noopener noreferrer" : (item.rel || "")}'
                      aria-current='{item.active ? "page" : ""}'
                      class="wire-footer__link"
                      @click='output.select({ item: item, itemIndex: itemIndex }); item.action && output.action({ item: item, itemIndex: itemIndex })'
                    >
                      {#if item.icon}
                        <span
                          class='{item.icon}'
                          aria-hidden="true"
                        >
                        </span>
                      {/if}

                      <span>
                        {item.label || item.title}
                      </span>

                      {#if item.badge}
                        <span
                          class="wire-badge wire-badge--default"
                        >
                          {item.badge}
                        </span>
                      {/if}

                      {#if item.external}
                        <span
                          class="icon-[lucide--arrow-up-right]"
                          aria-hidden="true"
                        >
                        </span>
                      {/if}
                    </a>
                  </div>
                </section>

              {:else}
                <section
                  class="wire-footer__column"
                  aria-labelledby='footer-heading-{itemIndex}'
                >
                  {#if item.icon}
                    <span
                      class='{item.icon}'
                      aria-hidden="true"
                    >
                    </span>
                  {/if}

                  {#if item.title || item.label}
                    <h2
                      id='footer-heading-{itemIndex}'
                      class="wire-footer__heading"
                    >
                      {item.title || item.label}
                    </h2>
                  {/if}

                  {#if item.description}
                    <p>
                      {item.description}
                    </p>
                  {/if}

                  {#if (item.items || item.links || []).length > 0}
                    <div
                      class="wire-footer__column-links"
                    >
                      {#each item.items || item.links || [] as child, childIndex}
                        <a
                          href='{child.href || "#"}'
                          target='{child.target || ""}'
                          rel='{child.external ? "noopener noreferrer" : (child.rel || "")}'
                          aria-current='{child.active ? "page" : ""}'
                          class="wire-footer__link"
                          @click='output.select({ item: child, parent: item, itemIndex: childIndex, sectionIndex: itemIndex }); child.action && output.action({ item: child, parent: item, itemIndex: childIndex, sectionIndex: itemIndex })'
                        >
                          {#if child.icon}
                            <span
                              class='{child.icon}'
                              aria-hidden="true"
                            >
                            </span>
                          {/if}

                          <span>
                            {child.label || child.title}
                          </span>

                          {#if child.badge}
                            <span
                              class="wire-badge wire-badge--default"
                            >
                              {child.badge}
                            </span>
                          {/if}

                          {#if child.external}
                            <span
                              class="icon-[lucide--arrow-up-right]"
                              aria-hidden="true"
                            >
                            </span>
                          {/if}
                        </a>
                      {/each}
                    </div>
                  {/if}
                </section>
              {/if}
            {/each}
          </nav>
        {/if}

        <div
          class="wire-footer__post"
        >
          <slot
            name="post-footer"
          >
          </slot>
        </div>
      </div>

      <div
        class="wire-footer__bottom wire-footer__bottom--slots"
      >
        <div
          class="wire-footer__copyright-left"
        >
          <slot
            name="copyright-left"
          >
          </slot>
        </div>

        {#if copyright}
          <div
            class="wire-footer__bottom"
          >
            <div></div>
            <p
              class="wire-footer__copyright"
            >
              {copyright}
            </p>
            <div></div>
          </div>
        {/if}

        <div
          class="wire-footer__copyright-right"
        >
          <slot
            name="copyright-right"
          >
          </slot>
        </div>
      </div>
    </footer>
  }

  style {
    .wire-footer--columns-1 {
      --wire-footer-columns: 1;
    }

    .wire-footer--columns-2 {
      --wire-footer-columns: 2;
    }

    .wire-footer--columns-3 {
      --wire-footer-columns: 3;
    }

    .wire-footer--columns-4 {
      --wire-footer-columns: 4;
    }

    .wire-footer--columns-5 {
      --wire-footer-columns: 5;
    }

    .wire-footer--columns-6 {
      --wire-footer-columns: 6;
    }

    @media (max-width: 900px) {
      .wire-footer--columns-1 .wire-footer__links {
        grid-template-columns: 1fr;
      }

      .wire-footer--columns-2 .wire-footer__links {
        grid-template-columns: repeat(2, minmax(0, 1fr));
      }
    }

    @media (max-width: 600px) {
      .wire-footer--columns-1 .wire-footer__links {
        grid-template-columns: 1fr;
      }
    }

    /* --- Badge ---------------------------------------------------------------- */
    .wire-badge {
      display: inline-flex;
      align-items: center;
      font-size: 0.75rem;
      font-weight: 700;
      line-height: 1;
      padding: 0.25rem 0.5rem;
      border-radius: 999px;
    }

    .wire-badge--default {
      background: var(--wire-color-surface-2);
      color: var(--wire-color-text);
    }

    /* Structured responsive footer */
    .wire-footer {
      width: 100%;
      color: var(--wire-color-text);
      background: var(--wire-color-surface);
      border-top: 1px solid var(--wire-color-border);
      font-size: 0.875rem;
      font-weight: 400;
    }

    .wire-footer__grid {
      display: grid;
      grid-template-columns: minmax(13rem, 1.2fr) minmax(0, 3fr) minmax(13rem, 1fr);
      width: min(100%, 90rem);
      margin-inline: auto;
      padding: clamp(2rem, 5vw, 4rem) clamp(1rem, 4vw, 3rem);
      gap: clamp(1.5rem, 4vw, 3.5rem);
    }

    .wire-footer--width-full .wire-footer__grid {
      width: 100%;
      max-width: none;
    }

    .wire-footer__pre:empty,
    .wire-footer__post:empty,
    .wire-footer__pre:not(:has(*)),
    .wire-footer__post:not(:has(*)) {
      display: none;
    }

    .wire-footer__pre,
    .wire-footer__post {
      min-width: 0;
    }

    .wire-footer__pre strong,
    .wire-footer__post strong {
      font-size: 0.875rem;
      font-weight: 600;
    }

    .wire-footer__pre p,
    .wire-footer__post p {
      font-size: 0.8125rem;
      font-weight: 400;
      line-height: 1.6;
    }

    .wire-footer__links {
      display: grid;
      grid-template-columns: repeat(var(--wire-footer-columns, 3), minmax(0, 1fr));
      align-content: start;
      gap: 1.5rem;
    }

    .wire-footer__column {
      display: grid;
      min-width: 0;
      align-content: start;
      gap: 0.8rem;
    }

    .wire-footer__column-links {
      display: grid;
      align-content: start;
      gap: 0.55rem;
    }

    .wire-footer__heading {
      display: block;
      color: var(--wire-color-text);
      font-size: 0.8125rem;
      font-weight: 600;
    }

    .wire-footer__link {
      display: flex;
      width: fit-content;
      min-height: 2rem;
      align-items: center;
      gap: 0.4rem;
      color: var(--wire-color-muted);
      font-size: 0.8125rem;
      font-weight: 400;
      text-decoration: none;
    }

    .wire-footer__link:hover {
      color: var(--wire-component-color, var(--wire-color-primary));
      text-decoration: underline;
      text-underline-offset: 0.2em;
    }

    .wire-footer__bottom {
      display: grid;
      grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
      align-items: center;
      gap: 1rem;
      padding: 1rem clamp(1rem, 4vw, 3rem);
      color: var(--wire-color-muted);
      border-top: 1px solid var(--wire-color-border);
      font-size: 0.75rem;
      font-weight: 400;
    }

    .wire-footer__bottom--slots {
      grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    }

    .wire-footer__bottom--slots:not(
      :has(.wire-footer__copyright-left > *, .wire-footer__copyright-right > *)
    ) {
      display: none;
    }

    .wire-footer__copyright {
      text-align: center;
    }

    .wire-footer__copyright-left,
    .wire-footer__copyright-right {
      display: flex;
      min-width: 0;
      align-items: center;
      gap: 0.75rem;
    }

    .wire-footer__copyright-right {
      justify-content: flex-end;
      text-align: right;
    }

    .wire-footer__copyright-left:empty,
    .wire-footer__copyright-right:empty,
    .wire-footer__copyright-left:not(:has(*)),
    .wire-footer__copyright-right:not(:has(*)) {
      min-height: 0;
    }

    @media (max-width: 900px) {
    .wire-footer__grid {
        grid-template-columns: 1fr;
      }
    .wire-footer__links {
        grid-template-columns: repeat(3, minmax(0, 1fr));
      }
    }

    @media (max-width: 600px) {
    .wire-footer__links {
        grid-template-columns: repeat(2, minmax(0, 1fr));
      }
    .wire-footer__bottom,
      .wire-footer__bottom--slots {
        grid-template-columns: 1fr;
        justify-items: center;
        text-align: center;
      }
    .wire-footer__copyright-left,
      .wire-footer__copyright-right {
        justify-content: center;
        text-align: center;
      }
    }

    @media (max-width: 420px) {
    .wire-footer__links {
        grid-template-columns: 1fr;
      }
    }
  }
}
