import { Component } from '@angular/core';
import { Module } from '../../../models/user-management.api.models';
import { GuiGridModule } from '@generic-ui/ngx-grid';
import { BaseTableComponent } from '../base-table/base-table.component';
import { ModuleService } from '../../../services/api/module.service'
import { ColorModeService } from '../../../services/button/color-mode.service';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { env } from '../../../../environments/environment';
import { ModuleOfUserService } from '../../../services/api/module-of-user.service';

@Component({
  standalone: true,
  imports: [CommonModule, FormsModule, GuiGridModule],
  selector: 'app-module-table',
  templateUrl: '../base-table/base-table.component.html',
  styleUrl: './module-table.component.css'
})
export class ModuleTableComponent extends BaseTableComponent<Module, ModuleService> {
  constructor(
    service: ModuleService, cModeService: ColorModeService, private mouService: ModuleOfUserService) {
      super(service, env.columnNames.module, cModeService)
  }

  fetchDataByUsername(username: string) {
    this.mouService.getByUsername(username)
      .then(mou_list => mou_list.map(mou => mou.module))
      .then(modules => this.source = modules)
  }
}