(function ($) {
  "use strict";

  /* -----------------------------------------------------
        Variables
    ----------------------------------------------------- */
  var leftArrow = '<i class="fa fa-angle-left"></i>';
  var rightArrow = '<i class="fa fa-angle-right"></i>';

  /*------------------------------------
      lasest post slidr
    ------------------------------------*/
  var LatestPostSlider = function ($scope, $) {

    $('.eblog-slider-1').owlCarousel({
      loop: true,
      margin: 20,
      nav: false,
      dots: false,
      smartSpeed: 1500,
      navText: [leftArrow, rightArrow],
      responsive: {
        0: {
          items: 1
        },
        576: {
          items: 2
        },
        992: {
          items: 3
        },
      }
    });

  }

  var TrendingPostSlider = function ($scope, $) {

    $('.post-slider').owlCarousel({
      loop: true,
      margin: 30,
      nav: true,
      dots: false,
      smartSpeed: 1500,
      navText: [leftArrow, rightArrow],
      responsive: {
        0: {
          items: 1
        },
        576: {
          items: 1
        },
        992: {
          items: 1
        },
      }
    });
  }

  /*------------------------------------
       isotop 
  ------------------------------------*/
  var PostFilter = function ($scope, $) {

    $(function () {
      var $grid = $('.grid').isotope({
        itemSelector: 'article'
      });

      // filter buttons
      $('.filters-button-group').on('click', 'button', function () {
        var filterValue = $(this).attr('data-filter');
        $grid.isotope({ filter: filterValue });
      });

      if (jQuery('.grid').css('height') == '0px') { // width not set
        $('.grid').height('auto');
      }

      $('.button-group').each(function (i, buttonGroup) {
        var $buttonGroup = $(buttonGroup);
        $buttonGroup.on('click', 'button', function () {
          $buttonGroup.find('.is-checked').removeClass('is-checked');
          $(this).addClass('is-checked');
        });
      });
    });

  }

  /*------------------------------------
       Magnific 
  ------------------------------------*/
  var MagnificFilter = function ($scope, $) {

    $('.video-play-btn').magnificPopup({
      type: 'iframe',
      removalDelay: 260,
      mainClass: 'mfp-zoom-in',
      gallery: {
        enabled: true
      },
    });
    $.extend(true, $.magnificPopup.defaults, {
      iframe: {
        patterns: {
          youtube: {
            index: 'youtube.com/',
            id: function (url) {
              var m = url.match(/[\\?\\&]v=([^\\?\\&]+)/);
              if (!m || !m[1]) return null;
              return m[1];
            },
            src: '//www.youtube.com/embed/%id%?autoplay=1'
          }
        }
      }
    });

  }

  $(document).on('click', '.eleblog-pagi a.page-link', function (e) {

    e.preventDefault();

    var AjaxId = $('.ajaxid').data('ajaxid');
    var Style = $('.ajaxid').data('style');
    var paged = $(this).text();
    $.ajax({
      type: 'post',
      url: elebloglocalize.ajax_url,
      data: {
        action: 'eleblog_pagination',
        AjaxId: AjaxId,
        paged: paged,
        Style: Style,
      },
      beforeSend: function () {
        // setting a timeout
        $('.modal').addClass('show');
      },
      success: function (res) {
        $('.ajaxid .eblog-row').empty();
        $('.modal').removeClass('show');
        $('.ajax').html(res);
      }
    });
  });


  $(window).on('elementor/frontend/init', function () {
    elementorFrontend.hooks.addAction('frontend/element_ready/style_three.default', LatestPostSlider);
    elementorFrontend.hooks.addAction('frontend/element_ready/style_seven.default', PostFilter);
    elementorFrontend.hooks.addAction('frontend/element_ready/eleblog_what_is_new.default', TrendingPostSlider);
    elementorFrontend.hooks.addAction('frontend/element_ready/ele_blog_trending_widget.default', TrendingPostSlider);
    elementorFrontend.hooks.addAction('frontend/element_ready/latest_news_slider.default', TrendingPostSlider);
    elementorFrontend.hooks.addAction('frontend/element_ready/eleblog_video_grid.default', MagnificFilter);
  });


})(jQuery);
