"use client" import { Card, CardContent } from "@repo/ui/components/card" import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@repo/ui/components/alert-dialog" import { ExternalLink, Trash2 } from "lucide-react" import { useState } from "react" import { cn } from "@lib/utils" import { getPastelBackgroundColor } from "../memories-utils" import { colors } from "@repo/ui/memory-graph/constants" interface WebsiteCardProps { title: string url: string image?: string description?: string className?: string onClick?: () => void onOpenDetails?: () => void onDelete?: () => void showExternalLink?: boolean } export const WebsiteCard = ({ title, url, image, description, className, onClick, onOpenDetails, onDelete, showExternalLink = true, }: WebsiteCardProps) => { const [imageError, setImageError] = useState(false) const [isDialogOpen, setIsDialogOpen] = useState(false) const handleCardClick = () => { if (!isDialogOpen) { if (onClick) { onClick() } else if (onOpenDetails) { onOpenDetails() } else { window.open(url, "_blank", "noopener,noreferrer") } } } const handleExternalLinkClick = (e: React.MouseEvent) => { e.stopPropagation() window.open(url, "_blank", "noopener,noreferrer") } const hostname = (() => { try { return new URL(url).hostname } catch { return url } })() return ( {onDelete && ( e.stopPropagation()}> Delete Document Are you sure you want to delete this document and all its related memories? This action cannot be undone. { e.stopPropagation() }} > Cancel { e.stopPropagation() onDelete() }} > Delete )} {image && !imageError && (
{title setImageError(true)} loading="lazy" />
)}
{title}
{showExternalLink && ( )}
{description && (

{description}

)}

{hostname}

) } WebsiteCard.displayName = "WebsiteCard"