"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_core_1 = require("@patternfly/react-core");
const dataTypes_1 = require("../data/dataTypes");
const common_1 = require("../../../../../common");
const ConfirmationModal_1 = tslib_1.__importDefault(require("../../../../../common/components/ui/ConfirmationModal"));
const OcmFormFields_1 = require("../../../ui/OcmFormFields");
const StaticIpViewRadioGroup = ({ initialView, confirmOnChangeView, onChangeView, }) => {
    const { clearAlerts } = (0, common_1.useAlerts)();
    const GROUP_NAME = 'select-static-ip-view';
    const [confirmView, setConfirmView] = react_1.default.useState();
    const [view, setView] = react_1.default.useState(initialView);
    const handleChange = (event) => {
        const selectedView = event.currentTarget.value;
        if (confirmOnChangeView) {
            setConfirmView(selectedView);
        }
        else {
            setView(selectedView);
            onChangeView(selectedView);
        }
    };
    const onConfirm = (selectedView) => {
        clearAlerts();
        setView(selectedView);
        setConfirmView(undefined);
        onChangeView(selectedView);
    };
    const onCancel = () => {
        setConfirmView(undefined);
    };
    const getCurrentViewText = () => {
        return view === dataTypes_1.StaticIpView.YAML ? 'YAML' : 'form';
    };
    const isFormViewSelected = view === dataTypes_1.StaticIpView.FORM;
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(react_core_1.Form, { isHorizontal: true },
            react_1.default.createElement(react_core_1.FormGroup, { fieldId: (0, common_1.getFieldId)(GROUP_NAME, 'radio'), isInline: true, label: "Configure via :", className: "static-config-type-label" },
                react_1.default.createElement(OcmFormFields_1.OcmRadio, { label: "Form view", name: GROUP_NAME, "data-testid": "select-form-view", id: "select-form-view", value: dataTypes_1.StaticIpView.FORM, isChecked: isFormViewSelected, onChange: handleChange }),
                react_1.default.createElement(OcmFormFields_1.OcmRadio, { label: "YAML view", name: GROUP_NAME, "data-testid": "select-yaml-view", id: "select-yaml-view", value: dataTypes_1.StaticIpView.YAML, isChecked: !isFormViewSelected, onChange: handleChange }))),
        isFormViewSelected && (react_1.default.createElement(react_core_1.Alert, { variant: react_core_1.AlertVariant.info, isInline: true, title: 'Form view supports basic configurations. Select YAML view for advanced configurations.' })),
        confirmView && (react_1.default.createElement(ConfirmationModal_1.default, { title: 'Change configuration option?', titleIconVariant: 'warning', confirmationButtonText: 'Change', confirmationButtonVariant: react_core_1.ButtonVariant.primary, content: react_1.default.createElement(react_1.default.Fragment, null,
                react_1.default.createElement("p", null, `All data and configuration done in ${getCurrentViewText()} view will be lost.`)), onClose: onCancel, onConfirm: () => onConfirm(confirmView) }))));
};
exports.default = StaticIpViewRadioGroup;
//# sourceMappingURL=StaticIpViewRadioGroup.js.map