import React from "react";

type ManagedFormElement<T = string> = {
  onChange: (v: T) => void;
  value: T;
}
type UnmanagedFormElement = {
  onChange?: never;
  value?: never;
}

type ValidatedFormElement<T = string> = {
  validation: ((value: T) => boolean | string) | RegExp;
  validationMessage: string;
}
type NonValidatedFormElement = {
  validation?: never;
  validationMessage?: never;
}

type BaseFormElement = {
  className?: string;
  disabled?: boolean;
  label?: React.ReactNode;
  nullable?: boolean;
  placeholder?: string;
}

export type FormElement<T = string> =
  & BaseFormElement
  & (ManagedFormElement<T> | UnmanagedFormElement)
  & (ValidatedFormElement<T> | NonValidatedFormElement)
