import { Component } from '@angular/core';
import { ISCommonService } from '../iscommon.service';
import { MatTableDataSource } from '@angular/material/table';
import { Protocol, ProtocolParams } from '../model/controller.model';

export interface ProtocolDatasource {
  protocol: string;
  datasource: MatTableDataSource<ProtocolParams>;
}

@Component({
  selector: 'app-protocols',
  templateUrl: './protocols.component.html',
  styleUrls: ['./protocols.component.css']
})
export class ProtocolsComponent {
  protDatasources:ProtocolDatasource[] = [];
  colums : string[] = ['name', 'label', 'type', 'optional', 'hasSelFunction'];

  constructor(public service:ISCommonService)  {
    this.service.loadProtocols().subscribe({
      next:(data:Protocol[]) => {
        data.forEach(p => {
          this.protDatasources.push({
            protocol   : p.id,
            datasource : new MatTableDataSource(p.params)
         });
        })
      },
      error:error => console.log(error),
      complete:() => console.log("Completed")
    })
  }

}
