import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
import { Button, PanelBody, Placeholder, Spinner } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { __, sprintf } from '@wordpress/i18n';
import { ReactComponent as ElementIcon } from '../../assets/admin/images/icon-gutenberg.svg';
import IframePreview from '../components/iframe-preview';
import SelectControl from '../components/select-control';
const { plugin_name: pluginName } = window.VPGutenbergVariables;
/**
* Block Edit Class.
*
* @param props
*/
export default function BlockEdit(props) {
const { clientId, setAttributes, attributes } = props;
const { id } = attributes;
const { portfolioLayouts } = useSelect(
(select) => ({
portfolioLayouts: select('visual-portfolio').getPortfolioLayouts(),
}),
[]
);
function getSelector() {
let portfolioLayoutsSelect = false;
let currentItemUrl = false;
// prepare portfolios list.
if (portfolioLayouts) {
portfolioLayoutsSelect = {
'': __('--- Select Layout ---', 'visual-portfolio'),
};
Object.keys(portfolioLayouts).forEach((key) => {
const val = portfolioLayouts[key];
portfolioLayoutsSelect[
` ${val.id}`
] = `${val.title} (#${val.id})`;
if (id && parseInt(id, 10) === val.id) {
currentItemUrl = val.edit_url;
}
});
} else if (id) {
portfolioLayoutsSelect = {
[` ${id}`]: `#${id}`,
};
}
return (
<>
{!portfolioLayoutsSelect ?