<?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">
        <?= $block->escapeHtml(__('Set time for auto text transfer and new product detection')) ?>
        <?php if (!$hasProAccess): ?>
            <span class="wtai-premium">
                <?= $block->escapeHtml(__('PRO')) ?>
            </span>
        <?php endif; ?>
    </div>
    <p class="wtai-fieldset-content">
        <?= $block->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">
        <?= $block->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">
        <?= $block->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><?= $block->escapeHtml(__('PHP max_execution_time: 3600 seconds')) ?></li>
        <li><?= $block->escapeHtml(__('PHP memory_limit: 524M')) ?></li>
    </ul>
    <p class="wtai-fieldset-content">
        <?= $block->escapeHtml(__(
            "This helps prevent timeouts and ensures smooth publishing."
        )) ?>
    </p>
    <div class="<?= $block->escapeHtmlAttr($isDisabledClass) ?> wtai-field-column-container">
        <span class="tooltip-toggle"></span>
        <?php if (!$hasProAccess): ?>
            <span class="tooltip-content">
                <?= $block->escapeHtml(__('These settings are enabled for Pro accounts only.')) ?>
            </span>
        <?php endif; ?>
        <div class="wtai-field-column">
            <div class="wtai-fieldset-title">
                <?= $block->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="<?= $block->escapeHtmlAttr($data['value']) ?>"
                                <?php if ($defaultAutoTransferSchedule === $data['value']): ?>
                                    selected
                                <?php endif ?>
                            ><?= $block->escapeHtml($data['label']) ?></option>
                        <?php endforeach ?>
                    </select>
                    <label class="wtai-label"><?= $block->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"><?= $block->escapeHtml($cronJobDisabledMessage) ?>
                </span>
            </div>
        <?php endif; ?>
    </div>
</fieldset>