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

<?php
/** @var \WriteTextAI\WriteTextAI\ViewModel\Tooltip $tooltip */
/** @var \WriteTextAI\WriteTextAI\ViewModel\Permissions $permissions */
/** @var \WriteTextAI\WriteTextAI\ViewModel\Settings $settings */
/** @var \WriteTextAI\WriteTextAI\ViewModel\Timezone $timezone */

$tooltip = $block->getTooltip();
$permissions = $block->getPermissions();
$settings = $block->getSettings();
$timezone = $block->getTimezone();
?>

<div class="wtai-keyword-analysis-content" data-bind="scope: 'wtaiKeywordAnalysis'">
    <div class="wtai-keyword-analysis-header">
        <!-- ko if: showPipelines -->
        <div class="wtai-last-updated" data-bind="text: lastUpdated"></div>
        <div class="wtai-refresh-container">
            <button class="wtai-link-style-button wtai-refresh"
                data-bind="click: createSnapshotRequest,
                hidden: hideRefreshNow">
                <?= $escaper->escapeHtml(__('Refresh now')) ?>
            </button>
            <div class="wtai-refresh-loading" data-bind="visible: refreshingData">
                <?= $escaper->escapeHtml(__('Refreshing data')) ?>
            </div>
        </div>
        <!-- /ko -->
        <div class="wtai-language">
            <?= $escaper->escapeHtml(__('Language')) ?>
            <span data-bind="text: language"></span>
        </div>
        <div class="wtai-country">
            <?= $escaper->escapeHtml(__('Country')) ?>
            <span data-bind="text: country"></span>
        </div>
        <div class="wtai-help-container">
            <div class="admin__field-tooltip wtai-small">
                <a class="admin__field-tooltip-action" href="#" data-toggle="dropdown"></a>
                <div class="admin__field-tooltip-content wtai-upper-right-corner" data-target="dropdown">
                    <div class="wtai-content-wrapper">
                        <?= /* @noEscape */ $tooltip->keywordsDrawerTooltip() ?>
                    </div>
                </div>
            </div>
        </div>
        <div class="wtai-close">
            <span class="wtai-close-icon" data-bind="click: closeAnalysis"></span>
        </div>
    </div>
    <div class="wtai-keyword-analysis-failed" data-bind="visible: showFailedPage">
        <p class="wtai-failed-text" data-bind="html: failedText"></p>
        <div class="wtai-actions">
            <button class="action" data-bind="click: closeAnalysis">
                <?= $escaper->escapeHtml(__('Back')) ?>
            </button>
            <button class="action action-primary" data-bind="
                click: tryAgain,
                visible: showTryAgain
            ">
                <?= $escaper->escapeHtml(__('Try again')) ?>
            </button>
            <button class="action action-primary" data-bind="
                click: proceed,
                visible: showProceed
            ">
                <?= $escaper->escapeHtml(__('Proceed')) ?>
            </button>
        </div>
    </div>
    <div class="wtai-keyword-analysis-loading" data-bind="
        visible: showLoadingPage
    ">
        <div class="wtai-loading-container">
            <div class="wtai-spinner"></div>
            <div class="wta-loading-group">
                <div class="wtai-loading-text" data-bind="html: progressText"></div>
                <progress class="wtai-progress-bar"
                    max="100"
                    data-bind="attr: { 'value': progressPerc }"></progress>
            </div>
        </div>
    </div>
    <div class="wtai-pipelines-container" data-bind="
        css: { 'wtai-history-mode': historyMode }
    ">
        <div class="wtai-pipelines-header" data-bind="
            visible: showBack
        ">
            <div class="wtai-actions">
                <div class="wtai-history-mode-elements" data-bind="visible: showPipelines">
                    <div class="wtai-history-mode-label">
                        <?= $escaper->escapeHtml(__('Currently viewing')) ?>
                        <span class="wtai-history-mode-label-date" data-bind="text: historySelectedDatetime"></span>
                    </div>
                    <div class="wtai-history-mode-exit">
                        <button class="wtai-link-style-button" data-bind="click: exitHistoryMode">
                            <?= $escaper->escapeHtml(__('Exit')) ?>
                        </button>
                    </div>
                </div>
                <!-- ko if: showPipelines -->
                <?= /* @noEscape */ $block->getChildHtml('wtai.keyword.ranking.history') ?>
                <!-- /ko -->
            </div>
        </div>
        <?= /* @noEscape */ $block->getChildHtml('wtai.keywords.error.messages') ?>
        <!-- ko if: showPipelines -->
        <?= /* @noEscape */ $block->getChildHtml('wtai.keyword.pipelines') ?>
        <div class="wtai-keyword-analysis-loader" data-bind="visible: showLoader"></div>
        <!-- /ko -->
    </div>
    <?= /* @noEscape */ $block->getChildHtml('wtai.keyword.pool') ?>
    <!-- ko if: showPipelines -->
    <button class="wtai-go-to-bottom" data-bind="
        click: goToBottom,
        visible: showGoToBottom
    "></button>
    <!-- /ko -->
</div>

<script type="text/x-magento-init">
    {
        "*": {
            "Magento_Ui/js/core/app": {
                "components": {
                    "wtaiKeywordAnalysis": {
                        "component": "<?= $escaper->escapeJs($block->getJsComponent()) ?>",
                        "entityType": "<?= $escaper->escapeJs($block->getEntityType()) ?>",
                        "getOptimizationUrl": "<?= $escaper->escapeJs(
                            $block->getUrl('wtai/edit/keywordsOptimization_get')
                        ) ?>",
                        "deleteOptimizationUrl": "<?= $escaper->escapeJs(
                            $block->getUrl('wtai/edit/keywordsOptimization_delete')
                        ) ?>",
                        "updateOptimizationUrl": "<?= $escaper->escapeJs(
                            $block->getUrl('wtai/edit/keywordsOptimization_update')
                        ) ?>",
                        "createSnapshotUrl": "<?= $escaper->escapeJs(
                            $block->getUrl('wtai/edit/snapshots_create')
                        ) ?>",
                        "timezone": "<?= $escaper->escapeJs($timezone->getTimezone()) ?>",
                        "audienceGetUrl": "<?= $escaper->escapeJs($block->getUrl('wtai/edit/audience_get')) ?>",
                        "audienceGetUrlCategories":
                            "<?= $escaper->escapeJs($block->getUrl('wtai/categories/edit_audience_get')) ?>"
                    }
                }
            }
        }
    }
</script>