$(document).on('click', '#coupon-button', function () {
    // alert();
    // $('#couponModal').modal('show');

    $('#couponModal').modal('show');
    var get_code = $(this).data('code');
    var get_url = $(this).data('url');
    var get_title = $(this).data('title');
    var get_des = $(this).data('des');
    var get_id = $(this).data('coupon_id');
    var get_img = $(this).data("img");
    $(this).parents('a').attr('href', get_url);
    console.log(get_code);
    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        url: "{{ route('update_coupon_used') }}",
        dataType: "json",
        data: {
            id: get_id
        },
        success: function (data) {
            console.log(data);
        },
        error: function (data) {
            console.log(data);
        }
    });

    if (get_code == "") {
        $('.visit_site').css('display', 'none');
        $('.for-deal').css('display', 'block');
        $('.modal-url').attr('href', get_url);
    } else {
        $('.visit_site').css('display', 'block');
        $('.for-deal').css('display', 'none');
        $('.modal-url').attr('href', 'javascript:void(0)');
    }

    $('.code_text').text(get_code);
    $('.modal-url').attr('href', get_url);
    $('.modal-title').text(get_title);
    $('.modal_title').text(get_title);
    $('.modal-desc').text(get_des);
    $(".modal-img").attr("src", get_img);

});



$(function () {
    $(".close").click(function () {
        $("#couponModal").modal("hide");
    });
});

function copyToClipboard(element) {
    var $temp = $("<input>");
    $("body").append($temp);
    $temp.val($(element).text()).select();
    navigator.clipboard.writeText($temp);
    $temp.remove();
    $('.code_text').text('Copied');
}

$(document).on('keyup', '.search-input', function () {
    var keyword = $('.search-input').val();
    console.log(keyword);
    $.ajax({
        type: 'GET',
        url: "{{ route('get-stores') }}",
        data: {
            key: keyword
        },
        success: function (resp) {
            console.log(resp);
            $('.autocomplete').css('display', 'block');
            $('.autocomplete').html(resp);
        },
        error: function (resp) {
            console.log(resp);
        }
    });
});

$('.store_list_head').click(function () {
    $(this).siblings('.store_list_body').slideToggle();
    $(this).parent(".store_list_item").siblings().find(".store_list_body").slideUp();
})

$('.disclaimer_btn button').click(function (e) {
    $(this).addClass('disclaimer_btn_active').siblings().removeClass('disclaimer_btn_active');
    var getIndext = $(this).attr('data-index');
    $('.content_div').hide();
    $('.content_div[data-index="' + getIndext + '"]').fadeIn('fast');

    e.prDefault();
});



function showHideText(sSelector, options) {
    // Def. options
    var defaults = {
        charQty: 100,
        ellipseText: "...",
        moreText: "Show more",
        lessText: "Show less"
    };

    var settings = $.extend({}, defaults, options);

    var s = this;

    s.container = $(sSelector);
    s.containerH = s.container.height();

    s.container.each(function () {
        var content = $(this).html();

        if (content.length > settings.charQty) {

            var visibleText = content.substr(0, settings.charQty);
            var hiddenText = content.substr(settings.charQty, content.length - settings.charQty);

            var html = visibleText +
                '<span class="moreellipses">' +
                settings.ellipseText +
                '</span><span class="morecontent"><span class="d-none">' +
                hiddenText +
                '</span><a href="" class="morelink">' +
                settings.moreText +
                '</a></span>';

            $(this).html(html);
        }

    });

    s.showHide = function (event) {
        event.preventDefault();
        if ($(this).hasClass("less")) {
            $(this).removeClass("less");
            $(this).html(settings.moreText);

            $(this).prev().fadeToggle('fast', function () {
                $(this).parent().prev().fadeIn();
            });
        } else {
            $(this).addClass("less");
            $(this).html(settings.lessText);

            $(this).parent().prev().hide();
            $(this).prev().fadeToggle('fast');
        }
    }

    $(".morelink").bind('click', s.showHide);
}


new showHideText('.short-desc', {
    charQty: 40,
    ellipseText: "...",
    moreText: "Read more",
    lessText: "Read less"
});



