import styles from "@/features/predictions/styles/predictions.module.css";
import type { FieldRendererProps } from "./types";

export function DateFieldRenderer({ card, draftValues, disabled, setDate }: FieldRendererProps) {
  return (
    <div className={styles.fieldGrid}>
      {card.fields.map((field) => {
        const draft = draftValues.find((value) => value.fieldId === field.id);

        return (
          <div key={field.id} className="field">
            <label htmlFor={`field-${field.id}`}>
              {field.label}
              {field.points > 0 ? ` (${field.points} pts)` : ""}
            </label>
            <input
              id={`field-${field.id}`}
              type="date"
              value={draft?.valueDate ?? ""}
              disabled={disabled}
              onChange={(event) => setDate(field.id, event.target.value)}
            />
          </div>
        );
      })}
    </div>
  );
}
