"use client"; import React from "react"; import Link from "next/link"; import { CalendarCheck, RefreshCw } from "lucide-react"; import { getDays, getMonths, getYears } from "@/lib/frontend/apiClient"; import { dayPath, monthPath, yearPath } from "@/lib/frontend/routes"; import { sortNumericStringsDesc } from "@/lib/frontend/explorer/sorters"; import { mapExplorerError } from "@/lib/frontend/explorer/errorMapping"; import { buildLoginUrl, LOGIN_REASONS } from "@/lib/frontend/authRedirect"; import { useExplorerQuery } from "@/lib/frontend/hooks/useExplorerQuery"; import ExplorerBreadcrumbs from "@/components/explorer/breadcrumbs/ExplorerBreadcrumbs"; import ExplorerPageShell from "@/components/explorer/ExplorerPageShell"; import ExplorerSectionCard from "@/components/explorer/ExplorerSectionCard"; import ExplorerLoading from "@/components/explorer/states/ExplorerLoading"; import ExplorerEmpty from "@/components/explorer/states/ExplorerEmpty"; import ExplorerError from "@/components/explorer/states/ExplorerError"; import ExplorerNotFound from "@/components/explorer/states/ExplorerNotFound"; import ForbiddenView from "@/components/system/ForbiddenView"; import { Button } from "@/components/ui/button"; /** * DaysExplorer * * Explorer level: days for a given branch/year/month. * Loads years + months for breadcrumb dropdowns (fail-open). * * @param {{ branch: string, year: string, month: string }} props */ export default function DaysExplorer({ branch, year, month }) { const daysLoadFn = React.useCallback( () => getDays(branch, year, month), [branch, year, month] ); const daysQuery = useExplorerQuery(daysLoadFn, [daysLoadFn]); const yearsLoadFn = React.useCallback(() => getYears(branch), [branch]); const yearsQuery = useExplorerQuery(yearsLoadFn, [yearsLoadFn]); const monthsLoadFn = React.useCallback( () => getMonths(branch, year), [branch, year] ); const monthsQuery = useExplorerQuery(monthsLoadFn, [monthsLoadFn]); const mapped = React.useMemo( () => mapExplorerError(daysQuery.error), [daysQuery.error] ); React.useEffect(() => { if (mapped?.kind !== "unauthenticated") return; const next = typeof window !== "undefined" ? `${window.location.pathname}${window.location.search}` : monthPath(branch, year, month); window.location.replace( buildLoginUrl({ reason: LOGIN_REASONS.EXPIRED, next }) ); }, [mapped?.kind, branch, year, month]); const yearOptions = yearsQuery.status === "success" && Array.isArray(yearsQuery.data?.years) ? yearsQuery.data.years : null; const monthOptions = monthsQuery.status === "success" && Array.isArray(monthsQuery.data?.months) ? monthsQuery.data.months : null; const breadcrumbsNode = ( ); const actions = ( ); if (daysQuery.status === "loading") { return ( ); } if (daysQuery.status === "error" && mapped) { if (mapped.kind === "forbidden") return ; if (mapped.kind === "notfound") { return ( ); } if (mapped.kind === "unauthenticated") { return ( ); } return ( ); } const days = Array.isArray(daysQuery.data?.days) ? daysQuery.data.days : []; const sorted = sortNumericStringsDesc(days); return ( {sorted.length} Tag{sorted.length === 1 ? "" : "e"} } > {sorted.length === 0 ? ( ) : (
{sorted.map((d) => ( ))}
)}
); }