import { __rest } from "tslib";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { useCallback, useState } from 'react';
import { styled } from '@mui/material/styles';
import { Icon, IconButton } from '@mui/material';
import classNames from 'classnames';
import { useThemeProps } from '@mui/system';
import { SCPreferences, useSCPreferences, useSCUser } from '@selfcommunity/react-core';
import NavigationMenuDrawer from './NavigationMenuDrawer';
const PREFIX = 'SCNavigationMenuIconButton';
const classes = {
    root: `${PREFIX}-root`
};
const Root = styled(IconButton, {
    name: PREFIX,
    slot: 'Root',
    overridesResolver: (props, styles) => styles.root
})(({ theme }) => ({}));
/**
 * > API documentation for the Community-JS Navigation Menu Icon Button component. Learn about the available props and the CSS API.

 #### Import

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

 #### Component Name

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


 #### CSS

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

 * @param inProps
 */
export default function NavigationMenuIconButton(inProps) {
    var _a;
    // PROPS
    const props = useThemeProps({
        props: inProps,
        name: PREFIX
    });
    const { className = null, DrawerProps = {}, onMenuIconClick = null, showDrawer = true } = props, rest = __rest(props, ["className", "DrawerProps", "onMenuIconClick", "showDrawer"]);
    // STATE
    const [anchorEl, setAnchorEl] = useState(null);
    // CONTEXT
    const { preferences } = useSCPreferences();
    const scUserContext = useSCUser();
    // HANDLERS
    const handleOpen = useCallback((event) => {
        setAnchorEl(event.currentTarget);
    }, []);
    const handleClose = useCallback(() => {
        setAnchorEl(null);
    }, []);
    if (!preferences[SCPreferences.CONFIGURATIONS_CONTENT_AVAILABILITY].value && !((_a = scUserContext.user) === null || _a === void 0 ? void 0 : _a.id)) {
        return null;
    }
    return (_jsxs(_Fragment, { children: [_jsx(Root, Object.assign({ className: classNames(classes.root, className) }, rest, { onClick: onMenuIconClick !== null && onMenuIconClick !== void 0 ? onMenuIconClick : handleOpen }, { children: _jsx(Icon, { children: "menu" }) })), showDrawer && _jsx(NavigationMenuDrawer, Object.assign({ open: Boolean(anchorEl), onClose: handleClose }, DrawerProps))] }));
}
