import { __rest } from "tslib";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Button, Icon } from '@mui/material';
import { styled } from '@mui/material/styles';
import { useThemeProps } from '@mui/system';
import { SCUserContext, useSCPreferences } from '@selfcommunity/react-core';
import classNames from 'classnames';
import React, { useContext, useMemo } from 'react';
import { FormattedMessage } from 'react-intl';
import CreateLivestreamDialog from '../CreateLiveStreamDialog';
const PREFIX = 'SCCreateLivestreamButton';
const classes = {
    root: `${PREFIX}-root`
};
const Root = styled(Button, {
    name: PREFIX,
    slot: 'Root',
    overridesResolver: (props, styles) => styles.root
})(() => ({}));
/**
 *> API documentation for the Community-JS CreateLiveStreamButton component. Learn about the available props and the CSS API.
 *
 #### Import
 ```jsx
 import {CreateLiveStreamButton} from '@selfcommunity/react-ui';
 ```

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

 #### CSS

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

 * @param inProps
 */
export default function CreateLiveStreamButton(inProps) {
    var _a;
    //PROPS
    const props = useThemeProps({
        props: inProps,
        name: PREFIX
    });
    const { className, CreateLiveStreamDialogComponentProps = {}, onSuccess, children } = props, rest = __rest(props, ["className", "CreateLiveStreamDialogComponentProps", "onSuccess", "children"]);
    // CONTEXT
    const scUserContext = useContext(SCUserContext);
    // STATE
    const [open, setOpen] = React.useState(false);
    // CONST
    const authUserId = scUserContext.user ? scUserContext.user.id : null;
    const { preferences, features } = useSCPreferences();
    // TODO
    const liveStreamEnabled = true;
    /* const liveStreamEnabled = useMemo(
          () =>
              preferences &&
              features &&
              features.includes(SCFeatureName.LIVE_STREAM) &&
              SCPreferences.CONFIGURATIONS_LIVE_STREAM_ENABLED in preferences &&
              preferences[SCPreferences.CONFIGURATIONS_LIVE_STREAM_ENABLED].value,
          [preferences, features]
      ); */
    // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
    // @ts-ignore
    const canCreateLiveStream = useMemo(() => true /* scUserContext?.user?.permission?.create_livestream */, [(_a = scUserContext === null || scUserContext === void 0 ? void 0 : scUserContext.user) === null || _a === void 0 ? void 0 : _a.permission]);
    /**
     * Handle close
     */
    const handleClose = () => {
        setOpen((o) => !o);
    };
    /**
     * Handle close
     */
    const handleSuccess = (data) => {
        onSuccess && onSuccess(data);
        setOpen((o) => !o);
    };
    /**
     * If there's no authUserId, component is hidden.
     */
    if (!liveStreamEnabled || !canCreateLiveStream || !authUserId) {
        return null;
    }
    /**
     * Renders root object
     */
    return (_jsxs(React.Fragment, { children: [_jsx(Root, Object.assign({ className: classNames(classes.root, className), onClick: handleClose, variant: "contained", color: "secondary", startIcon: _jsx(Icon, { children: "photo_camera" }) }, rest, { children: children !== null && children !== void 0 ? children : _jsx(FormattedMessage, { id: "ui.createEventButton.goLive", defaultMessage: "ui.createEventButton.goLive" }) })), open && _jsx(CreateLivestreamDialog, Object.assign({ open: true, onClose: handleClose, onSuccess: handleSuccess }, CreateLiveStreamDialogComponentProps))] }));
}
