import React from 'react'; import { useUserStore } from '@/store/userStore'; import { Lock, Pin, Info } from 'lucide-react'; interface VariableControlProps { name: string; displayName: string; controlType: string; value: any; onChange: (value: any) => void; minValue?: number; maxValue?: number; step?: number; unit?: string; options?: string[]; locked?: boolean; pinned?: boolean; description?: string; onLock?: () => void; onPin?: () => void; } const VariableControl: React.FC = ({ name, displayName, controlType, value, onChange, minValue = 0, maxValue = 100, step = 1, unit = '', options = [], locked = false, pinned = false, description, onLock, onPin, }) => { const { isDark } = useUserStore(); const formatValue = (v: any) => { if (typeof v !== 'number') return String(v); if (unit === '₹') { if (v >= 10000000) return `₹${(v / 10000000).toFixed(2)} Cr`; if (v >= 100000) return `₹${(v / 100000).toFixed(1)} L`; return `₹${v.toLocaleString()}`; } if (unit === '%') return `${v.toLocaleString()}%`; return v.toLocaleString(); }; // Calculate slider fill percentage const fillPct = controlType === 'slider' && typeof value === 'number' ? ((value - (minValue || 0)) / ((maxValue || 100) - (minValue || 0))) * 100 : 0; return (
{/* Label row */}
{description && (
{description}
)}
{onPin && ( )} {onLock && ( )} {formatValue(value)}
{/* Control */} {controlType === 'slider' && (
onChange(parseFloat(e.target.value))} className="absolute inset-0 w-full h-full opacity-0 cursor-pointer" style={{ margin: 0 }} />
{formatValue(minValue)} {formatValue(maxValue)}
)} {controlType === 'number' && ( onChange(parseFloat(e.target.value))} className="w-full px-3 py-2 rounded-xl text-sm border outline-none focus:ring-2 focus:ring-indigo-500/30 transition-all" style={{ background: isDark ? 'rgba(255,255,255,0.03)' : '#f8fafc', borderColor: isDark ? 'rgba(255,255,255,0.08)' : 'rgba(0,0,0,0.08)', color: isDark ? '#f8fafc' : '#0f172a', }} /> )} {controlType === 'dropdown' && ( )} {controlType === 'categorical' && (
{options.map((opt) => ( ))}
)} {controlType === 'boolean' && ( )}
); }; export default VariableControl;