import UserContext from '@/contexts/UserContext'; import useGetBreweryPostLikeCount from '@/hooks/data-fetching/brewery-likes/useGetBreweryPostLikeCount'; import useTimeDistance from '@/hooks/utilities/useTimeDistance'; import BreweryPostQueryResult from '@/services/BreweryPost/types/BreweryPostQueryResult'; import { format } from 'date-fns'; import { FC, useContext } from 'react'; import { FaRegEdit } from 'react-icons/fa'; import { z } from 'zod'; import Link from 'next/link'; import BreweryPostLikeButton from '../BreweryIndex/BreweryPostLikeButton'; interface BreweryInfoHeaderProps { breweryPost: z.infer; } const BreweryInfoHeader: FC = ({ breweryPost }) => { const createdAt = new Date(breweryPost.createdAt); const timeDistance = useTimeDistance(createdAt); const { user } = useContext(UserContext); const idMatches = user && breweryPost.postedBy.id === user.id; const isPostOwner = !!(user && idMatches); const { likeCount, mutate } = useGetBreweryPostLikeCount(breweryPost.id); return (

{breweryPost.name}

Located in {` ${breweryPost.location.city}, ${ breweryPost.location.stateOrProvince || breweryPost.location.country }`}

{' posted by '} {`${breweryPost.postedBy.username} `} {timeDistance && ( {`${timeDistance} ago`} )}

{isPostOwner && (
)}

{breweryPost.description}

{(!!likeCount || likeCount === 0) && ( Liked by {likeCount} {likeCount === 1 ? 'user' : 'users'} )}
{user && ( )}
); }; export default BreweryInfoHeader;