import { Component, Input, ChangeDetectionStrategy, ViewEncapsulation } from '@angular/core';
import { CommonModule } from '@angular/common';

type StackSpacing = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl';
type VerticalAlignment = 'start' | 'center' | 'end' | 'stretch' | 'baseline';
type HorizontalJustify = 'start' | 'center' | 'end' | 'between' | 'around' | 'evenly';
type StackWrap = 'nowrap' | 'wrap' | 'wrap-reverse';

@Component({
  selector: 'ui-hstack',
  standalone: true,
  imports: [CommonModule],
  changeDetection: ChangeDetectionStrategy.OnPush,
  encapsulation: ViewEncapsulation.None,
  template: `
    <div 
      [ngClass]="getClasses()"
      [attr.role]="role"
      [style.gap]="customGap">
      
      <ng-content></ng-content>
    </div>
  `,
  styleUrl: './hstack.component.scss'
})
export class HStackComponent {
  @Input() spacing: StackSpacing = 'md';
  @Input() align?: VerticalAlignment;
  @Input() justify?: HorizontalJustify;
  @Input() wrap?: StackWrap;
  @Input() inline = false;
  @Input() responsive = true;
  @Input() divider = false;
  @Input() fullWidth = false;
  @Input() customGap?: string;
  @Input() role?: string;

  getClasses(): Record<string, boolean> {
    const classes: Record<string, boolean> = {
      'ui-hstack': true,
      [`ui-hstack--spacing-${this.spacing}`]: true,
      'ui-hstack--inline': this.inline,
      'ui-hstack--responsive': this.responsive,
      'ui-hstack--divider': this.divider,
      'ui-hstack--full-width': this.fullWidth
    };

    if (this.align) {
      classes[`ui-hstack--align-${this.align}`] = true;
    }

    if (this.justify) {
      classes[`ui-hstack--justify-${this.justify}`] = true;
    }

    if (this.wrap) {
      classes[`ui-hstack--wrap-${this.wrap}`] = true;
    }

    return classes;
  }
}