'use client'; import { Cog8ToothIcon, PlusCircleIcon, ShareIcon } 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, useToast } from "react-toastify"; export interface LocationCardProps { location: BillingLocation } export const LocationCard:FC = ({location: { _id, name, yearMonth, bills }}) => { const t = useTranslations("home-page.location-card"); const currentLocale = useLocale(); // sum all the billAmounts 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 ?

{ t("payed-total-label") } ${formatCurrency(monthlyExpense)}

: null }
); };