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

<?php
$entityType = $block->getEntityType();
?>

<div data-bind="scope: 'wtaiKeywordsProgress'">
    <div class="wtai-progress-bar-container wtai-keywords-section wtai-no-display" data-bind="
        css: { 'wtai-no-display': !showProgress() }
    ">
        <div class="wtai-message-container" data-bind="css: { 'wtai-no-comment': commentHidden }">
            <div class="wtai-user-status-container">
                <div class="wtai-user-status" data-bind="css: {
                    'wtai-completed': showPipelines,
                    'wtai-error': showFailedPage
                }">
                    <div class="wtai-content" data-bind="css: { 'wtai-is-uploading': isUploading() }">
                        <span class="wtai-label" data-bind="
                            html: progressText,
                            hidden: showFailedPage
                        "></span>
                        <span class="wtai-label wtai-error" data-bind="
                            html: failedText,
                            visible: showFailedPage
                        "></span>
                        <progress class="wtai-progress-bar"
                            max="100"
                            data-bind="
                                attr: { 'value': progressPerc },
                                hidden: showFailedPage
                            "
                        ></progress>
                    </div>
                    <div class="wtai-action">
                        <!-- <button class="wtai-cancel" data-bind="
                            click: cancelRequest,
                            disable: cancelling() || !cancelable(),
                            hidden: showTryAgain
                        ">
                            <span><?= $escaper->escapeHtml(__('Cancel')) ?></span>
                        </button> -->
                        <button class="wtai-cancel" data-bind="
                            visible: showTryAgain,
                            click: cancel
                        ">
                            <span><?= $escaper->escapeHtml(__('Cancel')) ?></span>
                        </button>
                        <button class="wtai-cancel" data-bind="
                            visible: showTryAgain,
                            click: tryAgain
                        ">
                            <span><?= $escaper->escapeHtml(__('Restart')) ?></span>
                        </button>
                    </div>
                </div>
            </div>
            <div class="wtai-comment" data-bind="hidden: showFailedPage">
                <span><?=
                    $escaper->escapeHtml(__('These processes run in the background.'
                        . ' You can safely navigate away from this page'
                        . ' (i.e., close the tab and come back later) while these are'
                        . ' in progress.')); ?>
                </span>
                <br><br>
                <?php if ($entityType == 'Product'): ?>
                    <span><?=
                        /* @noEscape */ __('Keyword analysis can take 3–10 minutes due to the'
                        . ' detailed processing required. <strong>For a more efficient workflow,'
                        . ' select multiple products in the grid view and do bulk keyword analysis.</strong>'
                        . ' This lets you handle other tasks while'
                        . ' the analysis runs in the background. Once complete, you can review and adjust keywords,'
                        . ' then generate text. You can also choose full automation'
                        . ' so text is generated and optionally transferred right after analysis.'); ?>
                </span>
                <?php elseif ($entityType == 'Category'): ?>
                    <span><?=
                        /* @noEscape */ __('Keyword analysis can take 3–10 minutes due to the'
                        . ' detailed processing required.'); ?>
                <?php endif; ?>
                <br><br>
                <span><?=
                    /* @noEscape */ sprintf(
                        __('There is a very logical reason why keyword analysis takes time.'
                            . ' <a href="%s" target="_blank">Read to learn more.</a>'),
                        'https://writetext.ai/knowledge-base/seo-geo-aeo/why-does-keyword-analysis-take-so-much-time'
                    ) ?>
                </span>
            </div>
            <button class="wtai-see-more" data-bind="
                click: showComment,
                visible: commentHidden() && !showFailedPage()
            ">
                <span><?= $escaper->escapeHtml(__('View')) ?></span>
            </button>
            <button class="wtai-see-less" data-bind="
                click: hideComment,
                hidden: commentHidden() || showFailedPage()
            ">
                <span><?= $escaper->escapeHtml(__('Hide')) ?></span>
            </button>
        </div>
    </div>
</div>
<script type="text/x-magento-init">
    {
        "*": {
            "Magento_Ui/js/core/app": {
                "components": {
                    "wtaiKeywordsProgress": {
                        "component": "WriteTextAI_WriteTextAI/js/edit/keywords/progress",
                        "deleteOptimizationUrl": "<?= $escaper->escapeJs(
                            $block->getUrl('wtai/edit/keywordsOptimization_delete')
                        ) ?>",
                        "updateOptimizationUrl": "<?= $escaper->escapeJs(
                            $block->getUrl('wtai/edit/keywordsOptimization_update')
                        ) ?>",
                        "entityType": "<?= $escaper->escapeJs($entityType) ?>",
                        "cancelUrl": "<?= $escaper->escapeJs($block->getUrl('wtai/grid/generate_cancel')) ?>"
                    }
                }
            }
        }
    }
</script>
