<?php
/**
 * @author 1902 Software
 * @copyright Copyright © 2023 1902 Software (https://1902software.com/magento/)
 * @package WriteTextAI_WriteTextAI
 */

$slugs = $block->getRequest()->getParam('wtai_slugs', '');
$storeId = $block->getRequest()->getParam('wtai-store-id', 0);
?>

<?php if (!empty($slugs)): ?>
<div id="wtai-cannibalization-analyzer-container" data-bind="scope: 'wtaiSlugAnalyzer'">
    <div class="wtai-cannibalization-preloader">
        <div class="logo">
            <img src="<?= /** @noEscape */ $block->getViewFileUrl(
                'WriteTextAI_WriteTextAI::images/logo_writetext.png'
                      ) ?>" alt="WriteText.ai">
        </div>
        <div class="title"><?= $block->escapeHtml(__('Preparing your keyword cannibalization report')) ?></div>
        <div class="subtitle">
            <p>
                <?= $block->escapeHtml(__('We’re reviewing the URLs that are ranking for'
                    . ' the same keyword to determine their page types (product, category, or CMS page)'
                    . ' and apply the correct filters for display.')) ?>
            </p>
            <p>
                <?= $block->escapeHtml(__('Hang tight—this will only take a moment.'
                    . ' Please don’t close or refresh the page.')) ?>
            </p>
        </div>
    </div>
</div>
<script type="text/x-magento-init">
    {
        "*": {
            "Magento_Ui/js/core/app": {
                "components": {
                    "wtaiSlugAnalyzer": {
                        "component": "WriteTextAI_WriteTextAI/js/grid/slug-analyzer",
                        "analyzeUrl": "<?= $block->escapeJs($block->getUrl('wtai/cannibalization/analyzeSlugs')) ?>",
                        "productsUrl": "<?= $block->escapeJs($block->getUrl('wtai/grid/index')) ?>",
                        "categoriesUrl": "<?= $block->escapeJs($block->getUrl('wtai/categories/index')) ?>",
                        "slugs": "<?= $block->escapeJs($slugs) ?>",
                        "storeId": "<?= $block->escapeJs($storeId) ?>"
                    }
                }
            }
        }
    }
</script>
<script>
    require([
        'jquery'
    ], function ($) {
        $(document).ready(function() {
            $('.wtai-grid-index').addClass('wtai-cannibalizing');
        });
    });
</script>
<?php endif; ?>