import classnames from 'classnames/dedupe';
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
import {
ExternalLink,
PanelBody,
Placeholder,
Spinner,
TextControl,
ToggleControl,
} from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { applyFilters } from '@wordpress/hooks';
import { __ } from '@wordpress/i18n';
import GapSettings from '../../components/gap-settings';
import RangeControl from '../../components/range-control';
import getIcon from '../../utils/get-icon';
/**
* Block Edit Class.
*
* @param props
*/
export default function BlockEdit(props) {
const { setAttributes, attributes } = props;
let { className } = props;
const {
accessToken,
count,
columns,
gap,
gapCustom,
showProfileAvatar,
profileAvatarSize,
showProfileName,
showProfileStats,
showProfileBio,
showProfileWebsite,
} = attributes;
const { instagramFeed, instagramProfile } = useSelect((select) => {
if (!accessToken) {
return false;
}
return {
instagramFeed: select('ghostkit/blocks/instagram').getInstagramFeed(
{
access_token: accessToken,
count,
}
),
instagramProfile: select(
'ghostkit/blocks/instagram'
).getInstagramProfile({
access_token: accessToken,
}),
};
});
const showProfile =
attributes.showProfile &&
(showProfileName ||
showProfileAvatar ||
showProfileBio ||
showProfileWebsite ||
showProfileStats);
className = classnames(
'ghostkit-instagram',
gap && `ghostkit-instagram-gap-${gap}`,
columns && `ghostkit-instagram-columns-${columns}`,
className
);
className = applyFilters('ghostkit.editor.className', className, props);
const blockProps = useBlockProps({ className });
return (
<>
{__(
'A valid Access Token is required to use Instagram feed. How to get token',
'ghostkit'
)}{' '}