<?php
/**
 * @var WriteTextAI\WriteTextAI\Block\Adminhtml\Setup\Index\Keywords $block
 */

$autoTransferSchedule = $block->getAutoTransferSchedule();
$isCronRunning = $block->isCronRunning();
$cronJobDisabledMessage = $block->getCronJobDisabledMessage();
$defaultAutoTransferSchedule = $block->getAutotransferSettings('cron_schedule');
$timezone = $block->getTimezone();
$hasProAccess = $block->getHasProAccess();
$isDisabledClass = $hasProAccess ? '' : 'wtai-disabled';
?>
<fieldset class="wtai-fieldset wtai-auto-transfer">
    <div class="wtai-fieldset-title">
        <?= $escaper->escapeHtml(__('Set time for auto text transfer and new product detection')) ?>
        <?php if (!$hasProAccess): ?>
            <span class="wtai-premium">
                <?= $escaper->escapeHtml(__('PRO')) ?>
            </span>
        <?php endif; ?>
    </div>
    <p class="wtai-fieldset-content">
        <?= $escaper->escapeHtml(__(
            "At the selected time, WriteText.ai will check your connected webshop(s) for newly"
            . " added products and send you an email notification if any are found. This"
            . " lets you decide whether to generate content for these products — individually,"
            . " in bulk, or through a Full Automation run."
        )) ?>
    </p>
    <p class="wtai-fieldset-content">
        <?= $escaper->escapeHtml(__(
            "Detection is scheduled once per day to balance performance and reliability,"
            . " preventing unnecessary load on your webshop while ensuring you stay updated"
            . " on new product additions."
        )) ?>
    </p>
    <p class="wtai-fieldset-content">
        <?= $escaper->escapeHtml(__(
            "Make sure your server can handle scheduled tasks efficiently. We recommend"
            . " verifying the following minimum PHP settings with your hosting provider:"
        )) ?>
    </p>
    <ul class="wtai-fieldset-content wtai-ul-padding-left">
        <li><?= $escaper->escapeHtml(__('PHP max_execution_time: 3600 seconds')) ?></li>
        <li><?= $escaper->escapeHtml(__('PHP memory_limit: 524M')) ?></li>
    </ul>
    <p class="wtai-fieldset-content">
        <?= $escaper->escapeHtml(__(
            "This helps prevent timeouts and ensures smooth publishing."
        )) ?>
    </p>
    <div class="<?= $escaper->escapeHtmlAttr($isDisabledClass) ?> wtai-field-column-container">
        <span class="tooltip-toggle"></span>
        <?php if (!$hasProAccess): ?>
            <span class="tooltip-content">
                <?= $escaper->escapeHtml(__('These settings are enabled for Pro accounts only.')) ?>
            </span>
        <?php endif; ?>
        <div class="wtai-field-column">
            <div class="wtai-fieldset-title">
                <?= $escaper->escapeHtml(__('Set daily automation time')) ?>
            </div>
            <div class="wtai-field admin__field row">
                <div class="wtai-control">
                    <select name="auto_transfer_schedule" class="admin__control-select"
                        <?php if (!$isCronRunning): ?>
                            disabled
                        <?php endif ?>
                    >
                        <?php foreach ($autoTransferSchedule as $data): ?>
                            <option value="<?= $escaper->escapeHtmlAttr($data['value']) ?>"
                                <?php if ($defaultAutoTransferSchedule === $data['value']): ?>
                                    selected
                                <?php endif ?>
                            ><?= $escaper->escapeHtml($data['label']) ?></option>
                        <?php endforeach ?>
                    </select>
                    <label class="wtai-label"><?= $escaper->escapeHtml(__($timezone)) ?></label>
                </div>
            </div>
        </div>
        <?php if (!$isCronRunning): ?>
            <div class="wtai-disabled-cron-job-message">
                <span class="wtai-icon-info"></span>
                <span class="wtai-disabled-cron-job-message-text">
                    <?=
                        $escaper->escapeHtml(
                            $cronJobDisabledMessage
                        )
                    ?>
                </span>
            </div>
        <?php endif; ?>
    </div>
</fieldset>