import { _ as __rest } from './tslib.es6-ab63fd84.js';
import React__default, { createContext, useContext } from 'react';
import { clsx, useMantineTheme } from '@mantine/core';
import { useForm, isNotEmpty } from '@mantine/form';
import './index-c3177e04.js';
import { D as DatePicker } from './index-122829d2.js';
import { T as Text } from './index-d0a1200e.js';
import './index-f71a880f.js';
import './index-38e03570.js';
import './index.styles-3ba274d2.js';
import { u as useTranslations } from './index-960c3169.js';
import '@mantine/hooks';
import './index-4e6b8a2b.js';
import './utils-32d7d5af.js';
import './index-f21110d2.js';
import { C as CardWrapperContext } from './context-e9fa0aef.js';
import { H as HealthToolFormWrapper } from './index-70e81356.js';
import { G as GenderOptionControl } from './index-f3c67a5d.js';
import { CalendarMB } from '@hhgtech/icons/other';

const BabyVaccineFormContext = createContext({});

const DefaultLayout = (_a) => {
    var props = __rest(_a, []);
    const { t } = useTranslations();
    const { currentUrl, submitProps, form } = useContext(BabyVaccineFormContext);
    const { classes: wrapperClasses = {} } = useContext(CardWrapperContext);
    return (React__default.createElement(HealthToolFormWrapper, Object.assign({ formLayout: "default" }, props),
        React__default.createElement(HealthToolFormWrapper.FormRow, null,
            React__default.createElement(GenderOptionControl, Object.assign({ isBaby: true }, form.getInputProps('gender')))),
        React__default.createElement(HealthToolFormWrapper.FormRow, null,
            React__default.createElement(DatePicker, Object.assign({ label: React__default.createElement(Text, { size: "p2", weight: "semiBold" }, t('babyGrowth.input.birthday')), placeholder: 'DD/MM/YYYY', popoverProps: {
                    withinPortal: true,
                }, maxDate: new Date() }, form.getInputProps('age')))),
        React__default.createElement(HealthToolFormWrapper.FormRow, { className: wrapperClasses.submitWrapper },
            React__default.createElement(HealthToolFormWrapper.Submit, Object.assign({ type: "submit", className: clsx('due-date-calculate-button', wrapperClasses.submitBtn), dataEventCategory: "Health Tool", dataEventAction: "Vaccination Tool", dataEventLabel: currentUrl }, submitProps), t('dueDatePage.lastPeriod.calculate')))));
};

const InlineLayout = (_a) => {
    var props = __rest(_a, []);
    const { t } = useTranslations();
    const { currentUrl, submitProps, form } = useContext(BabyVaccineFormContext);
    const { classes: wrapperClasses = {} } = useContext(CardWrapperContext);
    return (React__default.createElement(HealthToolFormWrapper, Object.assign({ formLayout: "inline" }, props),
        React__default.createElement(HealthToolFormWrapper.FormRow, null,
            React__default.createElement(HealthToolFormWrapper.BorderInlineControl, { label: t('tools.selectBabyGender'), width: 'none' },
                React__default.createElement(GenderOptionControl, Object.assign({ isBaby: true, hideLabel: true, type: "radio" }, form.getInputProps('gender')))),
            form.errors.gender && (React__default.createElement(HealthToolFormWrapper.Error, null, form.errors.gender))),
        React__default.createElement(HealthToolFormWrapper.FormRow, null,
            React__default.createElement(HealthToolFormWrapper.BorderInlineControl, { label: t('babyGrowth.input.birthday') },
                React__default.createElement(DatePicker, Object.assign({ placeholder: 'DD/MM/YYYY', popoverProps: {
                        withinPortal: true,
                    }, maxDate: new Date() }, form.getInputProps('age'), { error: null }))),
            form.errors.age && (React__default.createElement(HealthToolFormWrapper.Error, null, form.errors.age))),
        React__default.createElement(HealthToolFormWrapper.FormRow, { className: wrapperClasses.submitWrapper },
            React__default.createElement(HealthToolFormWrapper.Submit, Object.assign({ type: "submit", className: clsx('due-date-calculate-button', wrapperClasses.submitBtn), dataEventCategory: "Health Tool", dataEventAction: "Vaccination Tool", dataEventLabel: currentUrl }, submitProps), t('dueDatePage.lastPeriod.calculate')))));
};

const MbLayout = (_a) => {
    var props = __rest(_a, []);
    const { t } = useTranslations();
    const { currentUrl, submitProps, form } = useContext(BabyVaccineFormContext);
    return (React__default.createElement(HealthToolFormWrapper, Object.assign({ formLayout: "default" }, props),
        React__default.createElement(HealthToolFormWrapper.Control, null,
            React__default.createElement(GenderOptionControl, Object.assign({ isBaby: true }, form.getInputProps('gender'), { error: null }))),
        form.errors.gender && (React__default.createElement(HealthToolFormWrapper.Error, null, form.errors.gender)),
        React__default.createElement(HealthToolFormWrapper.FormRow, null,
            React__default.createElement(HealthToolFormWrapper.BorderBoxControl, { label: t('babyGrowth.input.birthday'), rightSection: React__default.createElement(CalendarMB, null) },
                React__default.createElement(DatePicker, Object.assign({ placeholder: 'DD/MM/YYYY', popoverProps: {
                        withinPortal: true,
                    }, maxDate: new Date(), rightSection: null }, form.getInputProps('age'), { error: null }))),
            form.errors.age && (React__default.createElement(HealthToolFormWrapper.Error, null, form.errors.age))),
        React__default.createElement(HealthToolFormWrapper.Submit, Object.assign({ type: "submit", className: "due-date-calculate-button", dataEventCategory: "Health Tool", dataEventAction: "Vaccination Tool", dataEventLabel: currentUrl }, submitProps), t('dueDatePage.lastPeriod.calculate'))));
};

var OvulationCalculatorType;
(function (OvulationCalculatorType) {
    OvulationCalculatorType[OvulationCalculatorType["trackPeriod"] = 0] = "trackPeriod";
    OvulationCalculatorType[OvulationCalculatorType["conceive"] = 1] = "conceive";
    OvulationCalculatorType[OvulationCalculatorType["avoidPregnancy"] = 2] = "avoidPregnancy";
})(OvulationCalculatorType || (OvulationCalculatorType = {}));
const BabyVaccineForm = (_a) => {
    var { formLayout = 'default', submitProps, currentUrl, onSubmit } = _a, props = __rest(_a, ["formLayout", "submitProps", "currentUrl", "onSubmit"]);
    const { t } = useTranslations();
    const theme = useMantineTheme();
    const isMarryBaby = theme.other.template === 'mb';
    const form = useForm({
        validate: {
            gender: isNotEmpty(t('validation.error.requiredField')),
            age: isNotEmpty(t('validation.error.requiredField')),
        },
    });
    const commonProps = Object.assign({ onSubmit: form.onSubmit(onSubmit) }, props);
    return (React__default.createElement(BabyVaccineFormContext.Provider, { value: { submitProps, currentUrl, form } }, formLayout === 'inline' ? (React__default.createElement(InlineLayout, Object.assign({}, commonProps))) : isMarryBaby ? (React__default.createElement(MbLayout, Object.assign({ formLayout: formLayout }, commonProps))) : (React__default.createElement(DefaultLayout, Object.assign({}, commonProps)))));
};

export { BabyVaccineForm as B };
