import { Component, Input } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MatIconModule } from '@angular/material/icon';

@Component({
  selector: 'app-page-header',
  standalone: true,
  imports: [CommonModule, MatIconModule],
  template: `
    <header class="page-header" role="banner">
      <div class="page-header-content">
        @if (icon) {
          <div class="page-header-icon">
            <mat-icon>{{ icon }}</mat-icon>
          </div>
        }
        <div class="page-header-text">
          <h1 class="page-title" [id]="titleId">{{ title }}</h1>
          @if (subtitle) {
            <p class="page-subtitle" [attr.aria-describedby]="titleId">{{ subtitle }}</p>
          }
        </div>
      </div>
      <div class="page-actions" role="group" aria-label="Page actions">
        <ng-content></ng-content>
      </div>
    </header>
  `,
  styles: [
    `
      .page-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 24px;
        flex-wrap: wrap;
        gap: 16px;
      }

      .page-header-content {
        display: flex;
        align-items: center;
        gap: 16px;
        flex: 1;
        min-width: 200px;
      }

      .page-header-icon {
        width: 48px;
        height: 48px;
        border-radius: 12px;
        background: linear-gradient(135deg, #1D0A69 0%, #2563EB 100%);
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;

        mat-icon {
          color: white;
          font-size: 24px;
          width: 24px;
          height: 24px;
        }
      }

      .page-title {
        margin: 0;
        font-size: 1.75rem;
        font-weight: 700;
        color: var(--dbim-brown, #150202);
        line-height: 1.2;
      }

      .page-subtitle {
        margin: 8px 0 0;
        font-size: 0.875rem;
        color: var(--dbim-grey-2, #8E8E8E);
        line-height: 1.5;
      }

      .page-actions {
        display: flex;
        gap: 8px;
        flex-wrap: wrap;
      }

      @media (max-width: 600px) {
        .page-header {
          flex-direction: column;
          align-items: flex-start;
        }

        .page-title {
          font-size: 1.5rem;
        }
      }
    `,
  ],
})
export class PageHeaderComponent {
  @Input({ required: true }) title!: string;
  @Input() subtitle?: string;
  @Input() icon?: string;

  // Generate unique ID for accessibility
  readonly titleId = `page-title-${Math.random().toString(36).substr(2, 9)}`;
}
