import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useCallback } from 'react';
import { Box, TextField, Typography } from '@mui/material';
import { styled } from '@mui/material/styles';
import classNames from 'classnames';
import Editor from '../../../Editor';
import { FormattedMessage, useIntl } from 'react-intl';
import { COMPOSER_TITLE_MAX_LENGTH } from '../../../../constants/Composer';
import { PREFIX } from '../../constants';
const classes = {
    root: `${PREFIX}-content-discussion-root`,
    generalError: `${PREFIX}-general-error`,
    title: `${PREFIX}-content-discussion-title`,
    medias: `${PREFIX}-content-discussion-medias`,
    editor: `${PREFIX}-content-discussion-editor`
};
const Root = styled(Box, {
    name: PREFIX,
    slot: 'ContentDiscussionRoot'
})(({ theme }) => ({}));
/**
 * Default post
 */
const DEFAULT_DISCUSSION = {
    title: '',
    categories: [],
    group: null,
    event: null,
    medias: [],
    html: '',
    addressing: []
};
export default (props) => {
    // PROPS
    const { className = null, value = Object.assign({}, DEFAULT_DISCUSSION), error = {}, disabled = false, onChange, EditorProps = {} } = props;
    const { titleError = null, error: generalError = null } = Object.assign({}, error);
    // HOOKS
    const intl = useIntl();
    // HANDLERS
    const handleChangeTitle = useCallback((event) => {
        onChange(Object.assign(Object.assign({}, value), { title: event.target.value }));
    }, [value]);
    const handleChangeHtml = useCallback((html) => {
        onChange(Object.assign(Object.assign({}, value), { html }));
    }, [value]);
    // RENDER
    return (_jsxs(Root, Object.assign({ className: classNames(classes.root, className) }, { children: [generalError && (_jsx(Typography, Object.assign({ className: classes.generalError }, { children: _jsx(FormattedMessage, { id: `ui.composer.error.${generalError}`, defaultMessage: `ui.composer.error.${generalError}` }) }))), _jsx(TextField, { className: classes.title, placeholder: intl.formatMessage({
                    id: 'ui.composer.content.discussion.title.label',
                    defaultMessage: 'ui.composer.content.discussion.title.label'
                }), autoFocus: true, fullWidth: true, variant: "outlined", value: value.title, multiline: true, onChange: handleChangeTitle, InputProps: {
                    endAdornment: _jsx(Typography, Object.assign({ variant: "body2" }, { children: COMPOSER_TITLE_MAX_LENGTH - value.title.length }))
                }, error: Boolean(titleError), helperText: titleError, disabled: disabled }), _jsx(Editor, Object.assign({}, EditorProps, { editable: !disabled, className: classes.editor, onChange: handleChangeHtml, defaultValue: value.html }))] })));
};
