import * as tslib_1 from "tslib";
import { Component } from '@angular/core';
import { Location } from '@angular/common';
import { Router } from '@angular/router';
import { ServiceService } from './../../config/service.service';
import { WishService } from './../../config/wish.service';
import { ProductsService } from './../../config/products.service';
let WishlistPage = class WishlistPage {
    constructor(location, router, service, wishService, prodService) {
        this.location = location;
        this.router = router;
        this.service = service;
        this.wishService = wishService;
        this.prodService = prodService;
        this.loader = true;
        setTimeout(() => {
            this.loader = false;
        }, 2000);
        const users = this.service.get('user').then(data => {
            if (data) {
                data = JSON.parse(data);
                this.custId = data.uid;
                this.wishService.wishList(this.custId);
            }
        });
    }
    ngOnInit() { }
    goBack() {
        this.location.back();
    }
    clearAll() {
        this.loader = true;
        this.wishService
            .clearWish(this.custId)
            .then(data => {
            this.loader = false;
            this.service.showToast('Wish list cleared successfully', 'top', 'my-toast', 2000);
        })
            .catch(err => {
            this.loader = false;
            this.service.showToast('Something went wrong', 'top', 'my-error', 1000);
        });
    }
    addToCart() {
        this.loader = true;
        this.wishService
            .addToCart(this.custId, this.wishService.whishItem)
            .then(data => {
            this.wishService
                .clearWish(this.custId)
                .then(datas => {
                this.loader = false;
                this.service.showToast('Added to cart', 'top', 'my-toast', 2000);
            })
                .catch(err => {
                this.loader = false;
                this.service.showToast('Something went wrong', 'top', 'my-error', 1000);
            });
        })
            .catch(err => {
            this.loader = false;
            this.service.showToast('Something went wrong', 'top', 'my-error', 1000);
        });
    }
    removeItem(prodId) {
        this.loader = true;
        this.wishService
            .clearWishItem(this.custId, prodId)
            .then(data => {
            this.loader = false;
            this.service.showToast('Wish list cleared successfully', 'top', 'my-toast', 2000);
        })
            .catch(err => {
            this.loader = false;
            this.service.showToast('Something went wrong', 'top', 'my-error', 1000);
        });
    }
    goToPage(path, data = null) {
        this.router.navigateByUrl(path, { queryParams: data });
        document.body.scrollTop = document.documentElement.scrollTop = 0;
    }
    prodDetails(index) {
        console.log(this.wishService.whishItem[index]);
        this.prodService.setProd(this.wishService.whishItem[index]);
        this.router.navigateByUrl('productdetail');
        document.body.scrollTop = document.documentElement.scrollTop = 0;
    }
};
WishlistPage = tslib_1.__decorate([
    Component({
        selector: 'app-wishlist',
        templateUrl: './wishlist.page.html',
        styleUrls: ['./wishlist.page.scss']
    }),
    tslib_1.__metadata("design:paramtypes", [Location,
        Router,
        ServiceService,
        WishService,
        ProductsService])
], WishlistPage);
export { WishlistPage };
//# sourceMappingURL=wishlist.page.js.map