var mainService = (function () {
    function appendProdToRootDiv($root, prod) {
        var prodImage = prod.prodImage ? "/clfd/image/" + prod.imageDir + "_" + prod.prodImage : "";
        var prodNm = prod.prodNm ? prod.prodNm : "";
        var prodCpcty = prod.prodCpcty ? prod.prodCpcty + "ml" : "-";
        var prodPrc = prod.prodPrc ? clfdUtils.formattingDot(prod.prodPrc) + "원" : 0;

        var $card = $("<div class=\"main-inner__rec\"></div>");
        var $anchor = $("<a href='/clfd/prod/dtl.do?prod=" + prod.prodId + "'></a>");
        var $divImg = $("<div class=\"main-inner__divImg\"></div>");
        var $img = $("<img src='" + prodImage + "' alt=\"\">");
        var $prodDiv = $("<div class=\"main-inner__rec_list\"></div>");
        var $prodNm = $("<div class=\"main-text__pr\">" + prodNm + "</div>");
        var $prodDtlDiv = $("<div class=\"main-inner__rec_list__ac\"></div>");
        var $price = $("<div class=\"main-text__am\">" + prodPrc + "</div>");
        var $capacity = $("<div class=\"main-text__ca\"> / " + prodCpcty + "</div>");

        $prodDtlDiv.append($price);
        $prodDtlDiv.append($capacity);
        $prodDiv.append($prodNm);
        $prodDiv.append($prodDtlDiv);
        $divImg.append($img);
        $anchor.append($divImg);
        $anchor.append($prodDiv);
        $card.append($anchor);
        $root.append($card);
    }

    return {
        drawBestProdList: function ($root, prodTyArr) {
            clfdCommonService.prodListApiRequest(
                {
                    scb: function (res) {
                        if (!res.prodList) return;
                        for (var i = 0; i < res.prodList.length; i++) {
                            appendProdToRootDiv($root, res.prodList[i]);
                        }
                    },
                    ecb: function (res) {
                        console.log(res);
                    }
                },
                {
                    start: 0,
                    length: 4,
                    pagingYn: true,
                    prodNmLike: null,
                    prodTyArray: prodTyArr,
                    skTyArray: null,
                    sortOrd: 'DESC',
                    sort: 'RCMD_NO'
                }
            );
        },
    }
}());
