// Angular Core
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

// Services
import { ApiService } from '../api/api.service';

@Injectable({
  providedIn: 'root'
})
export class QuickcartService {

  constructor(private http: HttpClient, public api: ApiService) { }

  /**
  * Stores cart count data
  * @type Object
  */
  quickcart = {
    data: {
      count: []
    }
  };

  /**
   * Initiates the ajax call to get quickcart data
   * @returns {promise}
   */
  get() {
    return this.api.read('/Cart-QuickCart');
    // r.then(function(response) {
    //     quickcart.data = response.data.data;
    // }, api.errorCallback);
    // return r;
  };

  /**
   * Handles error with ajax API
   * @param {object} response
   * @returns {undefined}
   */
  errorCallBack(response: any) {
    this.api.errorCallback(response);
  };
}
