"use client"; import Link from "next/link"; import { useEffect, useMemo, useRef, useState } from "react"; import { CountrySelect, PlaceSearch } from "@/app/profil/BirthForm"; import { AspectGrid, AspectList, BigThree, PositionTables } from "@/components/ChartTables"; import { ChartWheel, WheelLegend } from "@/components/ChartWheel"; import { Tabs } from "@/components/Tabs"; import { ZODIAC_BY_ID } from "@/content/zodiac"; import { ApiError, api, errorText } from "@/lib/api"; import { ASPECTS, countryName, formatBirthDate } from "@/lib/astro"; import { BIRTH_DRAFT_KEY, MONTHS, type BirthDraft, composeDate, composeTime, daysIn } from "@/lib/birth"; import type { BirthData, Chart, ChartResult, Place } from "@/lib/types"; interface Result { highlights: Chart["highlights"]; /** Without a birth time: the sign may have been the neighbouring one at the start or end of the day. */ uncertain: { sun: boolean; moon: boolean }; chart: ChartResult; } const ERRORS: Record = { place_not_found: "Nem találjuk ezt a települést. Válassz a listából.", nonexistent_local_time: "Ez az időpont az óraátállítás miatt nem létezett ezen a napon (az órát előreállították). Ellenőrizd a születési időt.", invalid_date: "Érvénytelen dátum.", too_many_requests: "Erről a címről most túl sok számítás érkezett. Próbáld újra egy óra múlva.", }; const GRID_LEGEND = ["conjunction", "sextile", "square", "trine", "opposition"]; /** * The calculated chart and the typed birth data, kept for this browser tab * only (sessionStorage: not a cookie, gone when the tab is closed), so they * are there again after visiting another page, and the profile can offer the * birth data after signing up in the same tab. Storage that only keeps what * the visitor typed, for the session, needs no consent. Nothing of this is * stored on the server. */ const CHART_KEY = "sf_public_chart"; type Saved = { result: Result; birth: BirthData }; /** Links to the sign pages of the Sun, Moon and Ascendant. */ function SignLinks({ result }: { result: Result }) { const links: [string, string | null, string, boolean][] = [ ["Napjegy", result.highlights.sun, "nap", result.uncertain.sun], ["Holdjegy", result.highlights.moon, "hold", result.uncertain.moon], ["Aszcendens", result.highlights.time_known ? result.highlights.ascendant : null, "aszcendens", false], ]; return (
Mit jelentenek?
); } /** The calculated chart: the wheel and the tables of the chart pages, without the AI parts. */ function ChartView({ result, birth }: { result: Result; birth: BirthData }) { const r = result.chart; const timeKnown = result.highlights.time_known; const chart: Chart = { id: "", label: "Születési horoszkóp", is_primary: false, kind: "person", editable_until: null, birth_data: birth, highlights: result.highlights, chart: r, created_at: "", }; const place = r.location.place; const country = place?.country_code ?? birth.country; return ( <>

A születési horoszkópod

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

A rövid összefoglalóhoz lépj be

A képletedhez ingyen írunk egy rövid, személyre szabott összefoglalót, ehhez azonban be kell jelentkezned. Belépés után a képleted is megmarad: a most megadott születési adataidat áthozzuk.

Belépés és ingyenes összefoglaló
}, { id: "matrix", label: "Mátrix", content: (
    {GRID_LEGEND.map((k) => (
  • {" "} {ASPECTS[k]?.hu}
  • ))}
), }, { id: "reszletek", label: "Fényszögek", content: }, ]} />
); } /** The public birth chart: a calculation only, nothing is saved and no AI is used. */ export function PublicChart() { const [year, setYear] = useState(""); const [month, setMonth] = useState(""); const [day, setDay] = useState(""); const [hour, setHour] = useState(""); const [minute, setMinute] = useState(""); const [timeUnknown, setTimeUnknown] = useState(false); const [country, setCountry] = useState("HU"); const [place, setPlace] = useState(null); const [ambiguous, setAmbiguous] = useState(false); const [ambiguity, setAmbiguity] = useState<"earlier" | "later">("earlier"); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const [result, setResult] = useState(null); const [stored, setStored] = useState(false); /** After a calculation (smooth) or on coming back (at once): show the drawn chart. */ const [reveal, setReveal] = useState(null); const minuteRef = useRef(null); const resultRef = useRef(null); const today = useMemo(() => new Date().toISOString().slice(0, 10), []); // Back on the page: the birth data typed earlier and, in this tab, the chart. useEffect(() => { let draft: BirthDraft | null = null; let saved: Saved | null = null; try { draft = JSON.parse(sessionStorage.getItem(BIRTH_DRAFT_KEY) ?? "null"); saved = JSON.parse(sessionStorage.getItem(CHART_KEY) ?? "null"); } catch { return; } if (draft && /^\d{4}-\d{2}-\d{2}$/.test(draft.date) && draft.geonames_id) { setYear(draft.date.slice(0, 4)); setMonth(String(Number(draft.date.slice(5, 7)))); setDay(String(Number(draft.date.slice(8, 10)))); setHour(draft.time ? draft.time.slice(0, 2) : ""); setMinute(draft.time ? draft.time.slice(3, 5) : ""); setTimeUnknown(!draft.time); setCountry(draft.country); setPlace({ geonames_id: draft.geonames_id, name: draft.placeName, region: draft.region, population: null, country_code: draft.country, }); setStored(true); } if (saved?.result?.chart && saved.birth?.date) { setResult(saved); setStored(true); setReveal("instant"); } }, []); // Scrolls to the drawn chart, once it is on the page. An old tab in the // address (#bolygok) would pull the page down to the tables instead. useEffect(() => { if (!reveal || !result) return; if (window.location.hash) history.replaceState(null, "", window.location.pathname + window.location.search); resultRef.current?.scrollIntoView({ behavior: reveal, block: "start" }); setReveal(null); }, [reveal, result]); /** Forgets the birth data and the chart in this browser. */ function clear() { try { sessionStorage.removeItem(BIRTH_DRAFT_KEY); sessionStorage.removeItem(CHART_KEY); } catch { // storage blocked } setYear(""); setMonth(""); setDay(""); setHour(""); setMinute(""); setTimeUnknown(false); setCountry("HU"); setPlace(null); setAmbiguous(false); setResult(null); setError(null); setStored(false); } async function submit(e: React.FormEvent) { e.preventDefault(); setError(null); const date = composeDate(year, month, day); const time = composeTime(hour, minute); if (!date) return setError("Ellenőrizd a dátumot: az év négy számjegy, és a nap legyen az adott hónapban."); if (date > today) return setError("A születési dátum nem lehet a jövőben."); if (!timeUnknown && !time) return setError("Add meg a születési időt (óra 0–23, perc 0–59), vagy jelöld, hogy nem tudod."); if (!place) return setError("Válaszd ki a születési helyet a listából."); setBusy(true); try { const birth = { date, ...(timeUnknown ? {} : { time }), country, geonames_id: place.geonames_id, }; const r = await api("/public/chart", { body: { ...birth, ...(ambiguous ? { ambiguous_time: ambiguity } : {}) }, }); setResult({ result: r, birth }); // Kept in this browser only: for coming back to the page, and for the profile after sign-up. const draft: BirthDraft = { ...birth, time: birth.time ?? null, placeName: place.name, region: place.region }; try { sessionStorage.setItem(BIRTH_DRAFT_KEY, JSON.stringify(draft)); sessionStorage.setItem(CHART_KEY, JSON.stringify({ result: r, birth })); setStored(true); } catch { // storage blocked or full: the chart is still shown } setReveal("smooth"); } catch (err) { if (err instanceof ApiError && err.code === "ambiguous_local_time") { setAmbiguous(true); setError( "Ez az időpont az óraátállítás miatt kétszer is előfordult ezen a napon. Válaszd ki, melyikben születtél.", ); } else { setError(err instanceof ApiError ? (ERRORS[err.code] ?? errorText(err)) : errorText(err)); } } finally { setBusy(false); } } return ( <>
Születési dátum
setYear(e.target.value.replace(/\D/g, ""))} />
Születési idő (helyi idő)
{ const v = e.target.value.replace(/\D/g, ""); setHour(v); setAmbiguous(false); if (v.length === 2 || (v.length === 1 && Number(v) > 2)) minuteRef.current?.focus(); }} /> { setMinute(e.target.value.replace(/\D/g, "")); setAmbiguous(false); }} />
{ setCountry(c); setPlace(null); }} />
{ambiguous && (
Melyik időpontban születtél?
)} {error && (

{error}

)}
{stored && ( )}

Ingyenes, belépés nélkül. Az adataidat a szerveren nem tároljuk: csak ebben a böngészőlapban maradnak meg, hogy oldalváltáskor ne vesszenek el, és a lap bezárásakor törlődnek.

{result && (
)} ); }