"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const styles_1 = require("@mui/material/styles");
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const system_1 = require("@mui/system");
const material_1 = require("@mui/material");
const react_intl_1 = require("react-intl");
const react_core_1 = require("@selfcommunity/react-core");
const BaseDialog_1 = tslib_1.__importDefault(require("../../shared/BaseDialog"));
const AccountDataPortability_1 = tslib_1.__importDefault(require("../AccountDataPortability"));
const PREFIX = 'SCAccountDataPortabilityButtonn';
const classes = {
    root: `${PREFIX}-root`,
    dialogRoot: `${PREFIX}-dialog-root`
};
const Root = (0, styles_1.styled)(material_1.Button, {
    name: PREFIX,
    slot: 'Root',
    overridesResolver: (props, styles) => [styles.root, styles.voted]
})(({ theme }) => ({}));
const DialogRoot = (0, styles_1.styled)(BaseDialog_1.default, {
    name: PREFIX,
    slot: 'Root',
    overridesResolver: (props, styles) => styles.dialogRoot
})(({ theme }) => ({}));
/**
 * > API documentation for the Community-JS Account Data Portability Button component. Learn about the available props and the CSS API.
 *
 *
 * This component display a button that open a Dialog that display the [AccountDataPortability](/docs/sdk/community-js/react-ui/Components/AccountDataPortability) component.

 #### Import

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

 #### Component Name

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


 #### CSS

 |Rule Name|Global class|Description|
 |---|---|---|
 |root|.SCAccountDataPortabilityButtonn-root|Styles applied to the root element.|
 |dialogRoot|.SCAccountDataPortabilityButtonn-dialog-root|Styles applied to the dialog root element.|
 * @param inProps
 */
function AccountDataPortabilityButton(inProps) {
    // PROPS
    const props = (0, system_1.useThemeProps)({
        props: inProps,
        name: PREFIX
    });
    const { className } = props, rest = tslib_1.__rest(props, ["className"]);
    // STATE
    const [open, setOpen] = (0, react_1.useState)(false);
    // CONTEXT
    const scUserContext = (0, react_core_1.useSCUser)();
    // HANDLERS
    const handleOpen = () => {
        setOpen(true);
    };
    const handleClose = () => {
        setOpen(false);
    };
    // RENDER
    if (!scUserContext.user) {
        return null;
    }
    return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Root, Object.assign({ onClick: handleOpen, className: (0, classnames_1.default)(classes.root, className) }, rest, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.accountDataPortabilityButton.buttonLabel", defaultMessage: "ui.accountDataPortabilityButton.buttonLabel" }) })), open && ((0, jsx_runtime_1.jsx)(DialogRoot, Object.assign({ title: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.accountDataPortabilityButton.dialogTitle", defaultMessage: "ui.accountDataPortabilityButton.dialogTitle", values: { username: scUserContext.user.username } }), onClose: handleClose, open: open, DialogContentProps: {} }, { children: (0, jsx_runtime_1.jsx)(AccountDataPortability_1.default, {}) })))] }));
}
exports.default = AccountDataPortabilityButton;
