"use client";
import { useTranslation } from "@turbostarter/i18n";
import { cn } from "@turbostarter/ui";
import { Button } from "@turbostarter/ui-web/button";
import { Icons } from "@turbostarter/ui-web/icons";
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@turbostarter/ui-web/tooltip";
import type { VoiceButtonProps } from "../types";
const formatDuration = (seconds: number): string => {
const mins = Math.floor(seconds / 60);
const secs = seconds % 60;
return `${mins}:${secs.toString().padStart(2, "0")}`;
};
const VoiceLevelBars = ({ level }: { level: number }) => {
// Create 3 bars with different thresholds
const bars = [
{ threshold: 10, delay: "0ms" },
{ threshold: 30, delay: "100ms" },
{ threshold: 50, delay: "200ms" },
];
return (
{bars.map((bar, i) => (
bar.threshold ? "opacity-100" : "opacity-30"
)}
style={{
height: level > bar.threshold ? `${Math.min(12, 4 + (level / 100) * 8)}px` : "4px",
animationDelay: bar.delay,
}}
/>
))}
);
};
export const VoiceButton = ({
state,
duration,
audioLevel,
disabled = false,
onToggle,
onCancel: _onCancel,
}: VoiceButtonProps) => {
const { t } = useTranslation("common");
const isRecording = state === "recording";
const isProcessing = state === "processing";
const getTooltipContent = () => {
if (isRecording) {
return t("pressEscapeToCancel");
}
if (isProcessing) {
return t("transcribing");
}
return t("record");
};
return (
{/* Recording state indicator - shows duration and level */}
{isRecording && (
{formatDuration(duration)}
)}
{getTooltipContent()}
);
};
export default VoiceButton;