import { Component, OnInit, Inject } from '@angular/core';
import { ApiService } from 'app/api.service';
import { Title } from '@angular/platform-browser';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';

@Component({
  selector: 'app-customers-invitations-add',
  templateUrl: './customers-invitations-add.component.html',
  styleUrls: ['./customers-invitations-add.component.scss']
})
export class CustomersInvitationsAddComponent implements OnInit {

  public action: string = '';
  public cities: any = [];
  public states: any = [];

  constructor(private title: Title, public apiService: ApiService, public dialogRef: MatDialogRef<CustomersInvitationsAddComponent>, @Inject(MAT_DIALOG_DATA) public data: any) {
    if (this.data.type == 'add') {
      this.action = 'Agregar';
    }
    else if (this.data.type == 'edit') {
      this.action = 'Editar';
    }
  }

  ngOnInit() {

  }
  loadCities(evt?:any) {
    /*this.adminService.getCities(this.data.state).subscribe((data:any) => {
      this.cities = data.data;
    }); 
    */   
  }
 
  save() {
    this.apiService.saveInvitation(this.data).subscribe((data:any) => {
      if (data.res == "OK") {
        this.dialogRef.close();
      } else {
        this.apiService.showError("Error",data.msg);
      }
    });
  }
  dismiss() {
    this.dialogRef.close();
  }

}
