/**
 * WordPress dependencies
 */
import { useDispatch } from '@safe-wordpress/data';
import { PluginPostStatusInfo } from '@safe-wordpress/editor';
import { store as EDIT_POST } from '@safe-wordpress/edit-post';

/**
 * External dependencies
 */
import {
	QualityAnalysisSummary,
	SocialMediaSummary,
	store as NC_EDIT_POST,
} from '@nelio-content/edit-post';

/**
 * Internal dependencies
 */
import { useIsFeatureEnabled } from '~/nelio-content-pages/post/gutenberg/plugin/hooks';

export type PostStatusInfoProps = {
	readonly isQualityFullyIntegrated?: boolean;
};

export const PostStatusInfo = ( {
	isQualityFullyIntegrated,
}: PostStatusInfoProps ): JSX.Element => {
	const { openGeneralSidebar } = useDispatch( EDIT_POST );
	const { togglePanel } = useDispatch( NC_EDIT_POST );
	const viewAnalysisDetails = () => {
		void togglePanel( 'post-quality-analysis', true );
		// @ts-expect-error This function should be defined.
		void openGeneralSidebar(
			'nelio-content/nelio-content-content-tools-sidebar'
		);
	};

	const areQualityChecksEnabled = useIsFeatureEnabled( 'quality-checks' );
	const isSocialMediaEnabled = useIsFeatureEnabled( 'social' );

	return (
		<>
			{ !! isQualityFullyIntegrated && !! areQualityChecksEnabled && (
				<PluginPostStatusInfo>
					<QualityAnalysisSummary onClick={ viewAnalysisDetails } />
				</PluginPostStatusInfo>
			) }
			{ !! isSocialMediaEnabled && (
				<PluginPostStatusInfo>
					<SocialMediaSummary />
				</PluginPostStatusInfo>
			) }
		</>
	);
};
