import type { UseFormReturn } from 'react-hook-form';
import type { z } from 'zod';
import type { loginEmailFormSchema, loginPhoneFormSchema } from '../../validations';
/** Login mode: phone number or email */
export type LoginEntryMode = 'phone' | 'email';
/** Form values for phone-based login, inferred from the Zod schema. */
export type PhoneFormValues = z.infer<typeof loginPhoneFormSchema>;
/** Form values for email-based login, inferred from the Zod schema. */
export type EmailFormValues = z.infer<typeof loginEmailFormSchema>;
/** Discriminated union of phone or email login form values. */
export type LoginEntryFormValues = PhoneFormValues | EmailFormValues;
/** Payload when login entry form is valid (phone or email). */
export type LoginEntrySubmitData = {
    phone?: string;
    email?: string;
    countryCode?: string;
};
/**
 * Params passed to onSuccess after submitApi resolves.
 * Lets the consumer redirect to OTP with mode and recipient (for recipientDisplay) without storing them in refs.
 */
export interface LoginEntrySuccessParams {
    /** Current login entry mode (phone or email). */
    mode: LoginEntryMode;
    /** Submitted phone or email string; use for OTP page recipientDisplay or verify API. */
    recipient: string;
}
export interface UseLoginEntryFormOptions {
    mode: LoginEntryMode;
    /**
     * Sync callback with valid form data. Used when parent owns API (e.g. AuthFlow passes actions.submitIdentifier).
     * Ignored when submitApi is provided.
     */
    onSubmit?: ((data: LoginEntrySubmitData) => void) | undefined;
    /**
     * When provided, hook runs business logic: validate → call submitApi(data) → onSuccess(params).
     * Use from consumer (e.g. Next.js): submitApi = sendOtp, onSuccess = (params) => router.push(`/otp?mode=${params.mode}&recipient=${encodeURIComponent(params.recipient)}`).
     */
    submitApi?: ((data: LoginEntrySubmitData) => Promise<void>) | undefined;
    /** Called after submitApi resolves successfully; receives mode and recipient for OTP redirect/display. */
    onSuccess?: ((params: LoginEntrySuccessParams) => void) | undefined;
    /** Called when submitApi rejects or throws. */
    onError?: ((error: unknown) => void) | undefined;
}
/** Return value of the `useLoginEntryForm` hook, providing form state and mode info. */
export interface UseLoginEntryFormReturn {
    /** react-hook-form methods bound to the current login mode's schema. */
    methods: UseFormReturn<LoginEntryFormValues>;
    /** Submit handler to pass to the form's `onSubmit`. Validates and dispatches the login data. */
    handleSubmit: (data: LoginEntryFormValues) => void;
    /** True when the current mode is `'phone'`; use for conditional field rendering. */
    isPhone: boolean;
    /** True when current form values pass validation (for disabling Continue until valid – edge cases 3, 4). */
    isFormValid: (data: LoginEntryFormValues) => boolean;
    /** True while submitApi is in flight. Use to disable Continue button and show loading. */
    isSubmitting: boolean;
}
