import { ReactNode } from "react";
import { SelectItem } from "../../Select/Select";
import { UploadTask } from "firebase/storage";
import { FromOnePercentUtility, UnresolvableOr } from "../../../type-utils";
export type GenericFormFieldProps<T extends FormField["type"]> = {
    value: AnswerByField<{
        type: T;
    }> | undefined;
    onAnswer: (FormFieldProps<{
        type: T;
    }> & {
        mode: FormMode.WRITE;
    })["onAnswer"];
    question: FormFieldView & {
        type: T;
    };
    error?: string;
    disabled?: boolean;
} & FromOnePercentUtility<`UIElements.FormExtension.fields`> & {
    type: T;
};
export type FormFieldProps<Q extends Pick<FormFieldView, "type">> = {
    config: Q;
    value: AnswerByField<Q>;
    "data-testid"?: string;
    disabled?: boolean;
} & ({
    mode: FormMode.READ_ONLY;
} | {
    mode?: FormMode.WRITE;
    onAnswer: <T extends Q["type"]>(questionType: T, questionId: string, answer: AnswerAction<{
        type: T;
    }> | undefined) => void;
    error?: string | string[];
});
export declare enum FormMode {
    READ_ONLY = 0,
    WRITE = 1
}
export type FormFieldView = FormField & {
    title: string;
};
export type AnswerAction<F extends Pick<FormField, "type">> = F["type"] extends "file" ? File : AnswerByField<F>;
export type BasicFormFields = {
    type: "select";
    filter?: (item: SelectItem, term: string) => boolean;
    options: SelectItem[];
} | {
    type: "text";
    multiline?: number;
} | {
    type: "number";
};
type DistributeValidatorOverUnion<FormFieldTypes extends {
    type: any;
}> = FormFieldTypes extends any ? keyof FormFieldTypes extends "validator" ? FormFieldTypes : FormFieldTypes & {
    validator?: (val: AnswerAction<FormFieldTypes> | undefined) => boolean | string;
} : never;
export type FormField = {
    optional?: boolean;
    id: string;
    readOnly?: boolean;
} & DistributeValidatorOverUnion<BasicFormFields | {
    type: "radio";
    options: SelectItem[];
} | ({
    type: "check" | "rawcheck";
    options: SelectItem[];
} & ({
    validator: (val: AnswerAction<{
        type: "check";
    }> | undefined) => boolean | string;
    optional: false;
} | {
    optional?: true;
})) | {
    type: "file";
    fileUsageDescription: string;
    extensions: string[];
    footer: string;
    openFile?: {
        action: () => void;
        label: string | ReactNode;
    };
} | {
    type: "accept";
    link: {
        type: "file" | "route";
        to: string;
    };
    contract: {
        action: () => void;
        label: string | ReactNode;
    };
    accept: {
        label: string;
        optional?: true;
    }[];
} | UnresolvableOr<FromOnePercentUtility<"UIElements.FormExtension">["fields"], BasicFormFields>>;
export type FormFieldTypes = FormField["type"] | "accept";
type ExternalQuestionFields = UnresolvableOr<FromOnePercentUtility<"UIElements.FormExtension">["fieldAnswer"], {}>;
export type AnswerByField<F extends Pick<FormField, "type">> = F["type"] extends "file" ? UploadTask | true : F["type"] extends "accept" | "check" | "rawcheck" ? boolean[] : F["type"] extends "radio" | "text" | "select" | "number" ? string : F["type"] extends keyof ExternalQuestionFields ? FromOnePercentUtility<"UIElements.FormExtension">["fieldAnswer"][F["type"]] : unknown;
export {};
