import { __rest } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { useThemeProps } from '@mui/system';
import { styled } from '@mui/material/styles';
import { FormattedMessage } from 'react-intl';
import { useSCFetchGroup, useSCUser } from '@selfcommunity/react-core';
import classNames from 'classnames';
import CreateGroupButton from '../CreateGroupButton';
const PREFIX = 'SCEditGroupButton';
const classes = {
    root: `${PREFIX}-root`
};
const Root = styled(CreateGroupButton, {
    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
 */
export default function EditGroupButton(inProps) {
    //PROPS
    const props = useThemeProps({
        props: inProps,
        name: PREFIX
    });
    const { className, groupId, group, onEditSuccess } = props, rest = __rest(props, ["className", "groupId", "group", "onEditSuccess"]);
    const { scGroup, setSCGroup } = useSCFetchGroup({ id: groupId, group });
    const scUserContext = useSCUser();
    const handleSuccess = (data) => {
        setSCGroup(data);
        onEditSuccess && onEditSuccess(data);
    };
    if (!scUserContext.user) {
        return null;
    }
    /**
     * Renders root object
     */
    return (_jsx(Root, Object.assign({ variant: "outlined", className: classNames(classes.root, className), GroupFormProps: { group: scGroup, onSuccess: handleSuccess } }, rest, { children: _jsx(FormattedMessage, { id: "ui.editGroupButton", defaultMessage: "ui.editGroupButton" }) })));
}
