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

@Component({
  selector: 'au-row-selection',
  imports: [HlmCheckboxImports],
  host: {
    class: 'flex',
    'aria-label': 'Select Row',
  },
  template: `
    <hlm-checkbox
      [checked]="context.row.getIsSelected()"
      (checkedChange)="context.row.getToggleSelectedHandler()($event)"
    />
  `,
})
export class RowSelection {
  protected readonly context = injectFlexRenderContext<CellContext<unknown, unknown>>();
}
