import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { AuthService } from 'src/app/auth/services/auth.service';
import { DashboardSeller } from 'src/app/models/dashboard-seller.model';
import { OrderService } from 'src/app/services/order.service';

@Component({
  selector: 'app-kpisales',
  templateUrl: './kpisales.component.html',
  styleUrls: ['./kpisales.component.scss']
})

export class KpisalesComponent implements OnInit, OnDestroy {
  constructor(
    private orderService: OrderService,
    private authService: AuthService,
    private router: Router) { }

  metaMes = 'Meta do Mês';
  metaDia = 'Meta do dia';
  comissao = 'Comissão';
  clientes = 'Clientes Atendidos';
  notas = 'Notas emitidas';
  orcamentosPendentes = 'Orçamentos pendentes';
  loading = false;
  sellerId = 0;

  subscriptionDash: Subscription;
  dataDashboardSeller: DashboardSeller;

  // Controles window de orçamentos pendentes //
  public windowPreOrderWidth = 900;
  public windowPreOrderHeight = 600;
  public showPreOrder = false;

  public openClose(isOpened: boolean): void {
    this.showPreOrder = isOpened;
  }

  ngOnInit(): void {
    this.sellerId = this.authService.getSeller();
    this.loading = true;
    this.subscriptionDash = this.orderService
      .getDashboardSeller(this.sellerId).subscribe(result => {
        this.dataDashboardSeller = result;
        this.loading = false;
    });
  }

  ngOnDestroy(): void {
    if (this.subscriptionDash){
      this.subscriptionDash.unsubscribe();
    }
  }

  openNewOrder() {
    this.router.navigate(['/sales/home']);
  }

}
