import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2023-2025 GoodData Corporation
import { useState } from "react";
import { useIntl } from "react-intl";
import { v4 as uuid } from "uuid";
import { useBackendStrict } from "@gooddata/sdk-ui";
import { ConfirmDialogBase, Input, Overlay, useToastMessage } from "@gooddata/sdk-ui-kit";
import { messages } from "./locales.js";
import { useTelemetry, withTelemetry } from "./TelemetryContext.js";
const alignPoints = [{ align: "cc cc" }];
function CreateUserGroupDialogComponent({ organizationId, onSuccess, onCancel, }) {
    const intl = useIntl();
    const backend = useBackendStrict();
    const { addSuccess, addError } = useToastMessage();
    const [userGroupName, setUserGroupName] = useState("");
    const [isProcessing, setIsProcessing] = useState(false);
    const trackEvent = useTelemetry();
    const onSubmit = () => {
        setIsProcessing(true);
        backend
            .organization(organizationId)
            .users()
            .createUserGroup({
            id: uuid(),
            ref: undefined, //this violates api types
            name: userGroupName,
        })
            .then(() => {
            addSuccess(messages.userGroupCreatedSuccess);
            trackEvent("group-created");
            onSuccess();
            onCancel();
        })
            .catch(() => {
            addError(messages.userGroupCreatedFailure);
        })
            .finally(() => setIsProcessing(false));
    };
    const onChange = (value) => setUserGroupName(String(value));
    return (_jsx(Overlay, { alignPoints: alignPoints, isModal: true, positionType: "fixed", className: "gd-user-management-dialog", children: _jsx(ConfirmDialogBase, { onSubmit: onSubmit, isSubmitDisabled: userGroupName === "" || isProcessing, onCancel: onCancel, isPositive: true, className: "s-user-management-create-group-dialog gd-user-management-create-dialog", headline: intl.formatMessage(messages.createUserGroupDialogTitle), submitButtonText: intl.formatMessage(messages.createUserGroupButton), showProgressIndicator: isProcessing, cancelButtonText: intl.formatMessage(messages.cancelUserGroupButton), children: _jsx(Input, { value: userGroupName, onChange: onChange, autofocus: true, placeholder: intl.formatMessage(messages.createUserGroupInputPlaceholder), className: "gd-user-management-create-user-group-input s-group-name-input" }) }) }));
}
/**
 * @internal
 */
export const CreateUserGroupDialog = withTelemetry(CreateUserGroupDialogComponent);
//# sourceMappingURL=CreateUserGroupDialog.js.map