import FormField from "../components/UI/Forms/FormField/FormField";
import {CustomSelectOptions} from "./ReactComponents";


/***
 * API RELATED
 */

export interface getFormRes {
    form_data: Record<string, any>,
    form : DynamicFormInterface
}

/*** */

export interface DuaDocument {
    created_at:string
    form_view_name:string
    form_id:number
    form_name:string
    id:number
    dua_code:string
}

export interface DynamicFormInterface {
    id: number,
    name: string,
    form_json: JsonForm
    qr_path: string,
}

export interface JsonForm {
    form_sections: FormSection[],
    name?: string
}

export interface FormSection {

    form_fields: FormField[],
    name: string,
    is_iterable: boolean

}


/**
 *
 *JSON FORM EXCLUSIVES
 */


export type FormField = SelectField | TextField | DateField | TimeField | Checkbox | RadioField |TextArea | TextBox | FileUpload

/**
 * COMMON PROPERTIES THAT ALL FIELD TYPES SHARE
 */
interface GenericFieldType {
    name: string                             //systemic name the form will submit and the backend will expect
    label: string
    readonly?: boolean
    required?: boolean
    col?: 4 | 6                              //bootstrap cols the field occupies (default is 6)
    tooltip?: string                         //can include html tags
    helper?: FormHelper                       //predefined D.U.A.helpers
    depends_on?: {                           //if the field appearing depends on some other field of the form
        field: string,
        values: string[]
    }
}

interface SelectField extends GenericFieldType {
    type:'select'
    options?: {                               //info about the endpoint to fetch the options
        source: 'model' | 'custom'
        model?: string
        custom?: CustomSelectOptions
        endpoint: string
        param?: string                       //params when the options' dataset depend on some other form field else leave it null
    }
    searchable?: boolean
}

interface TextField extends GenericFieldType {
    type:'text',
    autosum: boolean
    rule?: {
        condition: string,
        message: string

    }             //predefined rules for the validation (a function rule and a message)
}

interface DateField extends GenericFieldType{
    type:'date',
    minDate?: string,
    maxDate?: string
}

interface TimeField extends GenericFieldType{
    type:'time',
    minTime?: string,
    maxTime?: string
}

interface Checkbox extends GenericFieldType{
    type:'checkbox',
}

interface RadioField extends GenericFieldType{
    type:'radio',
    options: CustomSelectOptions
}

interface TextArea extends GenericFieldType {
    placeholder?: string
    type: 'textarea',
    cols?: number,
    rows?: number,
    maxLength?: number,
    custom_text?: string
}

interface TextBox extends GenericFieldType  {
    type: 'textbox',
    custom_text?: string
    text_styles?: 'custom-text-label' | 'custom-text-bold' | string
}

interface FileUpload extends GenericFieldType {
    type: 'file',
}

export type FormFieldType =  'text' | 'date' | 'select' |'radio';
export type FormHelper = "unit" | "buildings"