import React, { useState } from 'react';
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import toastr from 'toastr';
import { useTranslation } from '../../providers/TranslationProvider';
import { Icon } from '../../basic/Icon';
import { useReactiveValue } from '../../../hooks/useReactiveValue';
import { Button } from '../../basic/Button';
import { handleError } from '../../../../app/utils/client';
export function StringSettingInput({
_id,
multiline,
value,
placeholder,
readonly,
autocomplete,
disabled,
onChange,
}) {
const handleChange = (event) => {
const { value } = event.currentTarget;
onChange({ value });
};
if (multiline) {
return ;
}
return ;
}
export function RelativeUrlSettingInput({
_id,
value,
placeholder,
readonly,
autocomplete,
disabled,
onChange,
}) {
const handleChange = (event) => {
const { value } = event.currentTarget;
onChange({ value });
};
return ;
}
export function PasswordSettingInput({
_id,
value,
placeholder,
readonly,
autocomplete,
disabled,
onChange,
}) {
const handleChange = (event) => {
const { value } = event.currentTarget;
onChange({ value });
};
return ;
}
export function IntSettingInput({
_id,
value,
placeholder,
readonly,
autocomplete,
disabled,
onChange,
}) {
const handleChange = (event) => {
const value = parseInt(event.currentTarget.value, 10);
onChange({ value });
};
return ;
}
export function SelectSettingInput({
_id,
value,
readonly,
values,
disabled,
onChange,
}) {
const t = useTranslation();
const handleChange = (event) => {
const { value } = event.currentTarget;
onChange({ value });
};
return
;
}
export function LanguageSettingInput({
_id,
value,
readonly,
disabled,
onChange,
}) {
const languages = useReactiveValue(() => {
const languages = TAPi18n.getLanguages();
const result = Object.entries(languages)
.map(([key, language]) => ({ ...language, key: key.toLowerCase() }))
.sort((a, b) => a.key - b.key);
result.unshift({
name: 'Default',
en: 'Default',
key: '',
});
return result;
}, []);
const handleChange = (event) => {
const { value } = event.currentTarget;
onChange({ value });
};
return
;
}
export function ColorSettingInput({
_id,
value,
editor,
allowedTypes,
autocomplete,
disabled,
onChange,
}) {
const t = useTranslation();
const handleChange = (event) => {
const { value } = event.currentTarget;
onChange({ value });
};
const handleEditorTypeChange = (event) => {
const editor = event.currentTarget.value.trim();
onChange({ editor });
};
return <>
{editor === 'color' &&
}
{editor === 'expression' &&
}
Variable name: {_id.replace(/theme-color-/, '@')}
>;
}
export function FontSettingInput({
_id,
value,
placeholder,
readonly,
autocomplete,
disabled,
onChange,
}) {
const handleChange = (event) => {
const { value } = event.currentTarget;
onChange({ value });
};
return ;
}
export function CodeSettingInput({
_id,
i18nLabel,
disabled,
}) {
const t = useTranslation();
return disabled
? <>{/* {> CodeMirror name=_id options=(getEditorOptions true) code=(i18nDefaultValue) }*/}>
:
{(i18nLabel && t(i18nLabel)) || (_id || t(_id))}
{/* {> CodeMirror name=_id options=getEditorOptions code=value editorOnBlur=setEditorOnBlur}*/}
;
}
export function ActionSettingInput({
value,
actionText,
disabled,
didSectionChange,
}) {
const t = useTranslation();
const handleClick = async () => {
Meteor.call(value, (err, data) => {
if (err) {
err.details = Object.assign(err.details || {}, {
errorTitle: 'Error',
});
handleError(err);
return;
}
const args = [data.message].concat(data.params);
toastr.success(TAPi18n.__.apply(TAPi18n, args), TAPi18n.__('Success'));
});
};
return didSectionChange
? {t('Save_to_enable_this_action')}
: ;
}
export function AssetSettingInput({
value,
fileConstraints,
}) {
const t = useTranslation();
return value.url
?
: ;
}
export function RoomPickSettingInput({ _id }) {
// const collection = usePrivateSettingsCollection();
const [selectedRooms] = useState({});
// useEffect(() => {
// const withRoomPickType = (f) => (data) => {
// if (data.type !== 'roomPick') {
// return;
// }
// f(data);
// };
// collection.find().observe({
// added: withRoomPickType((data) => {
// setSelectedRooms({
// ...selectedRooms,
// [data._id]: data.value,
// });
// }),
// changed: withRoomPickType((data) => {
// setSelectedRooms({
// ...selectedRooms,
// [data._id]: data.value,
// });
// }),
// removed: withRoomPickType((data) => {
// setSelectedRooms(
// Object.entries(selectedRooms)
// .filter(([key]) => key !== data._id)
// .reduce((obj, [key, value]) => ({ ...obj, [key]: value }), {})
// );
// }),
// });
// }, [collection]);
return
{/* {{> inputAutocomplete settings=autocompleteRoom id=_id name=_id class="search autocomplete rc-input__element" autocomplete="off" disabled=isDisabled.disabled}} */}
{(selectedRooms[_id] || []).map(({ name }) =>
-
{name}
)}
;
}