import type { Metadata } from "next"; import Link from "next/link"; import { notFound } from "next/navigation"; import { AspectGrid, AspectList, BigThree, PositionTables } from "@/components/ChartTables"; import { ChartSummary } from "@/components/ChartSummary"; import { ChartSwitcher } from "@/components/ChartSwitcher"; import { DetailedAnalysis } from "@/components/DetailedAnalysis"; import { ChartWheel, WheelLegend } from "@/components/ChartWheel"; import { Tabs } from "@/components/Tabs"; import { ASPECTS, ELEMENTS, MODALITIES, MOON_PHASES, countryName, formatBirthDate, pointName } from "@/lib/astro"; import { backendGet, requireMe } from "@/lib/server"; import type { Analysis, Chart, ChartListItem, PublicConfig } from "@/lib/types"; export const metadata: Metadata = { title: "Képlet" }; const GRID_LEGEND = ["conjunction", "sextile", "square", "trine", "opposition"]; const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; /** One saved chart: the wheel and the tables, read from the database (not recalculated). */ export default async function ChartPage({ params }: { params: Promise<{ id: string }> }) { const { id } = await params; const me = await requireMe(`/kepletek/${id}`); if (!UUID.test(id)) notFound(); const [chart, analyses, config, chartList] = await Promise.all([ backendGet(`/v1/charts/${id}`), backendGet<{ analyses: Analysis[] }>(`/v1/charts/${id}/analyses`), backendGet("/v1/config"), backendGet<{ charts: ChartListItem[] }>("/v1/charts"), ]); const charts = chartList?.charts ?? []; const persons = charts.filter((c) => c.kind === "person"); if (!chart) notFound(); const list = analyses?.analyses ?? []; const summary = list.find((a) => a.kind === "summary" && a.status !== "failed") ?? null; const natal = list.filter((a) => a.kind === "natal"); const detailed = natal.find((a) => a.status !== "failed") ?? natal[0] ?? null; const result = chart.chart; const timeKnown = chart.highlights.time_known; const place = result.location.place; const country = place?.country_code ?? chart.birth_data.country; const elements = result.summary?.elements; const modalities = result.summary?.modalities; const phase = result.moon_phase; return (
c.is_primary) ?? null} persons={persons} canAdd={me.persons.left !== 0} />

{formatBirthDate(chart.birth_data.date)} {timeKnown ? `, ${result.time.local.slice(11, 16)} (UTC${result.time.utc_offset}${result.time.dst ? ", nyári idő" : ""})` : ", ismeretlen időpont"} {" · "} {place?.name ?? chart.birth_data.place ?? "–"} {country ? `, ${countryName(country)}` : ""}

{(elements || modalities || phase) && (
{elements && ( <>
Elemek
{Object.entries(elements) .map(([k, v]) => `${ELEMENTS[k] ?? k} ${v.count}`) .join(" · ")}
)} {modalities && ( <>
Minőségek
{Object.entries(modalities) .map(([k, v]) => `${MODALITIES[k] ?? k} ${v.count}`) .join(" · ")}
)} {phase && ( <>
Holdfázis
{MOON_PHASES[phase.phase] ?? phase.phase}, {Math.round(phase.illumination * 100)}%
)}
{elements && (

Az elemek és minőségek a tíz bolygóból számolva:{" "} {Object.entries(elements) .filter(([, v]) => v.count > 0) .map(([k, v]) => `${ELEMENTS[k] ?? k}: ${v.points.map(pointName).join(", ")}`) .join("; ")} .

)}
)} {chart.is_primary && ( Személyek {persons.length > 0 ? `${persons.length} felvett személy` : "Társad, családod képlete"} {persons.length > 0 ? persons.slice(0, 3).map((p) => p.label).join(", ") + (persons.length > 3 ? "…" : "") : "Vedd fel őket, és nézd meg az ő képletüket és elemzésüket is."} )}
), }, { id: "bolygok", label: "Bolygók", content: }, { id: "matrix", label: "Mátrix", content: (
    {GRID_LEGEND.map((k) => (
  • {" "} {ASPECTS[k]?.hu}
  • ))}
), }, { id: "reszletek", label: "Részletek", content: }, ]} />
); }