"use client";

import { useEffect } from "react";
import { useParams } from "next/navigation";
import DappPage from "../../../../page";

export default function PositionDeepLinkPage() {
  const params = useParams<{ network: string; preset: string; tokenId: string }>();

  useEffect(() => {
    try {
      const network = String(params?.network || '').toUpperCase();
      const preset = Number(params?.preset || '1');
      const tokenId = String(params?.tokenId || '');
      if (!network || !preset || !tokenId) return;
      // Persist for Dapp page to consume on mount; keep URL unchanged
      const payload = { network, preset, tokenId, ts: Math.floor(Date.now() / 1000) };
      if (typeof window !== 'undefined') {
        localStorage.setItem('dapp:deeplink:v1', JSON.stringify(payload));
      }
    } catch {}
  }, [params]);

  // Render the main Dapp UI without redirect; it will consume the deep-link
  return <DappPage />;
}
