import * as __WEBPACK_EXTERNAL_MODULE__testing_library_react__ from "@testing-library/react";
import * as __WEBPACK_EXTERNAL_MODULE__Form_mjs__ from "./Form.mjs";
import * as __WEBPACK_EXTERNAL_MODULE_yup__ from "yup";
import * as __WEBPACK_EXTERNAL_MODULE__FormProvider_mjs__ from "./FormProvider.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__FormField_FormField_mjs__ from "../FormField/FormField.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__chakra_ui_react__ from "@chakra-ui/react";
describe('Form', ()=>{
    test('should render a form and display errors conditionally for each missing field', async ()=>{
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__FormProvider_mjs__["default"], null, /*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__Form_mjs__["default"], {
            mode: "all",
            autofocus: true,
            onValid: ()=>{
            // no op
            },
            onInvalid: ()=>{
            // no op
            },
            fields: [
                {
                    name: 'name',
                    fieldType: 'text',
                    label: 'Name',
                    placeholder: 'Name',
                    schema: __WEBPACK_EXTERNAL_MODULE_yup__.string().required('Provide a name')
                },
                {
                    name: 'someField',
                    fieldType: 'hidden',
                    label: 'Hidden',
                    placeholder: 'This should not be visible',
                    schema: __WEBPACK_EXTERNAL_MODULE_yup__.string()
                },
                {
                    name: 'description',
                    fieldType: 'textarea',
                    label: 'Description',
                    placeholder: 'Description',
                    schema: __WEBPACK_EXTERNAL_MODULE_yup__.string().required('Provide a description')
                },
                {
                    name: 'someNumber',
                    fieldType: 'number',
                    label: 'Number',
                    placeholder: '12345',
                    schema: __WEBPACK_EXTERNAL_MODULE_yup__.number().required('Provide a number')
                },
                {
                    name: 'deploymentType',
                    fieldType: 'toggle',
                    label: 'Deployment',
                    defaultValue: 'false',
                    placeholder: 'Deployment type',
                    schema: __WEBPACK_EXTERNAL_MODULE_yup__.string().required('Provide BYOC/FMC deployment type')
                },
                {
                    name: 'maxThroughput',
                    fieldType: 'radio',
                    label: 'Throughput',
                    placeholder: 'Max throughput',
                    defaultValue: '1',
                    schema: __WEBPACK_EXTERNAL_MODULE_yup__.string().required('Provide max throughput'),
                    options: [
                        {
                            value: '1',
                            label: 'Option 1'
                        },
                        {
                            value: '2',
                            label: 'Option 2',
                            disabled: true
                        },
                        {
                            value: '3',
                            label: 'Option 3',
                            invalid: true
                        },
                        {
                            value: '4',
                            label: 'Option 4',
                            invalid: true,
                            disabled: true
                        }
                    ]
                }
            ],
            button: {
                label: 'confirm_some_form',
                text: 'Create'
            },
            developerView: true
        })));
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('name_field')).toBeVisible();
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByText('someField_field')).not.toBeInTheDocument();
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('description_field')).toBeVisible();
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('someNumber_field')).toBeVisible();
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('deploymentType_field')).toBeVisible();
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('maxThroughput_field')).toBeVisible();
            // expect(screen.getByTestId('region_field')).toBeVisible();
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByTestId('confirm_some_form')).toBeVisible();
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByTestId('confirm_some_form')).toBeEnabled();
        });
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.click(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('confirm_some_form'));
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.blur(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('name_field'));
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByText('Provide a name')).toBeVisible();
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByTestId('confirm_some_form')).toBeDisabled();
        });
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.focus(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('description_field'));
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.blur(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('description_field'));
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByText('Provide a description')).toBeVisible();
        });
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.focus(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('someNumber_field'));
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.blur(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('someNumber_field'));
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByText('Provide a number')).toBeVisible();
        });
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.focus(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('deploymentType_field'));
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.blur(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('deploymentType_field'));
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            // Value is already provided
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByText('Provide BYOC/FMC deployment type')).not.toBeInTheDocument();
        });
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.focus(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('maxThroughput_field'));
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.blur(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('maxThroughput_field'));
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            // Value is already provided
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByText('Provide max throughput')).not.toBeInTheDocument();
        });
    // fireEvent.focus(screen.getByTestId('region_field'));
    // fireEvent.blur(screen.getByTestId('region_field'));
    // await waitFor(() => {
    //   expect(screen.getByText('Provide a region')).toBeVisible();
    // });
    });
    test('should allow filling in the form with correct values', async ()=>{
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__FormProvider_mjs__["default"], null, /*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__Form_mjs__["default"], {
            mode: "all",
            autofocus: true,
            onValid: ()=>{},
            onInvalid: ()=>{},
            fields: [
                {
                    name: 'name',
                    fieldType: 'text',
                    label: 'Name',
                    placeholder: 'Name',
                    schema: __WEBPACK_EXTERNAL_MODULE_yup__.string().required('Provide a name')
                },
                {
                    name: 'someField',
                    fieldType: 'hidden',
                    label: 'Hidden',
                    placeholder: 'This should not be visible',
                    schema: __WEBPACK_EXTERNAL_MODULE_yup__.string()
                },
                {
                    name: 'description',
                    fieldType: 'textarea',
                    label: 'Description',
                    placeholder: 'Description',
                    schema: __WEBPACK_EXTERNAL_MODULE_yup__.string().required('Provide a description')
                },
                {
                    name: 'someNumber',
                    fieldType: 'number',
                    label: 'Number',
                    placeholder: '12345',
                    schema: __WEBPACK_EXTERNAL_MODULE_yup__.number().required('Provide a number')
                },
                {
                    name: 'deploymentType',
                    fieldType: 'toggle',
                    label: 'Deployment',
                    placeholder: 'Deployment type',
                    schema: __WEBPACK_EXTERNAL_MODULE_yup__.string().required('Provide BYOC/FMC deployment type')
                },
                {
                    name: 'maxThroughput',
                    fieldType: 'radio',
                    label: 'Throughput',
                    placeholder: 'Max throughput',
                    schema: __WEBPACK_EXTERNAL_MODULE_yup__.string().required('Provide max throughput'),
                    options: [
                        {
                            value: '1',
                            label: 'Option 1'
                        },
                        {
                            value: '2',
                            label: 'Option 2',
                            disabled: true
                        },
                        {
                            value: '3',
                            label: 'Option 3',
                            invalid: true
                        },
                        {
                            value: '4',
                            label: 'Option 4',
                            invalid: true,
                            disabled: true
                        }
                    ]
                }
            ],
            button: {
                label: 'confirm_some_form',
                text: 'Create'
            },
            developerView: true
        })));
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('confirm_some_form')).toBeEnabled();
        });
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.change(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('name_field'), {
            target: {
                value: 'asdf'
            }
        });
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('name_field')).toHaveValue('asdf');
        });
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.change(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('description_field'), {
            target: {
                value: 'desc'
            }
        });
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('description_field')).toHaveValue('desc');
        });
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.change(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('someNumber_field'), {
            target: {
                value: 12345
            }
        });
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('someNumber_field')).toHaveValue('12345');
        });
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.change((0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.within)(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('deploymentType_field')).getByRole('checkbox'), {
            target: {
                checked: true
            }
        });
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect((0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.within)(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('deploymentType_field')).getByRole('checkbox')).toBeChecked();
        });
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.click(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByText('Option 1'));
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByText('Option 1')).toHaveAttribute('data-checked');
        });
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.click(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('confirm_some_form'));
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('confirm_some_form')).toBeEnabled();
        });
    });
    test('should render a form with custom section and display errors conditionally for each missing field', async ()=>{
        const CustomFormSectionComponent = ({ form, setValidationContext })=>{
            const { register, formState: { errors } } = form;
            return /*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__FormField_FormField_mjs__["default"], {
                description: 'custom description...',
                label: 'custom label',
                showRequiredIndicator: false,
                isInvalid: !!errors.customText,
                errorText: errors.customText?.message
            }, /*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__chakra_ui_react__.Input, {
                placeholder: "custom field placeholder",
                type: "text",
                "data-testid": "customText_field",
                ...register('customText')
            }));
        };
        (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.render)(/*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__FormProvider_mjs__["default"], null, /*#__PURE__*/ React.createElement(__WEBPACK_EXTERNAL_MODULE__Form_mjs__["default"], {
            mode: "all",
            autofocus: true,
            onValid: ()=>{
            // no op
            },
            onInvalid: ()=>{
            // no op
            },
            fields: [
                {
                    name: 'name',
                    fieldType: 'text',
                    label: 'Name',
                    placeholder: 'Name',
                    schema: __WEBPACK_EXTERNAL_MODULE_yup__.string().required('Provide a name')
                },
                {
                    fieldType: 'custom',
                    name: 'customField',
                    label: 'customField',
                    component: CustomFormSectionComponent,
                    fields: [
                        {
                            fieldType: 'text',
                            label: 'Custom Text Field',
                            name: 'customText',
                            schema: __WEBPACK_EXTERNAL_MODULE_yup__.string().required('Provide a custom field value')
                        }
                    ]
                }
            ],
            button: {
                label: 'confirm_some_form',
                text: 'Create'
            },
            developerView: true
        })));
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('name_field')).toBeVisible();
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('customText_field')).toBeVisible();
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByTestId('confirm_some_form')).toBeVisible();
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByTestId('confirm_some_form')).toBeEnabled();
        });
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.click(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('confirm_some_form'));
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.blur(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('name_field'));
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByText('Provide a name')).toBeVisible();
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.queryByTestId('confirm_some_form')).toBeDisabled();
        });
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.focus(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('customText_field'));
        __WEBPACK_EXTERNAL_MODULE__testing_library_react__.fireEvent.blur(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByTestId('customText_field'));
        await (0, __WEBPACK_EXTERNAL_MODULE__testing_library_react__.waitFor)(()=>{
            expect(__WEBPACK_EXTERNAL_MODULE__testing_library_react__.screen.getByText('Provide a custom field value')).toBeVisible();
        });
    });
});
