import * as React from "react"; import * as Styles from "~/common/styles"; import * as Constants from "~/common/constants"; import * as SVG from "~/common/svg"; import * as Validations from "~/common/validations"; import * as Utilities from "~/common/utilities"; import { css } from "@emotion/react"; import { FollowButton, ShareButton } from "~/components/core/CollectionPreviewBlock/components"; import { useFollowHandler } from "~/components/core/CollectionPreviewBlock/hooks"; import { Link } from "~/components/core/Link"; import { motion, useAnimation } from "framer-motion"; import { Preview } from "~/components/core/CollectionPreviewBlock/components"; import { AspectRatio } from "~/components/system"; import { P3, H5, P2 } from "~/components/system/components/Typography"; import { useMediaQuery, useMounted } from "~/common/hooks"; import ProfilePhoto from "~/components/core/ProfilePhoto"; const STYLES_CONTAINER = (theme) => css` position: relative; display: flex; flex-direction: column; background-color: ${theme.semantic.bgLight}; box-shadow: 0 0 0 1px ${theme.system.grayLight4}, ${theme.shadow.lightSmall}; border-radius: 16px; width: 100%; overflow: hidden; `; const STYLES_DESCRIPTION = (theme) => css` position: relative; border-radius: 0px 0px 16px 16px; box-sizing: border-box; width: 100%; background-color: ${theme.semantic.bgLight}; z-index: 1; `; const STYLES_INNER_DESCRIPTION = (theme) => css` position: absolute; top: 0; left: 0; width: 100%; background-color: ${theme.semantic.bgLight}; padding: 9px 16px 0px; border-top: 1px solid ${theme.system.grayLight4}; `; const STYLES_SPACE_BETWEEN = css` justify-content: space-between; `; const STYLES_PROFILE_IMAGE = (theme) => css` display: block; background-color: ${theme.semantic.bgLight}; height: 16px; width: 16px; border-radius: 4px; object-fit: cover; `; const STYLES_METRICS = css` position: relative; z-index: 1; margin-top: auto; padding: 4px 16px 8px; ${Styles.CONTAINER_CENTERED}; ${STYLES_SPACE_BETWEEN} `; const STYLES_CONTROLS = css` position: absolute; z-index: 1; right: 16px; top: 16px; ${Styles.VERTICAL_CONTAINER}; align-items: flex-end; & > * + * { margin-top: 8px !important; } `; const STYLES_TEXT_GRAY = (theme) => css` color: ${theme.semantic.textGray}; `; const STYLES_SECURITY_LOCK_WRAPPER = (theme) => css` background-color: ${theme.semantic.bgDark}; border-radius: 4px; padding: 4px; color: ${theme.semantic.textGrayLight}; `; export default function CollectionPreview({ collection, viewer, owner, onAction }) { const [areControlsVisible, setShowControls] = React.useState(false); const showControls = () => setShowControls(true); const hideControls = () => setShowControls(false); const description = collection?.body; const media = useMediaQuery(); const { isDescriptionVisible, showDescription, hideDescription } = useShowDescription({ disabled: !description || media.mobile, }); const extendedDescriptionRef = React.useRef(); const descriptionRef = React.useRef(); const animationController = useAnimateDescription({ extendedDescriptionRef: extendedDescriptionRef, descriptionRef: descriptionRef, isDescriptionVisible, }); const { follow, followCount, isFollowed } = useFollowHandler({ collection, viewer }); const { fileCount, isPublic } = collection; const title = collection.name || collection.slatename; const isOwner = viewer?.id === collection.ownerId; const preview = React.useMemo(() => getObjectToPreview(collection.coverImage), [ collection.coverImage, ]); return (