<?php

declare(strict_types=1);

/** 付費評論表單欄位；需 $masseurReviewPaidCfg、$storeMasseurNcoinEsc 就緒。 */

if (!fate_masseur_review_paid_enabled()) {
    return;
}

$paidDefaultPreview = (int) ($masseurReviewPaidCfg['default_preview_chars'] ?? 200);
$paidMaxPrice = (int) ($masseurReviewPaidCfg['max_price'] ?? 500);
$paidMinPreview = (int) ($masseurReviewPaidCfg['min_preview_chars'] ?? 50);
$paidMaxPreview = (int) ($masseurReviewPaidCfg['max_preview_chars'] ?? 2000);
$paidCommission = (int) ($masseurReviewPaidCfg['commission_pct'] ?? 20);
$paidMinBody = (int) ($masseurReviewPaidCfg['min_body_chars'] ?? 500);
$authorGetsPct = max(0, 100 - $paidCommission);

?>
<div class="masseur-review-paid-fields" data-min-body-chars="<?= (int) $paidMinBody ?>">
    <label class="masseur-review-paid-fields__toggle-row">
        <input type="checkbox" name="is_paid" value="1" class="masseur-review-paid-fields__toggle">
        <span class="masseur-review-paid-fields__toggle-label">設為付費評論（以 <?= htmlspecialchars($storeMasseurNcoinEsc, ENT_QUOTES, 'UTF-8') ?>販售全文）</span>
    </label>
    <?php if ($paidMinBody > 0): ?>
        <p class="masseur-note masseur-note--sm masseur-review-paid-fields__hint">正文至少 <?= number_format($paidMinBody) ?> 字才可勾選付費。</p>
    <?php endif; ?>
    <div class="masseur-review-paid-fields__opts" hidden>
        <label class="masseur-field">
            <span class="masseur-field__label">售價（<?= htmlspecialchars($storeMasseurNcoinEsc, ENT_QUOTES, 'UTF-8') ?>，上限 <?= number_format($paidMaxPrice) ?>）</span>
            <input type="number" name="paid_price" min="1" max="<?= (int) $paidMaxPrice ?>" step="1" placeholder="例如 50">
        </label>
        <label class="masseur-field">
            <span class="masseur-field__label">免費預讀字數（<?= (int) $paidMinPreview ?>～<?= (int) $paidMaxPreview ?> 字）</span>
            <input type="number" name="paid_preview_chars" min="<?= (int) $paidMinPreview ?>" max="<?= (int) $paidMaxPreview ?>" step="1" value="<?= (int) $paidDefaultPreview ?>">
        </label>
        <p class="masseur-note masseur-note--sm">平台抽成 <?= (int) $paidCommission ?>%，您實收約 <?= (int) $authorGetsPct ?>%。</p>
    </div>
</div>
