import { assign } from 'lodash';
import { __ } from '@wordpress/i18n';
import {
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption
} from '@wordpress/components'
import { FormTokenField } from '@wordpress/components';
export default function ControlsCommon({ attributes, setAttributes }) {
const { TrpContentRestriction } = attributes;
const allLanguages = trpBlockEditorData.all_languages;
const languageNames = Object.keys( allLanguages ).map( key => allLanguages[key] )
const handleLanguagePick = (newSelectedLanguages) => {
setAttributes({
TrpContentRestriction: assign(
{ ...TrpContentRestriction },
{ selected_languages: newSelectedLanguages }
),
});
};
const helpText = TrpContentRestriction.restriction_type === 'include'
? __("Choose in which languages to show the block.", "translatepress-multilingual")
: __("Choose from which languages the block is excluded.", "translatepress-multilingual");
const validateInput = ( token ) => {
return languageNames.includes(token);
};
const renderItem = ({ item }) => {
const languageCode = Object.keys(allLanguages).find( (key) => allLanguages[key] === item );
const flag = trpBlockEditorData.plugin_url + '/assets/images/flags/' + languageCode + '.png';
return (
{item}
);
};
return (
<>
{helpText}