/**
 * Made by mkcomponent.sh
 * * Change to Fileheader info *
*/

// Core imports
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'

// Services
import { BasketHelperService } from '@k-core/modules/basket/services/svc.basket-helper'

@Component({
    moduleId: module.id+ '',
    selector: 'basket-sku-product',
    templateUrl: './template/t--skuProduct.pug',
    styleUrls: ['sty.skuProduct.scss']
})

export class SkuproductComponent {

    // ---- Variables ---- \\
    @Input('product') product: any
    @Output('qty') qty: any = new EventEmitter()
    isMarkedForDeletion: boolean = false
    price: any = {
        price: 0,
    }

    constructor(
        private _basketHelper: BasketHelperService
    ) { }


    // ---- Lifecycle hooks ---- \\
    ngOnInit() {
        // this._basketHelper.requestPriceAndPriceTier(this.product)

    }


    // ---- Functions ---- \\
    /**
     * Displays the deletion button
     */
    prepareRemoval() {
        this.isMarkedForDeletion = true
    }

    /**
     * Deletes the product
     * TODO: Make it re-draw the list
     * 
     * @param id
     */
    removeProduct(id) {
        this._basketHelper.removeProduct(id)
    }

    changeQuantity(qty) {
        this.product.quantity = qty
        this.qty.emit({id: this.product.sku, quantity: this.product.quantity})
    }

    getQuantity() {

        return this.product.quantity
    }
}
