import { jsx as n, jsxs as u } from "react/jsx-runtime";
import { useState as d, useEffect as p } from "react";
import { useSearchParams as y, useNavigate as S } from "react-router";
import { validateToken as h, setInternalTrafficCookie as v } from "./internalTrafficUtils.js";
const w = ({ token: l }) => {
  const [a] = y(), c = S(), [e, s] = d("validating"), [f, t] = d("Processing...");
  p(() => {
    const o = a.get("enable"), b = a.get("k");
    if (!h(b, l)) {
      s("error"), t("Invalid or missing token. Access denied."), console.error("Invalid token provided for internal traffic toggle");
      return;
    }
    if (o !== "0" && o !== "1") {
      s("error"), t("Invalid enable parameter. Use ?enable=0 or ?enable=1"), console.error("Invalid enable parameter:", o);
      return;
    }
    try {
      const r = o === "1";
      v(r), s("success"), t(
        r ? "✓ Internal traffic enabled. GA4 events will be tagged as internal." : "✓ Internal traffic disabled. GA4 events will be tagged as external."
      ), console.log(`Internal traffic ${r ? "enabled" : "disabled"} successfully`), setTimeout(() => {
        c("/");
      }, 3e3);
    } catch (r) {
      s("error"), t(`Error: ${r instanceof Error ? r.message : "Unknown error"}`), console.error("Error setting internal traffic cookie:", r);
    }
  }, [a, l, c]);
  const g = {
    display: "flex",
    justifyContent: "center",
    alignItems: "center",
    minHeight: "100vh",
    fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif'
  }, i = {
    textAlign: "center",
    padding: "2rem",
    borderRadius: "8px",
    boxShadow: "0 2px 8px rgba(0, 0, 0, 0.1)",
    maxWidth: "500px"
  }, m = e === "success" ? {
    ...i,
    backgroundColor: "#f0f9ff",
    borderLeft: "4px solid #10b981"
  } : e === "error" ? {
    ...i,
    backgroundColor: "#fef2f2",
    borderLeft: "4px solid #ef4444"
  } : {
    ...i,
    backgroundColor: "#f3f4f6",
    borderLeft: "4px solid #3b82f6"
  };
  return /* @__PURE__ */ n("div", { style: g, children: /* @__PURE__ */ u("div", { style: m, children: [
    /* @__PURE__ */ n("h1", { style: {
      fontSize: "1.5rem",
      fontWeight: "600",
      margin: "0 0 1rem 0",
      color: e === "success" ? "#059669" : e === "error" ? "#dc2626" : "#1f2937"
    }, children: e === "success" ? "Success" : e === "error" ? "Error" : "Processing" }),
    /* @__PURE__ */ n("p", { style: {
      fontSize: "1rem",
      margin: "1rem 0",
      color: e === "success" ? "#047857" : e === "error" ? "#991b1b" : "#374151",
      lineHeight: "1.5"
    }, children: f }),
    e === "success" && /* @__PURE__ */ n("p", { style: {
      fontSize: "0.875rem",
      color: "#6b7280",
      marginTop: "1.5rem",
      fontStyle: "italic"
    }, children: "Redirecting to home page in 3 seconds..." })
  ] }) });
};
export {
  w as default
};
