"use client";
import Link from "next/link";
import { useState } from "react";
import { createHref, homeHref, researchHref, systemHref, toolsHref, workHref } from "@/lib/hrefs";
import { useHydrated } from "@/components/ui/use-hydrated";
import type { Theme } from "@/lib/theme";
import { cn } from "@/lib/utils";
import { JUMP_EVENT } from "./JumpPalette";
import { usePhone } from "./phone";
import RailCount from "./RailCount";
import { Sheet } from "./Sheet";
import ThemeControl from "./ThemeControl";
// ---------------------------------------------------------------------------
// THE PHONE DOCK: the rail's places at the foot of a phone's screen, where the
// thumb is -- Inbox · Research · Work · Tools, and ≡ More (Settings, + Create,
// Jump to…, the theme), which is a sheet. 56 px and the safe area under it.
// The place you are in carries `aria-current` and the Signal edge along its
// top: the rail's lit edge, turned on its side.
//
// Rendered by AppRail beside the rail; the desk never draws it (md:hidden) and
// the rail is not drawn on a phone (app/globals.css, "phone: the shell"). Its
// counts are the rail's (RailCount), under their own attribute, and its
// `aria-current` is set on a phone only (the lit edge is `data-lit`): on the
// desk the rail's place is the one current link to it.
// ---------------------------------------------------------------------------
const PLACES = [
{ id: "inbox", label: "Inbox", href: homeHref(), count: "inbox" as const },
{ id: "research", label: "Research", href: researchHref() },
{ id: "work", label: "Work", href: workHref(), count: "work" as const },
{ id: "tools", label: "Tools", href: toolsHref() },
];
/** The theme as says it now: a choice made since the page was served (ThemeControl stamps it there) wins. */
function current(served: Theme): Theme {
if (typeof document === "undefined") return served;
const t = document.documentElement.dataset.theme;
return t === "light" || t === "dark" ? t : "auto";
}
export default function PhoneDock({ place, theme }: { place: string; theme: Theme }) {
const hydrated = useHydrated();
const phone = usePhone();
const [more, setMore] = useState(false);
const moreLit = place === "settings" || place === "create";
return (
<>
{more && (
setMore(false)}>