import { jsx as _jsx } from "react/jsx-runtime";
import React from "react";
export function WaveformFeedback({ levels, tokens, compact = false, }) {
    const normalizedLevels = normalizeLevels(levels, compact ? 13 : 17);
    return (_jsx("div", { style: {
            display: "flex",
            alignItems: "flex-end",
            justifyContent: "center",
            gap: compact ? 2 : 3,
            minHeight: compact ? 24 : 30,
            filter: compact ? "blur(0.15px)" : "blur(0.1px)",
        }, children: normalizedLevels.map((level, index) => {
            const distanceFromCenter = Math.abs(index - (normalizedLevels.length - 1) / 2);
            const centerWeight = 1 - distanceFromCenter / ((normalizedLevels.length + 1) / 2);
            const shapedLevel = Math.max(compact ? 0.18 : 0.1, level * (compact ? 0.82 + centerWeight * 0.9 : 0.58 + centerWeight * 0.82));
            const baseHeight = compact ? 6 : 6;
            const dynamicHeight = compact ? 12 : 14;
            const opacity = compact ? 0.5 + centerWeight * 0.4 : 0.36 + centerWeight * 0.52;
            return (_jsx("span", { style: {
                    width: compact ? 3 : 4,
                    height: `${baseHeight + Math.round(shapedLevel * dynamicHeight)}px`,
                    borderRadius: tokens.radius.waveformBar,
                    background: tokens.color.voiceWaveformActive,
                    opacity,
                    boxShadow: `0 0 ${compact ? 7 : 8}px rgba(124, 92, 255, ${compact ? 0.12 + centerWeight * 0.16 : 0.08 + centerWeight * 0.14})`,
                    transition: `height ${tokens.motion.waveformPulse}, opacity ${tokens.motion.pressFeedback}`,
                } }, index));
        }) }));
}
function normalizeLevels(levels, targetBars) {
    if (levels.length === targetBars) {
        return levels;
    }
    if (levels.length === 0) {
        return Array.from({ length: targetBars }, () => 0.18);
    }
    return Array.from({ length: targetBars }, (_, index) => {
        const mappedIndex = (index / Math.max(1, targetBars - 1)) * Math.max(0, levels.length - 1);
        const left = Math.floor(mappedIndex);
        const right = Math.min(levels.length - 1, Math.ceil(mappedIndex));
        const mix = mappedIndex - left;
        return levels[left] * (1 - mix) + levels[right] * mix;
    });
}
