var Wick = Wick || {};
Wick.TextClamp = (function () {
    var rangeListCardDescr = $('.range-list__next-steps .card__descr');
    var categoryHubCardDescr = $('.page_category-hub .card__descr');
    var categoryLandingCards = $('.category-landing .card__title a');
    var productCardHorizontal = $('.product-card-preview .product-card__title');
    var productCardList = $('.products-list .product-card__title');
    var productCardListV2 = $('.products-list-v2 .product-card__title');
    var productCardDesc = $('.products-list .product-card__description .card__descr');
    var wismoProductLink = $('.wismo-order__name-link');
    var complementCardHeader = $('.complem__head');
    var orderItemTitle = $('.oder-item__title-link')


    if (wismoProductLink.length) {
        wismoProductLink.each(function (index, value) {
            $clamp(value, {clamp: 2});
        });
    }

    if (rangeListCardDescr.length) {
        rangeListCardDescr.each(function (index, value) {
            $clamp(value, {clamp: 2});
        });
    }

    if (categoryHubCardDescr.length) {
        categoryHubCardDescr.each(function (index, value) {
            $clamp(value, {clamp: 3});
        });
    }

    if (categoryLandingCards.length) { //TODO: make one function
        categoryLandingCards.each(function (index, value) {
            $clamp(value, {clamp: 3});
        });
    }

    if (productCardHorizontal.length) {
        productCardHorizontal.each(function (index, value) {
            $clamp(value, {clamp: 3});
        });
    }
        /*!!!*/
    if (window.matchMedia('(min-width: 768px)').matches) {
        if (productCardList.length) {
            productCardList.each(function (index, value) {
                $clamp(value, {clamp: 3});
            });
        }
    } else {
        if (productCardList.length) {
            productCardList.each(function (index, value) {
                $clamp(value, {clamp: 3});
            });
        }
    }

    if (productCardListV2.length) {
        productCardListV2.each(function (index, value) {
            $clamp(value, {clamp: 3});
        });
    }

    if (complementCardHeader.length) {
        complementCardHeader.each(function (index, value) {
            $clamp(value, {clamp: 3});
        });
    }

    if (orderItemTitle.length) {
        orderItemTitle.each(function (index, value) {
            $clamp(value, {clamp: 2});
        });
    }

    window.onresize = function () {
        if (window.matchMedia('(min-width: 768px)').matches) {
            if (productCardList.length) {
                productCardList.each(function (index, value) {
                    $clamp(value, {clamp: 2});
                });
            }
        } else {
            if (productCardList.length) {
                productCardList.each(function (index, value) {
                    $clamp(value, {clamp: 3});
                });
            }
        }

        if (window.matchMedia('(min-width: 768px)').matches) {
            if (productCardListV2.length) {
                productCardListV2.each(function (index, value) {
                    $clamp(value, {clamp: 3});
                });
            }
        }

        if (window.matchMedia('(min-width: 768px)').matches) {
            if (productCardDesc.length) {
                productCardDesc.each(function (index, value) {
                    $clamp(value, {clamp: 2});
                });
            }
        } else {
            if (productCardDesc.length) {
                productCardDesc.each(function (index, value) {
                    $clamp(value, {clamp: 3});
                });
            }
        }
    }

})();
