import { Component, Inject } from '@angular/core';
import { GroupOfUserService } from '../../../services/group-of-user.service';
import { GroupOfUser } 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/color-mode.service';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { env } from '../../../../environments/environment';

@Component({
  standalone: true,
  imports: [CommonModule, FormsModule, GuiGridModule ],
  selector: 'app-group-user-table',
  templateUrl: '../base-table/base-table.component.html',
  styleUrl: './group-user-table.component.css'
})
export class GroupUserTableComponent extends BaseTableComponent<GroupOfUser, GroupOfUserService> {
  constructor(service: GroupOfUserService, cModeService: ColorModeService) {
    super(service, env.columnNames.groupOfUser, cModeService)
    this.initData = () => this.fetchDataWith(true,true);
    this.loading = false;
  }

  fetchDataWith(withUser: boolean, withGroup: boolean){
    this.service.getAll(withUser, withGroup).subscribe ({
      next: (response) => {
          this.source = response;
      },
      error: (error) => {}
    });
  }
}