import * as tslib_1 from "tslib";
import { Component } from '@angular/core';
import { Location } from '@angular/common';
import { Router, ActivatedRoute } from '@angular/router';
import { CartsService } from './../../config/cart.service';
import { ProductsService } from './../../config/products.service';
import { ServiceService } from './../../config/service.service';
import { SocialSharing } from '@ionic-native/social-sharing/ngx';
let ProductdetailPage = class ProductdetailPage {
    constructor(router, route, location, cartService, prodService, service, socialSharing) {
        this.router = router;
        this.route = route;
        this.location = location;
        this.cartService = cartService;
        this.prodService = prodService;
        this.service = service;
        this.socialSharing = socialSharing;
        this.disCart = true;
        this.bannerOptions = {
            slidesPerView: 1,
            speed: 2000,
            autoplay: true
        };
        this.slideOpts = {
            slidesPerView: 3.5
        };
        this.relatedProd = {
            slidesPerView: 2
        };
        const params = this.prodService.selItem;
        this.service.state = true;
        this.loader = true;
        this.prodService.similarProd(params.shopperId, params.category, params.subCate, params.prodId);
        this.service.get('params').then(val => {
            this.data = val;
        });
        this.cartService.cartList();
        setTimeout(() => {
            this.loader = false;
        }, 1000);
        // console.log(this.prodService.fav);
    }
    ngOnInit() {
        // console.log("[qwe]", this.prodService.selItem);
        const params = this.prodService.selItem;
        this.getProd(params);
    }
    unEscape(text) {
        const regex = '%uFFFD';
        return unescape(text.replace(/%uFFFD/g, ''));
    }
    getProd(params) {
        if (params) {
            let slideItem = [];
            slideItem.push(params.image);
            this.slideData = slideItem;
            const prod = {
                prodId: params.prodId,
                subCate: params.subCate,
                tag: params.tag,
                prodName: params.prodName,
                prodCode: params.prodCode,
                prodDesc: params.prodDesc,
                prodStatus: params.prodStatus,
                brand: params.brand,
                category: params.category,
                shopperId: params.shopperId,
                color: params.color,
                discount: params.discount,
                featured: params.featured,
                centerId: params.centerId,
                centerRef: params.center,
                image: params.image,
                price: params.price,
                qty: params.qty,
                rating: params.rating,
                shopper: params.shopper,
                skuCode: params.skuCode,
                status: params.status,
                size: params.size
            };
            this.product = prod;
            this.prodService.fetchGallery(params.skuCode).then((galleryData) => {
                slideItem = galleryData;
                this.slideData = slideItem;
            });
        }
        else {
            this.product = undefined;
        }
        // console.log(this.product.image);
    }
    stringObject(items) {
        items.forEach(element => {
            // console.log(element.sizeId);
            element = JSON.parse(element);
            // console.log(element);
        });
    }
    goToPage(path, data = null) {
        this.router.navigateByUrl(path, { queryParams: data });
        document.body.scrollTop = document.documentElement.scrollTop = 0;
    }
    goBack() {
        this.service.state = false;
        this.location.back();
    }
    buyNow(product, type) {
        this.cartService.buyNow(product).then(() => {
            if (type === 1) {
                this.router.navigateByUrl('cart');
            }
            else {
                this.service.showToast('Added into cart', 'top', 'my-toast', 2000);
            }
            this.cartService.cartList();
        });
    }
    viewProd(prod) {
        this.getProd(prod);
    }
    checkFavStatus(index) {
        const state = this.prodService.fav.findIndex(x => x === index);
        return state > -1 ? 'fav_active' : 'fav';
    }
    changeFav(index) {
        this.prodService.changeFav(index, 'yes');
        const state = this.prodService.fav.findIndex(x => x === index);
        // console.log(state);
        // console.log(this.prodService.fav);
        if (state > -1) {
            this.prodService.fav.splice(state, 1);
            this.prodService.changeFav(index, 'yes');
        }
        else {
            this.prodService.fav.push(index);
            this.prodService.changeFav(index, 'no');
        }
        return;
        // console.log(this.prodService.fav);
    }
    socialShare(prodName, category, subCate, price, image) {
        const desc = category + ', ' + subCate + ', ' + price;
        const content = {
            message: desc,
            subject: prodName,
            files: image,
            chooserTitle: 'GetMi'
        };
        this.socialSharing.shareWithOptions(content);
    }
};
ProductdetailPage = tslib_1.__decorate([
    Component({
        selector: 'app-productdetail',
        templateUrl: './productdetail.page.html',
        styleUrls: ['./productdetail.page.scss']
    }),
    tslib_1.__metadata("design:paramtypes", [Router,
        ActivatedRoute,
        Location,
        CartsService,
        ProductsService,
        ServiceService,
        SocialSharing])
], ProductdetailPage);
export { ProductdetailPage };
//# sourceMappingURL=productdetail.page.js.map