class ArtboxBasket {
    private _items;
    get items() {
        return this._items;
    }
    constructor() {
        this.init(true, true);
    }
    public init(update_modal, update_cart) {
        $.get('/basket', function (data) {
            this._items = data.basket;
            if(update_modal) {
                this.updateModal(data.modal, false);
            }
            if(update_cart) {
                this.updateCart(data.cart);
            }
        }.bind(this), 'json').fail(function() {
            console.error('Basket cannot be init');
        });
    }
    public add(product_variant_id) {
        $.post('/basket/add?product_variant_id='+product_variant_id, function (data) {
            this._items = data.basket;
            this.updateModal(data.modal, data.cart, true);
            showForm();
        }.bind(this), 'json').fail(function (xhr, status, error) {
            console.error(error);
        });
    }
    public remove(product_variant_id) {
        $.post('/basket/remove?product_variant_id='+product_variant_id, function (data) {
            this._items = data.basket;
            this.updateCart(data.cart);
            // this.updateModal(data.modal, data.cart, true);
        }.bind(this), 'json').fail(function (xhr, status, error) {
            console.error(error);
        });
    }
    public updateModal(modal, cart_html, show = false)
    {
        var modalBox = $('#modal_form-2');
        modalBox.html(modal);
        if(cart_html) {
            this.updateCart(cart_html);
        }
    }
    public updateCart(cart_html) {
        var cart = $('.question-form ');
        cart.html(cart_html);
    }
    get count(): number {
        return Object.keys(this._items).length;
    }
}