import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faEllipsis, faLink } from "@fortawesome/free-solid-svg-icons";
import Link from "next/link";
import { CollectionIncludingMembers } from "@/types/global";
import useLinkStore from "@/store/links";
import Dropdown from "./Dropdown";
import { useState } from "react";
import ProfilePhoto from "./ProfilePhoto";
import { faCalendarDays } from "@fortawesome/free-regular-svg-icons";
import useModalStore from "@/store/modals";
type Props = {
collection: CollectionIncludingMembers;
className?: string;
};
export default function CollectionCard({ collection, className }: Props) {
const { setModal } = useModalStore();
const { links } = useLinkStore();
const formattedDate = new Date(collection.createdAt as string).toLocaleString(
"en-US",
{
year: "numeric",
month: "short",
day: "numeric",
}
);
const [expandDropdown, setExpandDropdown] = useState(false);
return (
setExpandDropdown(!expandDropdown)}
id={"expand-dropdown" + collection.id}
className="inline-flex absolute top-5 right-5 rounded-md cursor-pointer hover:bg-slate-200 duration-100 p-1"
>
{collection.name}
{collection.members
.sort((a, b) => (a.userId as number) - (b.userId as number))
.map((e, i) => {
return (
);
})
.slice(0, 4)}
{collection.members.length - 4 > 0 ? (
+{collection.members.length - 4}
) : null}
{links.filter((e) => e.collectionId === collection.id).length}
{expandDropdown ? (
{
setModal({
modal: "COLLECTION",
state: true,
method: "UPDATE",
active: collection,
});
setExpandDropdown(false);
},
},
{
name: "Share/Collaborate",
onClick: () => {
setModal({
modal: "COLLECTION",
state: true,
method: "UPDATE",
active: collection,
defaultIndex: 1,
});
setExpandDropdown(false);
},
},
{
name: "Delete Collection",
onClick: () => {
setModal({
modal: "COLLECTION",
state: true,
method: "UPDATE",
active: collection,
defaultIndex: 2,
});
setExpandDropdown(false);
},
},
]}
onClickOutside={(e: Event) => {
const target = e.target as HTMLInputElement;
if (target.id !== "expand-dropdown" + collection.id)
setExpandDropdown(false);
}}
className="absolute top-[3.2rem] right-5 z-10 w-36"
/>
) : null}
);
}