/**
 * Copyright Aquera Inc 2025
 *
 * This source code is licensed under the BSD-3-Clause license found in the
 * LICENSE file in the root directory of this source tree.
 */

import { html, CSSResultArray, TemplateResult } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { styles } from './nile-inline-sidebar-group.css';
import NileElement from '../internal/nile-element';

/**
 * Nile inline sidebar group.
 *
 * @tag nile-inlinesidebar-group
 *
 * @attr label - Optional group label
 * @attr divider - Whether to show a divider below the group (default: true)
 *
 * @slot - Inline sidebar items
 * @slot label - Optional label/header for the group
 */
@customElement('nile-inline-sidebar-group')
export class NileInlineSidebarGroup extends NileElement {
  @property({ type: String }) label: string = '';
  @property({ type: Boolean, reflect: true }) divider: boolean = false;

  public static get styles(): CSSResultArray {
    return [styles];
  }

  public render(): TemplateResult {
    return html`
      <div class="group">
        ${this.label || this.hasLabelSlot()
          ? html`
              <div class="group-label">
                <slot name="label">${this.label}</slot>
              </div>
            `
          : null}
        <div class="group-items">
          <slot></slot>
        </div>
      </div>
    `;
  }

  private hasLabelSlot(): boolean {
    const slot = this.shadowRoot?.querySelector('slot[name="label"]');
    return !!slot;
  }
}

export default NileInlineSidebarGroup;

declare global {
  interface HTMLElementTagNameMap {
    'nile-inline-sidebar-group': NileInlineSidebarGroup;
  }
}
