import { BaseComponent } from '@/shared/base/BaseComponent';
import { getAttribute } from '@/shared/utils/locator-utils';

export class DataTableActionHandler extends BaseComponent {
  private readonly actionMenuButtons = this.host.getByTestId('ui-action-button');

  async clickAction(index: number, actionTestId: string): Promise<void> {
    const actionMenuButton = this.actionMenuButtons.nth(index);
    const actionMenuTestId = await getAttribute(actionMenuButton, 'aria-controls');
    const actionMenu = this.host.page().locator(`div[id=${actionMenuTestId}]`);
    const action = actionMenu.getByTestId(actionTestId);

    await actionMenuButton.click();
    await action.click();
  }
}
