var THEMETAGS = THEMETAGS || {};
jQuery(function ($) {
  "use strict";

  AOS.init();

  //Data Background Set
  $('[data-background]').each(function () {
    $(this).css('background-image', 'url(' + $(this).attr('data-background') + ')');
  });

  //offcanvas function
  function offCanvus() {
    $(".ofcanvus-toggle").on("click", function () {
      $(".at_offcanvus_menu").addClass("active");
    });
    $(".at-offcanvus-close").on("click", function () {
      $(".at_offcanvus_menu").removeClass("active");
    });
    $(document).on("mouseup", function (e) {
      var offCanvusMenu = $(".at_offcanvus_menu");
      if (!offCanvusMenu.is(e.target) && offCanvusMenu.has(e.target).length === 0) {
        $(".at_offcanvus_menu").removeClass("active");
      }
    });
  }
  offCanvus();

  //mobile menu 
  $(".mobile-menu-toggle").on("click", function () {
    $(".mobile-menu").addClass("active");
  });
  $(".mobile-menu .close-menu").on("click", function () {
    $(".mobile-menu").removeClass("active");
  });
  $(".mobile-menu ul li.has-submenu a").each(function () {
    $(this).on("click", function () {
      $(this).siblings('ul').slideToggle();
      $(this).toggleClass("icon-rotate");
    });
  });
  $(document).on("mouseup", function (e) {
    var offCanvusMenu = $(".mobile-menu");
    if (!offCanvusMenu.is(e.target) && offCanvusMenu.has(e.target).length === 0) {
      $(".mobile-menu").removeClass("active");
    }
  });
  var software_slider = new Swiper(".software-slider", {
    slidesPerView: 5,
    spaceBetween: 24,
    autoplay: true,
    loop: true,
    speed: 600,
    breakpoints: {
      0: {
        slidesPerView: 1
      },
      300: {
        slidesPerView: 2
      },
      768: {
        slidesPerView: 3
      },
      992: {
        slidesPerView: 4
      },
      1200: {
        slidesPerView: 5
      }
    }
  });

  // Brand Slider 
  const brandSlider = document.querySelector('.brand-slider');
  if (brandSlider) {
    const brandSliderInit = new Swiper(brandSlider, {
      slidesPerView: 2,
      spaceBetween: 16,
      loop: true,
      speed: 6000,
      autoplay: {
        delay: 1,
        disableOnInteraction: false
      },
      breakpoints: {
        768: {
          slidesPerView: 4
        },
        992: {
          slidesPerView: 5
        },
        1400: {
          slidesPerView: 6
        }
      }
    });
  }

  // Counter Up by Odometer
  let counterUp = $(".cta-counter");
  if (counterUp) {
    counterUp.each(function () {
      $(this).isInViewport(function (status) {
        if (status === "entered") {
          for (var i = 0; i < document.querySelectorAll(".odometer").length; i++) {
            var el = document.querySelectorAll(".odometer")[i];
            el.innerHTML = el.getAttribute("data-odometer-final");
          }
        }
      });
    });
  }
  // Counter Up by Odometer
  let clientCounterUp = $(".dgm-client-counter");
  if (clientCounterUp) {
    clientCounterUp.each(function () {
      $(this).isInViewport(function (status) {
        if (status === "entered") {
          for (var i = 0; i < document.querySelectorAll(".odometer").length; i++) {
            var el = document.querySelectorAll(".odometer")[i];
            el.innerHTML = el.getAttribute("data-odometer-final");
          }
        }
      });
    });
  }

  // Portfolio Slider 
  const portfolioSlider = document.querySelector('.agf-portfolio-slider');
  if (portfolioSlider) {
    const portfolioSliderInit = new Swiper(portfolioSlider, {
      slidesPerView: 1,
      spaceBetween: 20,
      loop: true,
      breakpoints: {
        768: {
          slidesPerView: 2
        },
        992: {
          slidesPerView: 3
        },
        1920: {
          slidesPerView: 4
        }
      },
      navigation: {
        nextEl: '.agf-portfolio-slider__btn-next',
        prevEl: '.agf-portfolio-slider__btn-prev'
      }
    });
  }

  // Brand Slider 
  const dgmBrandSlider = document.querySelector('.dgm-brand-slider');
  if (dgmBrandSlider) {
    const dgmBrandSliderInit = new Swiper(dgmBrandSlider, {
      slidesPerView: 1,
      spaceBetween: 20,
      loop: true,
      speed: 6000,
      autoplay: {
        delay: 1,
        disableOnInteraction: false
      },
      breakpoints: {
        375: {
          slidesPerView: 2
        },
        576: {
          slidesPerView: 3
        },
        768: {
          slidesPerView: 4
        },
        992: {
          slidesPerView: 5
        },
        1200: {
          slidesPerView: 6
        }
      },
      navigation: {
        nextEl: '.agf-portfolio-slider__btn-next',
        prevEl: '.agf-portfolio-slider__btn-prev'
      }
    });
  }
  // Testimonial Slider 
  const testimonialSlider = document.querySelector('.agf-testimonial-slider');
  if (testimonialSlider) {
    const testimonialSliderInit = new Swiper(testimonialSlider, {
      slidesPerView: 1,
      spaceBetween: 16,
      loop: true,
      autoplay: true,
      breakpoints: {
        768: {
          slidesPerView: 2
        },
        992: {
          slidesPerView: 2,
          spaceBetween: 24
        },
        1200: {
          slidesPerView: 3,
          spaceBetween: 24
        },
        1920: {
          slidesPerView: 4,
          spaceBetween: 24
        }
      }
    });
  }
  // Feedback Slider 
  const dgmFeedbackSlider = document.querySelector('.dgm-feedback-slider');
  if (dgmFeedbackSlider) {
    const dgmFeedbackSliderInit = new Swiper(dgmFeedbackSlider, {
      slidesPerView: 1,
      spaceBetween: 16,
      loop: true,
      effect: 'fade',
      fadeEffect: {
        crossFade: false
      },
      navigation: {
        nextEl: '.dgm-feedback-slider__btn-next',
        prevEl: '.dgm-feedback-slider__btn-prev'
      }
    });
  }

  //Toggle Pricing
  const togglePricingInput = document.querySelectorAll('.toggle-pricing');
  const monthlyPricing = document.querySelectorAll('.dgm-price-monthly');
  const yearlyPricing = document.querySelectorAll('.dgm-price-yearly');
  if (togglePricingInput || monthlyPricing || yearlyPricing) {
    togglePricingInput.forEach(e => {
      e.addEventListener('click', () => {
        if (e.checked === true) {
          monthlyPricing.forEach(mp => {
            mp.classList.add('d-none');
            mp.classList.remove('d-flex');
          });
          yearlyPricing.forEach(yp => {
            yp.classList.remove('d-none');
            yp.classList.add('d-flex');
          });
        } else {
          monthlyPricing.forEach(mp => {
            mp.classList.add('d-flex');
            mp.classList.remove('d-none');
          });
          yearlyPricing.forEach(yp => {
            yp.classList.remove('d-flex');
            yp.classList.add('d-none');
          });
        }
      });
    });
  }
  var feedback_slider = new Swiper(".feedback-slider", {
    slidesPerView: 1,
    spaceBetween: 24,
    autoplay: true,
    loop: true
  });
  var team_slider = new Swiper(".team-slider", {
    slidesPerView: 3,
    spaceBetween: 24,
    autoplay: true,
    loop: true,
    speed: 700,
    breakpoints: {
      0: {
        slidesPerView: 1
      },
      576: {
        slidesPerView: 3
      }
    }
  });
  var brands_slider = new Swiper(".brands-slider", {
    slidesPerView: 5,
    spaceBetween: 24,
    autoplay: true,
    loop: true,
    speed: 700,
    breakpoints: {
      0: {
        slidesPerView: 1
      },
      400: {
        slidesPerView: 2
      },
      576: {
        slidesPerView: 3
      },
      992: {
        slidesPerView: 4
      },
      1200: {
        slidesPerView: 5
      }
    }
  });
  var blog_list_slider = new Swiper(".blog-list-slider", {
    slidesPerView: 1,
    autoplay: true,
    spaceBetween: 24,
    speed: 700,
    pagination: {
      el: '.slider-doted-pagination',
      clickable: true
    }
  });
  var gallery_slider = new Swiper(".hm2-gallery-slider", {
    slidesPerView: 1,
    autoplay: true,
    speed: 800,
    spaceBetween: 24,
    pagination: {
      el: '.gallery-slider-pagination',
      clickable: true,
      renderBullet: function (index, className) {
        return "<span class=" + className + ">" + (index + 1) + "</span>";
      }
    }
  });
  var hm2_service_slider = new Swiper(".hm2-service-slider", {
    slidesPerView: 3,
    autoplay: true,
    speed: 800,
    spaceBetween: 24,
    pagination: {
      el: '.slider-bullet-pagination',
      clickable: true
    },
    breakpoints: {
      0: {
        slidesPerView: 1
      },
      768: {
        slidesPerView: 2
      },
      992: {
        slidesPerView: 3
      }
    }
  });
  var recent_project_slider = new Swiper(".rp-project-slider", {
    slidesPerView: 3,
    // autoplay: true,
    loop: true,
    speed: 800,
    spaceBetween: 24,
    navigation: {
      prevEl: '.rp-prev-btn',
      nextEl: '.rp-next-btn'
    },
    breakpoints: {
      0: {
        slidesPerView: 1
      },
      768: {
        slidesPerView: 2
      },
      1200: {
        slidesPerView: 3
      }
    }
  });
  var team_slider2 = new Swiper(".team-slider-2", {
    slidesPerView: 4,
    spaceBetween: 24,
    autoplay: true,
    loop: true,
    speed: 700,
    breakpoints: {
      0: {
        slidesPerView: 1
      },
      768: {
        slidesPerView: 2
      },
      992: {
        slidesPerView: 3
      },
      1200: {
        slidesPerView: 4
      }
    }
  });
  var hm2_feedback_slider = new Swiper(".hm2-feedback-slider", {
    slidesPerView: 1,
    spaceBetween: 24,
    autoplay: true,
    loop: true,
    speed: 700,
    pagination: {
      el: '.hmf-slider-pagination',
      type: 'bullets',
      clickable: true
    }
  });
  var dg_brand_slider = new Swiper(".dg-brands-slider", {
    slidesPerView: 10,
    spaceBetween: 24,
    autoplay: true,
    loop: true,
    speed: 700,
    breakpoints: {
      0: {
        slidesPerView: 2
      },
      470: {
        slidesPerView: 3
      },
      640: {
        slidesPerView: 4
      },
      800: {
        slidesPerView: 5
      },
      1200: {
        slidesPerView: 6
      },
      1300: {
        slidesPerView: 7
      },
      1400: {
        slidesPerView: 10
      }
    }
  });
  var dg_projects_slider = new Swiper(".dg-projects-slider", {
    slidesPerView: 3,
    spaceBetween: 24,
    autoplay: true,
    speed: 700,
    pagination: {
      el: '.dg-project-slider-control',
      type: 'progressbar'
    },
    breakpoints: {
      0: {
        slidesPerView: 1
      },
      768: {
        slidesPerView: 2
      },
      1400: {
        slidesPerView: 3
      }
    }
  });
  var dg_exp_slider = new Swiper(".dg-exp-slider", {
    slidesPerView: 4,
    spaceBetween: 24,
    autoplay: true,
    speed: 700,
    pagination: {
      el: '.dg-exp-slider-control',
      type: 'progressbar'
    },
    breakpoints: {
      0: {
        slidesPerView: 1
      },
      768: {
        slidesPerView: 2
      },
      992: {
        slidesPerView: 3
      },
      1400: {
        slidesPerView: 4
      }
    }
  });
  var dg_exp_slider = new Swiper(".dg-feedback-slider", {
    slidesPerView: 4,
    spaceBetween: 24,
    autoplay: true,
    speed: 700,
    pagination: {
      el: '.dg-feedback-slider-control',
      type: 'progressbar'
    },
    breakpoints: {
      0: {
        slidesPerView: 1
      },
      768: {
        slidesPerView: 2
      },
      1400: {
        slidesPerView: 3
      }
    }
  });

  //services hover tab
  if ($(".services-category-list").length) {
    $(".services-category-list li a").each(function () {
      var active_btn_value = $(this).parents("ul.services-category-list").find("a.active").data("target");
      $(this).parents("ul.services-category-list").siblings(".feature-images").find('[data-image="' + active_btn_value + '"]').addClass("active");
      $(this).on("mouseenter", function () {
        $(this).parents("ul.services-category-list").find("a.active").removeClass("active");
        $(this).addClass("active");
        var active_btn_value = $(this).parents("ul.services-category-list").find("a.active").data("target");
        $(this).parents("ul.services-category-list").siblings(".feature-images").find("img.active").removeClass("active");
        $(this).parents("ul.services-category-list").siblings(".feature-images").find('[data-image="' + active_btn_value + '"]').addClass("active");
      });
    });
  }
  jQuery(function () {
    //isotop filter 
    var $filter_items = $('.filter_items').isotope({});
    // filter items on button click
    $('.attonce-filter-btn-group').on('click', 'button', function () {
      var filterValue = $(this).attr('data-filter');
      $filter_items.isotope({
        filter: filterValue
      });
    });
    $(".attonce-filter-btn-group").on("click", 'button', function () {
      $(this).parents(".attonce-filter-btn-group").find("button.active").removeClass("active");
      $(this).addClass("active");
    });
    $('.grid_massonry').isotope({
      itemSelector: '.grid_item',
      percentPosition: true,
      masonry: {
        columnWidth: 1
      }
    });
  });

  //video popup btn
  $('.video-popup-btn').magnificPopup({
    type: 'iframe'
  });
  $("body").on("mousemove", function (n) {
    a.css({
      'left': n.clientX + "px"
    });
    a.css({
      'top': n.clientY + "px"
    });
    b.css({
      'left': n.clientX + "px"
    });
    b.css({
      'top': n.clientY + "px"
    });
    c.css({
      'left': n.clientX + "px"
    });
    c.css({
      'top': n.clientY + "px"
    });
  });
  var a = $("#cursor"),
    b = $("#cursor2"),
    c = $("#cursor3");
  function n(t) {
    b.addClass("hover");
    c.addClass("hover");
  }
  function s(t) {
    b.removeClass("hover");
    c.removeClass("hover");
  }
  s();
  $("a, button").on('mouseover', n);
  $("a, button").on('mouseout', s);

  //window scroll functions
  $(window).on("scroll", function () {
    //scroll top button
    var scrollBar = $(this).scrollTop();
    if (scrollBar > 150) {
      $(".scroll-top-btn").addClass("active");
    } else {
      $(".scroll-top-btn").removeClass("active");
    }

    //sticky header
    if (scrollBar > 160) {
      $(".sticky-header").addClass("sticky-active");
    } else {
      $(".sticky-header").removeClass("sticky-active");
    }
  });
  $(".scroll-top-btn").on("click", function () {
    $("body,html").animate({
      scrollTop: 0
    }, 1000, 'easeInQuad');
  });

  //pricing switch
  $(".dg-pricing-switch .switch").each(function () {
    $(this).on("click", function () {
      $(this).toggleClass("active");
    });
    if ($(this).hasClass("active")) {
      $(this).parents(".dg-pricing-plans").find(".price-yearly").show();
      $(this).parents(".dg-pricing-plans").find(".price-monthly").hide();
    } else {
      $(this).parents(".dg-pricing-plans").find(".price-yearly").hide();
      $(this).parents(".dg-pricing-plans").find(".price-monthly").show();
    }
    $(this).on("click", function () {
      if ($(this).hasClass("active")) {
        $(this).parents(".dg-pricing-plans").find(".price-yearly").show();
        $(this).parents(".dg-pricing-plans").find(".price-monthly").hide();
      } else {
        $(this).parents(".dg-pricing-plans").find(".price-yearly").hide();
        $(this).parents(".dg-pricing-plans").find(".price-monthly").show();
      }
    });
  });
});