import {Component} from '@angular/core';
import {MaterialTypeService} from "../../service/material-type.service";
import {SubscribingComponent} from "../../../shared/components/subscribing.component";
import {EmployeePermission} from "../../../shared/model/employee";
import {FormBuilder} from "@angular/forms";
import {ActivatedRoute, Router} from "@angular/router";

@Component({
  selector: 'cre-list',
  templateUrl: './list.component.html',
  styleUrls: ['./list.component.sass']
})
export class ListComponent extends SubscribingComponent {
  materialTypes$ = this.materialTypeService.all
  columns = [
    {def: 'name', title: 'Nom', valueFn: t => t.name},
    {def: 'prefix', title: 'Préfixe', valueFn: t => t.prefix},
    {def: 'usePercentages', title: 'Utilise les pourcentages', valueFn: t => t.usePercentages ? 'Oui' : 'Non'}
  ]
  buttons = [
    {
      text: 'Modifier',
      linkFn: t => `/catalog/materialtype/edit/${t.id}`,
      permission: EmployeePermission.EDIT_MATERIAL_TYPE,
      disabledFn: t => t.systemType
    }
  ]

  constructor(
    private materialTypeService: MaterialTypeService,
    router: Router,
    activatedRoute: ActivatedRoute
  ) {
    super(activatedRoute, router)
  }
}
