'use client' import { MetricsBlock as MetricsBlockType, MetricItem } from '../types' import { Button } from '../../ui/button' import { Input } from '../../ui/input' import { Label } from '../../ui/label' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '../../ui/select' import { Plus, Trash2, TrendingUp, TrendingDown, Minus } from 'lucide-react' import { cn } from '../../../lib/utils' interface MetricsBlockProps { block: MetricsBlockType onChange: (block: MetricsBlockType) => void isEditing?: boolean } export function MetricsBlockEditor({ block, onChange, isEditing = true }: MetricsBlockProps) { const updateMetric = (metricId: string, updates: Partial) => { onChange({ ...block, metrics: block.metrics.map((m) => m.id === metricId ? { ...m, ...updates } : m ), }) } const addMetric = () => { const newMetric: MetricItem = { id: `metric-${Date.now()}`, label: 'New Metric', value: '0', change: '+0%', changeType: 'neutral', } onChange({ ...block, metrics: [...block.metrics, newMetric] }) } const removeMetric = (metricId: string) => { onChange({ ...block, metrics: block.metrics.filter((m) => m.id !== metricId) }) } const getChangeColor = (type?: 'positive' | 'negative' | 'neutral') => { switch (type) { case 'positive': return 'text-green-600' case 'negative': return 'text-red-600' default: return 'text-gray-500' } } const getChangeIcon = (type?: 'positive' | 'negative' | 'neutral') => { switch (type) { case 'positive': return case 'negative': return default: return } } if (!isEditing) { return (
{block.title && (

{block.title}

)}
{block.metrics.map((metric) => (
{metric.value}
{metric.label}
{metric.change && (
{getChangeIcon(metric.changeType)} {metric.change}
)}
))}
) } return (
onChange({ ...block, title: e.target.value })} placeholder="Key Metrics" />
{block.metrics.map((metric) => (
updateMetric(metric.id, { label: e.target.value })} placeholder="Label" className="text-xs" /> updateMetric(metric.id, { value: e.target.value })} placeholder="Value" className="text-xs" /> updateMetric(metric.id, { change: e.target.value })} placeholder="+15%" className="text-xs" />
))}
) }