import { FormControlLabel, TextField } from '@material-ui/core';
import React, { useCallback } from 'react';
import { DateTimeField } from '../UI/inputs/datetimes/DateTimeField';
import { Field } from '../utilities/form';
import { findTermByType } from '../utilities/maintenanceEngine/CrudBrowserUtilities';
import { FluentToggle } from '../UI/inputs/toggle/FluentToggle';
import { PropertyTypeEnum } from '../enums/propertyTypeEnums';
import { toLowerFirstChar } from '../utilities/input/StringUtilities';
import { toTitleCase } from '../utilities/input/StringUtilities';
export function useVirtualActions() {
    const renderInputByFieldType = useCallback((formField, index, virtualTableFormData, classes) => {
        var _a;
        const NUMBER_TYPE = [
            PropertyTypeEnum.Int,
            PropertyTypeEnum.Long,
            PropertyTypeEnum.Double
        ];
        if (formField.type === 'boolean' &&
            virtualTableFormData[toLowerFirstChar(formField.name)] === '') {
            virtualTableFormData[toLowerFirstChar(formField.name)] = false;
        }
        const fieldType = (_a = formField.type) === null || _a === void 0 ? void 0 : _a.toLowerCase();
        let fieldIsNumberType = NUMBER_TYPE.includes(fieldType);
        const DefaultTextField = (React.createElement(Field, { component: TextField, id: `${formField.name}${index}`, name: toLowerFirstChar(formField.name), label: toTitleCase(formField.name), initialValue: virtualTableFormData[toLowerFirstChar(formField.name)] || '', type: fieldIsNumberType && 'number', fullWidth: true, variant: "outlined", size: "small", required: !(formField === null || formField === void 0 ? void 0 : formField.nullable), margin: "dense", InputProps: {
                classes: {
                    root: classes === null || classes === void 0 ? void 0 : classes.input,
                    input: classes === null || classes === void 0 ? void 0 : classes.formTextInput
                }
            }, InputLabelProps: {
                classes: {
                    root: classes === null || classes === void 0 ? void 0 : classes.labelRoot
                }
            }, disabled: formField === null || formField === void 0 ? void 0 : formField.disabled }));
        const DefaultFluentToggle = (React.createElement(FormControlLabel, { control: React.createElement(Field, { component: FluentToggle, type: "checkbox", id: `${formField.name}${index}`, name: toLowerFirstChar(formField.name), label: toTitleCase(formField.name), initialValue: typeof virtualTableFormData[toLowerFirstChar(formField.name)] === 'boolean'
                    ? virtualTableFormData[toLowerFirstChar(formField.name)]
                    : virtualTableFormData[toLowerFirstChar(formField.name)] ===
                        'true'
                        ? true
                        : false, disabled: formField === null || formField === void 0 ? void 0 : formField.disabled, classes: { root: classes === null || classes === void 0 ? void 0 : classes.switchRoot }, color: "secondary", inputProps: { 'aria-label': 'Active condition' } }), label: toTitleCase(formField.name), labelPlacement: "start", style: { marginLeft: 4 } }));
        switch (fieldType.toLowerCase()) {
            case findTermByType(fieldType, 'int'):
            case findTermByType(fieldType, 'long'):
            case findTermByType(fieldType, 'double'):
            case findTermByType(fieldType, 'string'):
            case findTermByType(fieldType, 'string uuid'):
                return DefaultTextField;
            case findTermByType(fieldType, 'boolean'):
                return DefaultFluentToggle;
            case findTermByType(fieldType, 'datetime'):
                return (React.createElement(Field, { disabled: formField === null || formField === void 0 ? void 0 : formField.disabled, component: DateTimeField, id: `${formField.name}${index}`, name: toLowerFirstChar(formField.name), label: toTitleCase(formField.name), initialValue: virtualTableFormData[toLowerFirstChar(formField.name)]
                        ? new Date(virtualTableFormData[toLowerFirstChar(formField.name)])
                        : '', fullWidth: true, variant: "outlined", size: "small", required: !(formField === null || formField === void 0 ? void 0 : formField.nullable), style: { marginTop: 8 } }));
            default:
                return null;
        }
    }, []);
    return {
        renderInputByFieldType
    };
}
//# sourceMappingURL=virtualActions.js.map