"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_core_1 = require("@patternfly/react-core");
const formik_1 = require("formik");
const common_1 = require("../../../common");
const utils_1 = require("../../../common/utils");
const use_translation_wrapper_1 = require("../../../common/hooks/use-translation-wrapper");
const EditNtpSourcesModal = ({ isOpen, onClose, onSubmit, infraEnv, }) => {
    var _a, _b, _c;
    const [error, setError] = React.useState();
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    return (React.createElement(react_core_1.Modal, { "aria-label": t('ai:Edit Ntp sources dialog'), isOpen: isOpen, onClose: onClose, variant: react_core_1.ModalVariant.small, id: "edit-ntp-sources-modal" },
        React.createElement(react_core_1.ModalHeader, { title: t('ai:Edit NTP sources') }),
        React.createElement(formik_1.Formik, { initialValues: {
                enableNtpSources: ((_a = infraEnv.spec) === null || _a === void 0 ? void 0 : _a.additionalNTPSources) ? 'additional' : 'auto',
                additionalNtpSources: ((_c = (_b = infraEnv.spec) === null || _b === void 0 ? void 0 : _b.additionalNTPSources) === null || _c === void 0 ? void 0 : _c.join(',')) || '',
            }, onSubmit: (values) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
                try {
                    yield onSubmit(values, infraEnv);
                    onClose();
                }
                catch (err) {
                    setError((0, utils_1.getErrorMessage)(err));
                }
            }), validateOnMount: true }, ({ isSubmitting, isValid, values, submitForm, }) => {
            return (React.createElement(React.Fragment, null,
                React.createElement(react_core_1.ModalBody, null,
                    React.createElement(react_core_1.Form, null,
                        React.createElement(react_core_1.Stack, { hasGutter: true },
                            React.createElement(react_core_1.StackItem, null,
                                React.createElement(common_1.RadioField, { label: t('ai:Auto synchronized NTP (Network Time Protocol) sources'), value: "auto", name: "enableNtpSources" })),
                            React.createElement(react_core_1.StackItem, null,
                                React.createElement(common_1.RadioField, { name: "enableNtpSources", value: "additional", description: React.createElement(react_core_1.Stack, { hasGutter: true },
                                        React.createElement(react_core_1.StackItem, null, t('ai:Configure your own NTP sources to sychronize the time between the hosts that will be added to this infrastructure environment.')),
                                        React.createElement(react_core_1.StackItem, null,
                                            React.createElement(common_1.AdditionalNTPSourcesField, { name: "additionalNtpSources", isDisabled: values.enableNtpSources === 'auto', helperText: t('ai:A comma separated list of IP or domain names of the NTP pools or servers.') }))), label: t('ai:Your own NTP (Network Time Protocol) sources') })),
                            error && (React.createElement(react_core_1.StackItem, null,
                                React.createElement(react_core_1.Alert, { variant: "danger", title: error })))))),
                React.createElement(react_core_1.ModalFooter, null,
                    React.createElement(react_core_1.Button, { onClick: submitForm, isDisabled: isSubmitting || !isValid }, t('ai:Save')),
                    React.createElement(react_core_1.Button, { onClick: onClose, variant: react_core_1.ButtonVariant.secondary }, t('ai:Cancel')))));
        })));
};
exports.default = EditNtpSourcesModal;
//# sourceMappingURL=EditNtpSourcesModal.js.map