(function () {
    function productListPc(opt, remark) {
        var {imgCdn, curSymbol, posCurrency,giftHint, codTax, codTaxHint} = opt;
        var keyT = store.get("__gui_key");
        var data = keyT == "buynow" ? store.get("__gui_buynow") : store.get("__gui_addcart");
        var items = "";
        if(data && !(data instanceof Array)) {
            data = [data];
        }
        $.each(data, function (i, val) {
            var item = "";
            if (val.currencyId && val.currencyId != remark.toCurrencyId) return true;
            $.each(val.items, function (j, v) {
                if (!v.number) return;
                if (v.image && v.image.indexOf("http") == -1) {
                    v.image = imgCdn + v.image;
                }
                var curPrice = $.formatCurrency(v.price, curSymbol);
                var price = (typeof posCurrency != "undefined" && Number(posCurrency)) ? curSymbol + ' ' +   curPrice : curPrice + ' ' +  curSymbol;
                var htmlItem = '';
                if (Number(v.gift) !== 1 || typeof v.giftShow === 'undefined' || Number(v.giftShow)) {
                    htmlItem = `<div class="goods-item clearfix ${v.gift == 1 ? 'goods-gifts' : ''} d-flex">
                                <img src="${v.image}" alt="" class="lazy goods-img"/>
                                <div class="goods-text d-flex">
                                    <div>
                                        <p class="line-2 goods-name">${v.gift == 1 ? "<span class='label'>" + (typeof giftHint ? giftHint : "") + "</span>" : ""} ${v.name}</p>
                                        <p class="goods-spec">${v.spec}</p>
                                    </div>
                                    <div class="d-flex align-items-center justify-content-between">
                                        <p class="red">
                                            <span class="goods-price d-inline-flex">
                                            ${price}
                                            </span>
                                            ${(typeof codTax != "undefined" && codTax && typeof codTaxHint != "undefined") ? codTaxHint : ""}
                                        </p>
                                        <p class="goods-number">x${v.number}</p>
                                    </div>
                                </div>
                        </div>`;
                }
                item += htmlItem
            });
            items += '<div class="gui-cart-wrap"><dl class="gui-ddlist chekceout-product">' + item + '</div></div>';
        });
        $(".goods-items-box").html(items);
    }
    function productListMember(opt, remark) {
        var {imgCdn, curSymbol, posCurrency,giftHint, codTax, codTaxHint} = opt;
        var keyT = store.get("__gui_key");
        var data = keyT == "buynow" ? store.get("__gui_buynow") : store.get("__gui_addcart");
        var items = "";
        if(data && !(data instanceof Array)) {
            data = [data];
        }
        $.each(data, function (i, val) {
            var item = "";
            var curAmount = $.formatCurrency(val.amount, curSymbol);
            if (val.currencyId && val.currencyId != remark.toCurrencyId) return true;
            $.each(val.items, function (j, v) {
                if (v.image && v.image.indexOf("http") == -1) {
                    v.image = imgCdn + v.image;
                }
                var curPrice = $.formatCurrency(v.price, curSymbol);
                var price = (typeof posCurrency != "undefined" && posCurrency) ? curSymbol + ' ' +  curPrice : curPrice + ' ' +  curSymbol;
                var amount = (typeof posCurrency != "undefined" && posCurrency) ? curSymbol  + ' ' + curAmount : curAmount + ' ' +  curSymbol;
                var htmlItem = '';
                if (Number(v.gift) !== 1 || typeof v.giftShow === 'undefined' || Number(v.giftShow)) {
                    htmlItem += `<div class="goods-item clearfix ${v.gift == 1 ? 'goods-gifts' : ''} d-flex">
                        <div class="img-box d-flex">
                            <img src="${v.image}" alt="" class="lazy goods-img"/>
                            <div class="mx-2">
                                <p class="line-1 goods-name">${v.gift == 1 ? "<span class='label'>" + (typeof giftHint ? giftHint : "") + "</span>" : ""} ${v.name}</p>
                                <p class="goods-spec mt-2">${v.spec}</p>
                            </div>
                        </div>
                        <div class="goods-text">
                            <span class="goods-price">
                            ${price}
                            </span>
                            ${(typeof codTax != "undefined" && codTax && typeof codTaxHint != "undefined") ? codTaxHint : ""}
                        </div>
                        <div class="goods-text">${v.number}</div>
                        <div class="goods-text">
                            <span class="goods-price">
                                ${amount}
                            </span>
                            
                        </div>
					</div>`;
                }
                items += htmlItem;
            });
            items += '<div class="gui-cart-wrap"><dl class="gui-ddlist chekceout-product">' + item + '</div></div>';

        });
        $(".goods-items-box").html(items);
    }

    function productListTw(opt, remark) {
        var {imgCdn, curSymbol, posCurrency,giftHint, codTax, codTaxHint} = opt;
        var keyT = store.get("__gui_key");
        var data = keyT == "buynow" ? store.get("__gui_buynow") : store.get("__gui_addcart");
        var items = "";
        if(data && !(data instanceof Array)) {
            data = [data];
        }
        $.each(data, function (i, val) {
            var item = "";
            if (val.currencyId && val.currencyId != remark.toCurrencyId) return true;
            $.each(val.items, function (j, v) {
                if (!v.number) return;
                if (v.image && v.image.indexOf("http") == -1) {
                    v.image = imgCdn + v.image;
                }
                var curPrice = $.formatCurrency(v.price, curSymbol);
                var price = (typeof posCurrency != "undefined" && posCurrency) ? curSymbol +  ' ' + curPrice : curPrice + ' ' +  curSymbol;
                var htmlItem = '';
                if (Number(v.gift) !== 1 || typeof v.giftShow === 'undefined' || Number(v.giftShow)) {
                    htmlItem = `<div class="goods-item clearfix ${v.gift == 1 ? 'goods-gifts' : ''} d-flex">
                                <img data-original="${v.image}" alt="" class="lazy goods-img"/>
                                <div class="goods-text d-flex">
                                    <div class="d-flex">
                                        <p class="line-1 goods-name">${v.gift == 1 ? "<span class='label'>" + (typeof giftHint ? giftHint : "") + "</span>" : ""} ${v.name}</p>
                                        <p class="price">
                                            <span class="goods-price d-inline-flex">
                                            ${price}
                                            </span>
                                            ${(typeof codTax != "undefined" && codTax && typeof codTaxHint != "undefined") ? codTaxHint : ""}
                                        </p>
                                    </div>
                                    <div class="d-flex align-items-center justify-content-between">
                                        <p class="goods-spec">${v.spec}</p>
                                        <p class="goods-number">x${v.number}</p>
                                    </div>
                                </div>
                        </div>`;
                }
                item += htmlItem
            });
            items += '<div class="gui-cart-wrap"><dl class="gui-ddlist chekceout-product">' + item + '</div></div>';
        });
        $(".goods-items-box").html(items);
    }
    window.checkoutFn = {
        productListPc,
        productListMember,
        productListTw
    }
})()