//***** Sticky Header JS Start Here *****//
window.addEventListener("scroll", function () {
  var header = document.querySelector("header");
  header.classList.toggle("sticky", window.scrollY > 50);
});
//***** Sticky Header JS End Here *****//

//***** Banner Main Slider JS Start Here *****//
$('.banner-main-slider').slick({
  dots: false,
  arrows: false,
  infinite: true,
  speed: 500,
  slidesToShow: 1,
  slidesToScroll: 1,
  autoplay: true,
  autoplaySpeed: 2000,
});
//***** Banner Main Slider JS End Here *****//

//***** Banner Down Brands Slider JS Start Here *****//
$('.bandown-brands-item').slick({
  dots: false,
  arrows: false,
  infinite: true,
  speed: 400,
  slidesToShow: 7,
  slidesToScroll: 1,
  autoplay: true,
  autoplaySpeed: 2000,
  responsive: [
    {
      breakpoint: 1024,
      settings: {
        slidesToShow: 5,
        slidesToScroll: 1,
        infinite: true,
        dots: false
      }
    },
    {
      breakpoint: 768,
      settings: {
        slidesToShow: 3,
        slidesToScroll: 1
      }
    },
    {
      breakpoint: 520,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 1
      }
    }

  ]
});
//***** Banner Down Brands Slider JS End Here *****//

//***** Trusted & Reviewed Slider JS Start Here *****//
$(".trusted-reviewed-slider").slick({
  dots: false,
  arrows: false,
  infinite: true,
  speed: 400,
  slidesToShow: 7,
  slidesToScroll: 1,
  autoplay: true,
  autoplaySpeed: 2000,
  responsive: [
    {
      breakpoint: 1024,
      settings: {
        slidesToShow: 5,
        slidesToScroll: 1,
        infinite: true,
        dots: false,
      },
    },
    {
      breakpoint: 768,
      settings: {
        slidesToShow: 3,
        slidesToScroll: 1,
      },
    },
    {
      breakpoint: 520,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 1,
      },
    },
  ],
});
//***** Trusted & Reviewed Slider JS End Here *****//

//*****  Service Offer Slider JS Start Here *****//
$('.service-offer-slider').slick({
  dots: false,
  arrow: false,
  infinite: true,
  speed: 500,
  slidesToShow: 4,
  slidesToScroll: 1,
  autoplay: true,
  autoplaySpeed: 1000,
  responsive: [
    {
      breakpoint: 1024,
      settings: {
        slidesToShow: 3,
        slidesToScroll: 1,
        infinite: true,
        dots: false
      }
    },
    {
      breakpoint: 768,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 1
      }
    },
    {
      breakpoint: 576,
      settings: {
        slidesToShow: 1,
        slidesToScroll: 1
      }
    }

  ]
});
//***** Service Offer Slider JS End Here *****//

//*****  Award Brands Slider JS Start Here *****//
$('.award-brands-slider').slick({
  dots: false,
  arrow: false,
  infinite: true,
  speed: 500,
  slidesToShow: 5,
  slidesToScroll: 1,
  autoplay: true,
  autoplaySpeed: 1000,
  responsive: [
    {
      breakpoint: 1024,
      settings: {
        slidesToShow: 3,
        slidesToScroll: 1,
        infinite: true,
        dots: false
      }
    },
    {
      breakpoint: 768,
      settings: {
        slidesToShow: 3,
        slidesToScroll: 1
      }
    },
    {
      breakpoint: 520,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 1
      }
    }

  ]
});
//***** Award Brands Slider JS End Here *****//

