import {
  Component,
  ElementRef,
  OnDestroy,
  OnInit,
  ViewChild,
  ViewEncapsulation,
  AfterViewInit
} from '@angular/core';

import { Subject } from 'rxjs';
import { fuseAnimations } from 'src/@fuse/animations';
import { BankInfoListDataSource } from './bank-info-list.data-source';
import { BankInfoService } from 'src/modules/sites/bank-info/service/bank-info.service';
import {
  FormGroup,
  FormBuilder,
  Validators,
  FormArray,
  FormControl
} from '@angular/forms';

@Component({
  selector: 'app-page-sites-bank-info-list',
  templateUrl: './bank-info-list.component.html',
  styleUrls: ['./bank-info-list.component.scss'],
  animations: fuseAnimations,
  encapsulation: ViewEncapsulation.None
})
export class BankInfoListComponent implements OnInit, OnDestroy, AfterViewInit {
  dataSource: BankInfoListDataSource = new BankInfoListDataSource(
    this.bankInfoService
  );

  displayedColumns = ['id', 'name', 'number', 'holder', 'description'];
  public bankInfoFormGroup: FormGroup;
  public bankInfoFormArray: FormArray;

  @ViewChild('filter', { static: true })
  filter: ElementRef;

  // Private
  private _unsubscribeAll: Subject<any>;

  constructor(
    private bankInfoService: BankInfoService,
    private fb: FormBuilder
  ) {
    this._unsubscribeAll = new Subject();
  }

  ngOnInit() {
    this.bankInfoFormArray = this.fb.array([]);
    this.bankInfoFormGroup = this.fb.group({
      formarray: this.bankInfoFormArray
    });
    this.dataSource.formg = this.bankInfoFormGroup;
  }

  /**
   * On destroy
   */
  ngOnDestroy(): void {
    // Unsubscribe from all subscriptions
    this._unsubscribeAll.next();
    this._unsubscribeAll.complete();
  }

  ngAfterViewInit(): void {}

  bankInfoUpdate(): void {}
}
