"use client"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { RiExpandDiagonalLine } from "@remixicon/react"; import { useCallback, useEffect, useRef, useState } from "react"; import { Button } from "./ui/button"; import { title_font } from "@/public/fonts/font_index"; const OVERFLOW_THRESHOLD_PX = 16; const OVERFLOW_CHECK_DEBOUNCE_MS = 100; type WidgetProps = { title: string; subtitle: string; children: React.ReactNode; icon: React.ReactElement; action?: React.ReactNode; }; export default function WidgetCard({ title, subtitle, icon, children, action, }: WidgetProps) { const contentRef = useRef(null); const [hasOverflow, setHasOverflow] = useState(false); const [isOpen, setIsOpen] = useState(false); const debounceTimerRef = useRef(null); const checkOverflow = useCallback(() => { const el = contentRef.current; if (!el) return; if (debounceTimerRef.current) { clearTimeout(debounceTimerRef.current); } debounceTimerRef.current = setTimeout(() => { const hasOverflowNow = el.scrollHeight - el.clientHeight > OVERFLOW_THRESHOLD_PX; setHasOverflow(hasOverflowNow); }, OVERFLOW_CHECK_DEBOUNCE_MS); }, []); useEffect(() => { const el = contentRef.current; if (!el) return; // Checagem inicial checkOverflow(); // Observa apenas resize do container (suficiente para detectar overflow) const ro = new ResizeObserver(checkOverflow); ro.observe(el); return () => { ro.disconnect(); if (debounceTimerRef.current) { clearTimeout(debounceTimerRef.current); } }; }, [checkOverflow]); return (
{icon} {title} {subtitle}
{action &&
{action}
}
{children} {hasOverflow && (
)} {icon} {title} {subtitle ? (

{subtitle}

) : null}
{children}
); }