import { Component, OnInit, TemplateRef } from "@angular/core";
import { BsDatepickerConfig, BsModalRef, BsModalService } from "ngx-bootstrap";

declare var $: any;
declare var swal: any;
import * as moment from "moment";
import { ContactService } from "../../contact.service";
import { FormControl, FormGroup, Validators } from "@angular/forms";
import { MdDialogRef } from "@angular/material";
@Component({
  selector: "app-issue-add-kyc",
  templateUrl: "./issue-add.component.html",
  styleUrls: ["./issue-add.component.scss"],
})
export class IssueAddKycComponent implements OnInit {
  issues = [];

  bsConfig: Partial<BsDatepickerConfig>;
  issueForm: FormGroup;
  userId;
  colorTheme = "theme-dark-blue";
  Load: boolean;
  constructor(
    private contactService: ContactService,
    private dialogRef: MdDialogRef<IssueAddKycComponent>
  ) {
    this.bsConfig = Object.assign(
      { dateInputFormat: "DD-MM-YYYY, h:mm:ss a" },
      { containerClass: this.colorTheme }
    );
    this.issueForm = new FormGroup({
      VehicleNo: new FormControl("", [Validators.required]),
      DeviceIMEI: new FormControl("", [Validators.required]),
      email: new FormControl("", [Validators.required]),
      mobile: new FormControl("", [Validators.required]),
      fileName: new FormControl(""),
      msg: new FormControl("", [Validators.required]),
    });
  }
  get VehicleNo() {
    return this.issueForm.get("VehicleNo");
  }
  get DeviceIMEI() {
    return this.issueForm.get("DeviceIMEI");
  }
  get email() {
    return this.issueForm.get("email");
  }
  get mobile() {
    return this.issueForm.get("mobile");
  }
  get fileName() {
    return this.issueForm.get("fileName");
  }
  get msg() {
    return this.issueForm.get("msg");
  }

  ngOnInit() {
    this.userId = JSON.parse(
      window.atob(window.localStorage.token.split(".")[1])
    )._id;
    // this.getIssues()
  }
  submit() {
    if (this.issueForm.valid) {
      let postObj = this.issueForm.value;
      postObj.user = this.userId;
      this.contactService
        .post("/customer_support/post_inquiry", postObj)
        .subscribe((res) => {
          console.log(res);
          swal({
            title: "Saved!",
            html: "Your Issue has been Created.",
            icon: "success",
          });
          this.dialogRef.close();
        });
    }
  }
}