//***** Feedback Content Slider JS Start Here *****//
$('.customer-feedback-slider').slick({
  dots: false,
  arrow: true,
  infinite: true,
  speed: 400,
  slidesToShow: 1,
  slidesToScroll: 1,
  fade: true,
  asNavFor: '.customer-feedbcack-images',
  autoplay: false,
  autoplaySpeed: 2000,
  responsive: [
    {
      breakpoint: 1024,
      settings: {
        slidesToShow: 1,
        slidesToScroll: 1,
        infinite: true,
        dots: false
      }
    },
    {
      breakpoint: 768,
      settings: {
        slidesToShow: 1,
        slidesToScroll: 1
      }
    },
    {
      breakpoint: 520,
      settings: {
        slidesToShow: 1,
        slidesToScroll: 1
      }
    }

  ]
});
$('.customer-feedbcack-images').slick({
  dots: false,
  arrow: false,
  infinite: true,
  autoplay: true,
  slidesToShow: 1,
  slidesToScroll: 1,
  asNavFor: '.customer-feedback-slider',
  focusOnSelect: true,
});
//***** Feedback Content Slider JS End Here *****//

//***** Banner Main Slider JS Start Here *****//
$('.before-after-slider').slick({
  dots: false,
  arrows: true,
  infinite: true,
  autoplay: true,
  speed: 500,
  slidesToShow: 1,
  slidesToScroll: 1,
  autoplay: false,
  autoplaySpeed: 2000,
});
//***** Banner Main Slider JS End Here *****//

//*****  Reviews Trustpilot Slider JS Start Here *****//
$('.reviews-trustpilot-items').slick({
  dots: false,
  arrow: false,
  infinite: true,
  speed: 500,
  slidesToShow: 4,
  slidesToScroll: 1,
  autoplay: true,
  autoplaySpeed: 2000,
  responsive: [
    {
      breakpoint: 1400,
      settings: {
        slidesToShow: 3,
        slidesToScroll: 1,
        infinite: true,
        dots: false
      }
    },
    {
      breakpoint: 992,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 1,
        infinite: true,
        dots: false
      }
    },
    {
      breakpoint: 768,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 1
      }
    },
    {
      breakpoint: 576,
      settings: {
        slidesToShow: 1,
        slidesToScroll: 1
      }
    }

  ]
});
//***** Reviews Trustpilot Slider JS End Here *****//

//***** Counter Timer JS Start Here *****//
$.fn.jQuerySimpleCounter = function (options) {
  var settings = $.extend({
    start: 0,
    end: 100,
    easing: 'swing',
    duration: 400,
    complete: '',
    point_tag: 0
  }, options);

  var thisElement = $(this);

  $({ count: settings.start }).animate({ count: settings.end }, {
    duration: settings.duration,
    easing: settings.easing,
    point_tag: settings.point_tag,
    step: function () {

      if (settings.point_tag == 1) {

        var mathCount = parseFloat(this.count).toFixed(1);

      } else {

        var mathCount = Math.ceil(this.count);
      }
      thisElement.text(mathCount);

    },
    complete: settings.complete
  });
};

$('#number1').jQuerySimpleCounter({ end: parseFloat($('#number1').text()), duration: 2000, point_tag: 0 });
$('#number2').jQuerySimpleCounter({ end: parseInt($('#number2').text()), duration: 5000, point_tag: 0 });
$('#number3').jQuerySimpleCounter({ end: parseInt($('#number3').text()), duration: 3000, point_tag: 0 });
$('#number4').jQuerySimpleCounter({ end: parseInt($('#number4').text()), duration: 4000, point_tag: 0 });
$('#number5').jQuerySimpleCounter({ end: parseInt($('#number5').text()), duration: 5000, point_tag: 0 });
//***** Counter Timer JS End Here *****//

//***** Popup And Flaot Buttons JS Start Here *****//
// $(window).ready(function () {
//     setTimeout(function () {
//         $("#staticBackdrop").modal("show");
//     }, 5000);
// }),

// $(".float-form-clickbtn").click(function () {
//   $(".float-side-form").toggleClass("active");
// });
//***** Popup And Flaot Buttons JS End Here *****//

