'use client';
import React from 'react';
import styled from 'styled-components';
import { theme } from '@/styles/theme';
interface BarChartProps {
data: Array<{ label: string; value: number; color?: string }>;
maxValue?: number;
unit?: string;
title?: string;
}
const Wrapper = styled.div`
width: 100%;
`;
const Title = styled.div`
font-size: 12px;
font-weight: 600;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 0.08em;
margin-bottom: 16px;
`;
const ChartArea = styled.div`
display: flex;
align-items: flex-end;
gap: 10px;
height: 140px;
`;
const BarWrapper = styled.div`
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
gap: 6px;
height: 100%;
justify-content: flex-end;
`;
const Bar = styled.div<{ $height: number; $color: string }>`
width: 100%;
height: ${({ $height }) => $height}%;
min-height: 2px;
background: ${({ $color }) => $color};
border-radius: 4px 4px 0 0;
transition: height 0.4s ease;
position: relative;
&:hover::after {
content: attr(data-value);
position: absolute;
top: -24px;
left: 50%;
transform: translateX(-50%);
font-size: 11px;
color: var(--text-primary);
white-space: nowrap;
background: rgba(22,27,34,0.95);
padding: 2px 6px;
border-radius: 4px;
border: 1px solid var(--border-color);
}
`;
const Label = styled.div`
font-size: 10px;
color: var(--text-secondary);
text-align: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 60px;
`;
const Empty = styled.div`
padding: 32px;
text-align: center;
color: var(--text-secondary);
font-size: 13px;
`;
const COLORS = ['#58A6FF', '#00FF00', '#FF9800', '#E040FB', '#00BCD4'];
export default function BarChart({ data, maxValue, unit = '', title }: BarChartProps) {
if (!data.length) return 데이터 없음;
const max = maxValue ?? Math.max(...data.map((d) => d.value), 1);
return (
{title && {title}}
{data.map((item, i) => {
const height = Math.max((item.value / max) * 100, item.value > 0 ? 2 : 0);
const color = item.color ?? COLORS[i % COLORS.length];
const displayValue = unit === '$'
? `$${item.value.toFixed(4)}`
: `${item.value.toLocaleString()}${unit}`;
return (
);
})}
);
}