<?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
 */
// phpcs:disable Magento2.Functions.DiscouragedFunction.DiscouragedWithAlternative
?>

<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": "<?= $block->escapeHtmlAttr($block->getUrl('wtai/settings/prompt')) ?>",
        "saveUrl": "<?= $block->escapeHtmlAttr($block->getUrl('wtai/settings/save')) ?>",
        "restoreUrl": "<?= $block->escapeHtmlAttr($block->getUrl('wtai/grid/restore')) ?>",
        "triggerActionAfterNDaysValue": "<?= $block->escapeHtmlAttr($block->getTriggerActionAfterNDaysValue()) ?>",
        "triggerActionPageIsRankingValue": "<?= $block->escapeHtmlAttr($block->getTriggerActionPageIsRankingValue()) ?>",
        "triggerActionNoneValue": "<?= $block->escapeHtmlAttr($block->getTriggerActionNoneValue()) ?>"
    }}'
>
    <div class="wtai-bulk-prompt-header">
        <span class="wtai-bulk-prompt-title">
            <?= $block->escapeHtml(__('Bulk keyword analysis')) ?>
        </span>
        <span class="wtai-restore">
            <a href="#" data-bind="click: restore">
                <?= $block->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/why-keyword-analysis-takes-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'
            ); ?>
        </div>
    </form>
    <div class="wtai-loading-mask" data-bind="visible: isLoading"></div>
    <div class="wtai-restore-global-mask" data-bind="visible: isRestoreGlobalLoading"></div>
</div>

<script type="text/x-magento-init">
    {
        "*": {
            "Magento_Ui/js/block-loader":
                "<?= $block->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[]": "<?= $block->escapeJs(__('Please select at least one field to rewrite.')) ?>"
            },
            "errorPlacement": function (error, element) {
                $('.wtai-tabs-error-message').html(error);
            }
        });
        $("#wtaiKeywordAnalysisPrompt").trigger('contentUpdated');
    });
</script>
<?php
// phpcs:enable Magento2.Functions.DiscouragedFunction.DiscouragedWithAlternative
?>