"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const system_1 = require("@mui/system");
const styles_1 = require("@mui/material/styles");
const react_intl_1 = require("react-intl");
const react_core_1 = require("@selfcommunity/react-core");
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const CreateGroupButton_1 = tslib_1.__importDefault(require("../CreateGroupButton"));
const PREFIX = 'SCEditGroupButton';
const classes = {
    root: `${PREFIX}-root`
};
const Root = (0, styles_1.styled)(CreateGroupButton_1.default, {
    name: PREFIX,
    slot: 'Root',
    overridesResolver: (props, styles) => styles.root
})(({ theme }) => ({}));
/**
 *> API documentation for the Community-JS Create Group Button component. Learn about the available props and the CSS API.
 *
 #### Import
 ```jsx
 import {CreateGroupButton} from '@selfcommunity/react-ui';
 ```

 #### Component Name
 The name `SCEditGroupButton` can be used when providing style overrides in the theme.

 #### CSS

 |Rule Name|Global class|Description|
 |---|---|---|
 |root|.SCEditGroupButton-root|Styles applied to the root element.|

 * @param inProps
 */
function EditGroupButton(inProps) {
    //PROPS
    const props = (0, system_1.useThemeProps)({
        props: inProps,
        name: PREFIX
    });
    const { className, groupId, group, onEditSuccess } = props, rest = tslib_1.__rest(props, ["className", "groupId", "group", "onEditSuccess"]);
    const { scGroup, setSCGroup } = (0, react_core_1.useSCFetchGroup)({ id: groupId, group });
    const scUserContext = (0, react_core_1.useSCUser)();
    const handleSuccess = (data) => {
        setSCGroup(data);
        onEditSuccess && onEditSuccess(data);
    };
    if (!scUserContext.user) {
        return null;
    }
    /**
     * Renders root object
     */
    return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ variant: "outlined", className: (0, classnames_1.default)(classes.root, className), GroupFormProps: { group: scGroup, onSuccess: handleSuccess } }, rest, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.editGroupButton", defaultMessage: "ui.editGroupButton" }) })));
}
exports.default = EditGroupButton;
