<?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.svg')
                ?>"
                alt="WriteText.ai"
            >
        </div>
        <div class="title"><?= $escaper->escapeHtml(__('Preparing your keyword cannibalization report')) ?></div>
        <div class="subtitle">
            <p>
                <?= $escaper->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>
                <?= $escaper->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": "<?= $escaper->escapeJs($block->getUrl('wtai/cannibalization/analyzeSlugs')) ?>",
                        "productsUrl": "<?= $escaper->escapeJs($block->getUrl('wtai/grid/index')) ?>",
                        "categoriesUrl": "<?= $escaper->escapeJs($block->getUrl('wtai/categories/index')) ?>",
                        "slugs": "<?= $escaper->escapeJs($slugs) ?>",
                        "storeId": "<?= $escaper->escapeJs($storeId) ?>"
                    }
                }
            }
        }
    }
</script>
<script>
    require([
        'jquery'
    ], function ($) {
        $(document).ready(function() {
            $('.wtai-grid-index').addClass('wtai-cannibalizing');
        });
    });
</script>
<?php endif; ?>