import { __, sprintf } from '@wordpress/i18n'
import ExtendifyLibrary from '../../ExtendifyLibrary'
import { Modal, Button, ButtonGroup } from '@wordpress/components'
import { render } from '@wordpress/element'
import InstallingModal from './InstallingModal'
import { useWantedTemplateStore } from '../../state/Importing'
import { getPluginDescription } from '../../util/general'
import { useUserStore } from '../../state/User'
import NeedsPermissionModal from '../NeedsPermissionModal'
export default function RequiredPluginsModal({
forceOpen,
buttonLabel,
title,
message,
requiredPlugins,
}) {
// If there's a template in cache ready to be installed.
// TODO: this could probably be refactored out when overhauling required plugins
const wantedTemplate = useWantedTemplateStore(
(store) => store.wantedTemplate,
)
requiredPlugins =
requiredPlugins ?? wantedTemplate?.fields?.required_plugins
const closeModal = () => {
if (forceOpen) {
return
}
render(
,
document.getElementById('extendify-root'),
)
}
const installPlugins = () =>
render(
,
document.getElementById('extendify-root'),
)
if (!useUserStore.getState()?.canInstallPlugins) {
return
}
return (
{message ??
__(
sprintf(
'There is just one more step. This %s requires the following to be automatically installed and activated:',
wantedTemplate?.fields?.type ?? 'template',
),
'extendify',
)}
{message?.length > 0 || (
{
// Hardcoded temporarily to not force EP install
// requiredPlugins.map((plugin) =>
requiredPlugins
.filter((p) => p !== 'editorplus')
.map((plugin) => (