//***** Tilt Hover Effect Js Start Here *****//
VanillaTilt.init(document.querySelector(".box1"), {
  max: 10,
  speed: 1000,
  scale: 1,
  transition: true,
  easing: "cubic-bezier(.03,.98,.52,.99)",
  perspective: 700,
  glare: true
});
VanillaTilt.init(document.querySelector(".box3"), {
  max: 10,
  speed: 1000,
  perspective: 900
});
VanillaTilt.init(document.querySelectorAll(".box2"), {
  max: 30,
  speed: 600,
  scale: 1,
  transition: true,
  easing: "cubic-bezier(.03,.98,.52,.99)",
  perspective: 600,
  glare: true
});
//***** Tilt Hover Effect Js End Here *****//



$('.best-seller-inner').slick({
  dots: false,
  arrows: false,
  infinite: true,
  speed: 400,
  slidesToShow: 5,
  slidesToScroll: 1,
  autoplay: true,
  autoplaySpeed: 2000,
  responsive: [
    {
      breakpoint: 1024,
      settings: {
        slidesToShow: 4,
        slidesToScroll: 1,
        infinite: true,
        dots: false
      }
    },
    {
      breakpoint: 768,
      settings: {
        slidesToShow: 3,
        slidesToScroll: 1
      }
    },
    {
      breakpoint: 520,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 1
      }
    }

  ]
});


$('.why-choose-inner').slick({
  dots: false,
  arrows: false,
  infinite: true,
  speed: 400,
  slidesToShow: 4,
  slidesToScroll: 1,
  autoplay: true,
  autoplaySpeed: 2000,
  responsive: [
    {
      breakpoint: 1024,
      settings: {
        slidesToShow: 3,
        slidesToScroll: 1,
        infinite: true,
        dots: false
      }
    },
    {
      breakpoint: 768,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 1
      }
    },
    {
      breakpoint: 520,
      settings: {
        slidesToShow: 1,
        slidesToScroll: 1
      }
    }

  ]
});



$('.portfolioinner_mb').slick({
  dots: false,
  arrows: false,
  infinite: true,
  speed: 400,
  slidesToShow: 4,
  slidesToScroll: 1,
  autoplay: true,
  autoplaySpeed: 2000,
  responsive: [
    {
      breakpoint: 1024,
      settings: {
        slidesToShow: 3,
        slidesToScroll: 1,
        infinite: true,
        dots: false
      }
    },
    {
      breakpoint: 768,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 1
      }
    },
    {
      breakpoint: 520,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 1
      }
    }

  ]
});

$('.reviewSlider').slick({
  dots: false,
  arrows: false,
  infinite: true,
  speed: 400,
  slidesToShow: 2,
  slidesToScroll: 1,
  autoplay: true,
  autoplaySpeed: 2000,
  margin: 10,
  responsive: [
    {
      breakpoint: 1024,
      settings: {
        slidesToShow: 3,
        slidesToScroll: 1,
        infinite: true,
        dots: false
      }
    },
    {
      breakpoint: 768,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 1
      }
    },
    {
      breakpoint: 520,
      settings: {
        slidesToShow: 1,
        slidesToScroll: 1
      }
    }

  ]
});

// //***** Country Code JS Start Here *****//
// $("#countryCode , #countryCode-second , #countryCode-third , #countryCode-four , #countryCode-five , #countryCodesix , #countryCode-seven").intlTelInput({
// 	initialCountry: "us",
// 	separateDialCode: true,
// });
// $(document).ready(function() {
//   $("#countryCode , #countryCode-second , #countryCode-third , #countryCode-four , #countryCode-five , #countryCodesix , #countryCode-seven").on("input", function() {
//     var maxLength = 10;
//     if ($(this).val().length > maxLength) {
//       $(this).val($(this).val().slice(0, maxLength)); // Truncate to 10 characters
//     }
//   });
// });
// //***** Country Code JS End Here *****//



document.addEventListener('DOMContentLoaded', function () {
  const videos = document.querySelectorAll('.video-element');
  const playButtons = document.querySelectorAll('.play-btn');
  const playIcons = document.querySelectorAll('.play-btn i');

  playButtons.forEach((button, index) => {
    button.addEventListener('click', function () {
      const video = videos[index];
      const icon = playIcons[index];

      if (video.paused) {
        // Stop all other videos and reset their icons
        videos.forEach((v, i) => {
          if (i !== index) {
            v.pause();
            playIcons[i].className = 'fas fa-play';
          }
        });

        // Play this video
        video.play();
        icon.className = 'fas fa-pause';
      } else {
        // Pause this video
        video.pause();
        icon.className = 'fas fa-play';
      }
    });
  });

  // Add ended event listener to reset play button
  videos.forEach((video, index) => {
    video.addEventListener('ended', function () {
      playIcons[index].className = 'fas fa-play';
    });
  });
});



