"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FormViewNetworkWide = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const StaticIpForm_1 = require("../StaticIpForm");
const formViewNetworkWideValidationSchema_1 = require("./formViewNetworkWideValidationSchema");
const formDataToInfraEnvField_1 = require("../../data/formDataToInfraEnvField");
const FormViewNetworkWideFields_1 = require("./FormViewNetworkWideFields");
const fromInfraEnv_1 = require("../../data/fromInfraEnv");
const emptyData_1 = require("../../data/emptyData");
const FormViewNetworkWide = (_a) => {
    var { infraEnv } = _a, props = tslib_1.__rest(_a, ["infraEnv"]);
    const [formProps, setFormProps] = react_1.default.useState();
    const [hosts, setHosts] = react_1.default.useState();
    react_1.default.useEffect(() => {
        const _hosts = (0, fromInfraEnv_1.getFormData)(infraEnv).hosts;
        setHosts(_hosts);
        if (!_hosts) {
            return;
        }
        setFormProps(Object.assign(Object.assign({ infraEnv }, props), { validationSchema: formViewNetworkWideValidationSchema_1.networkWideValidationSchema, getInitialValues: (infraEnv) => {
                return (0, fromInfraEnv_1.getFormViewNetworkWideValues)(infraEnv);
            }, getUpdateParams: (currentInfraEnv, values) => (0, formDataToInfraEnvField_1.networkWideToInfraEnvField)(currentInfraEnv, values), getEmptyValues: () => (0, emptyData_1.getEmptyNetworkWideConfigurations)() }));
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);
    if (!hosts || !formProps) {
        return null;
    }
    return (react_1.default.createElement(StaticIpForm_1.StaticIpForm, Object.assign({}, formProps),
        react_1.default.createElement(FormViewNetworkWideFields_1.FormViewNetworkWideFields, { hosts: hosts })));
};
exports.FormViewNetworkWide = FormViewNetworkWide;
//# sourceMappingURL=FormViewNetworkWide.js.map