{*
 * Alsendo - PrestaShop shipping module
 *
 * CloudSync dependency resolver. Renders the PrestaShop MBO CDC widget that lets
 * the merchant install/enable the required components (ps_mbo, ps_accounts,
 * ps_eventbus) with one click, then reloads back into the module configuration.
 *
 * @author    Innovation Software
 * @copyright 2026 Innovation Software
 * @license   https://opensource.org/licenses/AFL-3.0  Academic Free License (AFL 3.0)
 *}
<div class="panel">
    <h3>
        <i class="icon icon-cogs"></i>
        {l s='Required PrestaShop components' mod='alsendo'}
    </h3>
    <p>
        {l s='Before configuring Alsendo, the following PrestaShop components must be installed and enabled. Use the button below to install them automatically.' mod='alsendo'}
    </p>

    {* Fallback list, also drives the CDC widget below *}
    <ul>
        {foreach from=$dependencies.dependencies item=dependency}
            <li>
                <strong>{$dependency.name|escape:'html':'UTF-8'}</strong>
                {if isset($dependency.installed) && $dependency.installed && isset($dependency.enabled) && $dependency.enabled}
                    &mdash; {l s='OK' mod='alsendo'}
                {else}
                    &mdash; {l s='not installed / disabled' mod='alsendo'}
                {/if}
            </li>
        {/foreach}
    </ul>

    {* PrestaShop CDC dependency resolver widget *}
    <script src="https://assets.prestashop3.com/dst/mbo/v1/mbo-cdc-dependencies-resolver.umd.js"></script>
    <div id="cdc-container"></div>

    <script defer>
        (function () {
            if (!window.mboCdcDependencyResolver || typeof window.mboCdcDependencyResolver.render !== 'function') {
                return;
            }
            var data = {$dependencies_json nofilter};
            var context = Object.assign({}, data, {
                onDependenciesResolved: function () { window.location.reload(); },
                onDependencyResolved: function (d) { /* one dependency installed */ },
                onDependencyFailed: function (d) { /* one dependency failed */ },
                onDependenciesFailed: function () { /* resolution failed */ }
            });
            window.mboCdcDependencyResolver.render(context, '#cdc-container');
        })();
    </script>
</div>
