/**
 * @license
 * Copyright 2019 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */

import {LitElement, html, css, unsafeCSS} from 'lit';
import {customElement, property} from 'lit/decorators.js';
import { breakpoints } from '../../breakpoints';

@customElement('iu-links-list')

export class LinksList extends LitElement {
  static override styles = css`
    :host{
      display: block;
      margin-bottom: var(--iu-spacing-block);
    }
    .columns-2{
      width: 50%;
    }
    p{
      font-weight: bold;
    }
    iu-link:last-child{
      border-bottom: 1px solid var(--iu-color-grey-200);
    }
  `;

  @property() label = 'Per approfondire';
  @property({ type: Number }) columns = 2;
  // @property({ type: Array }) items: Array<{ href: string; text: string }> = [];
  @property({ type: String }) items = '[]';

  get parsedItems() {
    try {
      return JSON.parse(this.items);
    } catch {
      return [];
    }
  }

  override render() {
    return html`
        <iu-container>
          <div class="columns-${this.columns}">
            ${this.label && html`<p>${this.label}</p>`}
            ${this.parsedItems.map(item => html`<iu-link href="${item.href}" text="${item.text}" nested></iu-link>`)}
          </div>
        </iu-container>
    `;
  }

}

declare global {
  interface HTMLElementTagNameMap {
    'iu-links-list': LinksList;
  }
}