import { Component, Inject } from '@angular/core';
import { GroupService } from '../../../services/api/group.service';
import { Group } from '../../../models/user-management.api.models';
import { GuiGridModule, GuiColumn } from '@generic-ui/ngx-grid';
import { BaseTableComponent } from '../base-table/base-table.component';
import { ColorModeService } from '../../../services/button/color-mode.service';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { env } from '../../../../environments/environment';
import { GroupOfUserService } from '../../../services/api/group-of-user.service';

@Component({
  standalone: true,
  imports: [CommonModule, FormsModule, GuiGridModule],
  selector: 'app-group-table',
  templateUrl: '../base-table/base-table.component.html',
  styleUrl: './group-table.component.css'
})
export class GroupTableComponent extends BaseTableComponent<Group, GroupService> {
  constructor(service: GroupService, cModeService: ColorModeService, private gouService: GroupOfUserService) {
    super(service, env.columnNames.group.basic, cModeService)
  }

  fetchDataByUsername(username: string) {
    this.gouService.getByUsername(username)
      .then(gos_list => gos_list.map(gos => gos.group))
      .then(groups => this.source = groups)
  }
}