/**
 * @aurora-catalyst-generated
 * @source cliter/iam/role.aurora.yaml
 */
import { ChangeDetectionStrategy, Component, input } from '@angular/core';
import { TranslocoDirective } from '@jsverse/transloco';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucideMoreHorizontal, lucidePencil, lucideTrash2 } from '@ng-icons/lucide';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmDropdownMenuImports } from '@spartan-ng/helm/dropdown-menu';
import { HlmIconImports } from '@spartan-ng/helm/icon';
import { type IamRole } from '@src/src/app/aurora.types';
import { injectFlexRenderContext, type CellContext } from '@tanstack/angular-table';

@Component({
  selector: 'au-role-list-actions-cell',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [TranslocoDirective, NgIcon, HlmButtonImports, HlmDropdownMenuImports, HlmIconImports],
  providers: [provideIcons({ lucideMoreHorizontal, lucidePencil, lucideTrash2 })],
  template: `
    <ng-container *transloco="let t">
      <div class="flex">
        <button
          class="h-6 w-6 p-0.5"
          [hlmDropdownMenuTrigger]="menu"
          align="start"
          hlmBtn
          variant="ghost"
        >
          <ng-icon
            name="lucideMoreHorizontal"
            hlm
            size="sm"
          />
          <span class="sr-only">{{ t('OpenMenu') }}</span>
        </button>
        <ng-template #menu>
          <hlm-dropdown-menu class="w-40">
            <button
              hlmDropdownMenuItem
              (click)="onEdit()"
            >
              <ng-icon
                name="lucidePencil"
                class="mr-2"
                hlm
                size="sm"
              />
              {{ t('Edit') }}
            </button>
            <button
              class="text-destructive"
              hlmDropdownMenuItem
              (click)="onDelete()"
            >
              <ng-icon
                name="lucideTrash2"
                class="mr-2"
                hlm
                size="sm"
              />
              {{ t('Delete') }}
            </button>
          </hlm-dropdown-menu>
        </ng-template>
      </div>
    </ng-container>
  `,
})
export class RoleListActionsCell {
  // injections
  private readonly context = injectFlexRenderContext<CellContext<IamRole, unknown>>();

  // inputs
  readonly onRequestEdit = input.required<(role: IamRole) => void>();
  readonly onRequestDelete = input.required<(role: IamRole) => void>();

  onEdit() {
    this.onRequestEdit()(this.context.row.original);
  }

  onDelete() {
    this.onRequestDelete()(this.context.row.original);
  }
}
