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

<?php
/**
 * @var WriteTextAI\WriteTextAI\Block\Adminhtml\Grid\KeywordAnalysisPrompt $block
 */
?>

<div class="wtai-bulk-keyword-analysis-form-container"
    id="wtaiKeywordAnalysisPrompt"
    data-bind="scope: 'wtaiKeywordAnalysisPrompt'"
    data-mage-init='{"WriteTextAI_WriteTextAI/js/grid/massactions/keyword-analysis-prompt": {
        "getSettingsUrl": "<?= $escaper->escapeHtmlAttr($block->getUrl('wtai/settings/prompt')) ?>",
        "saveUrl": "<?= $escaper->escapeHtmlAttr($block->getUrl('wtai/settings/save')) ?>",
        "saveConfigUrl": "<?= $escaper->escapeHtmlAttr($block->getUrl('wtai/settings/saveconfig')) ?>",
        "restoreUrl": "<?= $escaper->escapeHtmlAttr($block->getUrl('wtai/grid/restore')) ?>",
        "triggerActionAfterNDaysValue": "<?= $escaper->escapeHtmlAttr($block->getTriggerActionAfterNDaysValue()) ?>",
        "triggerActionPageIsRankingValue":
            "<?= $escaper->escapeHtmlAttr($block->getTriggerActionPageIsRankingValue()) ?>",
        "triggerActionNoneValue": "<?= $escaper->escapeHtmlAttr($block->getTriggerActionNoneValue()) ?>"
    }}'
>
    <div class="wtai-bulk-prompt-header">
        <span class="wtai-bulk-prompt-title">
            <?= $escaper->escapeHtml(__('Bulk keyword analysis')) ?>
        </span>
        <span class="wtai-global-settings-wrapper">
            <a href="#" data-bind="click: save">
                <?= $escaper->escapeHtml(__('Save to global settings')) ?>
            </a>
            <span class="wtai-separator"> | </span>
            <a href="#" data-bind="click: restore">
                <?= $escaper->escapeHtml(__('Restore global settings')) ?>
            </a>
        </span>
    </div>
    <p class="wtai-subtitle">
        <?= /* @noEscape */ sprintf(
            __('AI-powered keyword analysis may take a while to'
                    . ' complete with how extensive the process is, so doing bulk keyword analysis is encouraged.'
                    . ' <a href="%s" target="_blank">Understand why it takes time</a>.'
                    . ' You will receive an email once bulk processing is done.'
                    . ' Email notification settings can be configured in your account at'
                    . ' <a href="%s" target="_blank">platform.writetext.ai</a>'),
            'https://writetext.ai/knowledge-base/seo-geo-aeo/why-does-keyword-analysis-take-so-much-time',
            'https://platform.writetext.ai/email-notifications/'
        ) ?>
    </p>
    <div class="wtai-tabs-error-message"></div>
    <form method="post" id="wtaiBulkKeywordAnalysisForm" class="wtai-bulk-generate-form">
        <input type="hidden" name="auto_optimize_keywords" value="true" />
        <div class="wtai-form-fields">
            <?= /* @noEscape */ $block->createBlockContent(
                'WriteTextAI_WriteTextAI::grid/massactions/tabs/keyword_analysis.phtml',
                \WriteTextAI\WriteTextAI\Block\Adminhtml\Grid\Prompt::class
            ); ?>
        </div>
    </form>
    <div class="wtai-loading-mask" data-bind="visible: isLoading"></div>
    <div class="wtai-restore-global-mask" data-bind="visible: isRestoreGlobalLoading"></div>
    <div class="wtai-save-global-mask" data-bind="visible: isSaveGlobalLoading "></div>
</div>

<script type="text/x-magento-init">
    {
        "*": {
            "Magento_Ui/js/block-loader":
                "<?= $escaper->escapeJs($block->getViewFileUrl('images/loader-1.gif')) ?>"
        }
    }
</script>

<script>
    require([
    "jquery",
    "mage/mage",
    "mage/validation"
    ], function($) {
        $('#wtaiBulkKeywordAnalysisForm').mage('validation', {
            "rules": {
                "search_intent[]": {
                    "required": true
                },
                "cluster_count": {
                    "required": true
                },
                "automatic_text_optimization": {
                    "required": true
                },
                "product_texts[]": {
                    required: true
                }
            },
            "messages": {
                "product_texts[]": "<?= $escaper->escapeJs(__('Please select at least one field to rewrite.')) ?>"
            },
            "errorPlacement": function (error, element) {
                $('.wtai-tabs-error-message').html(error);
            }
        });
        $("#wtaiKeywordAnalysisPrompt").trigger('contentUpdated');
    });
</script>
<?php
?>