(function($){
    $.fn.lightModal = function(action) {
        var $modal = this;

        function openModal() {
            // Append backdrop
            var $backdrop = $('<div class="modal-backdrop fade"></div>');
            $('body').append($backdrop);
            setTimeout(function(){ $backdrop.addClass('in'); }, 10);

            // Prevent body scroll
            $('body').addClass('modal-open');

            // Show modal
            // $modal.show();
            setTimeout(function(){ $modal.addClass('in'); }, 10);

            // Focus modal
            $modal.attr('tabindex', '-1').focus();
        }

        function closeModal() {
            $('.modal-backdrop').removeClass('in').delay(150).queue(function(){
                $(this).remove();
            });

            $modal.removeClass('in').delay(150).queue(function(){
                $modal.hide();
            });

            $('body').removeClass('modal-open');
        }

        if (action === 'open') openModal();
        if (action === 'close') closeModal();

        // Close on backdrop click
        $(document).on('click', '.modal-backdrop', closeModal);

        // Close on [data-dismiss="modal"]
        $modal.find('[data-dismiss="modal"]').on('click', closeModal);

        return this;
    };


    jQuery(document).on('click', '[data-proqyz-modal="true"]', function(){
        let link = jQuery(this).data('href');
        jQuery(jQuery(this).data('target')).find('[data-href]').data('href', link);
        jQuery(jQuery(this).data('target')).lightModal('open');

        // $('#myModal').lightModal('close');
    });

    jQuery(document).on('click', '[data-dismiss="modal"]', function(){
        jQuery('#modal-fulltest').lightModal('close');
        // $('#myModal').lightModal('close');
    });

    jQuery(document).on('click', '.modal-fulltest__btn', function(){
        if(jQuery(this).data('href') !== ""){
            window.location.href = jQuery(this).data('href');
        }
        // $('#myModal').lightModal('close');
    });



    
}(jQuery));
