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

  countries:any = countries_json;
  same_info:boolean = true; //same info comercial que de fact
  country:string;

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

  ngOnInit(): void {
    this.registerService.setStep(1);
    this.countries = this.countries.default;
    this.registerService.request.company.fact_serie = (new Date().getFullYear()).toString();
  }

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

  setStreet1(val:string) {
    this.registerService.request.company.address = val;
    if(this.same_info) {
      this.registerService.request.company.fact_address_line1 = val;
    }
  }

  setStreet2(val:string) {
    if(this.same_info) {
      this.registerService.request.company.fact_address_line2 = val;
    }
  }
  
  setCity(val:string) {
    this.registerService.request.company.city = val;
    if(this.same_info) {
      this.registerService.request.company.fact_city = val;
    }
  }

  setZipcode(val:string) {
    this.registerService.request.company.zipcode = val;
    if(this.same_info) {
      this.registerService.request.company.fact_zipcode = val;
    }
  }

  setCounty(val:string) {
    this.registerService.request.company.county = val;
    if(this.same_info) {
      this.registerService.request.company.fact_county = val;
    }
  }

  setCountry(val:string) {
    this.registerService.request.company.country = val;
    if(this.same_info) {
      this.registerService.request.company.fact_country_code = val;
    }
  }

}
