import { __rest } from "tslib";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from 'react';
import { styled } from '@mui/material/styles';
import classNames from 'classnames';
import { useThemeProps } from '@mui/system';
import { Button } from '@mui/material';
import { FormattedMessage } from 'react-intl';
import { useSCUser } from '@selfcommunity/react-core';
import BaseDialog from '../../shared/BaseDialog';
import AccountDelete from '../AccountDelete';
const PREFIX = 'SCAccountDeleteButton';
const classes = {
    root: `${PREFIX}-root`,
    dialogRoot: `${PREFIX}-dialog-root`
};
const Root = styled(Button, {
    name: PREFIX,
    slot: 'Root',
    overridesResolver: (props, styles) => [styles.root, styles.voted]
})(({ theme }) => ({}));
const DialogRoot = styled(BaseDialog, {
    name: PREFIX,
    slot: 'Root',
    overridesResolver: (props, styles) => styles.dialogRoot
})(({ theme }) => ({}));
/**
 * > API documentation for the Community-JS Account Delete Button component. Learn about the available props and the CSS API.
 *
 *
 * This component display a button that open a Dialog that display the [AccountDelete](/docs/sdk/community-js/react-ui/Components/AccountDelete) component.

 #### Import

 ```jsx
 import {AccountDeleteButton} from '@selfcommunity/react-ui';
 ```

 #### Component Name

 The name `SCAccountDeleteButton` can be used when providing style overrides in the theme.


 #### CSS

 |Rule Name|Global class|Description|
 |---|---|---|
 |root|.SCAccountDeleteButton-root|Styles applied to the root element.|
 |dialogRoot|.SCAccountDeleteButton-dialog-root|Styles applied to the dialog root element.|
 * @param inProps
 */
export default function AccountDeleteButton(inProps) {
    // PROPS
    const props = useThemeProps({
        props: inProps,
        name: PREFIX
    });
    const { className, onDeleteAccount } = props, rest = __rest(props, ["className", "onDeleteAccount"]);
    // STATE
    const [open, setOpen] = useState(false);
    // CONTEXT
    const scUserContext = useSCUser();
    // HANDLERS
    const handleOpen = () => {
        setOpen(true);
    };
    const handleClose = () => {
        setOpen(false);
    };
    const handleDelete = (user) => {
        onDeleteAccount && onDeleteAccount(user);
        handleClose();
    };
    // RENDER
    if (!scUserContext.user) {
        return null;
    }
    return (_jsxs(_Fragment, { children: [_jsx(Root, Object.assign({ onClick: handleOpen, className: classNames(classes.root, className) }, rest, { children: _jsx(FormattedMessage, { id: "ui.accountDeleteButton.buttonLabel", defaultMessage: "ui.accountDeleteButton.buttonLabel" }) })), open && (_jsx(DialogRoot, Object.assign({ title: _jsx(FormattedMessage, { id: "ui.accountDeleteButton.dialogTitle", defaultMessage: "ui.accountDeleteButton.dialogTitle" }), onClose: handleClose, open: open, DialogContentProps: {} }, { children: _jsx(AccountDelete, { onDeleteAccount: handleDelete }) })))] }));
}
