import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2023-2025 GoodData Corporation
import { useCallback, useEffect } from "react";
import { useIntl } from "react-intl";
import { BackButton, ConfirmDialogBase } from "@gooddata/sdk-ui-kit";
import { useUserDetails } from "./detailsHooks.js";
import { UserDetailsView } from "./UserDetailsView.js";
import { messages } from "../locales.js";
import { extractUserName } from "../utils.js";
export function EditUserDetails({ user, isBootstrapUser, isAdmin, enableBackButton, changeUserMembership, onSubmit, onCancel, onClose, removeAdminGroup, }) {
    const intl = useIntl();
    const { updatedUser, isUpdatedAdmin, isProcessing, onSave, onChange, isDirty } = useUserDetails(user, isAdmin, onSubmit, onCancel, removeAdminGroup);
    // change user membership if dialog was opened for that reason, enable Save button, do it just once
    useEffect(() => {
        if (changeUserMembership) {
            onChange(updatedUser, !isUpdatedAdmin);
        }
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, []);
    const backButtonRenderer = useCallback(() => {
        return _jsx(BackButton, { onClick: onCancel, className: "s-user-management-navigate-back" });
    }, [onCancel]);
    return (_jsx(ConfirmDialogBase, { className: "gd-share-dialog gd-share-dialog-add-users s-user-management-edit-user", displayCloseButton: true, isPositive: true, isSubmitDisabled: !isDirty || isProcessing, showProgressIndicator: isProcessing, headline: extractUserName(user), cancelButtonText: intl.formatMessage(messages.closeEditMode), submitButtonText: intl.formatMessage(messages.saveEditedDetails), onCancel: onCancel, onSubmit: onSave, onClose: onClose, headerLeftButtonRenderer: enableBackButton ? backButtonRenderer : undefined, children: _jsx(UserDetailsView, { user: updatedUser, isAdmin: isUpdatedAdmin, isBootstrapUser: isBootstrapUser, mode: "EDIT", onChange: onChange }) }));
}
//# sourceMappingURL=EditUserDetails.js.map