<?php
// Partial view for a single modul field
// Usage: $this->include('guru/learning_device/rpm_field', ['fieldKey' => '...', 'label' => '...', 'value' => '...', 'placeholder' => '...', 'helper' => '...', 'promptHint' => '...', 'autoPopulated' => false]);
$fieldKey = $fieldKey ?? '';
$label = $label ?? '';
$value = $value ?? '';
$placeholder = $placeholder ?? '';
$helper = $helper ?? '';
$promptHint = $promptHint ?? '';
$autoPopulated = $autoPopulated ?? false;
$readonly = $autoPopulated ? 'readonly' : '';
$badgeClass = $autoPopulated ? 'bg-success bg-opacity-10 text-success' : 'bg-warning bg-opacity-10 text-warning';
$badgeIcon = $autoPopulated ? 'bi-check-circle-fill' : 'bi-cpu-fill';
$badgeText = $autoPopulated ? 'Otomatis' : 'AI + Edit';
?>
<div class="mb-3 field-item">
    <div class="d-flex align-items-center justify-content-between mb-2">
        <div class="d-flex align-items-center gap-2">
            <span class="badge <?= $badgeClass ?> px-3 py-1 rounded-pill"><i class="bi <?= $badgeIcon ?> me-1"></i><?= $badgeText ?></span>
            <span class="fw-semibold text-dark small"><?= $label ?></span>
        </div>
        <?php if (!$autoPopulated): ?>
        <button type="button" class="btn btn-sm btn-outline-crimson btn-generate-field" data-prompt-hint="<?= esc($promptHint) ?>">
            <i class="bi bi-cpu-fill me-1"></i> Generate AI
        </button>
        <?php endif; ?>
    </div>
    <?php if ($helper): ?>
    <p class="text-muted small mb-1 ms-1"><?= esc($helper) ?></p>
    <?php endif; ?>
    <textarea class="form-control form-control-sm field-textarea" rows="4"
        data-field="<?= $fieldKey ?>"
        placeholder="<?= esc($placeholder) ?>"
        <?= $readonly ?>><?= esc($value) ?></textarea>
</div>
