import { useState as d, useCallback as o, useRef as y, useEffect as g } from "react";
const A = () => {
  const [n, t] = d(null), [r, a] = d(0), [c, s] = d(!0), [h, l] = d(!1), [f, u] = d(!1), [E, v] = d(!1), i = o((e) => {
    a(e.activeIndex), l(e.isEnd), s(e.isBeginning);
  }, []), L = o(() => {
    n && (n.slidePrev(), i(n));
  }, [n, i]), k = o(() => {
    n && (n.slideNext(), i(n));
  }, [n, i]), I = o(
    (e) => {
      n && (n.slideTo(e), i(n));
    },
    [n, i]
  ), S = (e) => {
    t(e), u(e == null ? void 0 : e.isLocked), v(e == null ? void 0 : e.isLocked), i(e);
  }, m = o(
    (e) => {
      l(e.isEnd), u(e == null ? void 0 : e.isLocked), v(e == null ? void 0 : e.isLocked), i(e);
    },
    [i]
  ), b = o(() => {
    l(!0), s(!1);
  }, []), x = o(() => {
    s(!0), l(!1);
  }, []);
  return {
    swiper: n,
    setSwiper: t,
    activeIndex: r,
    setActiveIndex: a,
    isEnd: h,
    setIsEnd: l,
    hideNav: f,
    handleSlideChange: i,
    handlePrevClick: L,
    handleNextClick: k,
    handleSlideTo: I,
    onSwiperInit: S,
    handleSwiperResize: m,
    isBeginning: c,
    isLocked: E,
    setIsBeginning: s,
    handleReachEnd: b,
    handleReachBeginning: x
  };
}, B = (n = 3e3) => {
  const t = A(), [r, a] = d(!0), c = y(null), s = o(() => {
    a(!1), c.current && (clearInterval(c.current), c.current = null);
  }, []), h = o(() => {
    a(!0);
  }, []), l = o(() => {
    s();
  }, [s]);
  return g(() => {
    if (!(!r || !t.swiper || t.swiper.slides.length <= 1))
      return c.current = setInterval(() => {
        t.swiper && (t.isEnd ? t.swiper.slideTo(0) : t.swiper.slideNext());
      }, n), () => {
        c.current && (clearInterval(c.current), c.current = null);
      };
  }, [r, t.swiper, t.isEnd, n]), g(() => {
    const f = () => s(), u = () => {
      document.hidden && s();
    };
    return window.addEventListener("beforeunload", f), document.addEventListener("visibilitychange", u), () => {
      window.removeEventListener("beforeunload", f), document.removeEventListener("visibilitychange", u);
    };
  }, [s]), {
    ...t,
    isAutoPlay: r,
    stopAutoPlay: s,
    startAutoPlay: h,
    handleUserInteraction: l
  };
};
export {
  A as useSwiper,
  B as useSwiperWithAutoPlay
};
