import { FieldRendererRegistry } from "@/features/predictions/components/fields/field-renderer-registry";
import { PredictionTileBase } from "@/features/predictions/components/tiles/prediction-tile-base";
import { getCardIcon } from "@/features/predictions/domain/card-icons";
import type { PredictionTileController } from "@/features/predictions/hooks/use-prediction-tile-controller";
import type { PredictionCard } from "@/types/predictions";

type CustomPredictionTileProps = {
  card: PredictionCard;
  controller: PredictionTileController;
  disabled?: boolean;
  showSubmitButton?: boolean;
};

export function CustomPredictionTile({
  card,
  controller,
  disabled,
  showSubmitButton,
}: CustomPredictionTileProps) {
  return (
    <PredictionTileBase
      title={card.title}
      description={card.description}
      dirty={controller.dirty}
      saving={controller.saving}
      disabled={disabled}
      showSubmitButton={showSubmitButton}
      successMessage={controller.successMessage}
      errorMessage={controller.errorMessage}
      basePoints={card.basePoints}
      iconSrc={getCardIcon(card.code)}
      onSubmit={() => {
        void controller.submit();
      }}
    >
      <FieldRendererRegistry
        card={card}
        draftValues={controller.draftValues}
        disabled={disabled}
        setText={controller.setText}
        setNumber={controller.setNumber}
        setDate={controller.setDate}
      />
    </PredictionTileBase>
  );
}
