/**
 * WP Agentic Writer - Test Script
 *
 * @package WP_Agentic_Writer
 */

console.log('WP Agentic Writer script loaded!');
console.log('wpAgenticWriter data:', typeof wpAgenticWriter !== 'undefined' ? wpAgenticWriter : 'NOT DEFINED');

// Check if wp object is available
if (typeof wp !== 'undefined') {
	console.log('WordPress wp object available:', wp);
} else {
	console.error('WordPress wp object NOT available');
}

// Check dependencies
const deps = {
	wp: typeof wp !== 'undefined',
	element: typeof wp !== 'undefined' && typeof wp.element !== 'undefined',
	components: typeof wp !== 'undefined' && typeof wp.components !== 'undefined',
	data: typeof wp !== 'undefined' && typeof wp.data !== 'undefined',
	i18n: typeof wp !== 'undefined' && typeof wp.i18n !== 'undefined',
};

console.log('Dependencies check:', deps);

// Try to register a simple plugin
if (deps.wp && deps.element && deps.components) {
	const { registerPlugin } = wp.plugins;
	const { PluginSidebar } = wp.editPost;
	const { Panel, PanelBody } = wp.components;
	const { __ } = wp.i18n;

	const TestSidebar = () => {
		return wp.element.createElement(
			PluginSidebar,
			{ name: 'wp-agentic-writer-test', title: 'WP Agentic Writer Test' },
			wp.element.createElement(
				Panel,
				null,
				wp.element.createElement(
					PanelBody,
					null,
					wp.element.createElement('p', null, 'Plugin loaded successfully! 🎉')
				)
			)
		);
	};

	registerPlugin('wp-agentic-writer-test', {
		icon: 'edit',
		render: TestSidebar,
	});

	console.log('Plugin registered successfully!');
} else {
	console.error('Cannot register plugin - missing dependencies');
}
