"use client"; import { FC, useEffect, useRef } from "react"; import { formatYearMonth } from "../lib/format"; import { YearMonth } from "../lib/db-types"; import { formatCurrency } from "../lib/formatStrings"; import { useTranslations } from "next-intl"; export interface MonthCardProps { yearMonth: YearMonth, children?: React.ReactNode, unpaidTotal: number, payedTotal: number, currency?: string | null, expanded?:boolean, onToggle: (yearMonth:YearMonth) => void } export const MonthCard:FC = ({ yearMonth, children, unpaidTotal, payedTotal, currency, expanded, onToggle }) => { const elRef = useRef(null); const t = useTranslations("home-page.month-card"); // Setting the `month` will activate the accordion belonging to that month // If the accordion is already active, it will collapse it const handleChange = (event:any) => onToggle(yearMonth); useEffect(() => { if(expanded && elRef.current) { // if the element i selected > scroll it into view elRef.current.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }, [expanded]); return(
{`${formatYearMonth(yearMonth)}`} { unpaidTotal>0 ?

{t("total-due-label")} { formatCurrency(unpaidTotal, currency ?? "EUR") }

: null } { payedTotal>0 ?

{t("total-payed-label")} { formatCurrency(payedTotal, currency ?? "EUR") }

: null }
{children}
) };