import { Component, Inject, OnInit } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { ActivatedRoute } from '@angular/router';

@Component({
  selector: 'app-getbfo-viewexample',
  templateUrl: './getbfo-viewexample.component.html',
  styleUrls: ['./getbfo-viewexample.component.css']
})
export class GETBFOVIEWEXAMPLEComponent implements OnInit {

  public data_form: DataForm = {} as DataForm;
  public json: JsonForm = {} as JsonForm;
  public num_col: number;
  constructor(
    public dialogRef: MatDialogRef<GETBFOVIEWEXAMPLEComponent>,
    @Inject(MAT_DIALOG_DATA) public data: any,
    private _activatedRoute: ActivatedRoute
  ) {
    this.data_form = JSON.parse(this.data.data_form);
    this.json = JSON.parse(this.data.json);
    this.num_col = this.data.num_columns;
  }

  ngOnInit(): void { }

  public getFile(idInput: string) {
    document.getElementById(idInput)!!.click();
  }

  public sub(obj: any, label: string, idBtn: string) {
    var file = obj.value;
    if (file != '') {
      var fileName = file.split("\\");
      document.getElementById(idBtn)!!.innerHTML = fileName[fileName.length - 1];
    } else {
      document.getElementById(idBtn)!!.innerHTML = label;
    }
  }
}


export interface DataForm {
  modulo: string;
  submodulo: string;
  formulario: string;
}

export interface JsonForm {
  name: string;
  fields: Array<FieldsForm>;
}

export interface FieldsForm {
  step: string;
  multi_data: boolean;
  form: Array<any>;
  num_cols: number;
}
