'use client'; import { FC, useState } from 'react'; import { formatCurrency } from '@/helpers/formatCurrency'; import { formatStatus } from '@/helpers/formatStatus'; import { GiftModal } from '../GiftModal'; import { useGlobalStore } from '@/app/store/global'; import { DB } from '@/lib/db'; import { useRouter } from 'next/navigation'; import { Button } from '@/components/atoms/Button'; import { Badge } from '@/components/atoms/Badge'; import Link from 'next/link'; type Props = { hideDetails?: boolean; editable?: boolean; personId?: string; }; export const GiftCard: FC = ({ hideDetails = false, editable = false, personId, ...gift }) => { const [isOpen, setIsOpen] = useState(false); const year = useGlobalStore((s) => s.year); const router = useRouter(); const { title, description, cost, status, created, expand, link } = gift; const bgByStatus = { planned: 'bg-gray-100', decided: 'bg-blue-100', bought: 'bg-green-100', wrapped: 'bg-purple-100', }; const handleDelete = async () => { await DB.deleteGift(gift.id); router.refresh(); }; return ( <>
setIsOpen(true) : undefined}>

{title}

{link && (
{link.split('\n').map((line, index) => ( e.stopPropagation()}> Link {index + 1} ))}
)} {description &&

{description}

}
Data dodania: {new Date(created).toLocaleDateString()} Koszt: {formatCurrency(cost)} {!hideDetails && ( <> Dla: {expand?.person.name} )} Status: {formatStatus(status)} {editable && (
)}
setIsOpen(false)} yearId={year.id} personId={personId} gift={gift} onSave={async (data) => { await DB.updateGift(gift.id, data); router.refresh(); }} /> ); };