/**
 * NumberInput widget component with Nordic styling.
 *
 * ⚠️ AUTO-GENERATED BY PRISM - DO NOT EDIT
 */

import type { WidgetBaseProps } from '../types';
import type { JSX } from 'react';

interface NumberInputProps extends WidgetBaseProps<number | null> {
  min?: number;
  max?: number;
  step?: number;
}

export function NumberInput({
  name,
  value,
  onChange,
  label,
  description,
  placeholder,
  required,
  disabled,
  error,
  className,
  min,
  max,
  step,
}: NumberInputProps): JSX.Element {
  return (
    <div className={className}>
      {label && (
        <label htmlFor={name} className="label">
          {label}
          {required && <span className="text-red-500 ml-1">*</span>}
        </label>
      )}
      <input
        id={name}
        type="number"
        name={name}
        value={value ?? ''}
        onChange={(e) => {
          const val = e.target.value;
          onChange(val === '' ? null : Number(val));
        }}
        placeholder={placeholder}
        disabled={disabled}
        required={required}
        min={min}
        max={max}
        step={step}
        className={error ? 'input-error' : 'input'}
        aria-invalid={!!error}
        aria-describedby={description ? `${name}-desc` : error ? `${name}-error` : undefined}
      />
      {description && !error && (
        <p id={`${name}-desc`} className="mt-1.5 text-sm text-nordic-500">{description}</p>
      )}
      {error && (
        <p id={`${name}-error`} className="mt-1.5 text-sm text-red-600">
          {error}
        </p>
      )}
    </div>
  );
}
