import { ChangeDetectionStrategy, Component, input } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideCheck, lucideMinus } from '@ng-icons/lucide';
import { HlmIconImports } from '@spartan-ng/helm/icon';
import { type CellContext, injectFlexRenderContext } from '@tanstack/angular-table';

@Component({
  selector: 'au-boolean-cell',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [NgIcon, HlmIconImports],
  providers: [provideIcons({ lucideCheck, lucideMinus })],
  template: `
    <ng-icon
      [attr.aria-label]="value ? 'true' : 'false'"
      [name]="value ? trueIcon() : falseIcon()"
      [class]="value ? trueClass() : falseClass()"
      hlm
      size="sm"
    />
  `,
})
export class BooleanCell<T = unknown> {
  readonly trueIcon = input<string>('lucideCheck');
  readonly falseIcon = input<string>('lucideMinus');
  readonly trueClass = input<string>('text-emerald-600');
  readonly falseClass = input<string>('text-muted-foreground/60');

  private readonly context = injectFlexRenderContext<CellContext<T, boolean>>();

  protected get value(): boolean {
    return this.context.getValue();
  }
}
