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-box',
  templateUrl: './my-box.component.html',
  styleUrls: ['./my-box.component.css']
})
export class MyBoxComponent implements OnInit {

  countries:any = countries_json;

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

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

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

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

  private userValid() {
    return  this.registerService.request.owner.address != null &&
            this.registerService.request.owner.country != null &&
            this.registerService.request.owner.email != null &&
            this.registerService.request.owner.password != null &&
            this.registerService.request.owner.name != null &&
            this.registerService.request.owner.phone != null &&
            this.registerService.request.owner.poblacio != null &&
            this.registerService.request.owner.surnames != null &&
            this.registerService.request.owner.zipcode != null;
  }

}
