'use client'; import { CheckCircleIcon, Cog8ToothIcon, PlusCircleIcon, ShareIcon, BanknotesIcon } from "@heroicons/react/24/outline"; import { FC } from "react"; import { BillBadge } from "./BillBadge"; import { BillingLocation } from "../lib/db-types"; import { formatYearMonth } from "../lib/format"; import { formatCurrency } from "../lib/formatStrings"; import Link from "next/link"; import { useLocale, useTranslations } from "next-intl"; import { toast } from "react-toastify"; export interface LocationCardProps { location: BillingLocation } export const LocationCard:FC = ({location}) => { const { _id, name, yearMonth, bills, seenByTenant } = location; console.log("seenByTenant:", seenByTenant); const t = useTranslations("home-page.location-card"); const currentLocale = useLocale(); // sum all the paid bill amounts (regardless of who pays) const monthlyExpense = bills.reduce((acc, bill) => bill.paid ? acc + (bill.payedAmount ?? 0) : acc, 0); const handleCopyLinkClick = () => { // copy URL to clipboard const url = `${window.location.origin}/${currentLocale}/share/location/${_id}`; navigator.clipboard.writeText(url); // use NextJS toast to notiy user that the link was copied toast.success(t("link-copy-message"), {theme: "dark"}); } return(

{formatYearMonth(yearMonth)} {name}

{ bills.map(bill => ) } {t("add-bill-button-tooltip")}
{ monthlyExpense > 0 || seenByTenant ?
{t("monthly-statement-legend")} { monthlyExpense > 0 ?
{ t("payed-total-label") } ${formatCurrency(monthlyExpense)}
: null } {seenByTenant && (
{t("seen-by-tenant-label")}
)}
: null }
); };