var AppDispatcher = require('../dispatcher/appDispatcher');
var CartConstants = require('../constants/cartConstants');
var BurntToast = require('burnt-toast');



// Define action methods
var CartActions = {

    load: function() {
        AppDispatcher.handleAction({
            actionType: CartConstants.LOAD_CART_CONTENTS
        });
    },

    addNItems: function(item, count) {
        var burntToast = new BurntToast();7
        var message = "Ubacili ste " + item.get('name') + " u korpu!";
        burntToast.makeToast(message, {
            duration: 1500,
            position: "top"
        });
        AppDispatcher.handleAction({
            actionType: CartConstants.ADD_N_ITEMS,
            item: item,
            count: count
        });
    },

    dataLoaded: function() {
        AppDispatcher.handleAction({
            actionType: CartConstants.CART_DATA_LOADED
        });
    },

    saveCartStateForItem: function(itemId) {
        AppDispatcher.handleAction({
            actionType: CartConstants.SAVE_CART_STATE_FOR_ITEM,
            itemId: itemId
        });
    },

    changeDeliveryDestinationProperty: function(property, value) {
        AppDispatcher.handleAction({
            actionType: CartConstants.CHANGE_DELIVERY_DESTINATION_PROPERTY,
            propertyName: property,
            value: value
        });
    },
    confirmDelivery: function() {
        AppDispatcher.handleAction({
            actionType: CartConstants.CONFIRM_DELIVERY,
        });
    },

    takeItemOut: function(id) {
        AppDispatcher.handleAction({
            actionType: CartConstants.TAKE_ITEM_OUT,
            itemId: id
        });
    },
    setItemCount: function(itemId, count) {
        AppDispatcher.handleAction({
            actionType: CartConstants.SET_ITEM_COUNT,
            itemId: itemId,
            count: count
        });
    },

    setAddressColapsed: function(isColapsed) {
        AppDispatcher.handleAction({
            actionType: CartConstants.SET_ADDRESS_COLAPSED,
            isColapsed: isColapsed
        });
    }
};

module.exports = CartActions;