"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FormViewHosts = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const StaticIpForm_1 = require("../StaticIpForm");
const FormViewHostsFields_1 = require("./FormViewHostsFields");
const formViewHostsValidationSchema_1 = require("./formViewHostsValidationSchema");
const formDataToInfraEnvField_1 = require("../../data/formDataToInfraEnvField");
const emptyData_1 = require("../../data/emptyData");
const fromInfraEnv_1 = require("../../data/fromInfraEnv");
const common_1 = require("../../../../../../common");
const FormViewHosts = (_a) => {
    var { infraEnv } = _a, props = tslib_1.__rest(_a, ["infraEnv"]);
    const { t } = (0, common_1.useTranslation)();
    const [protocolType, setProtocolType] = react_1.default.useState();
    const [formProps, setFormProps] = react_1.default.useState();
    react_1.default.useEffect(() => {
        const networkWideValues = (0, fromInfraEnv_1.getFormViewNetworkWideValues)(infraEnv);
        setProtocolType(networkWideValues.protocolType);
        if (networkWideValues) {
            setFormProps(Object.assign({ infraEnv, validationSchema: (0, formViewHostsValidationSchema_1.getFormViewHostsValidationSchema)(networkWideValues, t), getInitialValues: (infraEnv) => {
                    return (0, fromInfraEnv_1.getFormViewHostsValues)(infraEnv);
                }, getUpdateParams: (currentInfraEnv, values) => (0, formDataToInfraEnvField_1.formViewHostsToInfraEnvField)(currentInfraEnv, values.hosts), getEmptyValues: () => (0, emptyData_1.getEmptyFormViewHostsValues)() }, props));
        }
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);
    if (!formProps || !protocolType) {
        return null;
    }
    return (react_1.default.createElement(StaticIpForm_1.StaticIpForm, Object.assign({}, formProps),
        react_1.default.createElement(FormViewHostsFields_1.FormViewHostsFields, { protocolType: protocolType })));
};
exports.FormViewHosts = FormViewHosts;
//# sourceMappingURL=FormViewHosts.js.map