import classnames from 'classnames/dedupe';
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
import { PanelBody, SelectControl, ToggleControl } from '@wordpress/components';
import { applyFilters } from '@wordpress/hooks';
import { __ } from '@wordpress/i18n';
import {
FieldDefaultSettings,
getFieldAttributes,
} from '../../field-attributes';
import FieldDescription from '../../field-description';
import FieldLabel from '../../field-label';
import FieldOptions from '../../field-options';
/**
* Block Edit Class.
*
* @param props
*/
export default function BlockEdit(props) {
const { attributes, setAttributes, isSelected } = props;
const { multiple } = attributes;
let { options } = attributes;
let { className = '' } = props;
className = classnames(
'ghostkit-form-field ghostkit-form-field-select',
className
);
className = applyFilters('ghostkit.editor.className', className, props);
if (!options || !options.length) {
options = [
{
label: '',
value: '',
selected: false,
},
];
}
let selectVal = multiple ? [] : '';
options.forEach((data) => {
if (multiple && data.selected) {
selectVal.push(data.value);
} else if (!multiple && !selectVal && data.selected) {
selectVal = data.value;
}
});
const blockProps = useBlockProps({ className });
return (
<>