import React, { forwardRef, useCallback, useImperativeHandle, useRef } from 'react';
import { FormControlLabel, Switch } from '@material-ui/core';
import { useTranslation } from 'react-i18next';
import { Field, Form } from '../../../../utilities/form';
import { AmbientAutoComplete, FluentTextField } from '../../../../UI/inputs/textField';
import { LayoutUnit } from '../../../../layout';
import { TRANSACTION_TYPE_STATUS_COLORS } from '../../../utilities/transactionConstants';
const UdpTransactionTypeStatusForm = (props, ref) => {
    const { onSubmit, initialData, } = props;
    const handleSubmitRef = useRef();
    const { t } = useTranslation();
    useImperativeHandle(ref, () => ({
        submit: () => {
            // eslint-disable-next-line no-unused-expressions
            handleSubmitRef === null || handleSubmitRef === void 0 ? void 0 : handleSubmitRef.current();
        }
    }));
    const handleSubmit = useCallback(formData => {
        onSubmit(formData, initialData);
    }, [initialData, onSubmit]);
    return (React.createElement(Form, { onSubmit: handleSubmit, render: ({ handleSubmit }) => {
            handleSubmitRef.current = handleSubmit;
            return (React.createElement(React.Fragment, null, React.createElement(Field, { component: FluentTextField, label: t("Name"), id: "name", name: "name", fullWidth: true, variant: "outlined", margin: "normal", size: "small", required: true, initialValue: (initialData === null || initialData === void 0 ? void 0 : initialData.name) || '' }), React.createElement(Field, { component: FluentTextField, label: t("Code"), id: "code", name: "code", fullWidth: true, variant: "outlined", margin: "normal", size: "small", initialValue: (initialData === null || initialData === void 0 ? void 0 : initialData.code) || '' }), React.createElement(Field, { component: AmbientAutoComplete, label: t("Color"), id: "color", name: "color", variant: "outlined", isMultiple: false, disableCloseOnSelect: false, options: TRANSACTION_TYPE_STATUS_COLORS || [], getOptionLabelFunction: option => option.name, initialValue: (TRANSACTION_TYPE_STATUS_COLORS === null || TRANSACTION_TYPE_STATUS_COLORS === void 0 ? void 0 : TRANSACTION_TYPE_STATUS_COLORS.find(color => (color === null || color === void 0 ? void 0 : color.value) === (initialData === null || initialData === void 0 ? void 0 : initialData.color))) || null }), React.createElement(LayoutUnit, { unit: "nudge" }), React.createElement(FormControlLabel, { control: (React.createElement(Field, { component: Switch, id: "isDefault", name: "isDefault", type: "checkbox", initialValue: !!(initialData === null || initialData === void 0 ? void 0 : initialData.isDefault) })), label: t("Default") }), React.createElement(LayoutUnit, { unit: "nudge" }), React.createElement(FormControlLabel, { control: (React.createElement(Field, { component: Switch, id: "isClosedStatus", name: "isClosedStatus", type: "checkbox", initialValue: !!(initialData === null || initialData === void 0 ? void 0 : initialData.isClosedStatus) })), label: t("Closed Status") }), React.createElement(LayoutUnit, { unit: "nudge" }), React.createElement(FormControlLabel, { control: (React.createElement(Field, { component: Switch, id: "isCancelledStatus", name: "isCancelledStatus", type: "checkbox", initialValue: !!(initialData === null || initialData === void 0 ? void 0 : initialData.isCancelledStatus) })), label: t("Cancelled Status") })));
        } }));
};
export default forwardRef(UdpTransactionTypeStatusForm);
//# sourceMappingURL=UdpTransactionTypeStatusForm.js.map