
(function ( $ ) {

    $.fn.modal = function(option) {
        let modal = this;
        console.log(modal, modal.attr('id'));

        if (option === 'hide') {
            modal.removeClass('show').slideUp(function () {
                modal.trigger('hidden.bs.modal');
            });
            $('.wpdm-mbd').remove(); // remove the backdrop
            return modal;            // keep jQuery chaining
        }

        modal.css({'z-index': 99999}).slideDown(function () {
            modal.addClass('show');
        });
        modal.after('<div class="modal-backdrop fade show wpdm-mbd" style="z-index: 9999;transition: all ease-in-out 400ms"></div>');
        modal.trigger('shown.bs.modal');
        modal.find('[data-dismiss="modal"]').on('click', function(e) {
            modal.removeClass('show').slideUp(function () {
                modal.trigger('hidden.bs.modal');
            });
            jQuery('.wpdm-mbd').remove();
        })
    };

    $.fn.tooltip = function (options) {
        // Default options
        var settings = $.extend({
            background: "#333",
            color: "#fff",
            padding: "5px 10px",
            borderRadius: "4px",
            fontSize: "12px"
        }, options);

        // Create tooltip element once
        var $tooltip = $("<div class='simple-tooltip'></div>").css({
            position: "absolute",
            maxWidth: "200px",
            display: "none",
            zIndex: 9999,
            background: settings.background,
            color: settings.color,
            padding: settings.padding,
            borderRadius: settings.borderRadius,
            fontSize: settings.fontSize,
            pointerEvents: "none",
        }).appendTo("body");

        // Attach events
        return this.each(function () {
            var $elem = $(this);
            var title = $elem.attr("title");

            $elem.on("mouseenter", function (e) {
                if (!title) return;
                $elem.data("tip-title", title).removeAttr("title"); // prevent default browser tooltip
                $tooltip.text(title).fadeIn(150);
                $tooltip.css({
                    top: e.pageY + 10,
                    left: e.pageX + 10
                });
            }).on("mousemove", function (e) {
                $tooltip.css({
                    top: e.pageY + 10,
                    left: e.pageX + 10
                });
            }).on("mouseleave", function () {
                $tooltip.hide();
                $elem.attr("title", $elem.data("tip-title")); // restore original title
            });
        });
    };

}( jQuery ));



jQuery(function($) {
    $body = $('body');
    $body.on('click', '.w3eden [data-toggle="collapse"]', function(e) {
        e.preventDefault();
        $($(this).attr('href')).slideToggle();
    });
    $body.on('click', '.w3eden [data-toggle="modal"], .w3eden[data-toggle="modal"]', function(e) {
        e.preventDefault();
        $($(this).data('target')).modal('show');
    });
    $body.on('click', '.w3eden [data-toggle="tab"]', function(e) {
        e.preventDefault();
        const $tabs = $(this).parents('.nav-tabs');
        console.log($tabs);
        $tabs.find('a[data-toggle="tab"]').each(function() {
            $(this).removeClass('active');
            $($(this).attr('href')).removeClass('active');
        });
        $(this).addClass('nav-link active');
        $($(this).attr('href')).addClass('active');
    });
});
