import { FieldError, StoredSubmission, FormDef } from '@platform-modules/forms';
export { FieldError, StoredSubmission } from '@platform-modules/forms';
import * as react from 'react';

type SubmitResult = {
    ok: true;
    id: string;
} | {
    ok: false;
    errors: FieldError[];
};
/** PUBLIC submit — the host's intake route. The SERVER runs validate + anti-spam; the browser only POSTs. */
type SubmitFn = (formId: string, data: Record<string, unknown>, renderToken?: string) => Promise<SubmitResult>;
/** ADMIN inbox — admin-authorized, formId-scoped routes. NO cross-form global read (IDOR floor). */
interface SubmissionClient {
    list(formId: string, opts?: {
        limit?: number;
        cursor?: string;
        includeSpam?: boolean;
    }): Promise<{
        items: StoredSubmission[];
        nextCursor?: string;
    }>;
    get(formId: string, id: string): Promise<StoredSubmission | null>;
    delete(formId: string, id: string): Promise<void>;
}

declare class FormsClientError extends Error {
    readonly code: string;
    constructor(message: string, code?: string);
}
declare function isFormsClientError(e: unknown): e is FormsClientError;

declare function useFormSubmit(submit: SubmitFn): {
    submit: (formId: string, data: Record<string, unknown>, renderToken?: string) => Promise<SubmitResult>;
    pending: boolean;
    fieldErrors: FieldError[];
};

interface FormRendererProps {
    form: FormDef;
    submit: SubmitFn;
    renderToken?: string;
    onSuccess?: (id: string) => void;
}
declare function FormRenderer({ form, submit, renderToken, onSuccess }: FormRendererProps): react.JSX.Element;

interface UseSubmissionsOpts {
    limit?: number;
    cursor?: string;
    includeSpam?: boolean;
}
declare function useSubmissions(client: SubmissionClient, formId: string, opts?: UseSubmissionsOpts): {
    items: StoredSubmission[];
    loading: boolean;
    error: FormsClientError | null;
    hasMore: boolean;
    loadMore: () => Promise<void>;
    remove: (id: string) => Promise<void>;
    reload: () => void;
};

interface SubmissionsTableProps {
    client: SubmissionClient;
    formId: string;
    /**
     * Render a stored `createdAt` ISO string for display. The host owns date
     * presentation (locale, ordering) — a CMS bound to a day-month-year
     * convention passes its own `Intl.DateTimeFormat` here. Defaults to the
     * runtime locale via `toLocaleString` (never a raw ISO string).
     */
    formatDate?: (iso: string) => string;
}
declare function SubmissionsTable({ client, formId, formatDate }: SubmissionsTableProps): react.JSX.Element;

export { FormRenderer, FormsClientError, type SubmissionClient, SubmissionsTable, type SubmitFn, type SubmitResult, isFormsClientError, useFormSubmit, useSubmissions };
