import { Component, OnInit, OnDestroy } from '@angular/core';
import { Router } from '@angular/router';

import { OperationCommerciale } from '../../../../models/OperationCommerciale';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';

import { AngularFireAuth } from 'angularfire2/auth';
import { AuthService } from '../../../services/auth/auth.service';
import { OpCommercialService } from '../../../services/opCommercial/op-commercial.service';

import { ActivatedRoute } from '@angular/router';
@Component({
  selector: 'app-list-scan-effecter',
  templateUrl: './list-scan-effecter.component.html',
  styleUrls: ['./list-scan-effecter.component.scss'],
  providers: [AuthService, OpCommercialService]
})
export class ListScanEffecterComponent implements OnInit, OnDestroy {

  opComm: OperationCommerciale;
  opCommList: FirebaseListObservable<any[]>;
  scanList: FirebaseListObservable<any[]>;

  constructor(public afAuth: AngularFireAuth, public afDb: AngularFireDatabase,
              private router: Router, private route: ActivatedRoute) {
    this.route.params.subscribe(params => {

      this.opCommList = this.afDb.list('/OperationCommercial/', {
        query: {
          orderByChild: 'uid',
          equalTo: params['idOp']
        }
      });
      this.opCommList.forEach(op => {
        op.forEach(element => {
          this.opComm = element;


          this.scanList = this.afDb.list('/Scan/', {
            query: {
              orderByChild: 'operationCommercial/uid',
              equalTo: params['idOp']
            }
          });

        });
      });
    });
  }

  goToOpComAdmin() {
    this.router.navigate(['/listOpCommercialAdmin']);
  }

  ngOnInit() {
  }
  ngOnDestroy() {
  }
}
