import { memo } from "react"; import type { AbLoop } from "../types.ts"; interface ProgressBarProps { progress: number; onSeek: (ratio: number) => void; abLoop?: AbLoop; duration?: number; } export const ProgressBar = memo(function ProgressBar({ progress, onSeek, abLoop, duration = 0, }: ProgressBarProps) { const seekFromClientX = (clientX: number, element: HTMLElement): void => { const rect = element.getBoundingClientRect(); if (rect.width <= 0) return; onSeek((clientX - rect.left) / rect.width); }; const hasAbLoop = Boolean( abLoop && (abLoop.a !== null || abLoop.b !== null) && duration > 0, ); const startRatio = hasAbLoop && abLoop ? Math.max(0, Math.min(1, (abLoop.a ?? 0) / duration)) : 0; const endRatio = hasAbLoop && abLoop ? Math.max(startRatio, Math.min(1, (abLoop.b ?? duration) / duration)) : 1; return (