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 { useSCFetchEvent, useSCUser } from '@selfcommunity/react-core';
import classNames from 'classnames';
import CreateEventButton from '../CreateEventButton';
const PREFIX = 'SCEditEventButton';
const classes = {
    root: `${PREFIX}-root`
};
const Root = styled(CreateEventButton, {
    name: PREFIX,
    slot: 'Root',
    overridesResolver: (props, styles) => styles.root
})(({ theme }) => ({}));
/**
 *> API documentation for the Community-JS Create Event Button component. Learn about the available props and the CSS API.
 *
 #### Import
 ```jsx
 import {CreateEventButton} from '@selfcommunity/react-ui';
 ```

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

 #### CSS

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

 * @param inProps
 */
export default function EditEventButton(inProps) {
    //PROPS
    const props = useThemeProps({
        props: inProps,
        name: PREFIX
    });
    const { className, eventId, event, onEditSuccess } = props, rest = __rest(props, ["className", "eventId", "event", "onEditSuccess"]);
    const { scEvent, setSCEvent } = useSCFetchEvent({ id: eventId, event });
    const scUserContext = useSCUser();
    const handleSuccess = (data) => {
        setSCEvent(data);
        onEditSuccess && onEditSuccess(data);
    };
    if (!scUserContext.user) {
        return null;
    }
    /**
     * Renders root object
     */
    return (_jsx(Root, Object.assign({ variant: "outlined", className: classNames(classes.root, className), EventFormDialogComponentProps: { EventFormComponentProps: { event: scEvent, onSuccess: handleSuccess } } }, rest, { children: _jsx(FormattedMessage, { id: "ui.editEventButton", defaultMessage: "ui.editEventButton" }) })));
}
