'use client'; import { ProviderControl } from '@/types/providers'; interface DynamicControlProps { control: ProviderControl; value: any; onChange: (name: string, value: any) => void; allValues: Record; } export default function DynamicControl({ control, value, onChange, allValues }: DynamicControlProps) { // Check if control should be visible based on dependencies const isVisible = () => { if (!control.dependsOn) return true; const dependencyValue = allValues[control.dependsOn.control]; return dependencyValue === control.dependsOn.value; }; if (!isVisible()) return null; const handleChange = (newValue: any) => { onChange(control.name, newValue); }; // Get current value or default const currentValue = value !== undefined && value !== null ? value : control.default; switch (control.type) { case 'select': return (
{control.description && (

{control.description}

)}
); case 'number': return (
{control.description && (

{control.description}

)} handleChange(parseFloat(e.target.value))} min={control.min} max={control.max} step={control.step} className="w-full bg-forge-dark border border-gray-700 rounded-lg px-4 py-2 text-white focus:outline-none focus:ring-2 focus:ring-forge-yellow" />
); case 'slider': return (
{currentValue}
{control.description && (

{control.description}

)} handleChange(parseFloat(e.target.value))} min={control.min} max={control.max} step={control.step ?? 1} className="w-full h-2 bg-gray-700 rounded-lg appearance-none cursor-pointer accent-forge-yellow" />
{control.min} {control.max}
); case 'checkbox': return (
handleChange(e.target.checked)} className="mt-1 rounded border-gray-700 bg-forge-dark text-forge-yellow focus:ring-forge-yellow focus:ring-2" />
{control.description && (

{control.description}

)}
); case 'text': return (
{control.description && (

{control.description}

)} handleChange(e.target.value)} className="w-full bg-forge-dark border border-gray-700 rounded-lg px-4 py-2 text-white focus:outline-none focus:ring-2 focus:ring-forge-yellow" />
); case 'textarea': return (
{control.description && (

{control.description}

)}