import { __rest } from "tslib";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { LoadingButton } from '@mui/lab';
import { Box, FormControl, FormGroup, Icon, IconButton, InputAdornment, InputLabel, MenuItem, Paper, Select, Stack, Switch, TextField, Typography } from '@mui/material';
import { styled } from '@mui/material/styles';
import { useThemeProps } from '@mui/system';
import { LocalizationProvider, MobileDatePicker, MobileTimePicker } from '@mui/x-date-pickers';
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
import { EventService, formatHttpErrorCode } from '@selfcommunity/api-services';
import { SCPreferences, useSCContext, useSCPreferences } from '@selfcommunity/react-core';
import { SCEventLocationType, SCEventPrivacyType, SCEventRecurrenceType } from '@selfcommunity/types';
import { Logger } from '@selfcommunity/utils';
import classNames from 'classnames';
import enLocale from 'date-fns/locale/en-US';
import itLocale from 'date-fns/locale/it';
import PubSub from 'pubsub-js';
import { useCallback, useMemo, useState } from 'react';
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
import { SCOPE_SC_UI } from '../../constants/Errors';
import { EVENT_DESCRIPTION_MAX_LENGTH, EVENT_TITLE_MAX_LENGTH } from '../../constants/Event';
import { SCGroupEventType, SCTopicType } from '../../constants/PubSub';
import { DAILY_LATER_DAYS, MONTHLY_LATER_DAYS, NEVER_LATER_DAYS, PREFIX, WEEKLY_LATER_DAYS } from './constants';
import EventAddress from './EventAddress';
import UploadEventCover from './UploadEventCover';
import { combineDateAndTime, getLaterDaysDate, getLaterHoursDate, getNewDate } from './utils';
const messages = defineMessages({
    name: {
        id: 'ui.eventForm.name.placeholder',
        defaultMessage: 'ui.eventForm.name.placeholder'
    },
    description: {
        id: 'ui.eventForm.description.placeholder',
        defaultMessage: 'ui.eventForm.description.placeholder'
    },
    startDate: {
        id: 'ui.eventForm.date.placeholder',
        defaultMessage: 'ui.eventForm.date.placeholder'
    },
    startTime: {
        id: 'ui.eventForm.time.placeholder',
        defaultMessage: 'ui.eventForm.time.placeholder'
    },
    frequency: {
        id: 'ui.eventForm.frequency.label',
        defaultMessage: 'ui.eventForm.frequency.label'
    },
    frequencyPlaceholder: {
        id: 'ui.eventForm.frequency.none.placeholder',
        defaultMessage: 'ui.eventForm.frequency.none.placeholder'
    },
    endDate: {
        id: 'ui.eventForm.date.end.placeholder',
        defaultMessage: 'ui.eventForm.date.end.placeholder'
    },
    endTime: {
        id: 'ui.eventForm.time.end.placeholder',
        defaultMessage: 'ui.eventForm.time.end.placeholder'
    }
});
const classes = {
    root: `${PREFIX}-root`,
    active: `${PREFIX}-active`,
    title: `${PREFIX}-title`,
    cover: `${PREFIX}-cover`,
    picker: `${PREFIX}-picker`,
    dateTime: `${PREFIX}-date-time`,
    frequency: `${PREFIX}-frequency`,
    form: `${PREFIX}-form`,
    switch: `${PREFIX}-switch`,
    switchLabel: `${PREFIX}-switch-label`,
    name: `${PREFIX}-name`,
    description: `${PREFIX}-description`,
    content: `${PREFIX}-content`,
    actions: `${PREFIX}-actions`,
    privacySection: `${PREFIX}-privacy-section`,
    privacySectionInfo: `${PREFIX}-privacy-section-info`,
    error: `${PREFIX}-error`
};
const Root = styled(Box, {
    name: PREFIX,
    slot: 'Root'
})(() => ({}));
/**
 *> API documentation for the Community-JS  Event Form component. Learn about the available props and the CSS API.
 *
 #### Import
 ```jsx
 import {EventForm} from '@selfcommunity/react-ui';
 ```

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

 #### CSS

 |Rule Name|Global class|Description|
 |---|---|---|
 |root|.SCEventForm-root|Styles applied to the root element.|
 |active|.SCEventForm-active|Styles applied to the  active element.|
 |title|.SCEventForm-title|Styles applied to the title element.|
 |cover|.SCEventForm-cover|Styles applied to the cover field.|
 |form|.SCEventForm-form|Styles applied to the form element.|
 |switch|.SCEventForm-switch|Styles applied to the switch element.|
 |switchLabel|.SCEventForm-switch-label|Styles applied to the switchLabel element.|
 |name|.SCEventForm-name|Styles applied to the name field.|
 |description|.SCEventForm-description|Styles applied to the description field.|
 |content|.SCEventForm-content|Styles applied to the  element.|
 |privacySection|.SCEventForm-privacy-section|Styles applied to the privacy section.|
 |privacySectionInfo|.SCEventForm-privacy-section-info|Styles applied to the privacy info section.|
 |error|.SCEventForm-error|Styles applied to the error elements.|

 * @param inProps
 */
