import { Component, OnInit } from '@angular/core';
import { RegisterService } from 'src/app/services/register.service';
import * as countries_json from "../../../../assets/data/country_codes.json";
import { Router } from '@angular/router';


@Component({
  selector: 'app-my-user',
  templateUrl: './my-user.component.html',
  styleUrls: ['./my-user.component.css']
})
export class MyUserComponent implements OnInit {

  countries:any = countries_json;

  constructor(public registerService:RegisterService,
              private router:Router) { }

  ngOnInit(): void {
    this.registerService.setStep(2);
    this.countries = this.countries.default;

    if(!this.businessValid()) {
      this.router.navigate(["/register", "business"]);
    }
  }

  next() {
    this.router.navigate(["/register", "box"]);
  }

  private businessValid():boolean {
    return  this.registerService.request.company.address != null &&
            this.registerService.request.company.cif != null &&
            this.registerService.request.company.city != null &&
            this.registerService.request.company.country != null &&
            this.registerService.request.company.county != null &&
            this.registerService.request.company.email != null &&
            this.registerService.request.company.fact_address_line1 != null &&
            //this.registerService.request.company.fact_address_line2 != null &&
            this.registerService.request.company.fact_city != null &&
            this.registerService.request.company.fact_country_code != null &&
            this.registerService.request.company.fact_county != null &&
            this.registerService.request.company.fact_name != null &&
            this.registerService.request.company.fact_serie != null &&
            this.registerService.request.company.fact_zipcode != null &&
            this.registerService.request.company.name != null &&
            this.registerService.request.company.phone != null &&
            this.registerService.request.company.zipcode != null;
  }

}
