"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 material_1 = require("@mui/material");
const ChangePictureDialog_1 = tslib_1.__importDefault(require("./ChangePictureDialog/ChangePictureDialog"));
const react_intl_1 = require("react-intl");
const Icon_1 = tslib_1.__importDefault(require("@mui/material/Icon"));
const react_core_1 = require("@selfcommunity/react-core");
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const system_1 = require("@mui/system");
const constants_1 = require("./constants");
const classes = {
    root: `${constants_1.PREFIX}-root`,
    dialog: `${constants_1.PREFIX}-dialog`
};
const Root = (0, styles_1.styled)(material_1.Button, {
    name: constants_1.PREFIX,
    slot: 'Root'
})(() => ({}));
/**
 * > API documentation for the Community-JS Change Picture component. Learn about the available props and the CSS API.
 *
 *
 * This component renders a button that allows users to manage their profile pictures.
 * Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/ChangePicture)

 #### Import

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

 #### Component Name

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

 #### CSS

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

 * @param inProps
 */
function ChangePicture(inProps) {
    //PROPS
    const props = (0, system_1.useThemeProps)({
        props: inProps,
        name: constants_1.PREFIX
    });
    const { iconButton, onChange, autoHide, className } = props, rest = tslib_1.__rest(props, ["iconButton", "onChange", "autoHide", "className"]);
    //STATE
    const [openChangePictureDialog, setOpenChangePictureDialog] = (0, react_1.useState)(false);
    //CONTEXT
    const scUserContext = (0, react_1.useContext)(react_core_1.SCUserContext);
    // Anonymous
    if (!scUserContext.user) {
        return null;
    }
    /**
     * Renders the component (if not hidden by autoHide prop)
     */
    if (!autoHide) {
        return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className), size: "small", variant: "contained", onClick: () => setOpenChangePictureDialog(true) }, rest, { children: iconButton ? ((0, jsx_runtime_1.jsx)(Icon_1.default, { children: "photo_camera" })) : ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.changePicture.button.change", defaultMessage: "ui.changePicture.button.change" })) })), openChangePictureDialog && ((0, jsx_runtime_1.jsx)(ChangePictureDialog_1.default, { className: classes.dialog, open: openChangePictureDialog, onChange: (avatar) => onChange && onChange(avatar), onClose: () => setOpenChangePictureDialog(false) }))] }));
    }
    return null;
}
exports.default = ChangePicture;
