import { Nullable } from '../../types/general';

/**
 * Options for form validation behavior.
 */
export type FormControlOption = {
	/**
	 * Whether disabled fields should be skipped.
	 */
	skipDisabled?: boolean;
	/**
	 * Whether invisible fields should be skipped.
	 */
	skipInvisible?: boolean;
};

/**
 * Result returned from form validation.
 */
export type FormValidateResult = {
	/**
	 * Whether the form is valid.
	 */
	isValid: boolean;
	/**
	 * List of invalid field names.
	 */
	invalidFields: string[];
	/**
	 * Optional map of field error messages.
	 */
	invalidFieldsErrorMessages?: Record<string, string>;
};

/**
 * Validation state for a single form field.
 */
export type VegaFormFieldValidationState = {
	/**
	 * The field name specified in the form field's `data-vega-form` attribute.
	 * Supports nested form fields using dot notation (e.g., "nestedForm.field").
	 */
	fieldName: string;
	/**
	 * Whether the field is valid or not.
	 */
	isValid: boolean;
	/**
	 * The error message to display when the field is invalid.
	 */
	errorMessage?: Nullable<string>;
};

/**
 * Event payload with a form host reference.
 */
export type FormEventsPayload = {
	/**
	 * Host element reference.
	 */
	host: HTMLElement;
};

/**
 * Event payload for pending validation updates.
 */
export type PendingValidPayload = {
	/**
	 * Host element reference.
	 */
	host: HTMLElement;
	/**
	 * Validation detail value.
	 */
	detail: boolean | null;
};

/**
 * Payload emitted when a form element is disconnected.
 */
export type DisconnectedElementOperationPayload = {
	/**
	 * Host element reference.
	 */
	host: HTMLElement;
};
