import { compact } from "es-toolkit/compat"; import { observer } from "mobx-react"; import * as React from "react"; import { useMemo, useCallback } from "react"; import { useTranslation } from "react-i18next"; import type Share from "~/models/Share"; import { Avatar, AvatarSize } from "~/components/Avatar"; import Badge from "~/components/Badge"; import Flex from "~/components/Flex"; import { HEADER_HEIGHT } from "~/components/Header"; import { type Props as TableProps, SortableTable, } from "~/components/SortableTable"; import { type Column as TableColumn } from "~/components/Table"; import { ContextMenu } from "~/components/Menu/ContextMenu"; import { useShareMenuActions } from "~/hooks/useShareMenuActions"; import Time from "~/components/Time"; import ShareMenu from "~/menus/ShareMenu"; import { useFormatNumber } from "~/hooks/useFormatNumber"; import { HStack } from "~/components/primitives/HStack"; const ROW_HEIGHT = 50; type Props = Omit, "columns" | "rowHeight"> & { canManage: boolean; }; const ShareRowContextMenu = observer(function ShareRowContextMenu({ share, menuLabel, children, }: { share: Share; menuLabel: string; children: React.ReactNode; }) { const action = useShareMenuActions(share); return ( {children} ); }); export function SharesTable({ data, canManage, ...rest }: Props) { const { t } = useTranslation(); const formatNumber = useFormatNumber(); const hasDomain = data.some((share) => share.domain); const applyContextMenu = useCallback( (share: Share, rowElement: React.ReactNode) => ( {rowElement} ), [t] ); const columns = useMemo[]>( () => compact>([ { type: "data", id: "title", header: t("Title"), accessor: (share) => share.sourceTitle || t("Untitled"), sortable: false, component: (share) => ( <> {share.sourceTitle || t("Untitled")}{" "} {share.collectionId ? {t("Collection")} : null} ), width: "4fr", }, { type: "data", id: "createdBy", header: t("Shared by"), accessor: (share) => share.createdBy, sortable: false, component: (share) => ( {share.createdBy && ( <> {share.createdBy.name} )} ), width: "2fr", }, { type: "data", id: "createdAt", header: t("Date shared"), accessor: (share) => share.createdAt, component: (share) => share.createdAt ? (