import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { SelectableSettings } from '@progress/kendo-angular-grid';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { CustomerAddress } from 'src/app/models/customer-address.model';
import { Customer } from 'src/app/models/customer.model';
import { ResultApi } from 'src/app/models/result-api.model';
import { AddressCustomerService } from '../../../services/address-customer.service';

@Component({
  selector: 'app-delivery-address',
  templateUrl: './delivery-address.component.html',
  styleUrls: ['./delivery-address.component.scss']
})
export class DeliveryAddressComponent implements OnInit {

  public selectableSettigns: SelectableSettings = {
    checkboxOnly: false
  };
  address$: Observable<CustomerAddress[]>;
  @Output() public submitForm: EventEmitter<any> = new EventEmitter();

  constructor(private addressService: AddressCustomerService) { }

  ngOnInit() {
    const dataCustomer = localStorage.getItem('customer');
    if (dataCustomer != null){
      const customer: Customer = JSON.parse(dataCustomer);
      this.address$ = this.addressService.getAddress(customer.customerId);
    }

  }

  selectionAddress(event) {
    const selAddress = event.selectedRows[0].dataItem as CustomerAddress;
   // this.store.dispatch(new SelectCustomerAction(selCustomer));
    localStorage.setItem('address', JSON.stringify(selAddress));
    this.submitForm.emit(this);
  }

}
