"use client"

import { useEffect } from "react"
import { useRouter } from "next/navigation"
import { appStartRoute } from "@/lib/platform"

/**
 * Root entry for the native shells. The Tauri window opens directly on the
 * per-app start route, but `/` is still generated by the static export; send
 * any cold load there. The `?mail=` deep-link param is handled client-side.
 */
export function MobileRootRedirect() {
  const router = useRouter()

  useEffect(() => {
    const params = new URLSearchParams(window.location.search)
    const mail = params.get("mail")
    if (mail) {
      router.replace(`/mail/inbox/message/${encodeURIComponent(mail)}`)
      return
    }
    router.replace(appStartRoute())
  }, [router])

  return null
}
