"use client";
import { jsx as i, Fragment as v, jsxs as $ } from "react/jsx-runtime";
import { useState as r, useEffect as w } from "react";
import { createPortal as k } from "react-dom";
import h from "../../../modules/ScienceHero/scienceHero.module.css";
function S({ children: l, backgroundImage: x, cursorLink: g }) {
  const [d, y] = r({ x: 0, y: 0 }), [c, a] = r(!1), [E, u] = r(!1), [e, p] = r(null), [o, M] = r(!1);
  w(() => {
    u(!0);
    const t = () => M(window.innerWidth <= 768);
    return t(), window.addEventListener("resize", t), () => {
      window.removeEventListener("resize", t), u(!1);
    };
  }, []), w(() => {
    if (o) return;
    const t = (n) => {
      y({
        x: n.clientX,
        y: n.clientY
      });
    }, s = () => {
      if (c && e) {
        const n = document.querySelector('[data-type="hero"]');
        n && p(n.getBoundingClientRect());
      }
    };
    return window.addEventListener("mousemove", t), window.addEventListener("scroll", s, { passive: !0 }), window.addEventListener("resize", s, { passive: !0 }), () => {
      window.removeEventListener("mousemove", t), window.removeEventListener("scroll", s), window.removeEventListener("resize", s);
    };
  }, [o, c, e]);
  const b = (t) => {
    o || (p(t.currentTarget.getBoundingClientRect()), a(!0));
  }, C = () => {
    o || a(!1);
  }, L = () => {
    window.location.href = g;
  };
  if (o)
    return /* @__PURE__ */ i(v, { children: l });
  const f = `circle(270px at ${d.x}px ${d.y}px)`, m = c && e && /* @__PURE__ */ i(
    "div",
    {
      className: h.cursorContainer,
      style: {
        position: "fixed",
        top: `${e.top}px`,
        left: `${e.left}px`,
        width: `${e.width}px`,
        height: `${e.height}px`,
        overflow: "hidden",
        cursor: "pointer"
      },
      children: /* @__PURE__ */ i(
        "div",
        {
          className: h.normalBackground,
          style: {
            position: "absolute",
            top: `${-e.top}px`,
            left: `${-e.left}px`,
            backgroundImage: `url(${x})`,
            clipPath: f,
            WebkitClipPath: f,
            backgroundPosition: "center"
          }
        }
      )
    }
  );
  return /* @__PURE__ */ $(v, { children: [
    /* @__PURE__ */ i(
      "div",
      {
        "data-type": "hero",
        onMouseEnter: b,
        onMouseLeave: C,
        onClick: L,
        style: { cursor: "pointer" },
        children: l
      }
    ),
    E && m && k(m, document.body)
  ] });
}
export {
  S as ScienceClientCursor
};
