<?php $config = $config ?? []; ?>

<div class="page-header">
    <div class="page-header-left">
        <h1 class="page-title">App Version</h1>
        <p class="page-subtitle">Manage the Android application version and update settings</p>
    </div>
</div>

<div class="card">
    <div class="card-body">
        <form method="POST" action="/admin/app-version">
            <input type="hidden" name="_csrf_token" value="<?= $this->csrfToken() ?>">

            <div class="form-group">
                <label for="app_version">Version Number</label>
                <input type="text" id="app_version" name="app_version" class="form-input"
                       value="<?= htmlspecialchars($config['app_version'] ?? '1.0.0') ?>"
                       placeholder="e.g. 1.0.1" required>
                <small class="form-hint">Semantic version (X.Y.Z). Must be higher than previous to trigger updates.</small>
            </div>

            <div class="form-group">
                <label for="apk_url">APK URL</label>
                <input type="text" id="apk_url" name="apk_url" class="form-input"
                       value="<?= htmlspecialchars($config['apk_url'] ?? '/sysadmin.apk') ?>"
                       placeholder="e.g. /sysadmin.apk" required>
                <small class="form-hint">Path or URL to the APK file.</small>
            </div>

            <div class="form-group">
                <label for="force_update">Force Update</label>
                <select id="force_update" name="force_update" class="form-select">
                    <option value="0" <?= ($config['force_update'] ?? '0') === '0' ? 'selected' : '' ?>>Optional — user can skip</option>
                    <option value="1" <?= ($config['force_update'] ?? '0') === '1' ? 'selected' : '' ?>>Forced — user must update</option>
                </select>
                <small class="form-hint">If forced, users cannot dismiss the update dialog.</small>
            </div>

            <div class="form-group">
                <label for="release_notes">Release Notes</label>
                <textarea id="release_notes" name="release_notes" class="form-input" rows="6"
                          placeholder="• What changed&#10;• Bug fixes&#10;• New features"><?= htmlspecialchars($config['release_notes'] ?? '') ?></textarea>
                <small class="form-hint">One change per line. These will be shown in the update dialog on Android.</small>
            </div>

            <div class="form-group">
                <button type="submit" class="btn btn-primary">
                    <i class="fas fa-save"></i> Save Version
                </button>
            </div>
        </form>
    </div>
</div>
