import { Component, OnInit, ViewChild, ElementRef,NgModule  } from '@angular/core';
import { HyperService } from '../../core/services/http.service';
import { Router, RouterModule, Routes, ActivatedRoute } from '@angular/router';
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
import { DatePipe } from '@angular/common';
import * as moment from 'moment';
import { LocalStorage } from '../../core/services/local_storage.service';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { DatepickerOptions } from 'ng2-datepicker';
import * as enLocale from 'date-fns/locale/en';
import { ConfirmPopupComponent } from '../../sales_executive/confirm-popup/confirm-popup.component';
// declare var $: any;
import { Subscription } from "rxjs";
import { Observable } from "rxjs/Observable";
import { Location } from '@angular/common';
import { ToasterService } from '@service/toaster.service';
import $ from 'jquery';
declare var $: $;
import { CONFIG } from '../../config';

@Component({
  selector: 'app-price-list-dealer',
  templateUrl: './price-list-dealer.component.html',
  styleUrls: ['./price-list-dealer.component.scss']
})
export class PriceListDealerComponent implements OnInit {

  pricedata:any=[];
  pricelist:any=[];
  modelarr:any=[];
  loader:boolean=false;
  modelselected:any='';
  dsename:any='';
  dsecityvalue:any='';
  smpinselected: any = '';
  smpinselectedname: any = '';
  dseselected:any='';
  dsearr:any=[];

  constructor(
    private server: HyperService, 
    private router: Router,
    private _eref: ElementRef,
    private route: ActivatedRoute,
    private formBuilder: FormBuilder,
    private toaster: ToasterService
    ) {
      
        
    }

  ngOnInit() {
    this.smpinselected = LocalStorage.getValue('setdseselected');
    this.smpinselectedname = LocalStorage.getValue('setdseselectedname');
  //  console.log("setdseselected--->", this.smpinselected);

    //console.log("CONFIG.selecteddsename-->",CONFIG.selecteddsename)
    this.dsename=LocalStorage.getValue('selecteddsename');
    this.dsecityvalue=LocalStorage.getValue('selecteddsecity');

   // console.log("this.dsename-->",this.dsename);
   // console.log("this.dsecityvalue-->",this.dsecityvalue);
   this.getuserlist();
  //  this.getcommondetails();
  }

  getpricelistdetails(){
    let modelvalue=this.modelselected;
    this.loader = true;
    this.server.post("dealerenquiry/pricelist/"+this.smpinselected,{model:modelvalue})
    .then((data) => {
      this.loader = false;
        if (data.status == 200 && data.result.response != 'failed') {
          this.pricedata=data.result.data;
        }else if (data.result.status == 406 ) {
        }
         else if (data.result.status == 401 && data.result.response == 'failed') {}
    });
  }
  //===
  getcommondetails() {
    this.loader = true;
    this.server.get("dealerenquiry/common/" + this.smpinselected)
    .then((data) => {
      this.loader = false;
        if (data.status == 200 && data.result.response != 'failed') {
        this.modelarr=data.result.data.model;
        }else if (data.result.status == 406 ) {
              //alert(data.result.message)
        }
         else if (data.result.status == 401 && data.result.response == 'failed') {

         }
    });
  }

  getuserlist() {
    this.loader = true;
    this.server.get("dealer/userlist")
    .then((data) => {
      this.loader = false;
        if (data.status == 200 && data.result.response != 'failed') {
        this.dsearr=data.result.data;
        }else if (data.result.status == 406 ) {
              //alert(data.result.message)
        }
         else if (data.result.status == 401 && data.result.response == 'failed') {

         }
    });
  }
  selectmodel(temp){
    this.getpricelistdetails();
  }
  //==
  selecteddse(temp){
    this.smpinselected = this.dseselected;
    this.getcommondetails();
  }


}