export default function EventForm(inProps) {
    var _a, _b, _c;
    //PROPS
    const props = useThemeProps({
        props: inProps,
        name: PREFIX
    });
    const { className, onSuccess, onError, event = null } = props, rest = __rest(props, ["className", "onSuccess", "onError", "event"]);
    // CONTEXT
    const scContext = useSCContext();
    // INTL
    const intl = useIntl();
    const startDateTime = useMemo(() => getNewDate(event === null || event === void 0 ? void 0 : event.start_date), [event]);
    const endDateTime = useMemo(() => getNewDate(event === null || event === void 0 ? void 0 : event.end_date), [event]);
    const initialFieldState = {
        imageOriginal: (event === null || event === void 0 ? void 0 : event.image_bigger) || '',
        imageOriginalFile: '',
        startDate: event ? startDateTime : getNewDate(),
        startTime: event ? startDateTime : getLaterHoursDate(1),
        endDate: (event === null || event === void 0 ? void 0 : event.end_date) ? endDateTime : getNewDate(),
        endTime: (event === null || event === void 0 ? void 0 : event.end_date) ? endDateTime : getLaterHoursDate(3),
        location: (event === null || event === void 0 ? void 0 : event.location) || SCEventLocationType.PERSON,
        geolocation: (event === null || event === void 0 ? void 0 : event.geolocation) || '',
        lat: (event === null || event === void 0 ? void 0 : event.geolocation_lat) || null,
        lng: (event === null || event === void 0 ? void 0 : event.geolocation_lng) || null,
        link: (event === null || event === void 0 ? void 0 : event.link) || '',
        recurring: (event === null || event === void 0 ? void 0 : event.recurring) || SCEventRecurrenceType.NEVER,
        name: (event === null || event === void 0 ? void 0 : event.name) || '',
        description: event ? event.description : '',
        isPublic: (event === null || event === void 0 ? void 0 : event.privacy) === SCEventPrivacyType.PUBLIC || true,
        isSubmitting: false
    };
    // STATE
    const [field, setField] = useState(initialFieldState);
    const [error, setError] = useState({});
    // PREFERENCES
    const scPreferences = useSCPreferences();
    const privateEnabled = useMemo(() => scPreferences.preferences[SCPreferences.CONFIGURATIONS_EVENTS_PRIVATE_ENABLED].value, [scPreferences.preferences]);
    const visibilityEnabled = useMemo(() => scPreferences.preferences[SCPreferences.CONFIGURATIONS_EVENTS_VISIBILITY_ENABLED].value, [scPreferences.preferences]);
    const disablePastStartTime = useMemo(() => field.startDate.getDate() === getNewDate().getDate(), [field]);
    const disablePastEndTime = useMemo(() => field.endDate.getDate() === getNewDate().getDate(), [field]);
    const _backgroundCover = Object.assign({}, (field.imageOriginal
        ? { background: `url('${field.imageOriginal}') center / cover` }
        : { background: `url('${scPreferences.preferences[SCPreferences.IMAGES_USER_DEFAULT_COVER].value}') center / cover` }));
    const handleChangeCover = useCallback((cover) => {
        setField((prev) => (Object.assign(Object.assign({}, prev), { ['imageOriginalFile']: cover })));
        const reader = new FileReader();
        reader.onloadend = () => {
            setField((prev) => (Object.assign(Object.assign({}, prev), { ['imageOriginal']: reader.result })));
        };
        reader.readAsDataURL(cover);
        if (error.imageOriginalError) {
            delete error.imageOriginalError;
            setError(error);
        }
    }, [error]);
    /**
     * Notify when a group info changed
     * @param data
     */
    const notifyChanges = useCallback((data) => {
        if (event) {
            // Edit group
            PubSub.publish(`${SCTopicType.EVENT}.${SCGroupEventType.EDIT}`, data);
        }
        else {
            // Create group
            PubSub.publish(`${SCTopicType.EVENT}.${SCGroupEventType.CREATE}`, data);
        }
    }, [event]);
    const handleGeoData = useCallback((data) => {
        setField((prev) => (Object.assign(Object.assign({}, prev), data)));
    }, []);
    const handleSubmit = useCallback(() => {
        setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: true })));
        const formData = new FormData();
        if (field.imageOriginalFile) {
            formData.append('image_original', field.imageOriginalFile);
        }
        formData.append('name', field.name);
        formData.append('start_date', combineDateAndTime(field.startDate, field.startTime));
        formData.append('recurring', field.recurring);
        formData.append('end_date', combineDateAndTime(field.endDate, field.endTime));
        formData.append('location', field.location);
        if (field.location === SCEventLocationType.ONLINE) {
            formData.append('link', field.link);
        }
        else if (field.location === SCEventLocationType.PERSON) {
            formData.append('geolocation', field.geolocation);
            formData.append('geolocation_lat', field.lat.toString());
            formData.append('geolocation_lng', field.lng.toString());
        }
        if (privateEnabled) {
            formData.append('privacy', field.isPublic ? SCEventPrivacyType.PUBLIC : SCEventPrivacyType.PRIVATE);
        }
        if (visibilityEnabled) {
            formData.append('visible', 'true');
        }
        formData.append('description', field.description);
        let eventService;
        if (event) {
            eventService = EventService.updateEvent(event.id, formData, { headers: { 'Content-Type': 'multipart/form-data' } });
        }
        else {
            eventService = EventService.createEvent(formData, { headers: { 'Content-Type': 'multipart/form-data' } });
        }
        eventService
            .then((data) => {
            notifyChanges(data);
            setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: false })));
            onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
        })
            .catch((e) => {
            const _error = formatHttpErrorCode(e);
            if (Object.values(_error)[0]['error'] === 'unique') {
                setError(Object.assign(Object.assign({}, error), { ['nameError']: _jsx(FormattedMessage, { id: "ui.eventForm.name.error.unique", defaultMessage: "ui.eventForm.name.error.unique" }) }));
            }
            else {
                setError(Object.assign(Object.assign({}, error), _error));
            }
            setField((prev) => (Object.assign(Object.assign({}, prev), { ['isSubmitting']: false })));
            Logger.error(SCOPE_SC_UI, e);
            onError === null || onError === void 0 ? void 0 : onError(e);
        });
    }, [field, privateEnabled, visibilityEnabled, onSuccess, onError, notifyChanges]);
    const handleChange = useCallback((event) => {
        const { name, value } = event.target;
        setField((prev) => (Object.assign(Object.assign({}, prev), { [name]: value })));
        if (error[`${name}Error`]) {
            delete error[`${name}Error`];
            setError(error);
        }
    }, [setField, error]);
    const handleChangeDateTime = useCallback((value, name) => {
        setField((prev) => (Object.assign(Object.assign({}, prev), { [name]: value })));
        if (error[`${name}Error`]) {
            delete error[`${name}Error`];
            setError(error);
        }
        else if (error['endDateError']) {
            delete error['endDateError'];
            setError(error);
        }
    }, [setField, error]);
    const shouldDisableDate = useCallback((date) => {
        let disabled = false;
        switch (field.recurring) {
            case SCEventRecurrenceType.DAILY:
                disabled = date.getTime() > getLaterDaysDate(DAILY_LATER_DAYS, field.startDate).getTime();
                break;
            case SCEventRecurrenceType.WEEKLY:
                disabled = date.getTime() > getLaterDaysDate(WEEKLY_LATER_DAYS, field.startDate).getTime();
                break;
            case SCEventRecurrenceType.MONTHLY:
                disabled = date.getTime() > getLaterDaysDate(MONTHLY_LATER_DAYS, field.startDate).getTime();
                break;
            case SCEventRecurrenceType.NEVER:
            default:
                disabled = date.getTime() > getLaterDaysDate(NEVER_LATER_DAYS, field.startDate).getTime();
        }
        return disabled;
    }, [field]);
    const shouldDisableTime = useCallback((date) => field.startTime.getTime() > date.getTime(), [field]);
    /**
     * Renders root object
     */
    return (_jsxs(Root, Object.assign({ className: classNames(classes.root, className) }, rest, { children: [_jsx(Paper, Object.assign({ style: _backgroundCover, classes: { root: classes.cover } }, { children: _jsx(UploadEventCover, { isCreationMode: true, onChange: handleChangeCover }) })), _jsxs(FormGroup, Object.assign({ className: classes.form }, { children: [_jsx(TextField, { required: true, className: classes.name, placeholder: `${intl.formatMessage(messages.name)}`, margin: "normal", value: field.name, name: "name", onChange: handleChange, InputProps: {
                            endAdornment: _jsx(Typography, Object.assign({ variant: "body2" }, { children: EVENT_TITLE_MAX_LENGTH - field.name.length }))
                        }, error: Boolean(field.name.length > EVENT_TITLE_MAX_LENGTH) || Boolean(error['nameError']), helperText: field.name.length > EVENT_TITLE_MAX_LENGTH ? (_jsx(FormattedMessage, { id: "ui.eventForm.name.error.maxLength", defaultMessage: "ui.eventForm.name.error.maxLength" })) : error['nameError'] ? (error['nameError']) : null }), _jsx(Box, Object.assign({ className: classes.dateTime }, { children: _jsxs(LocalizationProvider, Object.assign({ dateAdapter: AdapterDateFns, adapterLocale: scContext.settings.locale.default === 'it' ? itLocale : enLocale }, { children: [_jsx(MobileDatePicker, { className: classes.picker, disablePast: true, label: field.startDate && _jsx(FormattedMessage, { id: "ui.eventForm.date.placeholder", defaultMessage: "ui.eventForm.date.placeholder" }), value: field.startDate, slots: {
                                        textField: (params) => (_jsx(TextField, Object.assign({}, params, { InputProps: Object.assign(Object.assign({}, params.InputProps), { placeholder: `${intl.formatMessage(messages.startDate)}`, startAdornment: (_jsx(InputAdornment, Object.assign({ position: "start" }, { children: _jsx(IconButton, { children: _jsx(Icon, { children: "CalendarIcon" }) }) }))) }) })))
                                    }, slotProps: {
                                        toolbar: {
                                            // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
                                            // @ts-ignore
                                            toolbarTitle: _jsx(FormattedMessage, { id: "ui.eventForm.date.title", defaultMessage: "ui.eventForm.date.title" })
                                        }
                                    }, onChange: (value) => handleChangeDateTime(value, 'startDate') }), _jsx(MobileTimePicker, { className: classes.picker, disablePast: disablePastStartTime, label: field.startTime && _jsx(FormattedMessage, { id: "ui.eventForm.time.placeholder", defaultMessage: "ui.eventForm.time.placeholder" }), value: field.startTime, slots: {
                                        textField: (params) => (_jsx(TextField, Object.assign({}, params, { InputProps: Object.assign(Object.assign({}, params.InputProps), { placeholder: `${intl.formatMessage(messages.startTime)}`, startAdornment: (_jsx(InputAdornment, Object.assign({ position: "start" }, { children: _jsx(IconButton, { children: _jsx(Icon, { children: "access_time" }) }) }))) }) })))
                                    }, slotProps: {
                                        toolbar: {
                                            // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
                                            // @ts-ignore
                                            toolbarTitle: _jsx(FormattedMessage, { id: "ui.eventForm.time.title", defaultMessage: "ui.eventForm.time.title" })
                                        }
                                    }, onChange: (value) => handleChangeDateTime(value, 'startTime') })] })) })), _jsxs(FormControl, Object.assign({ className: classes.frequency }, { children: [field.recurring !== SCEventRecurrenceType.NEVER && _jsx(InputLabel, Object.assign({ id: "recurring" }, { children: `${intl.formatMessage(messages.frequency)}` })), _jsx(Select, Object.assign({ name: "recurring", label: field.recurring !== SCEventRecurrenceType.NEVER && `${intl.formatMessage(messages.frequency)}`, labelId: "recurring", value: field.recurring, onChange: handleChange, displayEmpty: true, renderValue: (selected) => {
                                    if (!selected) {
                                        return _jsx("em", { children: `${intl.formatMessage(messages.frequencyPlaceholder)}` });
                                    }
                                    return (_jsx(FormattedMessage, { id: `ui.eventForm.frequency.${selected}.placeholder`, defaultMessage: `ui.eventForm.frequency.${selected}.placeholder` }));
                                }, startAdornment: _jsx(InputAdornment, Object.assign({ position: "start" }, { children: _jsx(IconButton, { children: _jsx(Icon, { children: "frequency" }) }) })) }, { children: Object.values(SCEventRecurrenceType).map((f) => (_jsx(MenuItem, Object.assign({ value: f }, { children: _jsx(FormattedMessage, { id: `ui.eventForm.frequency.${f}.placeholder`, defaultMessage: `ui.eventForm.frequency.${f}.placeholder` }) }), f))) }))] })), _jsx(Box, Object.assign({ className: classes.dateTime }, { children: _jsxs(LocalizationProvider, Object.assign({ dateAdapter: AdapterDateFns, adapterLocale: scContext.settings.locale.default === 'it' ? itLocale : enLocale }, { children: [_jsx(MobileDatePicker, { className: classes.picker, minDate: field.startDate, label: _jsx(FormattedMessage, { id: "ui.eventForm.date.end.placeholder", defaultMessage: "ui.eventForm.date.end.placeholder" }), value: field.endDate, slots: {
                                        textField: (params) => (_jsx(TextField, Object.assign({}, params, { InputProps: Object.assign(Object.assign({}, params.InputProps), { placeholder: `${intl.formatMessage(messages.endDate)}`, startAdornment: (_jsx(InputAdornment, Object.assign({ position: "start" }, { children: _jsx(IconButton, { children: _jsx(Icon, { children: "calendar_off" }) }) }))) }) })))
                                    }, slotProps: {
                                        toolbar: {
                                            // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
                                            // @ts-ignore
                                            toolbarTitle: _jsx(FormattedMessage, { id: "ui.eventForm.date.title", defaultMessage: "ui.eventForm.date.title" })
                                        }
                                    }, onChange: (value) => handleChangeDateTime(value, 'endDate'), shouldDisableDate: shouldDisableDate }), _jsx(MobileTimePicker, { className: classes.picker, disablePast: disablePastEndTime, label: field.endTime && _jsx(FormattedMessage, { id: "ui.eventForm.time.end.placeholder", defaultMessage: "ui.eventForm.time.end.placeholder" }), value: field.endTime, slots: {
                                        textField: (params) => {
                                            var _a;
                                            return (_jsx(TextField, Object.assign({}, params, { InputProps: Object.assign(Object.assign({}, params.InputProps), { placeholder: `${intl.formatMessage(messages.endTime)}`, startAdornment: (_jsx(InputAdornment, Object.assign({ position: "start" }, { children: _jsx(IconButton, { children: _jsx(Icon, { children: "access_time" }) }) }))) }), error: Boolean(error['endDateError']), helperText: ((_a = error['endDateError']) === null || _a === void 0 ? void 0 : _a.error) ? (_jsx(FormattedMessage, { id: "ui.eventForm.time.end.error.invalid", defaultMessage: "ui.eventForm.time.end.error.invalid" })) : null })));
                                        }
                                    }, slotProps: {
                                        toolbar: {
                                            // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
                                            // @ts-ignore
                                            toolbarTitle: _jsx(FormattedMessage, { id: "ui.eventForm.time.title", defaultMessage: "ui.eventForm.time.title" })
                                        }
                                    }, onChange: (value) => handleChangeDateTime(value, 'endTime'), shouldDisableTime: shouldDisableTime })] })) })), _jsx(EventAddress, { forwardGeolocationData: handleGeoData, event: event !== null && event !== void 0 ? event : null }), privateEnabled && (_jsxs(Box, Object.assign({ className: classes.privacySection }, { children: [_jsxs(Stack, Object.assign({ direction: "row", spacing: 1, alignItems: "center", justifyContent: "center" }, { children: [_jsxs(Typography, Object.assign({ className: classNames(classes.switchLabel, { [classes.active]: !field.isPublic }) }, { children: [_jsx(Icon, { children: "private" }), _jsx(FormattedMessage, { id: "ui.eventForm.privacy.private", defaultMessage: "ui.eventForm.privacy.private" })] })), _jsx(Switch, { className: classes.switch, checked: field.isPublic, onChange: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['isPublic']: !field.isPublic }))), disabled: event && !field.isPublic }), _jsxs(Typography, Object.assign({ className: classNames(classes.switchLabel, { [classes.active]: field.isPublic }) }, { children: [_jsx(Icon, { children: "public" }), _jsx(FormattedMessage, { id: "ui.eventForm.privacy.public", defaultMessage: "ui.eventForm.privacy.public" })] }))] })), _jsx(Typography, Object.assign({ variant: "body2", textAlign: "center", className: classes.privacySectionInfo }, { children: field.isPublic ? (_jsx(FormattedMessage, { id: "ui.eventForm.privacy.public.info", defaultMessage: "ui.eventForm.privacy.public.info", values: {
                                        // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
                                        // @ts-ignores
                                        b: (chunks) => _jsx("strong", { children: chunks })
                                    } })) : (_jsx(FormattedMessage, { id: "ui.eventForm.privacy.private.info", defaultMessage: "ui.eventForm.private.public.info", values: {
                                        // eslint-disable-next-line @typescript-eslint/ban-ts-ignore,@typescript-eslint/ban-ts-comment
                                        // @ts-ignore
                                        b: (chunks) => _jsx("strong", { children: chunks })
                                    } })) }))] }))), _jsx(TextField, { multiline: true, className: classes.description, placeholder: `${intl.formatMessage(messages.description)}`, margin: "normal", value: field.description, name: "description", onChange: handleChange, InputProps: {
                            endAdornment: (_jsx(Typography, Object.assign({ variant: "body2" }, { children: ((_a = field.description) === null || _a === void 0 ? void 0 : _a.length) ? EVENT_DESCRIPTION_MAX_LENGTH - field.description.length : EVENT_DESCRIPTION_MAX_LENGTH })))
                        }, error: Boolean(((_b = field.description) === null || _b === void 0 ? void 0 : _b.length) > EVENT_DESCRIPTION_MAX_LENGTH), helperText: ((_c = field.description) === null || _c === void 0 ? void 0 : _c.length) > EVENT_DESCRIPTION_MAX_LENGTH ? (_jsx(FormattedMessage, { id: "ui.eventForm.description.error.maxLength", defaultMessage: "ui.eventForm.description.error.maxLength" })) : null }), _jsx(Box, Object.assign({ className: classes.actions }, { children: _jsx(LoadingButton, Object.assign({ loading: field.isSubmitting, disabled: !field.name ||
                                !field.startDate ||
                                !field.startTime ||
                                !field.endDate ||
                                !field.endTime ||
                                (field.location === SCEventLocationType.ONLINE && !field.link) ||
                                (field.location === SCEventLocationType.PERSON && !field.geolocation) ||
                                (field.recurring !== SCEventRecurrenceType.NEVER && !field.endDate && !field.endTime) ||
                                Object.keys(error).length !== 0 ||
                                field.name.length > EVENT_TITLE_MAX_LENGTH ||
                                field.description.length > EVENT_DESCRIPTION_MAX_LENGTH, variant: "contained", onClick: handleSubmit, color: "secondary" }, { children: event ? (_jsx(FormattedMessage, { id: "ui.eventForm.button.edit", defaultMessage: "ui.eventForm.button.edit" })) : (_jsx(FormattedMessage, { id: "ui.eventForm.button.create", defaultMessage: "ui.eventForm.button.create" })) })) }))] }))] })));
}
