import React from 'react';
import { addons, types } from '@storybook/addons';
import { STORY_RENDERED, DOCS_RENDERED } from '@storybook/core-events';
import { setBodyClass } from './SrUiPlugin';
import SrUiPropsWrapper from './components/SrUiPropsWrapper';

const ADDON_ID = 'srUi';
const PANEL_ID = `${ADDON_ID}/panel`;

addons.register(ADDON_ID, api => {
	console.log('---- SR UI Plugin registered', api);

	// Add hooks for custom body class
	api.on(STORY_RENDERED, () => setBodyClass(api));
	api.on(DOCS_RENDERED, () => setBodyClass(api));

	// Register props panel
	addons.add(PANEL_ID, {
		type: types.PANEL,
		title: 'API',
		render: SrUiPropsWrapper
	});
});

export { ADDON_ID };
