<?php
/**
 * Super Admin — Create Announcement
 */
$bp = defined('BASE_PATH') ? BASE_PATH : '/gmind';
$branches = $branches ?? [];
?>
<div class="admin-section">
    <div style="margin-bottom:20px;">
        <a href="<?= $bp ?>/super-admin/announcements" style="color:#6c3fe8;text-decoration:none;font-size:0.85rem;">← Back to Announcements</a>
    </div>

    <form method="POST" action="<?= $bp ?>/super-admin/announcements" enctype="multipart/form-data" style="max-width:720px;">
        <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrfToken ?? '', ENT_QUOTES, 'UTF-8') ?>">

        <div class="admin-card" style="background:#fff;border-radius:12px;padding:24px;margin-bottom:20px;box-shadow:0 2px 8px rgba(0,0,0,0.06);">
            <h2 style="margin:0 0 6px;font-size:1.1rem;color:#2c1e4a;">New Announcement</h2>
            <p style="margin:0 0 20px;font-size:0.85rem;color:#666;">Global announcements appear in ALL branch dashboards. Branch-specific announcements appear only in that branch's dashboard.</p>

            <div style="display:grid;grid-template-columns:1fr 1fr;gap:14px;margin-bottom:14px;">
                <div>
                    <label style="display:block;font-size:0.85rem;font-weight:600;color:#2c1e4a;margin-bottom:6px;">Title <span style="color:#e84118;">*</span></label>
                    <input type="text" name="title" required value="<?= htmlspecialchars($_POST['title'] ?? '', ENT_QUOTES, 'UTF-8') ?>" placeholder="e.g. New Certificate Templates Available" style="width:100%;padding:10px 12px;border:1px solid #ddd;border-radius:6px;font-size:0.88rem;">
                </div>
                <div>
                    <label style="display:block;font-size:0.85rem;font-weight:600;color:#2c1e4a;margin-bottom:6px;">Type</label>
                    <select name="type" style="width:100%;padding:10px 12px;border:1px solid #ddd;border-radius:6px;font-size:0.88rem;">
                        <option value="general" <?= ($_POST['type'] ?? 'general') === 'general' ? 'selected' : '' ?>>General</option>
                        <option value="info" <?= ($_POST['type'] ?? '') === 'info' ? 'selected' : '' ?>>Info (blue)</option>
                        <option value="urgent" <?= ($_POST['type'] ?? '') === 'urgent' ? 'selected' : '' ?>>Urgent (red)</option>
                    </select>
                </div>
            </div>

            <div style="margin-bottom:14px;">
                <label style="display:block;font-size:0.85rem;font-weight:600;color:#2c1e4a;margin-bottom:6px;">Short Text <span style="color:#e84118;">*</span></label>
                <input type="text" name="text" required maxlength="1000" value="<?= htmlspecialchars($_POST['text'] ?? '', ENT_QUOTES, 'UTF-8') ?>" placeholder="Short summary (shown in dashboard widget)" style="width:100%;padding:10px 12px;border:1px solid #ddd;border-radius:6px;font-size:0.88rem;">
            </div>

            <div style="margin-bottom:14px;">
                <label style="display:block;font-size:0.85rem;font-weight:600;color:#2c1e4a;margin-bottom:6px;">Full Content (optional)</label>
                <textarea name="content" rows="4" placeholder="Detailed announcement content..." style="width:100%;padding:10px 12px;border:1px solid #ddd;border-radius:6px;font-size:0.88rem;resize:vertical;"><?= htmlspecialchars($_POST['content'] ?? '', ENT_QUOTES, 'UTF-8') ?></textarea>
            </div>

            <div style="display:grid;grid-template-columns:1fr 1fr;gap:14px;margin-bottom:14px;">
                <div>
                    <label style="display:block;font-size:0.85rem;font-weight:600;color:#2c1e4a;margin-bottom:6px;">Scope</label>
                    <select name="branch_id" style="width:100%;padding:10px 12px;border:1px solid #ddd;border-radius:6px;font-size:0.88rem;">
                        <option value="">🌍 Global (all branches)</option>
                        <?php foreach ($branches as $b): ?>
                            <option value="<?= (int) $b['id'] ?>" <?= ($_POST['branch_id'] ?? '') == $b['id'] ? 'selected' : '' ?>>📍 <?= htmlspecialchars($b['branch_code'], ENT_QUOTES, 'UTF-8') ?> — <?= htmlspecialchars($b['name'], ENT_QUOTES, 'UTF-8') ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div>
                    <label style="display:block;font-size:0.85rem;font-weight:600;color:#2c1e4a;margin-bottom:6px;">Link (optional)</label>
                    <input type="url" name="link" value="<?= htmlspecialchars($_POST['link'] ?? '', ENT_QUOTES, 'UTF-8') ?>" placeholder="https://..." style="width:100%;padding:10px 12px;border:1px solid #ddd;border-radius:6px;font-size:0.88rem;">
                </div>
            </div>

            <div style="margin-bottom:14px;">
                <label style="display:block;font-size:0.85rem;font-weight:600;color:#2c1e4a;margin-bottom:6px;">Image (optional)</label>
                <input type="file" name="image" accept="image/jpeg,image/png,image/gif,image/webp" style="width:100%;font-size:0.85rem;padding:8px;border:1px solid #ddd;border-radius:6px;">
            </div>

            <div>
                <label style="display:flex;align-items:center;gap:8px;cursor:pointer;">
                    <input type="checkbox" name="is_active" value="1" checked style="width:18px;height:18px;accent-color:#6c3fe8;">
                    <span style="font-size:0.88rem;font-weight:600;color:#2c1e4a;">Active (visible to branches)</span>
                </label>
            </div>
        </div>

        <div style="display:flex;gap:12px;justify-content:flex-end;">
            <a href="<?= $bp ?>/super-admin/announcements" style="padding:12px 24px;border:1px solid #ddd;border-radius:8px;text-decoration:none;color:#666;font-weight:600;font-size:0.9rem;">Cancel</a>
            <button type="submit" style="padding:12px 28px;background:linear-gradient(135deg,#6c3fe8,#4a2db8);color:#fff;border:none;border-radius:8px;font-weight:600;font-size:0.9rem;cursor:pointer;">Create Announcement</button>
        </div>
    </form>
</div>
