<?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">
                <?= $block->escapeHtml(__('Refresh now')) ?>
            </button>
            <div class="wtai-refresh-loading" data-bind="visible: refreshingData">
                <?= $block->escapeHtml(__('Refreshing data')) ?>
            </div>
        </div>
        <!-- /ko -->
        <div class="wtai-language">
            <?= $block->escapeHtml(__('Language')) ?>
            <span data-bind="text: language"></span>
        </div>
        <div class="wtai-country">
            <?= $block->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">
                <?= $block->escapeHtml(__('Back')) ?>
            </button>
            <button class="action action-primary" data-bind="
                click: tryAgain,
                visible: showTryAgain
            ">
                <?= $block->escapeHtml(__('Try again')) ?>
            </button>
            <button class="action action-primary" data-bind="
                click: proceed,
                visible: showProceed
            ">
                <?= $block->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">
                        <?= $block->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">
                            <?= $block->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": "<?= $block->escapeJs($block->getJsComponent()) ?>",
                        "entityType": "<?= $block->escapeJs($block->getEntityType()) ?>",
                        "getOptimizationUrl": "<?= $block->escapeJs(
                            $block->getUrl('wtai/edit/keywordsOptimization_get')
                        ) ?>",
                        "deleteOptimizationUrl": "<?= $block->escapeJs(
                            $block->getUrl('wtai/edit/keywordsOptimization_delete')
                        ) ?>",
                        "updateOptimizationUrl": "<?= $block->escapeJs(
                            $block->getUrl('wtai/edit/keywordsOptimization_update')
                        ) ?>",
                        "createSnapshotUrl": "<?= $block->escapeJs(
                            $block->getUrl('wtai/edit/snapshots_create')
                        ) ?>",
                        "timezone": "<?= $block->escapeJs($timezone->getTimezone()) ?>",
                        "audienceGetUrl": "<?= $block->escapeJs($block->getUrl('wtai/edit/audience_get')) ?>",
                        "audienceGetUrlCategories":
                            "<?= $block->escapeJs($block->getUrl('wtai/categories/edit_audience_get')) ?>"
                    }
                }
            }
        }
    }
</script>