import { Component } from '@angular/core';
import { HlmCheckboxImports } from '@spartan-ng/helm/checkbox';
import { type HeaderContext, injectFlexRenderContext } from '@tanstack/angular-table';

@Component({
  selector: 'au-head-selection',
  imports: [HlmCheckboxImports],
  host: {
    class: 'flex',
    'aria-label': 'Select all',
  },
  template: `
    <hlm-checkbox
      [checked]="context.table.getIsAllRowsSelected()"
      [indeterminate]="context.table.getIsSomeRowsSelected()"
      (checkedChange)="context.table.toggleAllRowsSelected()"
    />
  `,
})
export class HeadSelection {
  protected readonly context = injectFlexRenderContext<HeaderContext<unknown, unknown>>();
}