$('.writer-video-slider').slick({
  dots: false,
  arrows: false,
  infinite: true,
  slidesToShow: 3,
  slidesToScroll: 1,
  autoplay: true,
  autoplaySpeed: 2000,
  margin: 50,
  responsive: [
    {
      breakpoint: 1024,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 1,
        infinite: true,
        dots: false
      }
    },
    {
      breakpoint: 768,
      settings: {
        slidesToShow: 1,
        slidesToScroll: 1
      }
    },
    {
      breakpoint: 520,
      settings: {
        slidesToShow: 1,
        slidesToScroll: 1
      }
    }

  ]
});



$('.testimonials-book-slider').slick({
  dots: false,
  arrows: false,
  infinite: false,
  slidesToShow: 4,
  slidesToScroll: 1,
  autoplay: false,
  margin: 50,
  responsive: [
    {
      breakpoint: 1024,
      settings: {
        slidesToShow: 2,
        slidesToScroll: 1,
        infinite: true,
        dots: false
      }
    },
    {
      breakpoint: 768,
      settings: {
        slidesToShow: 1,
        slidesToScroll: 1
      }
    },
    {
      breakpoint: 520,
      settings: {
        slidesToShow: 1,
        slidesToScroll: 1
      }
    }

  ]
});

// $(document).ready(function () {
//   // Common classes
//   const formClass = '.myForm';
//   const phoneInputClass = '.countryCode';
//   const fullPhoneClass = '.fullPhoneNumber';
//   const stepClass = '.selceted-box';
//   const nextBtnClass = '.next-btn';
//   const prevBtnClass = '.previous-btn';

//   // Initialize all phone inputs
//   $(phoneInputClass).each(function () {
//     const $input = $(this);
//     $input.intlTelInput({
//       initialCountry: "us",
//       separateDialCode: true,
//       utilsScript: "https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.13/js/utils.js"
//     });

//     // Input restriction
//     $input.on("input", function () {
//       const maxLength = 10;
//       if ($(this).val().length > maxLength) {
//         $(this).val($(this).val().slice(0, maxLength));
//       }
//     });
//   });

//   // Custom validation method
//   $.validator.addMethod("validPhone", function (value, element) {
//     const $form = $(element).closest(formClass);
//     const $phoneInput = $form.find(phoneInputClass);
//     return $phoneInput.intlTelInput("isValidNumber");
//   }, "Please enter a valid phone number");

//   // Initialize all forms
//   $(formClass).each(function () {
//     const $form = $(this);
//     const $steps = $form.find(stepClass);
//     let currentStep = 0;

//     // Show first step initially
//     $steps.hide().first().show();

//     // Radio button change handler
//     $form.on('change', 'input[name="Services"]', function () {
//       if ($(this).is(':checked')) {
//         $form.find('.error-msg.services-error').remove();
//         $form.validate().element('input[name="Services"]');
//       }
//     });

//     $form.on('click', nextBtnClass, function (e) {
//       e.preventDefault();

//       const $currentStep = $steps.eq(currentStep);
//       const $fields = $currentStep.find("input, select, textarea").not(":button");

//       let isValid = true;
//       $fields.each(function () {
//         if (!$(this).valid()) {
//           isValid = false;
//         }
//       });

//       if (isValid) {
//         if (currentStep < $steps.length - 1) {
//           $currentStep.hide();
//           currentStep++;
//           $steps.eq(currentStep).show();
//         }
//       }
//     });

//     $form.on('click', prevBtnClass, function (e) {
//       e.preventDefault();
//       if (currentStep > 0) {
//         $steps.eq(currentStep).hide();
//         currentStep--;
//         $steps.eq(currentStep).show();
//       }
//     });

