"use client" import type { KeyboardEvent, ReactNode } from "react" import Link from "next/link" import { Frame, FrameDescription, FrameHeader, FramePanel, FrameTitle, } from "@/components/reui/frame" import { Badge } from "@/components/reui/badge" import { IconTile } from "@/components/reui/icon-tile" import { cn } from "@/lib/utils" import { kpiCols } from "./kpi-cols" type QuickActionBase = { id: string title: string description: string icon?: ReactNode iconClassName?: string badge?: string disabled?: boolean } export type QuickActionItem = QuickActionBase & ( | { href: string; onClick?: never } | { onClick: () => void; href?: never } ) interface QuickActionGridProps { actions: QuickActionItem[] title?: string description?: string className?: string } const DEFAULT_ICON_CLASS = "text-muted-foreground [&_svg]:text-current" function resolveBadge(action: QuickActionItem): string { if (action.badge) return action.badge return action.onClick ? "Выполнить" : "Перейти" } function handleActionKeyDown(onActivate: () => void, event: KeyboardEvent) { if (event.key === "Enter" || event.key === " ") { event.preventDefault() onActivate() } } function QuickActionBody({ action }: { action: QuickActionItem }) { return (
{action.icon ? ( ) : null}
{action.title} {resolveBadge(action)}

{action.description}

) } function panelClassName(disabled?: boolean) { return cn( "relative isolate flex h-full flex-col transition-colors", disabled ? "cursor-not-allowed opacity-60" : "hover:bg-muted/40 focus-within:ring-ring cursor-pointer focus-within:ring-2", ) } /** * KPI-like quick actions strip (horizontal Frame tiles). * Preview: https://reui.io/preview/base/stats-12 · https://reui.io/preview/base/card-12 * Docs: https://reui.io/docs/components/base/frame · https://reui.io/docs/components/base/icon-tile */ export function QuickActionGrid({ actions, title = "Быстрые действия", description, className, }: QuickActionGridProps) { if (actions.length === 0) return null return ( {(title || description) && ( {title ? {title} : null} {description ? {description} : null} )}
{actions.map((action) => { const label = `${action.title}: ${action.description}` if ("href" in action && action.href) { return ( {action.disabled ? (
) : ( <> )}
) } const onClick = action.onClick const onActivate = () => { if (action.disabled || !onClick) return onClick() } return ( handleActionKeyDown(onActivate, e)} > ) })}
) }