//     $form.validate({
//       ignore: [],
//       debug: false,
//       errorClass: "error-msg",
//       rules: {
//         language: { required: true },
//         service: { required: true },
//         genre: { required: true },
//         'manuscript-ready': { required: true },
//         'published-before': { required: true },
//         'plan-on-publishing': { required: true },
//         name: { required: true, minlength: 3 },
//         email: { required: true, email: true },
//         message: { required: true, minlength: 3 },
//         phone: { required: true, minlength: 10 },
//         "recieve-updates": { required: true },
//         services: { required: true },
//         'page-count': {required: true,number: true,max: 300},
//       },
//       messages: {
//         language: "Please select language",
//         service: "Please select service",
//         genre: "Please select genre",
//         'manuscript-ready': "Please select manuscript",
//         'published-before': "Please select published before",
//         'plan-on-publishing': "Please select plan",
//         name: {
//           required: "Please enter your name",
//           minlength: "Name must be more than 3 characters long"
//         },
//         email: {
//           required: "Please enter your email",
//           email: "Please enter valid email"
//         },
//         message: {
//           required: "Please enter your message",
//           minlength: "Message must be more than 3 characters long"
//         },
//         phone: {
//           required: "Please enter your phone",
//           minlength: "Please enter 10 digit phone number"
//         },
//         'page-count': {
//         required: "Please enter page count",
//         number: "Please enter numeric value",
//         max: "Maximum 300 pages allowed",
//       },
//         services: {
//           required: "Please select a service"
//         },
//         "recieve-updates": {
//           required: "You must agree to the terms"
//         },
//       },
//       errorPlacement: function (error, element) {
//         if (element.hasClass('fld-input')) {
//           error.insertAfter(element);
//         }
//         else if (element.hasClass('field')) {
//           error.insertAfter(element);
//         }
//         else if (element.attr("name") === "Number") {
//           error.insertAfter($form.find('.iti--allow-dropdown'))
//         }
//         else if (element.attr("name") === "recieve-updates") {
//           error.insertAfter(element.parent());
//         }
//         else {
//           error.insertAfter(element);
//         }
//       },
//       submitHandler: function (form) {
//         const $form = $(form);
//         const fullNumber = $form.find(phoneInputClass).intlTelInput("getNumber");
//         $form.find(fullPhoneClass).val(fullNumber);
//         console.log("Submitted number:", fullNumber);
//         form.submit();
//       }
//     });
//   });
// });


document.addEventListener('DOMContentLoaded', function () {
    const steps = document.querySelectorAll('.selceted-box');
    const nextBtns = document.querySelectorAll('.next-btn');
    const prevBtns = document.querySelectorAll('.previous-btn');
    let currentStep = 0;

    function showStep(index) {
        steps.forEach((step, i) => {
            step.style.display = i === index ? 'block' : 'none';
        });
    }

    // Show first step initially
    showStep(currentStep);

    // Check if all required fields in the step are filled
    function isStepValid(step) {
        const requiredFields = step.querySelectorAll('input[required], select[required], textarea[required]');
        let valid = true;

        requiredFields.forEach(field => {
            if (!field.value.trim()) {
                valid = false;
                field.classList.add('error'); // optional: add a visual error
            } else {
                field.classList.remove('error');
            }
        });

        return valid;
    }

    // Next button click
    nextBtns.forEach(btn => {
        btn.addEventListener('click', function(e) {
            e.preventDefault();
            const currentStepEl = steps[currentStep];

            if (isStepValid(currentStepEl)) {
                if (currentStep < steps.length - 1) {
                    currentStep++;
                    showStep(currentStep);
                }
            } else {
                alert('Please fill all required fields before proceeding.');
            }
        });
    });

    // Previous button click
    prevBtns.forEach(btn => {
        btn.addEventListener('click', function(e) {
            e.preventDefault();
            if (currentStep > 0) {
                currentStep--;
                showStep(currentStep);
            }
        });
    });
});

